2017-01-02 62 views
0

Backstory和Context:我将尽我所能解释我正在处理的问题,以及我已经确定的问题,以及我的思考过程为我目前的代码。忍受我,因为我会尽量提供尽可能多的细节。请注意,我仍然在学习Quartz Composer,并且对Javascript语法不太熟悉。if语句中的if语句for循环/数组插入和构造

我正在与Quartz Composer一起修改程序附带的视觉均衡器模板。实质上,我的音频源被输入到程序中,并作为存储在数组中的16个音频频段进行处理。这16个频带中的每一个对应于该范围内频率的大小,并且最终将显示在具有各种均衡器电平的“条形图”上。这部分很好,很好。

我的任务要求我的图中有超过16个条。由于我无法进一步分割音频而没有转向一个复杂的外部过程,我想我可以通过在实际的音频条之间插入虚假的条和数值来伪装我的方式,这些虚拟条和数值之间的平均或均匀地位于真实音频小节值。

例如,假设我的输入数组看起来像“A B C”,其中“A”,“B”和“C”是某些音频值。我在我的代码中声明了一个“插入”值,该值确定在每个真实音频值之间要添加多少假条。在“A B C”的情况下,假设插入值被设置为0.不插入条,因此输出数组是“A B C”。假设插入值设置为1.将在每个真值之间插入1巴,返回“A(A + B)/ 2 B(B + C)/ 2 C”的数组。因此,如果插入值被设置为2,则将在A和B之间放置两个值,使得它们均匀分布在A和B之间的1/3和2/3rds之间。

相关代码:

var array = new Array(); 
 
function (__structure outputStructure) main (__structure inputStructure, __number insertions, __number time) { 
 
\t var result = new Object(); 
 
\t 
 
\t /* check if the input array for the sound bands is null or not */ 
 
\t if (inputStructure != null) { 
 
\t \t 
 
\t \t /* keep track of the number of times that a value is inserted so that, upon the counter being reset, a value from the original array can be inserted */ 
 
\t \t var counter = 0; 
 
\t \t 
 
\t \t /* keep track of which index location the original array value is to be pulled from */ 
 
\t \t var inputPlace = 0; 
 
\t \t 
 
\t \t /* build a new array that inserts a number of values equal to the value of the insertions variable in between all values of the original array */ 
 
\t \t for (i=0; i<((insertions + 1) * (inputStructure.length - 1) + 1); ++i) { 
 
\t \t \t 
 
\t \t \t /* if it is time to do so, pull a true audio bar value from the original string into the new string */ 
 
\t \t \t if (counter = 0) { 
 
\t \t \t \t array[i] = inputStructure[inputPlace]; 
 
\t \t \t \t 
 
\t \t \t /* if it is not time to pull a value from the original array, insert the specified number of evenly spaced, calculated bar values into the new array */ 
 
\t \t \t } else { \t 
 
\t \t \t \t /* space the insertion between the nearest two true values from the original input array */ 
 
\t \t \t \t array[i] = inputStructure[inputPlace] + ((inputStructure[inputPlace + 1] - inputStructure[inputPlace]) * counter/(insertions + 1)); 
 
\t \t \t } 
 
\t \t \t 
 
\t \t \t counter = counter + 1; 
 

 
\t \t \t /* reset the counter after each complete iteration of insertions is compelte so that an original array value can be pulled into the new array */ 
 
\t \t \t if (counter > insertions) { 
 
\t \t \t \t counter = 0; 
 
\t \t \t \t inputPlace = inputPlace + 1; 
 
\t \t \t } 
 
\t \t \t 
 
\t \t \t counter = counter + 1; 
 
\t \t \t 
 
\t \t } \t 
 
\t } 
 
\t 
 
\t result.outputStructure = array; 
 
\t return result; 
 
}

在这个特殊的代码,我没有手动声明的投入,将他们全部从石英作曲家拉。这部分我没有问题。我假设出于测试的目的,您可以在输入结构,插入和时间的值中进行硬编码。

问题: 我已经确定的问题似乎与我的for循环内的if语句。当我运行的代码,它设置了新的阵列中的每一个0值

问题:我想我的问题是我在做什么毛病在for循环的if语句是导致它覆盖所有我的其他迭代值?我能够使计数器工作,以便在插入设置为2的情况下,每次迭代都会返回计数器值“0 1 2 0 1 2”,但我无法说好,现在在每次迭代中检查,如果计数器为0,则从原始数组中拉出一个值。否则,请执行其他操作,在这种情况下,计算虚假栏值并将其添加到新数组中。

回答

1

你的问题是这样的一行: if (counter = 0) { 它将始终返回false,比较需要使用=====

+0

谢谢,解决它 –

+1

'如果(计数器= 0)'将永远是*假*为0是虚假的。 – Gerrit0

+0

修复它@ Gerrit0 – iagowp