MIDI Synthesis
I'll consider three approaches to synthesizing MIDI sound at runtime:
Send note-playing messages to a MIDI channel. The
MidiChannelclass offersnoteOn()andnoteOff()methods that transmitNOTE_ONandNOTE_OFFMIDI messages.Send MIDI messages to the synthesizer's receiver port. This is a generalization of the first approach. The advantages include the ability to deliver messages to different channels, and the ability to send a wider variety of messages.
Create a sequence, which is passed to the sequencer. This is a generalization of the second approach. Rather than send individual notes to the synthesizer, I build a complete sequence.
These approaches are labeled in the MIDI devices diagram in Figure 10-4.

Figure 10-4. Different MIDI synthesis approaches
Tip
There is a good Java Tech Tip on these topics at http://java.sun.com/jdc/JDCTechTips/2003/tt0805.html.
Sending Note-Playing Message to a MIDI Channel
The MidiChannel class offers noteOn() and noteOff() methods that correspond to the NOTE_ON and NOTE_OFF MIDI messages:
void noteOn(int noteNumber, int velocity);
void noteOff(int noteNumber, int velocity);
void noteOff(int noteNumber);The note number is the MIDI number assigned to a musical note, and velocity is equivalent to the loudness. A note will keep playing after a noteOn() call until it's terminated with noteOff(). The two-argument form of noteOff() can affect how ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access