#lang scribble/manual @(require (for-label racket (planet evhan/coremidi))) @title{CoreMIDI} @defmodule[(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: @bold{Note On}, @bold{Note Off}, @bold{Program Change}, and @bold{Aftertouch}. @section{MIDI Connections} In order to send MIDI messages anywhere you must first create a MIDI connection: @defproc[(midi-open [destination-n integer? 0] [client-name string? "rkt client"] [port-name string? "rkt outport"]) midi-connection?] Opens a @racket[midi-connection] to the @racket[destination-n]th available MIDI destination (as provided by the CoreMIDI system), or the first available destination if no @racket[destination-n] is given. @racket[client-name] and @racket[port-name] can optionally be the identifiers assigned to the new @racket[midi-connection]'s internal components within the CoreMIDI system. For most purposes you can ignore these names. @racket[midi-connection] handles will remain open until closed: @defproc[(midi-close [midi-destination midi-destination?]) void?] Destroys a @racket[midi-connection] (previously created with @racket[midi-open]). @section{MIDI Messages} The following MIDI messaging procedures all take a @racket[midi-connection] as a first argument. This will be the destination to which the message is sent. @defproc[(note-on [midi midi-connection?] [channel integer?] [note integer?] [velocity integer? 64]) void?] Sends a MIDI @bold{Note On} signal to the given @racket[midi-connection] on the given @racket[channel]. @racket[note] is the MIDI note number and @racket[velocity] is optionally the note's velocity. Both are integers from 0-127. @defproc[(note-off [midi midi-connection?] [channel integer?] [note integer?] [velocity integer? 64]) void?] Entirely mimics @racket[note-on]'s functionality, except that it sends a MIDI @bold{Note Off} message instead of a @bold{Note On}. @defproc[(aftertouch [midi midi-connection?] [channel integer?] [note integer?] [touch integer?]) void?] Sends a MIDI @bold{Aftertouch} signal to the given @racket[midi-connection] on the given @racket[channel]. @racket[note] is the note value and @racket[touch] is the weight of the aftertouch. Both are integers from 0-127. @defproc[(program-change [midi midi-connection?] [channel integer?] [preset integer?]) void?] Sends a MIDI @bold{Program Change} signal to the given @racket[midi-connection] on the given @racket[channel]. @racket[preset] is the program number from 0-127. @section{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. @racketblock[ (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.