I’m working on a multi-channel synth. I’m unsure of the general design flow with regard to SynthesiserVoice
usage in these channels, which are owned by juce::Synthesiser
. I’m doing this currently (extremely simplified):
struct Channel
{
Channel(int ch, juce::Synthesiser& s) : channelNumber(ch), synth( &s ) { }
/*
all of the noteOn/Off/etc stuff is in here
*/
void noteOn(int midiNoteNumber, float velocity);
private:
int channelNumber = -1;
juce::Synthesiser* synth = nullptr;
};
struct Synth : juce::Synthesiser
{
void noteOn(int midiChannel, int midiNoteNumber, float velocity) override;
private:
OwnedArray<Channel> channels;
friend Channel;
};
Channel
can access the voices
member of Synthesiser
like this:
void Synth::noteOn(int midiChannel, int midiNoteNumber, float velocity)
{
//after checking that midiChannel is a valid index...
channels[midiChannel]->noteOn(midiNoteNumber, velocity);
}
void Channel::noteOn(int midiNoteNumber, float velocity)
{
//a bunch of filtering to find the right sample and
//available voice leads to this:
auto* voice = synth->findFreeVoice(sound,
channelNumber,
midiNoteNumber,
synth->isNoteStealingEnabled());
//after checking that a voice is free
synth->startVoice( voice, sound, channelNumber, midiNoteNumber, velocity );
}
Is this the right way to go about handling things?
Or should I be doing a vector of Synthesiser
instances and have each instance handle a single channel? I haven’t found much info on the best design choice for this.
I don’t need multi-channel output, so that’s why I’m keeping all the voices in a single synth, since the juce::Synthesiser
class is designed to combine all active voices into a single stereo output buffer.