Synthesiser method to play a note

Hey,

I’m trying to make an app that can play a note on the JUCE synthesiser from an OSC message. My problem is that I can’t find the method in the synthesiser example that actually plays the note on the keyboard and I don’t know what infos to send via OSC to choose a specific note.

Does anyone have any experience with the juce synthesiser’s methods?

Can’t you fill the processBlock()'s MidiBuffer with notes, based on whatever is coming in via OSC?

I can send whatever I want via OSC but since I’m new to JUCE I don’t really know how to fill the MidiBuffer. From what I see in the code, the MidiBuffer is specified once:

void getNextAudioBlock (const juce::AudioSourceChannelInfo& bufferToFill) override
{
bufferToFill.clearActiveBufferRegion();

    juce::MidiBuffer incomingMidi;
    keyboardState.processNextMidiBuffer (incomingMidi, bufferToFill.startSample,
                                         bufferToFill.numSamples, true);    

    synth.renderNextBlock (*bufferToFill.buffer, incomingMidi,
                           bufferToFill.startSample, bufferToFill.numSamples);
}

I’m not sure what code you are referring to, but the Synthesiser has a function called renderNextBlock() which is usually called from the AudioProcessor::processBlock() function. renderNextBlock is passed a MidiBuffer, which is then picked up down the line. I would suggest filling this MidiBuffer. Check out the AudioPluginDemo. FWIW, I’m not sure this is the best approach, but it’s probably where I would start.

Ok, thank you so much for your help. I’ll try that.

If you want to process stuff coming in via OSC, I’d suggest you take a look at this one JUCE/juce_AudioProcessorPlayer.cpp at master · juce-framework/JUCE · GitHub

Interesting for you is line 345 – thats were you OSC Message gets in. And line 236 the audio callback. Instead of processing any plugin/au/VST3 in line 274, you’d be processing your Syntesiser object. You might be able to get rid of the double precision stuff. This is in to sample inside a double (64-bits) instead of a float (32-bits) per sample. This is only useful if you are actually calculating with the samples, as for the final audio interface you are sampling down into floats and you probably don’t have audio files in more than 32-bits, so no accuracy would be gained there.

1 Like