3.1 MIDI Device Interface

3.1.1 @octave_midi/hasdata

: tf = hasdata (dev)

Return whether there is data available to read

Inputs

dev - a octave midi device opened using mididevice.

Outputs

tf - true if device has data available to read

See also: mididevice.

3.1.2 mididevice

: dev = mididevice (mididev)
: dev = mididevice (mididir, mididev)
: dev = mididevice ("input", midiindev, "output", midioutdev)

Create a midi device using the input parameters.

When a single device name or id is provided, attempt to create the midi device using the same name for both input and output.

Otherwise, use the name or device id for the given input or output direction.

Inputs

mididev - name or id of device to load.
mididir - midi direction of "input" or "output"
midiindev - midi input name or id
midioutdev - midi output name or id

Outputs

dev - octave_midi class for opened device

Properties

Input - Input device name (read only).
Output - Output device name (read only).
InputID - Input device id (read only).
OutputID - Output device id (read only).

Examples

Open midi device with ID of 0.

 > dev = mididevice(0);

  mididevice connected to
    input: "SparkFun Pro Micro:SparkFun Pro Micro MIDI 1 20:0" (1)
    output: "SparkFun Pro Micro:SparkFun Pro Micro MIDI 1 20:0" (0)
 

Open a named midi device:

 > dev = mididevice("SparkFun Pro Micro:SparkFun Pro Micro MIDI 1 20:0");

  mididevice connected to
    input: "SparkFun Pro Micro:SparkFun Pro Micro MIDI 1 20:0" (1)
    output: "SparkFun Pro Micro:SparkFun Pro Micro MIDI 1 20:0" (0)
 

See also: mididevinfo.

3.1.3 mididevinfo

: devlist = mididevinfo ()
: mididevinfo ()

Retrieve the midi devices detected within the system.

The list will be stored with variable devlist as either a input or output device. If no output variable is provided, the devices will be displayed.

Inputs

None

Outputs

devlist - a structure containing the midi device information

Examples

Display the known devices of the system.

 > mididevinfo

 MIDI devices available
 ID Direction Interface  Name
  0 output    Alsa       Midi Through:Midi Through Port-0 14:0
  1 output    Alsa       Ensoniq AudioPCI:ES1371 16:0
  2 output    Alsa       SparkFun Pro Micro:SparkFun Pro Micro MIDI 1 20:0
  3 input     Alsa       Midi Through:Midi Through Port-0 14:0
  4 input     Alsa       Ensoniq AudioPCI:ES1371 16:0
  5 input     Alsa       SparkFun Pro Micro:SparkFun Pro Micro MIDI 1 20:0
 

Assign variable mididevices with the values from the known devices

 > mididevices = mididevinfo

 mididevices =
  scalar structure containing the fields:
    input =
    {
      [1,1] =
        scalar structure containing the fields:
          Name = SparkFun Pro Micro:SparkFun Pro Micro MIDI 1 20:0
          Interface = Alsa
          ID =  0
    }
    output =
    {
      [1,1] =
        scalar structure containing the fields:
          Name = SparkFun Pro Micro:SparkFun Pro Micro MIDI 1 20:0
          Interface = Alsa
          ID =  1
    }
 

See also: mididevice.

3.1.4 midiflush

: midiflush (dev)

Flush the receive buffers on a midi device

Inputs

dev - midi device opened using mididevice

Outputs

None

Examples

Flush a midi device

 midiflush(dev);
 

See also: mididevice, midireceive.

3.1.5 midimsg

: msg = midimsg (0)
: msg = midimsg (type ....)
: msg = midimsg ("note", channel, note, velocity, duration, timestamp)
: msg = midimsg ("noteon", channel, note, velocity, timestamp)
: msg = midimsg ("noteoff", channel, note, velocity, timestamp)
: msg = midimsg ("programchange", channel, prog, timestamp)
: msg = midimsg ("controlchange", channel, ccnum, ccval, timestamp)
: msg = midimsg ("polykeypressure", channel, note, keypressure, timestamp)
: msg = midimsg ("channelpressure", channel, chanpressure, timestamp)
: msg = midimsg ("localcontrol", channel, localcontrol, timestamp)
: msg = midimsg ("pitchbend", channel, pitchchange, timestamp)
: msg = midimsg ("polyon", channel, timestamp)
: msg = midimsg ("monoon", channel, monochannels, timestamp)
: msg = midimsg ("omnion", channel, timestamp)
: msg = midimsg ("omnioff", channel, timestamp)
: msg = midimsg ("allsoundoff", channel, timestamp)
: msg = midimsg ("allnotesoff", channel, timestamp)
: msg = midimsg ("resetallcontrollers", channel, timestamp)
: msg = midimsg ("start", timestamp)
: msg = midimsg ("stop", timestamp)
: msg = midimsg ("continue", timestamp)
: msg = midimsg ("systemreset", timestamp)
: msg = midimsg ("activesensing", timestamp)
: msg = midimsg ("timingclock", timestamp)
: msg = midimsg ("systemexclusive", timestamp)
: msg = midimsg ("systemexclusive", bytes, timestamp)
: msg = midimsg ("eox", timestamp)
: msg = midimsg ("data", bytes, timestamp)
: msg = midimsg ("songselect", song, timestamp)
: msg = midimsg ("songpositionpointer", songposition, timestamp)
: msg = midimsg ("tunerequest", timestamp)
: msg = midimsg ("miditimecodequarterframe", timeseq, timevalue, timestamp)

