How to create a MetaEvent


'MIDICompose' includes the most important MetaEvents like 'Tempo', 'TimeSignature' and 'TextMetaEvent'. If you need another one you have to create it. In this lesson we will create the MetaEvent called 'MIDIChannel'. The type of 'MIDIChannel' is 20hex (=32dec). It has one dataByte that specifies the channel. 'MIDIChannel' is a subclass of 'MetaEvent'.We will create two constructors both with parameter channel and one with deltaTime. We will also build methods for reading and setting the channel.

MIDIChannel.java

We also need to overwrite the method copy() defined abstract in 'MIDIObject' that returns a copy of itself. If you want to create MetaEvents with more than one DataValue, you must take care of the order you call the methods 'setDataValueAt(int value, int index)'. This method sets the dataByte at index or creates a dataByte with the specified value at index. If you try to set dataByte at index 2, but dataByte at index 1 is not existing jet, the program will abort. So set the dataBytes in the order of the index (in the constructor)!

If you want to create a MIDIRealtime or MIDICommon class, you have to make it a subclass of 'SystemExclusive'. We will create a class called 'MTC' (MIDI-Time-Code). We make the 'SystemExclusive' an escaped type and set the first dataByte to MTC-message (F1) and the second to timeCode.

MTC.java

If you want to append an usual 'SystemExclusive'-message, you only have to append a new SYSEX-typed 'SystemExclusive' and set its dataBytes using 'setDataByteAt(int value, int index)'.

You should be able to create all existing and future MetaEvents and EscapedEvents you need, by your own now.