SynthLab SDK
MIDI Note Events

SynthModule derived objects use shared resources that are created during construction if their pointers are non-null. When getting started with these objects, use the documentation and code. The object documentation will tell you where to read the rendered output, or apply audio input for processing. The sample code (SynthEngine and SynthVoice objects) will demonstrate the sequences of calls needed - this is also documented in the synth book. For sure you will need to understand the hierarchy of engine, voice, module and core as described in detail in Chapter 4 of the book.

In this section, we will create a set of standalone objects that we can put together as a complete minimal-synth in the next section.

MIDI Events

SynthLab uses a simple midiEvent structure to encode MIDI messages arriving from the plugin framework. The modules all expose the doNoteOn( ) and doNoteOff( ) methods. A smaller, simpler structure called midiNoteEvent is used to send note-on and note-off information to the modules. All SynthModules have access to incoming MIDI data in a read-only array named MidiInputData, so there is no reason for them to need generalized MIDI handlers, nor store MIDI information other than the note-on and note-off events, which almost always have very speicalized handlers unique to those objects. We will need to send midiNoteEvent structures to our stand-alone modules. The structure is simple and encodes the MIDI data bytes as uint32_t types:

struct MIDINoteEvent
{
double midiPitch = 0.0;
uint32_t midiNoteNumber = 0;
uint32_t midiNoteVelocity = 0;
};
// --- to get the MIDI note pitch use the function:
double midiPitch = midiNoteNumberToOscFrequency(midiNoteNumber);

You can see that it requires the MIDI note pitch. There are two ways to get this value, one uses a lookup table and the other uses the midiNoteNumberToOscFrequency function. The function is quite fast and only needs to be called when note-events occur. It also lets you re-tune the system from the A-440 standard (default) to any A-note pitch you like (see second argument in docs). You will need to establish the midiPitch prior to calling the note-on and note-off handlers of any module core. This will also limit the number of function calls to midiNoteNumberToOscFrequency to just one per note event. After you create the LFO object, you can test it with a fake MIDI message as I do below.


synthlab_4.png