CoreMIDI
(require (planet evhan/coremidi)) |
This module provides a minimal interface to Apple’s CoreMIDI library.
It provides for the creation & destruction of MIDI connections and for the following MIDI messages: Note On, Note Off, Program Change, and Aftertouch.
1 Interface
In order to send MIDI messages anywhere you must first create a MIDI connection.
| |||||||||||||||||||||
destination-n : integer? = 0 | |||||||||||||||||||||
client-name : string? = "rkt client" | |||||||||||||||||||||
port-name : string? = "rkt outport" |
Opens a midi-connection to the destination-nth available MIDI destination, or the first available destination if no destination-n is given. client-name and port-name will be the identifiers assigned to this midi-connection components within the CoreMIDI system.. For most purposes you can ignore these names.
(midi-close midi-destination) → void? |
midi-destination : midi-destination? |
Destroys a midi-connection (previously created with midi-open).
(note-on midi channel note [velocity]) → void? |
midi : midi-connection? |
channel : integer? |
note : integer? |
velocity : integer? = 64 |
Sends a MIDI Note On signal to the given midi-connection on the given channel. note is the MIDI note number and velocity is optionally the note’s velocity. Both are integers from 0-127.
(note-off midi channel note [velocity]) → void? |
midi : midi-connection? |
channel : integer? |
note : integer? |
velocity : integer? = 64 |
Entirely mimics note-on’s functionality, except that it sends a MIDI Note Off message instead of a Note On.
(aftertouch midi channel note touch) → void? |
midi : midi-connection? |
channel : integer? |
note : integer? |
touch : integer? |
Sends a MIDI Aftertouch signal to the given midi-connection on the given channel. note is the note value and touch is the weight of the aftertouch. Both are integers from 0-127.
(program-change midi channel preset) → void? |
midi : midi-connection? |
channel : integer? |
preset : integer? |
Sends a MIDI Program Change signal to the given midi-connection on the given channel. preset is the program number from 0-127.
2 Example
Here’s a simple example making use of most of the functions defined above. It simply plays a C major scale at 60 bpm.
(define (play-each notes) |
(define midi (midi-open)) |
(program-change midi 1 0) |
(for/list ((note notes)) |
(note-on midi 1 note 120) |
(sleep 1) |
(note-off midi 1 note)) |
(midi-close midi) (void)) |
(play-each '(60 62 64 65 67 69 71 72)) |
Please let me know of any bugs you encounter.