Skip to content

MIDI Message Parser

nyannkov edited this page Jun 28, 2020 · 2 revisions

1. Steps to create your MIDI driver with a MIDI Message Parser

MIDI Message Parser is located as follows:

https://github.com/nyannkov/nano_midi/tree/master/src/sound/midi

Examples are here:

https://github.com/nyannkov/nano_midi/tree/master/src/sound/app

STEP1. Create an instance of MIDI_Message_Callbacks_t

// If you have unnecessary handlers, register NULL to them.
const MIDI_Message_Callbacks_t _ymf825_midi_msg_callbacks = {
	// MIDI_ChannelMessage_t
	{
		// MIDI_ChannelVoiceMessage_t
		{
			_ymf825_NoteOff,
			_ymf825_NoteOn,
			NULL,
			_ymf825_ControlChange,
			_ymf825_ProgramChange,
			NULL,
			_ymf825_PitchBendChange
		}
	},
	// MIDI_SystemMessage_t
	{
		// MIDI_SystemExclusiveMessage_t
		{
			NULL
		}
	}
};

STEP2. Call MIDI_Init() to create the MIDI Handler of the audio driver

    MIDI_Handle_t *phMIDI;
    phMIDI = MIDI_Init(&_ymf825_midi_msg_callbacks);

NOTE

By default, allocation and free of any instance of MIDI_Handle_t are executed by following functions.

__WEAK__ MIDI_Handle_t *MIDI_Alloc(void)
{
  static MIDI_Handle_t hMIDI;
  return &hMIDI;
}

__WEAK__ void MIDI_Free(MIDI_Handle_t *phMIDI)
{
  (void)phMIDI;
}

If you need to create multiple instances of MIDI_Handle_t, please redefine these functions.