Module el.midi
MIDI factories and utilities.
Functions in this module do not check arguments. It is the responsibility of calling code to ensure correct data is passed.
Info:
- Author: Michael Fisher
Messages
| controller (channel, controller, value) | Make a controller message |
| noteon (channel, note, velocity) | Make a note on message |
| noteoff (channel, note) | Make a regular note off message |
| noteoff (channel, note, velocity) | Make a note off message with velocity |
| program (channel, program) | Make a program change message. |
| pitch (channel, position) | Make a pitch wheel message. |
| aftertouch (channel, note, value) | Make an after touch message. |
| channelpressure (channel, value) | Make a channel-pressure message. |
| allnotesoff (channel) | Make an all notes off message. |
| allsoundsoff (channel) | Make an all sounds off message. |
| allcontrollersoff (channel) | Make an all controllers off message. |
| clock () | Make a clock message. |
| start () | Make a start message. |
| stop () | Make a stop message. |
| continue () | Make a continue message. |
| songpositionpointer (position) | Make a SPP (Song Position Pointer) message. |
| quarterframe (sequenceNumber, value) | Make a quarter frame message. |
| quarterframetransport (currentSample, blockSize, sampleRate, framesPerSecond, sentMessagesCounter) | Make a quarter frame message from transport state. |
| mtcfullframe (hours, minutes, seconds, frames, rateType) | Make an MTC Full Frame SysEx message. |
| mtcfullframetransport (currentSample, sampleRate, framesPerSecond) | Make an MTC Full Frame SysEx message from transport state. |
Utils
| tohertz (note) | Convert a MIDI note to hertz. |
| clamp (value) | Clamp to a valid MIDI value (0 - 127) |
Messages
- controller (channel, controller, value)
-
Make a controller message
Parameters:
- channel integer MIDI Channel
- controller integer Controller number
- value integer Controller Value
Returns:
-
MIDI message packed as Integer
- noteon (channel, note, velocity)
-
Make a note on message
Parameters:
- channel integer MIDI Channel
- note integer Note number 0-127
- velocity integer Note velocity 0-127
Returns:
-
MIDI message packed as Integer
- noteoff (channel, note)
-
Make a regular note off message
Parameters:
- channel integer MIDI Channel
- note integer Note number
Returns:
-
MIDI message packed as Integer
- noteoff (channel, note, velocity)
-
Make a note off message with velocity
Parameters:
- channel integer MIDI Channel
- note integer Note number
- velocity integer Note velocity
Returns:
-
MIDI message packed as Integer
- program (channel, program)
-
Make a program change message.
Parameters:
- channel integer The midi channel (1 to 16)
- program integer Program number
Returns:
-
MIDI message packed as Integer
- pitch (channel, position)
-
Make a pitch wheel message.
Parameters:
- channel integer The midi channel (1 to 16)
- position integer The wheel position, in the range 0 to 16383
Returns:
-
MIDI message packed as Integer
- aftertouch (channel, note, value)
-
Make an after touch message.
Parameters:
- channel integer The midi channel (1 to 16)
- note integer The midi note, in the range 0 to 127
- value integer The after touch value.
Returns:
-
MIDI message packed as Integer
- channelpressure (channel, value)
-
Make a channel-pressure message.
Parameters:
- channel integer The midi channel (1 to 16)
- value integer The pressure value (0 to 127)
Returns:
-
MIDI message packed as Integer
- allnotesoff (channel)
-
Make an all notes off message.
Parameters:
- channel integer The midi channel (1 to 16)
Returns:
-
MIDI message packed as Integer
- allsoundsoff (channel)
-
Make an all sounds off message.
Parameters:
- channel integer The midi channel (1 to 16)
Returns:
-
MIDI message packed as Integer
- allcontrollersoff (channel)
-
Make an all controllers off message.
Parameters:
- channel integer The midi channel (1 to 16)
Returns:
-
MIDI message packed as Integer
- clock ()
-
Make a clock message.
Returns:
-
MIDI message packed as Integer
- start ()
-
Make a start message.
Returns:
-
MIDI message packed as Integer
- stop ()
-
Make a stop message.
Returns:
-
MIDI message packed as Integer
- continue ()
-
Make a continue message.
Returns:
-
MIDI message packed as Integer
- songpositionpointer (position)
-
Make a SPP (Song Position Pointer) message.
Parameters:
- position
integer
Song position in the number of MIDI beats counted from the beginning of the track.Each MIDI beat equals 6 MIDI clocks. Since a quarter-note consists of 24 MIDI clocks, that means each quarter-note contains 4 MIDI beats.
Returns:
-
MIDI message packed as Integer
- position
integer
- quarterframe (sequenceNumber, value)
-
Make a quarter frame message.
Parameters:
- sequenceNumber integer The sequence number (0-7) identifying which piece of the timecode is being sent
- value integer The value (0-15) for this piece of timecode
Returns:
-
MIDI message packed as Integer
- quarterframetransport (currentSample, blockSize, sampleRate, framesPerSecond, sentMessagesCounter)
-
Make a quarter frame message from transport state.
Computes the next MTC quarter frame message based on the current playback
position. Returns the updated counter, the packed MIDI message, and the
sample offset within the block. If no message falls within the current
block, only the unchanged counter is returned.
Raises an error if framesPerSecond is not 24, 25, 29, or 30.
Parameters:
- currentSample integer Current playback position in samples
- blockSize integer Audio block size in samples
- sampleRate number Audio sample rate in Hz
- framesPerSecond integer MTC frame rate (24, 25, 29, or 30)
- sentMessagesCounter integer Running count of quarter frame messages already sent in the current block
Returns:
- int Updated sentMessagesCounter
- int MIDI message packed as Integer (only when a message falls in this block)
- int Sample offset of the message within the block (only when a message falls in this block)
- mtcfullframe (hours, minutes, seconds, frames, rateType)
-
Make an MTC Full Frame SysEx message.
Constructs a 10-byte MIDI Time Code Full Frame SysEx message and writes it to the provided buffer.
The message format is: F0 7F 7F 01 01 hr mn sc fr F7, where the high 3 bits of hr encode the rate type.
Parameters:
- hours integer Hour value (0-23)
- minutes integer Minute value (0-59)
- seconds integer Second value (0-59)
- frames integer Frame value (0-29 depending on rate)
- rateType integer Frame rate type: 0=24fps, 1=25fps, 2=29.97df, 3=30fps
Returns:
- EL_Bytes buffer The buffer passed in (for chaining)
- int size Size of the message (always 10)
- mtcfullframetransport (currentSample, sampleRate, framesPerSecond)
-
Make an MTC Full Frame SysEx message from transport state.
Computes the timecode (hours, minutes, seconds, frames) from the current
playback position and builds the 10-byte Full Frame SysEx message.
The rate type is derived from framesPerSecond (24→0, 25→1, 29→2, 30→3).
Raises an error if framesPerSecond is not 24, 25, 29, or 30.
The message format is: F0 7F 7F 01 01 hr mn sc fr F7, where the high 3 bits
of hr encode the rate type.
Parameters:
- currentSample integer Current playback position in samples
- sampleRate number Audio sample rate in Hz
- framesPerSecond integer MTC frame rate (24, 25, 29, or 30)
Returns:
- EL_Bytes buffer The buffer passed in (for chaining)
- int size of the message (10)