First time here? Check out the FAQ!
x

Make array of sample durations

0 votes
366 views
Hi,

 

I'm trying to make an array of sample durations from the filenames. So i use fileDuration to get the sample duration. That works. I then try and use   fileNamesOfSameTypeInSameFolder  to get all the filenames I want to use, as all samples are placed in the same folder. But is there a way to make an array, which I can go through with a hotvalue !Index ?

My thought was that something like this would work:

{!Index of: #('mySample.wav' fileNamesOfSameTypeInSameFolder fileDuration removeUnits)}

But it gives me a weird error message that i don't exactly understand. Is it because I'm mixing smalltalk and capytalk in inappropriate ways? Or am i creating the array wrong?

Any ideas how to do this?

Thanks

Anders
asked Feb 6, 2020 in Capytalk & Smalltalk by anders-skibsted (Adept) (1,320 points)

1 Answer

+1 vote
 
Best answer

What you have is very close. To index into an array of durations, you could use:

!Index of: {'mySample.wav' fileNamesOfSameTypeInSameFolder collect: [ :wav | wav fileDuration]}

The message fileNamesOfSameTypeInSameFolder returns an Array of file names. Then you are sending the message collect: to that array and, in the block, you are gathering up the durations of all the filenames in that Array (and returning it as a new Array of durations). Then you can index into that Array. Note that !Index should have the range [0, <nbr wave files - 1]
 

answered Feb 6, 2020 by ssc (Savant) (128,000 points)
selected Feb 7, 2020 by anders-skibsted
I can't get it to work... It gives me this error message

'There is something wrong with the value parameter of the SoundToGlobalController named !Sample1dur.
Please contact Symbolic Sound if you need help resolving this problem'

I've put my the code you showed me in a SoundToGlobalController to make it into a hotvalue so i could send it via OSC to another device.
I also tried adding an removeUnits at the end of it to see if that helped.
It works when I just have one filename and fileDuration, like:
'fileName.wav' fileDuration removeUnits

Any idea where this error message comes from and how to resolve it?

Thanks again
Anders

Since you are using this in a SoundToGlobalController, it's necessary to remove the units from fileDuration (as you did do in your original expression) in other words,

!Index of: {'mySample.wav' fileNamesOfSameTypeInSameFolder collect: [ :wav | wav fileDuration removeUnits]}

 Here's an example of a SoundToGlobalController (wherever you actually use !Dur, you would add the units back on to the value: !Dur s)

 

fantastic. this works. thank you!
...