MIDIIn:
Filter:
Classes | External Control > MIDI

MIDIIn : Object

receive MIDI messages
Source: MIDIOut.sc

Description

This document explains technical details of the MIDI hardware interface class, MIDIIn.

MIDIIn is a simple and direct interface. When MIDI events come into SuperCollider, MIDIIn evaluates simple handler functions.

NOTE: For general programming, users should not use the MIDIIn class directly. See the MIDIFunc and MIDIdef classes for higher level event matching and more flexible handling of event handlers.

Certain MIDI messages are supported only through MIDIIn. These are: sysex, sysrt, smpte.

See the Using MIDI helpfile for practical considerations and techniques for using MIDI in SC.

The MIDIIn class

MIDIIn links MIDI input received from the operating system to a set of user defined functions. Only one set of MIDI input handling functions can be active at a time, they are stored in the following class variables:

noteOff, noteOn, polytouch, control, program, touch, bend, sysex, sysrt, smpte

The first argument these functions receive is an unique identifier that specifies the source of the data.

Class Methods

MIDIIn.findPort(deviceName, portName)

searches for a connected MIDIEndPoint by name.

MIDIIn.addFuncTo(what, func)

Add a Function or similar object to be evaluated whenever a particular MIDI message is received. This method is preferable to the setters below, since it will not overwrite any existing functions.

Arguments:

what

A Symbol indicating the message type to wait for, one of 'noteOn' 'noteOff', 'polytouch', 'control', 'program', 'touch', 'bend', 'sysex', 'sysrt', 'smpte', or 'invalid' (for invalid sysex messages).

func

A Function or similar object to be evaluated when a message of the specified type is received. See the setters below for the arguments which will be passed at evaluation time.

MIDIIn.removeFuncFrom(what, func)

Remove a Function or similar object from the list of those to be evaluated whenever a particular MIDI message is received. This method is preferable to the setters below, since it will leave any existing functions in place.

Arguments:

what

A Symbol indicating the message type, one of 'noteOn' 'noteOff', 'polytouch', 'control', 'program', 'touch', 'bend', 'sysex', 'sysrt', 'smpte', or 'invalid' (for invalid sysex messages).

func

The Function or similar object to be removed.

MIDIIn.replaceFuncTo(what, func, newFunc)

Replace a Function or similar object in the list to be evaluated whenever a particular MIDI message is received with another one. This method is preferable to the setters below, since it will not overwrite any existing functions.

Arguments:

what

A Symbol indicating the message type to wait for, one of 'noteOn' 'noteOff', 'polytouch', 'control', 'program', 'touch', 'bend', 'sysex', 'sysrt', 'smpte', or 'invalid' (for invalid sysex messages).

func

The Function or similar object to be replaced.

newFunc

A Function or similar object to be evaluated when a message of the specified type is received. See the setters below for the arguments which will be passed at evaluation time.

MIDIIn.noteOnZeroAsNoteOff

MIDIIn.noteOnZeroAsNoteOff = value

By default this flag is true and SuperCollider interprets incoming MIDI noteOn message with velocity 0 as noteOff messages. In case you do not want this automatic translation, you can set this flag to false

MIDIIn.connectAll(verbose: true)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Platform/linux/SystemOverwrites/extMIDIOut.sc

Connect to all possible MIDI inputs.

Arguments:

verbose

If set to true (default) it will print out the ports found in MIDIClient.init.

MIDIIn.disconnectAll

Disconnect from all MIDI inputs.

Getter/Setters for Specific Message Types

The methods below allow you to register a function to respond to a particular message type.

NOTE: It is preferable to use the *addFuncTo, *removeFuncFrom and *replaceFuncTo methods above instead of these methods, as they will not overwrite any functions added by system objects.

MIDIIn.noteOn

MIDIIn.noteOn = value

Arguments:

(value)

a Function evaluated whenever a MIDI noteOn message is received. It is passed the following arguments:

uid
unique identifier of the MIDI port
MIDIchannel
ranges from 0 to 15
keyNumber
0 - 127
velocity
0 - 127

MIDIIn.noteOff

MIDIIn.noteOff = value

Arguments:

(value)

a Function evaluated whenever a MIDI noteOff message is received. It is passed the following arguments:

uid
unique identifier of the MIDI port
MIDIchannel
ranges from 0 to 15
keyNumber
0 - 127
velocity
0 - 127 (typically 64 unless noteOff velocity is supported)

MIDIIn.polytouch

MIDIIn.polytouch = value

Arguments:

(value)

a Function evaluated whenever a MIDI polytouch message is received. It is passed the following arguments:

uid
unique identifier of the MIDI port
MIDIchannel
ranges from 0 to 15
keyNumber
0 - 127
pressure
0 - 127

