My plugin is a multichannel sequencer. I would appreciate any suggestions on how to multi-thread it considering the following design:
Each GUI sequencer channel has its own
AudioOutEngine object which is the brain under the hood.
PluginProcessor holds an
AudioOutEngine like this:
PluginProcessor also holds a sorted set to keep track of the currently active channels:
I use this set since I don’t want the plugin to waste time on empty channels. So whenever the user turns on a step (GUI click) the current channel number is added to the sorted set (just the channel index, not the object itself):
and if the has user turned off all steps, the channel number is removed from the currently active channel list
AudioOutEngine does the actual processing in the following function:
void AudioOutEngine::sendToOutput(AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
which takes as references the well-known parameters from
PluginProcessor::processBlock and feeds them. This is how looks like:
PluginProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
for (int i = 0; i < activeChannels.size(); ++i)
To put it in words: for each currently active GUI channel (an active channel is defined as having one or more steps about to play soon) the program repeatedly checks if it is time to send some audio out. The time is right when the clock is over an active sequencer step (
On = TRUE) and then
AudioOutEngine will process some audio stored in an
AudioBuffer and send the output directly to
PluginProcessor::processBlock where it sums all active channels into one
I hope that all makes sense. Now for my question:
Where and how should I use multi threads?
- different thread for each active channel, waiting for some note to get hit and closing the thread if all the channel’s notes were turned off by the user.
- different thread for each note that gets hit, closing the thread when the note has finished playing.
- different thread for each sendToOutput (or processBlock) call.
- Any other option?
Also - which is better to use in this case: ThreadPool or TimeSliceThread? What is the main difference between them?