Module xMidiInput
Use xMidiInput to interpret MIDI messages .
, support all common MIDI messages (including 14-bit)
Note that the multibyte/NRPN features require an extra bit of processing, and can delay the processing of "normal" (7-bit) messages - for this reason, the 14-bit processing is disabled by default.
How to use
The class is implemented with a callback, which will recieve xMidiMessages
-- define our callback
myCallback = function(msg)
-- do something with the message
end
-- Then, instantiate this class with the callback as argument:
myMidiInput = xMidiInput(myCallback)
-- Now you can feed it with raw midi messages:
myMidiInput:input({0x90,0x45,0x6F})
See also
Functions
input (msg, port_name) | process incoming message - will invoke the callback function when able to construct a xMidiMessage from the data that has been received |
_create_fingerprint (msg_type, midi_msgs) | Create MIDI 'fingerprint' for the provided message(s) (just enough information to identify the CC/NRPN source) |
assemble_nrpn_message (match_nrpn_num) | (Re)construct the table of MIDI messages that together form a complete NRPN message (compares the provided number with the active NRPN messages) |
add_multibyte_exempt (msg_type, msgs) | convenience method for adding messages to the exempt list |
on_idle () | Idle loop : process (or discard) multibyte messages, output messages which got delayed due to throttling |
Tables
self._multibyte_exempted | (table) messages that should never be interpreted as multibyte |
self._nrpn_msb_only | table |
self._mb_messages |
table of multibyte messages
|
self._nrpn_messages |
table of NRPN messages
|
Fields
self.callback_fn | (function) specify where messages should go |
self.multibyte_enabled | (bool) decide if multibyte (14-bit) support is enabled |
self.nrpn_enabled | (bool) decide if NRPN support is enabled |
self.terminate_nrpns | (bool) true when we expect a Null value from the device after receiving or transmitting a NRPN message (enabling this feature will transmit Null values too) important: only enable this feature if the device is known to transmit these messages (midi bytes 2&3: 0x65,0x7F followed by 0x64,0x7F) |
self.timeout | number, the amount of time that should pass before we consider a multibyte message obsolete (0.1 = tenth of a second) |
Functions
- input (msg, port_name)
-
process incoming message - will invoke the callback function when able
to construct a xMidiMessage from the data that has been received
Parameters:
- msg (table), raw MIDI message with 3 parts
- port_name (string), where message originated from
- _create_fingerprint (msg_type, midi_msgs)
-
Create MIDI 'fingerprint' for the provided message(s)
(just enough information to identify the CC/NRPN source)
Parameters:
- msg_type
- midi_msgs
Returns:
-
string
- assemble_nrpn_message (match_nrpn_num)
-
(Re)construct the table of MIDI messages that together form a complete
NRPN message (compares the provided number with the active NRPN messages)
Parameters:
- match_nrpn_num
Returns:
-
table or nil
[[
- add_multibyte_exempt (msg_type, msgs)
-
convenience method for adding messages to the exempt list
Parameters:
- msg_type
- msgs
- on_idle ()
- Idle loop : process (or discard) multibyte messages, output messages which got delayed due to throttling
Tables
- self._multibyte_exempted
- (table) messages that should never be interpreted as multibyte
- self._nrpn_msb_only
-
table
NRPN messages that only require the MSB part (7-bit) note that 7bit NRPN works without this, but might be a bit sluggish as we need to wait for the idle mode to determine that no LSB part arrived - self._mb_messages
-
table of multibyte messages
[fingerprint]{ type = [enum] msg_type timestamp = [number] channel = [int] num = [int] (only for CC messages) lsb = [int] msb = [int] port_name = [string] }
- self._nrpn_messages
-
table of NRPN messages
{ timestamp = [number] channel = [int] num_msb = [int] num_lsb = [int] data_msb = {int] data_lsb = [int] port_name = [string] }
Fields
- self.callback_fn
- (function) specify where messages should go
- self.multibyte_enabled
- (bool) decide if multibyte (14-bit) support is enabled
- self.nrpn_enabled
- (bool) decide if NRPN support is enabled
- self.terminate_nrpns
- (bool) true when we expect a Null value from the device after receiving or transmitting a NRPN message (enabling this feature will transmit Null values too) important: only enable this feature if the device is known to transmit these messages (midi bytes 2&3: 0x65,0x7F followed by 0x64,0x7F)
- self.timeout
- number, the amount of time that should pass before we consider a multibyte message obsolete (0.1 = tenth of a second)