Randomisation of which sample is loaded in the synthesiser

Is there any way using JUCE classes/methods that I can assign multiple samples to a key and randomise which one plays when the note is pressed? I wouldn’t mind round robins but if proper randomisation is possible I would prefer to use that.

You need to do your own subclass or subclasses inheriting from SamplerSound and/or SamplerVoice. (I am probably actually going to be implementing something like this soon myself…)

1 Like

That’s good to know, I’ll look into these things and keep in touch with you if I hit any road blocks, thanks

Actually you need to derive your own class from Synthesizer and handle the selection in selectSound()… but you do also need to subclass SamplerSound and samplerVoice and have a mechanism to assign a range to each sound.

Rail

1 Like

Is that so? I am adding my sounds using addSound() in my own class which is derived from Synthesizer in the setup() method, I’ve not come across selectSound() yet, how or why to use it so I guess I’ll read into that. Thank you!

Hmm I am not seeing a selectSound() method in that, virtual or non-virtual…?

Damn, it’s been years since I wrote that code… I thought that selectSound(0 was part of Synthesizer… it isn’t… basically you override Synthesizer::noteOn() and in there you call selectSound() to find the sound(s) that are in the correct range and you do your randomization, etc…

Cheers,

Rail

1 Like

So do I add all the sounds using addSound to the same note and then sift out which one to play in the overriden noteOn method?

Could I also use this for ascertaining velocity? Thus answering my earlier question?

in noteOn() you can get the current note, channel, velocity, etc… you look through the OwnedArray of sounds to find the sounds in the range of notes and velocity and select one of the sounds amongst those to play in selectSound(). Each sound should have a Range of notes and velocities assigned to it.

Rail