midi_specification
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
midi_specification [2006/08/28 23:48] – added MidiDefinition Listing (C) zeichensprecher | midi_specification [2012/10/02 06:42] (current) – Reverting spam from lauraholden cheater | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== MIDI Specifications ====== | ||
+ | |||
+ | If you'd like a simplified explanation, | ||
+ | |||
+ | [[MIDI]] is a standardized way for the communication between musical devices. It specifies the physical interface as well as the transmission protocol. There are different types of MIDI messages, for a full list please follow the links below. | ||
+ | |||
+ | Here a short overview: each message begins with a status byte, where the 8th (leftmost) bit is set. Thereafter additional data bytes are sent, where the leftmost bit is always zero. Accordingly, | ||
+ | |||
+ | The number of bytes which have to follow is strictly tied to the type of message, only exception are System Exclusive messages, where the data bytes are framed by a start and stop identifier. | ||
+ | |||
+ | Some MIDI messages like RPN, NRPN and Pitch Bender allow to combine two 7bit values to a 14bit value. This extends the value range to 0-16383 (decimal) or 0x0000-0x3FFF hexadecimal - more than enough for todays synthesizers (most of them still only support 7bit resolution). | ||
+ | |||
+ | MIDI bytes are mostly displayed in hexadecimal form to simplify the reading. Therefore we will continue with this value format below, and won't mention the appr. decimal values anymore. | ||
+ | |||
+ | Status bytes in the range of 0x80..0xEF contain a channel information, | ||
+ | |||
+ | For Example: | ||
+ | 0x90 identifies a Note On event at the first Channel | ||
+ | 0x91 identifies a Note On event at the second Channel | ||
+ | ... | ||
+ | 0x9F identifies a Note On event at the 16th Channel | ||
+ | |||
+ | Thanks to this coding, it's very simple to identify the Channel, just read the rightmost hexadecimal digit. | ||
+ | |||
+ | The last 4 bits (leftmost hexadecimal digit) identifies the MIDI event type: | ||
+ | 8: Note Off | ||
+ | 9: Note On | ||
+ | A: Polyphonic Key Pressure (Poly Aftertouch) | ||
+ | B: Control Change (CC) | ||
+ | C: Program Change | ||
+ | D: Channel Pressure (Aftertouch) | ||
+ | E: Pitch Bender | ||
+ | |||
+ | Follow this [[http:// | ||
+ | |||
+ | |||
+ | F identifies a System Message which either addresses all listeners (there is no MIDI channel), or which addresses dedicated MIDI devices which are parsing for a SysEx (System Exclusive) stream. | ||
+ | |||
+ | E.g., MIOS "feels addressed" | ||
+ | [[SysEx]] messages should be finished with 0xF7, thereafter any other MIDI event can be sent again. | ||
+ | |||
+ | The last Status Bytes within the range of 0xF8..0xFF - also called " | ||
+ | |||
+ | A typical realtime message is the MIDI clock 0xF8 - since it is allowed to send the clock at any time, regardless of the currently sent stream - the achievable latency is very low. In addition, realtime messages don't change the running status - more about this topic (status byte can be omitted if the same one was sent before) can be read in the MIDI spec. | ||
+ | |||
+ | |||
+ | \\ | ||
+ | \\ | ||
+ | |||
+ | ====== Programming Examples ====== | ||
+ | |||
+ | At the end some practical informations for MIOS programmers (examples are written in [[C]]): | ||
+ | |||
+ | MIDI bytes are sent with the MIOS_MIDI_TxBufferPut() function: | ||
+ | |||
+ | <code c> | ||
+ | MIOS_MIDI_TxBufferPut(0x90); | ||
+ | MIOS_MIDI_TxBufferPut(0x40); | ||
+ | MIOS_MIDI_TxBufferPut(0x64); | ||
+ | </ | ||
+ | |||
+ | will send a Note On event at Channel 0 (first channel, in most MIDI applications called Channel #1 when they are counting from 1). The Note number is 0x40 (E-3), the velocity is 0x64 | ||
+ | |||
+ | The appr Note Off event starts either with 0x80, or with 0x90 (running status optimisation) and velocity 0x00: | ||
+ | |||
+ | <code c> | ||
+ | MIOS_MIDI_TxBufferPut(0x90); | ||
+ | MIOS_MIDI_TxBufferPut(0x40); | ||
+ | MIOS_MIDI_TxBufferPut(0x00); | ||
+ | </ | ||
+ | |||
+ | |||
+ | Other typical MIDI events are Controllers (CC), they begin with 0xbn (n = Channel): | ||
+ | |||
+ | <code c> | ||
+ | MIOS_MIDI_TxBufferPut(0xb8); | ||
+ | MIOS_MIDI_TxBufferPut(0x01); | ||
+ | MIOS_MIDI_TxBufferPut(0x7f); | ||
+ | </ | ||
+ | |||
+ | |||
+ | If the MIDIbox Link mechanism should be used to tunnel MIDI events through the MIDIbox Link Endpoint, a MIDI stream has to be framed by a begin and end function in the following way: | ||
+ | |||
+ | <code c> | ||
+ | MIOS_MIDI_BeginStream(); | ||
+ | MIOS_MIDI_TxBufferPut(0xcf); | ||
+ | MIOS_MIDI_TxBufferPut(0x02); | ||
+ | MIOS_MIDI_EndStream(); | ||
+ | </ | ||
+ | |||
+ | |||
+ | And the last example shows, how to save MIDI bandwidth (the transmission of a single byte takes 320 uS) by using the Running Status feature (as mentioned above: so long the following status bytes are equal, we can omitt them): | ||
+ | |||
+ | <code c> | ||
+ | MIOS_MIDI_BeginStream(); | ||
+ | MIOS_MIDI_TxBufferPut(0x90); | ||
+ | MIOS_MIDI_TxBufferPut(0x3c); | ||
+ | MIOS_MIDI_TxBufferPut(0x7f); | ||
+ | MIOS_MIDI_TxBufferPut(0x40); | ||
+ | MIOS_MIDI_TxBufferPut(0x60); | ||
+ | MIOS_MIDI_TxBufferPut(0x43); | ||
+ | MIOS_MIDI_TxBufferPut(0x40); | ||
+ | MIOS_MIDI_EndStream(); | ||
+ | </ | ||
+ | |||
+ | |||
+ | \\ | ||
+ | \\ | ||
+ | |||
+ | ====== 14-bit MIDI Messages ====== | ||
+ | |||
+ | There are two ways to use 14-bit MIDI Messages; the trick is, to combine two 7-bit Messages to one 14-bit: | ||
+ | <code c> | ||
+ | unsigned int MSB = 127 << 7; // 16256 | ||
+ | unsigned char LSB = 127; // 127 | ||
+ | unsigned int largeNumber = MSB + LSB; // 16383: | ||
+ | </ | ||
+ | * using RPNs | ||
+ | * using NRPNs: <code c> | ||
+ | CC98 01100010 0x62 Non-Registered Parameter Number (NRPN) - LSB 0-127 LSB | ||
+ | CC99 01100011 0x63 Non-Registered Parameter Number (NRPN) - MSB 0-127 MSB | ||
+ | </ | ||
+ | * sending two Controller Messages, eg:< | ||
+ | CC 12, Effect Ctrl 1 (MSB = Most Significant Byte) | ||
+ | CC 44, Effect Ctrl 1 (LSB = Least Significant Byte)</ | ||
+ | |||
+ | Sending 14bit from one pot is only possible if you're hacking the code. Because Pots are being read as 10-bit value, you have to interpolate to 14 bit and implement a NRPN or dual-CC method. | ||
+ | |||
+ | Further informations: | ||
+ | [[http:// | ||
+ | [[http:// | ||
+ | |||
+ | |||
+ | \\ | ||
+ | \\ | ||
+ | |||
+ | ====== Tools & Helpers ====== | ||
+ | |||
+ | [[ACMidiDefines]] – a definition listing to access Midi Events by Name | ||
+ | |||
+ | |||
+ | \\ | ||
+ | \\ | ||
+ | ====== More Informations ====== | ||
+ | |||
+ | More informations can be found online:\\ | ||
+ | |||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | |||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | |||
+ | * [[http:// | ||
+ | |||
+ | * [[http:// | ||