8.2.0.0. MIDI with the sequencer device
|
(packages/music/midi-seq.lsh) |
Author(s): Yann LeCun
This package provides a couple of classes to receive and transmit simple
MIDI events from and to the ALSA sequencer device on Linux. The classes
are built on top of the ALSA API. Any MIDI port created with these
classes appears on the Jack MIDI panel and can be connected to physical
MIDI interfaces, software Synthesizers, or other MIDI-enabled software
using Jack Control or other MIDI patching software.
8.2.0.0.0. midi-input
|
(packages/music/midi-seq.lsh) |
a class to handle MIDI input through Linux's seq device. Here is a
typical example of use:
(setq z (new midi-input "lushmidi"))
(let ((r 0))
(while t
;; wait on midi port
(while (= 0 (==> z poll 1000) ) ())
;; process all events
(do-while (> (==> z pending-events) 0)
(setq r (==> z read-event))
(when (= 0 r)
(printf "chan=%2d, type=%3d, prm=%4d, val=%4d [r=%d]\n"
:z:eventchannel :z:eventtype :z:eventparam :z:eventvalue r))))))
8.2.0.0.0.0. (new midi-input name)
|
[CLASS] (packages/music/midi-seq.lsh) |
create a new MIDI input object. The midi input will appear as the string
name in the jack MIDI device list.
8.2.0.0.0.1. (==> midi-input poll timout)
|
[MSG] (packages/music/midi-seq.lsh) |
Waits for a MIDI event to arrive. return 1 if a midi event has arrived
before timeout milliseconds have
elapsed. If no event has arrived by that time, the call returns a zero.
8.2.0.0.0.2. (==> mid-input read-event)
|
[MSG] (packages/music/midi-seq.lsh) |
This reads the next available MIDI event. This method blocks if no event
is present on the queue. Checking whether a MIDI event is present can be
done with the poll method. If a MIDI
event of a known type was succesfully read, the slots
eventchannel , eventtype ,
eventparam , and eventvalue
are filled with the corresponding value from the event, and 0 is
returned. If an event of an unknown type was read, a -1 is returned.
After a succesful read, the eventchannel
slot contains the channel on which the MIDI event was sent.
eventtype contains the type of event as an integer (e.g.
SND_SEQ_EVENT_NOTEON, SND_SEQ_EVENT_CONTROLLER, SND_SEQ_EVENT_PITCHBEND,
see /usr/include/alsa/seq_event.h for
a list of types). eventparam contains
the event main parameter, i.e. the pitch for a NOTEON or NOTEOFF event,
the controller number for a CONTROLLER event, etc).
eventvalue contains the value of the parameters, i.e. the
velocity of a note, the value of a controller, etc. The known event
types are: SND_SEQ_EVENT_NOTEON ,
SND_SEQ_EVENT_NOTEOFF ,
SND_SEQ_EVENT_KEYPRESS ,
SND_SEQ_EVENT_CONTROLLER ,
SND_SEQ_EVENT_PITCHBEND ,
SND_SEQ_EVENT_PGMCHANGE .
8.2.0.0.0.3. (==> midi-input pending-events)
|
[MSG] (packages/music/midi-seq.lsh) |
return the number of pending MIDI events in the queue. This uses the
ALSA function snd_seq_event_input_pending
, which, strangely enough, returns zero even if the
poll method detected a MIDI event. It only seems to get
updated after snd_seq_event_input has
been called by the method read-event .
Hence, pending-events should be used
in a do-while loop, after a call to
poll , as in:
(setq z (new midi-input "lushmidi"))
(let ((r 0))
(while t
;; wait for an event on midi port
(while (= 0 (==> z poll 1000) ) ())
;; process all events
(do-while (> (==> z pending-events) 0)
(setq r (==> z read-event))
(when (= r 0) (do-midi-stuff z)))))
8.2.0.0.0.4. (==> midi-input debug-events)
|
[MSG] (packages/music/midi-seq.lsh) |
A simple method that displays every valid MIDI event that arrives to the
midi-input object.
8.2.0.0.0.5. (midi-input-test)
|
(packages/music/midi-seq.lsh) |
simple example function that creates a MIDI input port and prints all
events that arrive on it.
8.2.0.0.1. midi-output
|
(packages/music/midi-seq.lsh) |
A class to send simple MIDI events to the sequencer device.
8.2.0.0.1.0. (new midi-output client-name)
|
[CLASS] (packages/music/midi-seq.lsh) |
Creates a new MIDI client and port with which MIDI events can be sent
from Lush to a physical MIDI interface or another MIDI-enabled software.
client-name should be a string containing a name to identify
this client. The client opens a single port.
(setq z (new midi-output "lush-midi-out"))
8.2.0.0.1.1. (==> midi-output note ch key vel dur)
|
[MSG] (packages/music/midi-seq.lsh) |
send a note event to MIDI channel
ch . key ,
vel , dur are the key,
velocity and duration of the note.
8.2.0.0.1.2. (==> midi-output noteon ch key vel)
|
[MSG] (packages/music/midi-seq.lsh) |
send a noteon event to MIDI channel
ch . key , and
vel are the key, and velocity of the note. A subsequent
noteoff event with the same channel and key must be sent
subsequently to shut off the note.
8.2.0.0.1.3. (==> midi-output noteon ch key vel)
|
[MSG] (packages/music/midi-seq.lsh) |
send a noteon event to MIDI channel
ch . key , and
vel are the key, and velocity of the note. A subsequent
noteoff event with the same channel and key must be sent
subsequently to shut off the note.
8.2.0.0.1.4. (==> midi-output keypress ch key vel)
|
[MSG] (packages/music/midi-seq.lsh) |
send a keypress (aftertouch) event to
MIDI channel ch .
key , and vel are the key,
and velocity.
8.2.0.0.1.5. (==> midi-output controller ch cc val)
|
[MSG] (packages/music/midi-seq.lsh) |
Send a MIDI controller event to MIDI channel ch
. cc is the controller number, and
val the value. Here is a partial list of the most commonly
used MIDI controllers with their cc
value: 0: Bank Select; 1: Modulation Wheel or Lever; 2: Breath
Controller; 4: Foot Controller; 5: Portamento Time; 6: Data Entry MSB;
7: Channel Volume; 8: Balance; 10: Pan; 11: Expression Controller; 12:
Effect Control 1; 13: Effect Control 2. A complete table is available
at: http://www.midi.org/about-midi/table3.shtml
8.2.0.0.1.6. (==> midi-output modulation ch val)
|
[MSG] (packages/music/midi-seq.lsh) |
Send MIDI modulation value val .
Equivalent to calling controller with
cc=1 .
8.2.0.0.1.7. (==> midi-output breath ch val)
|
[MSG] (packages/music/midi-seq.lsh) |
Send MIDI breath control value val .
Equivalent to calling controller with
cc=2 .
8.2.0.0.1.8. (==> midi-output pgmchange ch val)
|
[MSG] (packages/music/midi-seq.lsh) |
Send MIDI program change val to
channel ch .
8.2.0.0.1.9. (==> midi-output pitchbend ch val)
|
[MSG] (packages/music/midi-seq.lsh) |
Send MIDI pitchbend value val to
channel ch .
8.2.0.0.1.10. (==> midi-output chanpress ch val)
|
[MSG] (packages/music/midi-seq.lsh) |
Send MIDI channel pressure val to
channel ch .
8.2.0.0.1.11. (==> midi-output sysex ch data)
|
[MSG] (packages/music/midi-seq.lsh) |
Send MIDI system exclusive data to channel ch
. data must be an IDX1 of ubytes (of
any size) containing the data to be transmitted.
8.2.0.0.1.12. (==> midi-output write-event ch type param value)
|
[MSG] (packages/music/midi-seq.lsh) |
Send a generic MIDI event to channel ch
.