MIDI API [Topic]

Opening and Closing MIDI

 
midi-open &key (max-logical-channels *midi-default-max-logical-channels*) (max-routes *midi-default-max-routes*) (max-connections *midi-default-max-connections*) (max-mappings *midi-default-max-mappings*) (queue-size *midi-default-queue-size*) (channel-map *midi-default-channel-map*) (route-map *midi-default-route-map*) (connections *midi-default-connections*) port [Mi_D API Function]

Open or re-initialize the MIDI environment. The first five keyword arguments specify size limits for various data structures internal to the environment and hence force an implicit shutdown and re-opening if re-set in runtime. More precisely. max-logical-channels, max-routes and max-connections determine the dimensions of the internal channel and route maps, max-mappings the maximal number of mappings that may be established across both maps, and queue-size the number of events that may be queued for output before calls to midi-write-message block.

channel-map, route-map and connections initialize or re-set the internal data structures. port is provided for backwards compatibility only and its use is deprecated.

All keyword parameters take their defaults from global variables that may (and should) be customized by users to simplify opening MIDI. See their respective documentation for more info on the data expected by each parameter.

Calling midi-open while MIDI is already open closes MIDI first, then re-opens it again.

midi-open returns t if MIDI is open or nil if it is not (i.e., the updated value of midi-open?.)

See Also:

*midi-default-max-logical-channels*, *midi-default-max-routes*, *midi-default-max-connections*, *midi-default-max-mappings*, *midi-default-queue-size*, *midi-default-channel-map*, *midi-default-route-map*, *midi-default-connections*, midi-open?
 
midi-close () [Mi_D API Function]
Close MIDI and dispose of all internal data structures. Returns the updated return value of midi-open?.

See Also:

midi-open?

MIDI Environment

 
midi-update-system-info () [Mi_D API Function]

Use this function to update the MIDI environment if you've added new devices to the system such as a new MIDI client that you want to receive messages.

 
midi-print-environment &optional (verbosity 1) (stream :stderr) [Mi_D API Function]

Print a summary of the current MIDI environment to stream. verbosity may be one of 0 (terse), 1 (default), or 2 (technical). stream must be either :stdout or :stderr, requesting output on either *standard-output* or *standard-error, respectively.

 
midi-get-environment-info &rest selectors [Mi_D API Function]

midi-get-environment-info takes as arguments any number of keyword info selectors in selectors and returns the query results for each selector as multiple values.

Possible information selectors are:

:mi_d-max-logical-channels
maximum number of channels
mi_d-max-routes
maximum number of routes
mi_d-max-connections
maximum number of connections
mi_d-max-map-cells
total number of mapping cells to disposal. Note that this number is twice the number specified in the max-mappings parameter to midi-open, since each mapping is registered in both, a standard map and its inverse map.
mi_d-map-cells-in-use
maximum number of mapping cells currently in use
:mi_d-queue-size
maximum number of events in the queue
:mi_d-nr-of-interfaces
number of interfaces currently known to the system
:mi_d-interface-info
list of each interface name string and its direction: 1 (input), 2 (output) or 3 (bidirectional)
:mi_d-input-interfaces
list of configured input interfaces
:mi_d-output-interfaces
list of configured output interfaces
:mi_d-channel-map
list of current mappings in the channel map
:mi_d-inv-channel-map
list of current mappings in the inverse channel map
:mi_d-route-map
list of current mappings in the route map
:mi_d-inv-route-map
list of current mappings in the inverse route map

Example:

? (midi-get-environment-info :mi_d-max-logical-channels
	                     :mi_d-max-routes
		             :mi_d-max-connections
			     :mi_d-max-map-cells
			     :mi_d-queue-size)
120
10
10
400
20000
  

See Also:

midi-open
 
midi-check-environment () [Mi_D API Function]

Performs an environment consistency check. Returns t if no inconsistencies were found, nil otherwise.

 
midi-connect connection interface direction [Mi_D API Function]

Associate connection connection with the interface named by interface. direction will be one of :input, :output or :bidirectional.

See Also:

midi-set-connections

MIDI I/O

 
midi-write-message msg &optional (time 0) [Mi_D API Function]

Schedules the message encoded in msg for output at time time. If time is not specified, it defaults to 0, i.e. the message is sent immediately.

See Also:

midi-write-note, midi-write-sysex, *midi-sysex-refcounter*
 
midi-write-sysex vector &key msg route length (time 0) (refcount *midi-sysex-refcounter*) [Mi_D API Function]

Schedules a system exclusive message for output at time time. vector contains a complete system exclusive message in form of an array of type

(simple-array (unsigned-byte 8) (*))
and length indicates the length of the message in bytes. The route on which to output the message may be given either explicitly via route or implicitly by passing the first return value of make-sysex-message in msg.

If the client wishes to free sysex data after sending it, she is encouraged to pass a refcounter object in refcounter whose value field may be initialized to any number that is meaningful to the client--typically 0. write-sysex increments the counter, schedules the message, and returns immediately, i.e., the message is written out asynchronously. The counter is decremented as soon as the message is written out completely. This mechanism allows the client to write a sysex message to different destinations at different times, while sharing the message's data across calls. After the counter has been decremented it will be safe to deallocate the data. refcounter defaults to *midi-sysex-refcounter*. Additional refcounter objects may be constructed by calling

mi_d:make-refcounter initial-value

See Also:

*midi-sysex-refcounter*, make-sysex-message
 
midi-write-note channel keynum velocity duration &optional (time 0) ( off-velocity 64) [Mi_D API Function]

Convenience function that schedules a note-on and note-off message pair given a note description.

 
midi-read-messages &optional (fun *midi-read-hook*) &key skip-data [Mi_D API Function]

Remove pending messages from the input queue and optionally map the function fun over each message. fun's lambda list must be compatible with

(msg &optional time &key data length &allow-other-keys)
and will be passed each message and its millisecond time in msg and time. Sysex data and its length will be passed to fun via its data and length keywords unless skip-data is t.

Example

 ? (midi-read-messages #'midi-print-message)

See Also:

*midi-read-hook*, midi-receive, midi-print-message
 
midi-flush-input () [Mi_D API Function]

Discards ("flushes") events pending in the input queue.

 
midi-flush-output () [Mi_D API Function]

Discards ("flushes") events pending in the output queue.

 
midi-all-notes-off () [Mi_D API Function]

Broadcast "All Notes Off", "All Sound Off", and "Reset All Controllers" control messages on all active output connections. Note that this does not work with some older MIDI devices that are unaware of these messages. These devices continue to need note-off messages on every channel and key number.

 
midi-hush () [Mi_D API Function]

midi-hush is equivalent to a calling midi-all-notes-off followed by midi-flush-input and midi-flush-output.

 
midi-get-time () [Mi_D API Function]

Return the current MIDI time in milliseconds.

 
midi-set-time ms [Mi_D API Function]

Set the MIDI timer to ms milliseconds.

 
midi-stop-timer [Mi_D API Function]

Provided for backwards compatibility. This function does not do anything.

 
midi-start-timer () [Mi_D API Function]

Start the MIDI timer. Equivalent to (midi-set-time 0).

 
midi-c-print-message msg &optional time &key data length ( maxlines 0) stream time-format &allow-other-keys [Mi_D API Function]

Prints MIDI messages in a slightly different format than midi-print-messageonto *standard-output*

See Also:

midi-print-message

Last Modified: 20-Aug-1998