超级对撞机2D阵列:生成嵌套:包装/尺寸问题
Supercollider 2D array : generative nesting : wrap / size issues
我正在学习超级对撞机,但在尝试创建用于存储频率的 2D 数组时遇到了问题......最初我希望数组是 12 x 9,这样行代表音符(c、d、e、f...(,列代表八度音阶,例如 f[0,0] = c0 , f[1,5] = c#5 , f[2,1] = d1 等。首先,SC 原生地从左到右包装行,所以这是我的第一个问题(稍后会解决(。
主要问题:我尝试嵌套 for(( 或 while(( 循环以迭代 3 个索引以手动将频率放入数组位置,但惨遭失败。我知道这充满了漏洞。斯里/谢谢。下面的代码。
//loading the frequency array with note values
(
f = Array.new(108);
for ( -57,50, { arg n;
f.add(440 * (( 2 ** (1/12)) ** (n)) );
} );
)
/* below attempt works, sort of... values in the
expected 12x9 array are what they're supposed to
be, but there are extra values, in that the array
size is larger than expected... e.g. k[0,9] should
return null, right? Don't want the array values
to wrap such that the first row is (108) entries
long!
*/
k = Array2D.fromArray(12,9,f);
k[0,0]; //returns proper entry
k[0,9]; //should be null???
k[0,107]; //shouldn't exist??
k[11,8]; //returns proper entry
/* attempts at manual entry, array size is too
large after 2nd for() loop is executed and double
entries exist in the array, which is now bigger
than it was initialized...
*/
h = Array2D.new(12,9);
for ( 0,8, { arg n; h.put(0,n,f[n]);} );
for ( 0,8, { arg n; h.put(1,n,f[n+12]); } );
//nested iteration attempted 1
(
f = Array.new(108);
for (-57, 50, { arg n;
f.add(440 * (( 2 ** (1/12) ) ** n) );
} );
q = Array2D.new(12,9);
for (0, 11, { arg i;
for (0, 8, { arg j;
for (0, 107, { arg k;
q.put(0,j,f[k]);
q[0,j].postln;
});
});
});
)
//nested iteration attempt 2
(
for (0, 107, { arg i;
for (0, 11, { arg j;
for (0, 8, { arg k;
q.put(j,k,f[i]);
q[j,k].postln;
// k = k+1;
});
// j = j+1;
});
// i = i+1;
});
)
可以像现在一样构建数组,但是您错过了SuperCollider的一些更好的语言功能,这些功能使表达这样的概念变得非常简单。
构造数组时,collect
方法可能非常有用:
var octaves = (1..7); // array of numbers 1..7
var degrees = (0..11);
var table = octaves.collect {
|oct|
degrees.collect {
|degree|
// Table value calculation here
}
}:
table[3][2]; // Octave three, degree two
超级对撞机还充分支持您手动进行的音符/频率转换 - 没有必要在这里重新发明轮子,看看Scale类,以及像|degreeToFreq| 和 |midiCps|这样的方法。
相关文章:
- 使用双包装器类进行位操作(C++、clang)修复性能下降问题
- 超级对撞机2D阵列:生成嵌套:包装/尺寸问题
- 使用 Swig 在成员中包装具有互斥锁的 C++ 类时出现问题
- 我的基于可变模板的包装器函数有什么问题?
- 尝试构造包装器测量函数调用时间时出现问题
- 使用带有 MEX 包装器的帮助程序 C 文件从 MATLAB 2016 调用C++代码时出现问题
- 包装 std::istream 时出现问题,移动后unique_ptr不为空
- Visual Studio:C++\CLI 包装程序集路径依赖性问题
- UE4包装错误:将问题与OpenSSL联系起来
- 为使用boost的预开发库构建c++包装器时未解决的外部问题
- 将C 类包装到Python的问题
- GCC:函数包装器模板问题
- 将问题包装在堆数据结构中
- 尝试实现 Windows API 包装器的事件处理程序时遇到问题
- 编译 TCL-DLL 包装器时出现的问题
- 何时会出现结构包装问题
- 线程包装器实现问题
- 包装和使用返回带有 SWIG (python) 的结构的函数时出现问题
- 包装类常量正确性问题
- 包装C++代码的问题