Create a midimsg object

If the input parameter is 0, create an empty midi message object Otherwise the first variable is the type of message to create, followed by the additional parameters for the message.

For each message type, the timestamp value is optional.

Inputs

type - string message type or a midimsgtype.
timestamp - optional seconds time stamp for the event
channel - the channel to use for the message (1..16)
note - the value of the note to play/stop
velocity - the velocity value for a note on/off, with 0 stopping a note from sounding.
duration - seconds between starting and stopping a note when created a ’note’ message.
prog - program number when doing a program change message.
ccnum - control change control number.
ccval - control change control value.
keypressure - key pressure value when creating a key pressure message.
chanpressure - channel pressure value when creating a channelpressure message.
pitchchange - pitch change value when creating a pitch bend message.
localcontrol - boolean value when creating a localcontrol message.
monochannels - channels specified for a mono on message.
bytes - array of data in range of 0 to 127 specified as part of a data message or system exclusive message.
song - song selection number for a song selection message.
songposition - song position value for a song position message.
timeseq - timecode sequence number for a miditimecodequarterframe message.
timevalue - timecode value number for a miditimecodequarterframe message.

Outputs

msg - a midimsg object containing the midi data of the message

Properties

timestamp - timestamp of the message, or an array or timestamps if the the message is a compound message.
msgbytes - the raw message bytes that make up the MIDI message.
nummsgbytes - the number of message bytes that make up the MIDI message.
type - string or midimsgtype that represents the message type.
channel - the channel number for message.
note - the note value for message (Only valid for noteon/off and polykeypressure).
velocity - the velocity value for message (Only valid for noteon/off).
keypressure - the keypressure value for message (Only valid for polykeypressure).
channelpressure - the chanpressure value for message (Only valid for channelpressure).
localcontrol - the localcontrol value for message (Only valid for localcontrol messages).
monochannels - channels specified for a mono on message.
program - program number specified for a program change message.
ccnumber - control change number specified for a control change message.
ccvalue - control change value specified for a control change message.
song - song number for a song selection message.
songposition - song position value for a song position message.
pitchchange - pitch change value for a pitch bend message.
timecodesequence - timecode sequence number for a miditimecodequarterframe message.
timecodevalue - timecode value number for a miditimecodequarterframe message.

Examples

Create a note on/off pair with a duration of 1.5 seconds

 msg = midimsg('note', 1, 60, 100, 1.5)
 

Create a separate note on/off pair with a time between them of 1.5 seconds

 msg = [midimsg('noteon', 1, 60, 100, 0), midimsg('noteoff', 1, 60, 0, 1.5)]
 

Create a system reset message

 msg = midimsg('systemreset')
 

See also: midifileread, midisend, midireceive, midimsgtype.

3.1.6 midireceive

: midimsg = midireceive (dev)
: midimsg = midireceive (dev, maxmsg)

Attempt to receive midi messages from a midi device.

Inputs

dev - a octave midi device opened using mididevice.
maxmsg - Maximum number of messages to retrieve. If not specified, the function will attempt to get all pending.

Outputs

midimsg - a midimsg containing the messages retrieved from the device.
If no messages are available, midimsg will be empty.

Examples

Open device 0, and poll and display read messages

 dev = mididevice(0);
 while true
    mx = midireceive(dev);
    if !isempty(mx)
      % display message
      mx
    endif
 endwhile
 

See also: mididevice, midisend.

3.1.7 midisend

: midisend (dev, msg)
: midisend (dev, ...)

Send a midimsg to a midi device

Inputs

dev - midi device opened using mididevice
msg - a midi message class with messages to send to the midi device
If the msg isn’t a midimsg class, the input data is expected to be in same format as the inputs to a midimsg object.

Outputs

None

Examples

Send a note on/off command to a opened midi device dev

 midisend(dev, midimsg("note", 1, 60, 100, 2.0));
 

See also: midimsg, mididevice, midireceive.


Next: MIDI Controller Interface, Up: Function Reference   [Contents][Index]