I’m going through the “Build a MIDI synthesiser” tutorial, but instead of doing it as a Audio App, I’m trying to do a synth plugin.
void MyPlugin::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages) {
buffer.clear();
synth.renderNextBlock(buffer, midiMessages, 0, buffer.getNumSamples());
}
Also added the voices and sound for the Synth Object:
for (auto i = 0; i < 4; ++i) // [1]
synth.addVoice(new SineWaveVoice());
synth.addSound(new SineWaveSound());
My SineWaveVoice contains the startNote(), stopNote() and renderNextBlock() functions.
The problem is now, that when I first start the App, I noticed that the stopNote() (startNote() weirdly works) will not be called on the first key release on my MIDI keyboard, so the note will always be on, only when I play a another note , for example, A4 will stop but now the other note will always be on.
I also checked directly with the synth.noteOn() / synth.noteOff() in the debugger and also tried to call multiple noteOn() with the synth object but only the last call will play the note and it still won’t stop with the noteOff() function.
void MyPlugin::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages) {
if (!noteOn) {
synth.noteOn(1, 23, 0.5f);
synth.noteOn(1, 24, 0.5f);
noteOn = true;
}
buffer.clear();
synth.renderNextBlock(buffer, midiMessages, 0, buffer.getNumSamples());
if (noteOn) {
synth.noteOff(1, 23, 0.5f, 1.0f);
synth.noteOn(1, 24, 0.5f, 1.0f);
}
}
What went wrong ? I’m completely stuck.