MIDIIn.control

MIDIIn.control = value

Arguments:

(value)

a Function evaluated whenever a MIDI control change message (CC) is received. It is passed the following arguments:

uid
unique identifier of the MIDI port
MIDIchannel
ranges from 0 to 15
controllerNumber
0 - 127
value
0 - 127

MIDIIn.program

MIDIIn.program = value

Arguments:

(value)

a Function evaluated whenever a MIDI program change message is received. It is passed the following arguments:

uid
unique identifier of the MIDI port
MIDIchannel
ranges from 0 to 15
programNumber
0 - 127

MIDIIn.touch

MIDIIn.touch = value

Arguments:

(value)

a Function evaluated whenever a MIDI after-touch message is received. It is passed the following arguments:

uid
unique identifier of the MIDI port
MIDIchannel
ranges from 0 to 15
pressure
0 - 127

MIDIIn.bend

MIDIIn.bend = value

Arguments:

(value)

a Function evaluated whenever a MIDI pitch wheel change message is received. It is passed the following arguments:

uid
unique identifier of the MIDI port
MIDIchannel
ranges from 0 to 15
bend
0 - 16383 (14bits, the midpoint is 8192)

MIDIIn.sysex

MIDIIn.sysex = value

NOTE: The current implementation assembles a complete system exclusive packet before evaluating the function.

Arguments:

(value)

a Function evaluated whenever a MIDI System Exclusive message is received. It is passed the following arguments:

uid
unique identifier of the MIDI port
data
an Int8Array (includes f0 and f7). See manufacturer references for details.

MIDIIn.sysrt

MIDIIn.sysrt = value

indexdatamessage
214bitssong pointer
37bitssong select
8midiclock
10start
11continue
12stop

Arguments:

(value)

a Function evaluated whenever a MIDI System Real-Time message is received. It is passed the following arguments:

uid
unique identifier of the MIDI port
index
ranges from 0 to 15
data

MIDIIn.smpte

MIDIIn.smpte = value

Over MIDI, SMPTE is transmitted at 1/4 frame intervals four times faster than the frame rate.
indexdata
0frames low nibble
1frames hi nibble
2seconds low nibble
3seconds hi nibble
4minutes low nibble
5minutes hi nibble
6hours low nibble
7hours hi bit OR'ed with frameRate
  • 0 -> 24 fps
  • 2 -> 25 fps
  • 4 -> 30 fps drop frame
  • 6 -> 30 fps

Nibbles are sent in ascending order.

Arguments:

(value)

a Function evaluated whenever a MIDI smpte message is received. It is passed the following arguments:

uid
unique identifier of the MIDI port
index
ranges from 0 to 7
data
0 - 15 (4bits)

Inherited class methods

Undocumented class methods

MIDIIn.action

MIDIIn.action = value

MIDIIn.bendList

MIDIIn.bendList = value

MIDIIn.connect(inport: 0, device: 0)

MIDIIn.controlList

MIDIIn.controlList = value

MIDIIn.disconnect(inport: 0, device: 0)

MIDIIn.doAction(src, status, a, b, c)

MIDIIn.doBendAction(src, chan, val)

MIDIIn.doControlAction(src, chan, num, val)

MIDIIn.doInvalidSysexAction(src, packet)

MIDIIn.doNoteOffAction(src, chan, num, veloc)

MIDIIn.doNoteOnAction(src, chan, num, veloc)

MIDIIn.doPolyTouchAction(src, chan, num, val)

MIDIIn.doProgramAction(src, chan, val)

MIDIIn.doSMPTEaction(src, frameRate, timecode)

MIDIIn.doSysexAction(src, packet)

MIDIIn.doSysrtAction(src, index, val)

MIDIIn.doTouchAction(src, chan, val)

MIDIIn.invalid

MIDIIn.invalid = value

MIDIIn.noteOffList

MIDIIn.noteOffList = value

MIDIIn.noteOnList

MIDIIn.noteOnList = value

MIDIIn.polyList

MIDIIn.polyList = value

MIDIIn.programList

MIDIIn.programList = value

MIDIIn.touchList

MIDIIn.touchList = value

MIDIIn.waitBend(port, chan, val)

MIDIIn.waitControl(port, chan, num, val)

MIDIIn.waitNoteOff(port, chan, note, veloc)

MIDIIn.waitNoteOn(port, chan, note, veloc)

MIDIIn.waitPoly(port, chan, note, veloc)

MIDIIn.waitProgram(port, chan, num)

MIDIIn.waitTouch(port, chan, val)

Instance Methods

Inherited instance methods

Examples

Quick start for 1 port

Quick start for 2 or more ports

example with sound

writing to the bus rather than directly to the synth

Keyboard Split for two voices