Topic
MIDICommon Music uses MIDI stream to support reading and writing MIDI data to to MIDI files, Portmidi and Midishare. Two levels of MIDI support are provided:
High level MIDI support consists of class definitions of MIDI scores and events and functions that operate on them in non-real time. Note that non-real does not imply slower than real time -- the high level interface generates output many times faster than real time. High level support is documented by main entries in the Common Music dictionary, the following topic list provides links to this documentation:
midimidi-note-onmidi-note-offmidi-key-pressuremidi-control-changemidi-program-changemidi-channel-pressuremidi-pitch-bendmidi-system-eventmidi-sequence-numbermidi-text-eventmidi-eotmidi-tempo-changemidi-smpte-offsetmidi-time-signaturemidi-key-signaturemidi-sequencer-eventmidi-port-eventmidi-chan-eventLow level MIDI support provides functions for working with specially formatted unsigned fixnum values called midi messages. Common Music supports all of the message types defined in the MIDI 1.0 specification as well as those described in the MIDI Time Code and Cueing supplement.
A MIDI message is a specially formatted fixnum (28-30 bits) containing up to three 7-bit bytes of information. Each MIDI message is implemented by a constructor function, a predicate, and one or more field accessors. Some message types, such as System Exclusive and Meta messages, are implemented as composite data. Constructors for these types return two values: a message and a vector of message data bytes.
(midi-copy-message msg {keyword value}*)Returns a copy of msg with fields altered according to keyword arguments.
midi-copy-message supports the
following keyword arguments:
Prints msg and an optional time value. Returns msg as its value.
Channel messages encode the performance information sent to particular
instruments on the synthesizer.
:opcode byte
:channel byte
:data1 byte
:data2 byte
Examples
;; Copying MIDI messages.
(define m1 (make-note-on 0 20 90))
(define m2 (midi-copy-message m1 :data1 73))
(midi-print-message m2)
#<Note-On 0 73 90>
⇒ 156890
(define m3 (midi-copy-message m2 :data1 73 :opcode #b1000 :data2 127))
(midi-print-message m3)
#<Note-Off 0 73 127>
⇒ 140543
(midi-print-message msg [time])Example
;; Printing MIDI messages.
(midi-print-message (make-note-on 0 60 90) )
#<Note-On 0 60 90>
⇒ 155226
(midi-print-message (make-note-off 9 60 90) 1000)
1000 #<Note-Off P "hi-bongo" 90>
⇒ 2514522
(midi-print-message (make-program-change 2 45))
#<Program-Change 2 "pizzicato-strings">
⇒ 726656
(midi-print-message (make-control-change 0 +sustain+ 60))
#<Control-Change 0 "hold-1" 60>
⇒ 188476
Message Constructors, Predicates and Accessors
Channel Messages
All Channel Messages
(make-channel-message opcode channel data1 . data2)
(channel-message-p message)
(channel-message-channel message)
(channel-message-opcode message)
(channel-message-data1 message)
(channel-message-data2 message)Note-On
(make-note-on channel key velocity)
(note-on-p message)
(note-on-channel message)
(note-on-key message)
(note-on-velocity message)Note-Off
(make-note-off channel key velocity)
(note-off-p message)
(note-off-channel message)
(note-off-key message)
(note-off-velocity message
(make-key-pressure channel key pressure)(key-pressure-p message)(key-pressure-channel message)(key-pressure-key message)(key-pressure-pressure message)(make-control-change channel controller value)(control-change-p message)(control-change-channel message)(control-change-controller message)(control-change-value message(make-program-change channel program)(program-change-p message)(program-change-channel message)(program-change-program message)(make-channel-pressure channel pressure)(channel-pressure-p message)(channel-pressure-channel message)(channel-pressure-pressure message)(make-pitch-bend channel lsb msb)(pitch-bend-p message)(pitch-bend-channel message)(pitch-bend-lsb message)(pitch-bend-msb message)System messages are sent to the device (or each device in a daisy-chain), as opposed to a specific channel.
(make-system-message type route . data1 data2)(system-message-p message)(system-message-route message)(system-message-status message)(system-message-data1 message)(system-message-data2 message)
A System Exclusive, or SysEx, message is a message that is specific to one vendor
or synthesizer. The first one or three data bytes of the sysex specifies the
vendor. The first one or three data bytes after the start
tag F0 of the sysex specifies the vendor. If the
synthesizer recognizes this Manufacturer's ID as its own, it will
listen to the rest of the message. Otherwise, the message will be
ignored. System Exclusive is used to send bulk dumps such as patch
parameters and other non-spec data.
(make-sysex route data)(sysex-p message)(sysex-route message
The make-sysex constructor returns two values, a message bitfield
indicating a system exclusive message and an array of system exclusive
data. data must be either:
FO and F7 tags(make-mtc-quarter-frame route tag nibble)(mtc-quarter-frame-p message)(mtc-quarter-frame-route message)(mtc-quarter-frame-tag message)(mtc-quarter-frame-nibble message)(make-song-position route lsb msb)(song-position-p message)(song-position-route message)(song-position-lsb message)(song-position-msb message)(make-song-select route song)(song-select-p message)(song-select-route message)(song-select-song message)(make-cable-select route cable)(cable-select-p message)(cable-select-route message)(cable-select-cable message)(make-tune-request route)(tune-request-p message)(tune-request-route message)(make-eox route)(eox-p message)(eox-route message)(make-timing-clock route)(timing-clock-p message)(timing-clock-route message)(make-timing-tick route)(timing-tick-p message)(timing-tick-route message)(make-start route)(start-p message)(start-route message)(make-continue route)(continue-p message)(continue-route message)(make-stop route)(stop-p message)(stop-route message)(make-active-sensing route)(active-sensing-p message)(active-sensing-route message)(make-system-reset route)(system-reset-p message)(system-reset-route message)Meta messages store various sorts of non-event information for MIDI tracks and MIDI files. The meta message constructors return two values, a message and an array of unsigned bytes. Meta messages should not be sent to MIDI devices.
(make-meta-message type)(meta-message-p message)(meta-message-type message)(make-sequence-number num)(sequence-number-p message)(make-text-event string . type)(text-event-p message)(make-copyright-note string)(copyright-note-p message)(make-sequence/track-name string)(sequence/track-name-p message)(make-instrument-name string)(instrument-name-p message)(make-lyric string)(lyric-p message)(make-marker string)(marker-p message)(make-cue-point string)(cue-point-p message)(make-midi-channel channel)(midi-channel-p message)(make-midi-port port)(midi-port-p message)(make-eot)(eot-p message)(make-tempo-change usec)(tempo-change-p message)(make-smpte-offset hours mins secs frames fractional-frames)(smpte-offset-p message)Denominator is a negative power of 2. clocks expresses the number of MIDI clocks per metronome click and 32nds the number of notated 32nd notes in a MIDI quarter note (i.e., 24 MIDI clocks). This event allows a program to relate what MIDI thinks of as a quarter to any desired value.
(make-time-signature numerator denominator . clocks 32nds)(time-signature-p message)
Key is either a number between -7 and 7 representing the number of
flats (-) or sharps (+) in the key signature or a note symbol such as
c, cf, cs etc. indicating the tonic.
mode is either :major (the default) or :minor.
(make-key-signature key mode)(key-signature-p message)(make-sequencer-event . data)(sequencer-event-p message)Common Music provides numerous constants and variables that symbolically encode common MIDI values such as program changes and controller values.
+acoustic-grand-piano+ +bright-acoustic-piano+ +electric-grand-piano+ +honky-tonk-piano+ +electric-piano-1+ +electric-piano-2+ +harpsichord+ +clavi+
+celesta+ +glockenspiel+ +music-box+ +vibraphone+ +marimba+ +xylophone+ +tubular-bells+ +dulcimer+
+drawbar-organ+ +percussive-organ+ +rock-organ+ +church-organ+ +reed-organ+ +accordion+ +harmonica+ +tango-accordion+
+acoustic-guitar-nylon+ +acoustic-guitar-steel+ +electric-guitar-jazz+ +electric-guitar-clean+ +electric-guitar-muted+ +overdriven-guitar+ +distortion-guitar+ +guitar-harmonics+
+acoustic-bass+ +electric-bass-finger+ +electric-bass-pick+ +fretless-bass+ +slap-bass-1+ +slap-bass-2+ +synth-bass-1+ +synth-bass-2+
+violin+ +viola+ +cello+ +contrabass+ +tremolo-strings+ +pizzicato-strings+ +orchestral-strings+ +timpani+
+string-ensemble-1+ +string-ensemble-2+ +synthstrings-1+ +synthstrings-2+ +choir-aahs+ +voice-oohs+ +synth-voice+ +orchestra-hit+
+trumpet+ +trombone+ +tuba+ +muted-trumpet+ +french-horn+ +brass-section+ +synthbrass-1+ +synthbrass-2+
+soprano-sax+ +alto-sax+ +tenor-sax+ +baritone-sax+ +oboe+ +english-horn+ +bassoon+ +clarinet+
+piccolo+ +flute+ +recorder+ +pan-flute+ +blown-bottle+ +skakuhachi+ +whistle+ +ocarina+
+lead-1-square+ +lead-2-sawtooth+ +lead-3-calliope+ +lead-4-chiff+ +lead-5-charang+ +lead-6-voice+ +lead-7-fifths+ +lead-8-bass+lead+
+pad-1-new-age+ +pad-2-warm+ +pad-3-polysynth+ +pad-4-choir+ +pad-5-bowed+ +pad-6-metallic+ +pad-7-halo+ +pad-8-sweep+
+fx-1-rain+ +fx-2-soundtrack+ +fx-3-crystal+ +fx-4-atmosphere+ +fx-5-brightness+ +fx-6-goblins+ +fx-7-echoes+ +fx-8-sci-fi+
+sitar+ +banjo+ +shamisen+ +koto+ +kalimba+ +bagpipe+ +fiddle+ +shanai+
+tinkle-bell+ +agogo+ +steel-drums+ +woodblock+ +taiko-drum+ +melodic-tom+ +synth-drum+ +reverse-cymbal+
+guitar-fret-noise+ +breath-noise+ +seashore+ +bird-tweet+ +telephone-ring+ +helicopter+ +applause+ +gunshot+
The GM drum map on channel 9 (zero-based counting) maps key numbers 35-81 to the following sounds:
+acoustic-bass-drum+ +bass-drum-1+ +side-stick+ +acoustic-snare+ +hand-clap+ +electric-snare+ +low-floor-tom+ +closed-hi-hat+ +high-floor-tom+ +pedal-hi-hat+ +low-tom+ +open-hi-hat+ +low-mid-tom+ +hi-mid-tom+ +crash-cymbal-1+ +high-tom+ +ride-cymbal-1+ +chinese-cymbal+ +ride-bell+ +tambourine+ +splash-cymbal+ +cowbell+ +crash-cymbal-2+ +vibraslap+ +ride-cymbal-2+ +hi-bongo+ +low-bongo+ +mute-hi-conga+ +open-hi-conga+ +low-conga+ +high-timbale+ +low-timbale+ +high-agogo+ +low-agogo+ +cabasa+ +maracas+ +short-whistle+ +long-whistle+ +short-guiro+ +long-guiro+ +claves+ +hi-wood-block+ +low-wood-block+ +mute-cuica+ +open-cuica+ +mute-triangle+ +open-triangle+
The following standard controller and Registered Parameter Numbers (RPNs) are defined:
+bank-select+ +modulation-wheel+ +breath-control+ +foot-controller+ +portamento-time+ +data-entry+ +channel-volume+ +volume+ +balance+ +pan+ +expression-controller+ +effect-control-1+ +effect-control-2+ +general-purpose-controller-1+ +general-purpose-controller-2+ +general-purpose-controller-3+ +general-purpose-controller-4+
+bank-select-fine+ +modulation-wheel-fine+ +breath-control-fine+ +foot-controller-fine+ +portamento-time-fine+ +data-entry-fine+ +channel-volume-fine+ +volume-fine+ +balance-fine+ +pan-fine+ +expression-controller-fine+ +effect-control-1-fine+ +effect-control-2-fine+ +general-purpose-controller-1-fine+ +general-purpose-controller-2-fine+ +general-purpose-controller-3-fine+ +general-purpose-controller-4-fine+
+sustain+ +portamento+ +sostenuto+ +soft-pedal+ +legato-footswitch+ +hold-2+
+sound-variation+ +sound-timbre+ +sound-release-time+ +sound-attack-time+ +sound-brightness+ +portamento-control+
+effects-level+ +tremolo-level+ +chorus-level+ +detune-level+ +phasor-level+
+data-entry-increment+ +data-entry-decrement+
+non-registered-parameter-number-fine+ +non-registered-parameter-number+ +registered-parameter-number-fine+ +registered-parameter-number+
+all-sound-off+ +reset-all-controllers+ +local-control+ +all-notes-off+ +omni-mode-off+ +omni-mode-on+ +poly-mode-on/off+ +poly-mode-on+
+rpn-pitch-bend-sensitivity+ +rpn-fine-tuning+ +rpn-coarse-tuning+ +rpn-reset+