Hello!
Why did you put s as the second argument of SoundFile.collect
?
According to the help document it has only one argument:
https://doc.sccode.org/Classes/SoundFile.html#*collect
You allocated an array to the interpreter variable z and used the array as the third argument of the Array.series
:
However, the third argument should be one of Number’s subclasses:
Array.series(3, 0, Complex(2, 5))
Array.series(3, 0, 1@2)
Array.series(3, 0, 0.1)
Array.series(3, 0, 1)
Since you used an array in place of Number’s subclasses, sclang processes each element of the array and returns it as the form of array:
Array.series(3, 0, [1, 2])
// the code above is the same as the following code:
Array.series(3, [0, 0], [1, 2])
// return:
[ [ 0, 0 ], [ 1, 2 ], [ 2, 4 ] ]
You should remove the arrays inside of the array as follows:
Array.series(3, 0, [1, 2]).flat
In this case, flatten(1)
is also applicable:
Array.series(3, 0, [1, 2]).flatten(1)
Array.series(3, 0, [1, 2]).flatten // The default value of the argument of .flatten is 1.
Then you get some values which are the same as follows:
[ 0, 0, 1, 2, 2, 4 ]
You can erase these duplications by converting the array into a set as follows:
Array.series(3, 0, [1, 2]).flat.asSet
Set[ 4, 0, 1, 2 ]
Then you should convert it again to an array:
Array.series(3, 0, [1, 2]).flat.asSet.asArray
then should sort it:
Array.series(3, 0, [1, 2]).flat.asSet.asArray.sort
Thus, your code should be as follows I believe:
b = SoundFile.collect(Platform.resourceDir +/+ "sounds" +/+ "*");
z = b.collect {arg n; n.duration };
x = Array.series(14, 0, z).flat.asSet.asArray.sort;
Post <<< x
Is the result the same as your expectation?
In addition, Array.series
can be written as follows:
Array.series(14, 0, 1)
Array.series(14, 0, 0.5)
(0, 1 .. 14 - 1)
(0, 0.5 .. 14 - 1 / 2)
//or
(0, 1 .. 13)
(0, 0.5 .. 6.5)