Tutorial

This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

MIDI Message Send - Output individual MIDI messages Reload page to restart example
While all "notes" sent from SoundCipher are sent as note on and off MIDI messages these details are normally hidden from view for the sake of convenience. However, there are times when you want more direct control or want to send MIDI messages other than note on and off. This examples shows how to send MIDI messages that control the starting and stopping of notes, selecting instruments, and dynamically changing the pitch and volume of a sounding note. The example is interactive - click and drag the mouse around inside the sketch window.

This example sends the MIDI messages to the JavaSound (internal) synthesizer. Messages can be sent to other synthesizers or devices using SoundCipher's setMidiDeviceOutput() method. See the reference section for details.



The first line imports (makes availible) the SoundCipher library.

The second line creates a instance of SoundChipher called sc, which will be referred to throughout the program.

The draw() method provides visual feedback about mouse dragging on the sketch by displaying a small circle that tracks mouse drag location.

The remainder of the methods are activated when the user click, drags and releases the mouse.

On mousePressed() a random instrument - program change - is selected and a middle C note  - number 60 - is started. The SoundCipher sendMIDI() method is the key to this tutorial, so we'll spend some time exaplining it. It takes four arguments, message status or type, channel, and two values. There are a range of message types that can be sent and SoundCipher provides constants for most of them - for example the sc.PROGRAM_CHANGE constant. There are 16 MIDI channels that can each play music using their own instrument, we use channel zero in this example. The two data values are particular to the type of message being sent. For a program change only the first message is important, for a not on or off message the first value indicates pitch and the second velocity, for example.

The mouseDragged() method check the current location of the mouse relative to the Processing sketch window and sends a pitch bend (frequency change) or volume control change (number 7) with appropriate values - vertical position controlling pitch and horizontal position controlling volume.

Whe the mouse is released a note off message is sent halting the audio. Be aware that some instrument sounds, such as piano, have a decay envelope that may mean they fade to silence even before the mouse is released.