Difference between revisions of "MIDI notes"

From Helpful
Jump to: navigation, search
m (RPN and NRPN)
(6 intermediate revisions by the same user not shown)
Line 317: Line 317:
::: many to specific synth parameters (portamento, soft, volume, balance, attack, sustain, release, brightness, detune, channel volume, other effect amount)
::: many to specific synth parameters (portamento, soft, volume, balance, attack, sustain, release, brightness, detune, channel volume, other effect amount)
:::: ...except for pitch bend - which has its own message (see above)
:::: ...except for pitch bend - which has its own message (see above)
:: '''6, (38,) 96, 97, 98,99, 100,101''' are intended as a more free-form extensible thing, including the [[#RPN and NRPN|RPN and NRPN]] extension
:: '''6,38, 96,97, 98,99, 100,101''' are involved in a more free-form extensible thing, including the [[#RPN and NRPN|RPN and NRPN]] extensions (which also allow 14-bit values) <!--
::: 98, 99 - NRPN
::: 100, 101 - RPN
::: 6, 38 - Data Entry for  RPN, NRPN
::: 96, 97 - increment, decrement for RPN, NRPN
:::: '''3, &nbsp; 9, &nbsp; 14 through 31, &nbsp; 85 through 90, &nbsp; 102 through 119''' are general-purpose or undefined, so
Line 344: Line 352:
=====RPN and NRPN=====
=====RPN and NRPN=====
Where CCs are a predefined and stable set of parameters,  
there was a wish for further control specific to devices.
Where a good set CCs are a predefined and stable set of parameters,  
and a number were undefined or general-purpose
there was a wish for more flexible control specific to devices.
NRPNs are sent via CC 99 (NRPN Most Significant Byte) CC 98 (NRPN Least Significant Byte)
NRPNs are sent via CC 99 (NRPN Most Significant Byte) CC 98 (NRPN Least Significant Byte)
Line 353: Line 362:
RPNs are sent via CC 101 (RPN Most Significant Byte) and CC 100 (NRPN Least Significant Byte)
RPNs are sent via CC 101 (RPN Most Significant Byte) and CC 100 (NRPN Least Significant Byte)
There are only a few RPNs:
* 0: pitch bend sensitivity (or rather range)
* 1: fine tuning
* 2: coarse tuning
* 127: RPN null
and apparently later{{verify}}
* 3: Tuning Program Select
* 4: Tuning Bank Select
There are only a few RPNs. In MSB, LSB pairs:
* (0,0): pitch bend range
* (0,1): fine tuning
* (0,2): coarse tuning
* (127,127): RPN null / reset (clears the parameter being modified)
After either CC99+CC98 or CC101+CC100
And apparently later{{verify}}
comes a CC06 (data entry MSB) and a CC38 (data entry LSB)
* (0,3): Tuning Program Select
* (0,4): Tuning Bank Select
And also:
* (0,5) Modulation Depth Range  (from GM2 specs)
* (0,6) MPE Configurarion Message (from MPE specs)
* (0x3D, 0 through 8): Three Dimensional Controllers
Ther eis also some use of CC96 (data increment) and CC97 (data decrement) {{verify}}
: CC 101 - RPN parameter's Most Significant Byte 
: CC 100 - RPN parameter's Least Significant Byte
: CC6 MSB value
: CC38 LSB value (optional)
Because the latter two set the last-selected (N)RPN,
you can save a few bytes when frequently altering ne thing.
RPN 127 exists to reset that behaviour to alter nothing instead,
which can
NRPNs are the same, but start with
: CC 99 - NRPN parameter's Most Significant Byte
: CC 98 - NRPN parameter's Least Significant Byte
and basically all
The rest isn't standardized, and will have to come from manuals of the devices you have
Since the last-selected parameter stays active
: you can also send CC96 (data increment) and CC97 (data decrement) {{verify}}
: it is considered good practice to set a reset after you're done
The rest isn't standardized, and will have to come from manuals of the devices you have
There are some groups of definitions, such as  
There are some groups of definitions, such as  
Line 385: Line 404:
: Rolands GS{{verify}}
: Rolands GS{{verify}}

Revision as of 20:09, 20 May 2020

This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)

MIDI buses

Serial MIDI

The classic, seen on thirty years of devices.

This is a fairly standard serial port, in one direction, sending octets, at 31250 (±1%) baud.

The plug is the 180-degree 5-pin DIN variant (see also IEC 60130-9).

DIN pin numbering
(note that some pinout charts use their own numbering, so pay attention)
  • 1 NC
  • 2 Shield (disconnected on the receiving side)
  • 3 NC
  • 4 Source
  • 5 Sink

Each device connection (pin 4+5) is a 5mA current loop (rather than voltage-referenced), so being able to drive that much is more important than exact voltage.

In most devices you effectively drive the LED part of an optocoupler, so you mostly just need to add a reasonable resistor for the voltage you have (and the max current of your output pinIO pins can sink, which usually isn't limiting).

MIDI cables may only have 3 wires, but might have 5.

This isn't relevant to standard uses of MIDI, since pins 1 and 3 are unconnected in sockets, on both ends.

There are non-standard devices that do use the extra pins, though.

The three ports, roughly according to the MIDI spec

In the schematic on the right:

  • D1 is used to protect the optocouple from reverse polarity, but also from cable effects. Most any fast-switching diode will do.
it's a good idea for DIY, though could be omitted.
  • R1 is current-limiting resistor for the optocoupler's LED.
frequently 220 Ohm but this doesn't matter very precisely
  • R2 is a current limiter and pullup(verify), and is often a higher value (0.5k .. 10kOhm), maybe check your optocouple specs
they're in the original MIDI specs because, at the time, many things couldn't directly drive 5mA (and in those specs it's two triangles, because two inversions on e.g. a 74LS14 hex inverter ICs was a simple and cheap solution)
These days you're probably using a microcontroller, which tend to have buffers on each pin that can drive on the order of 30mA, so you could omit this
It's still not a bad idea (ease-of-repair-wise) to protect your IC by using a transistor, though. Same for the diode.
Then it's a good idea to use a resistor (here R4, R6) to limit the current through it.
  • cable shield should be connected only on the source side (avoids ground loops)
...within the devices, that is. The cable itself should connect it on both ends so that cable doesn't have a direction.
note that the socket on the IN end should not connect the DIN barrel/pin 2

Simplified somewhat, showing wire shield, and drawn to clarify the "you're mainly just powering that LED through a long wire" view.

Plugging around devices

MIDI is one-directional , in that any earlier device can play (only) any later device (selectively because communication has channels), because that's the direction messages go.

This means the order devices are hooked up in matters. And you'ld generally put just-controllers earlier, just-synths at the end, and think a little harder about the playable-and-controllable things in the middle (including a PC if involved).

Devices may have three different sockets:

  • MIDI IN - usually means it will play sound
  • MIDI OUT - usually means the device itself generates messages
  • MIDI THRU - a (output-buffered but otherwise direct) copy of of the IN plug.

While you can think up complex cases, most real-world cases are relatively simple, largely because of what each device is.

Note that THRU connections in series will slowly add timing errors (due to optocouple time), so if you have a house full of devices in a single long chain you may notice some latency from start to end. Few people will run into this, and you can reduce it by adding splitters early (building a tree instead of one long chain).

MIDI and power

MIDI does not carry power. (This also helps it avoid ground loops)

There are some devices that use pins 1 and 3 to provide power. I haven't yet found anything on conventions about polarity or voltage.

There is also the rare oddity that puts something else on pins 1 and 3. In theory that conflicts, but doing it wrong usually requires you to wire an output to an output, with a 5-wire cable, and chances are decent against you doing that.

Still, if you want this in your design, consider the slightly safer option of using a 7-pin DIN socket, because the extra two pins won't connect when inserting a standard 5-pin plug.


This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)

USB-MIDI protocol is mostly modelled on serial MIDI packets, though it adds a few things, like a field called Cable Number, mostly for ease of routing(verify).

Since the transfer rate of USB is much higher (and devices are connected individually anyway), the timing pileup serial MIDI has is basically absent (though note it's not a realtime bus, so there are still some footnotes to this).

Distinct devices connected via USB-MIDI appear as distinct controllers with one MIDI device on them, so there's more focus on routing within the host (usually a PC) than before.

USB-MIDI is part of the USB standard, which means PCs support it easily, but more interestingly that relatively simple simple USB devices and hosts can speak it.

For example, an arduino with USB host shield can talk to USB-MIDI keyboards/pads with little code.

It also makes interconnecting less universal than DIN-to-DIN, as you now need a PC -- or something else designed for this interchange, like a USB midi host. There are also Raspberry Pi / Arduino style solutions. [1]



Byte protocol

Note that some of this focuses on the serial nature of the original serial implementation, and works a little differently in other variants.

Devices can ignore a messy message and focus on a new one immediately, without any state, because the highest bit is set only in the start byte of a message, and additional bytes never do. (The only sort-of-exception is SysEx, which also ends with one, but still should not contain any)

Message types are conceptually subdivided like:

  • Channel Message
    • Channel Voice messages - Note On, Note Off, and other voice triggering stuff
    • Channel Mode messages - say what the voices should do in response to voice messages (see more below)
...note that this is similar to ControlChange (which fall under Channel Voice)
  • System Message
    • System Real Time messages - meant for synchronization between MIDI devices (that support this, relatively few(verify)).
    • System Common messages - meant for all receivers, regardless of channel. Also used for some external hardware like tape (not seen very often).
    • System Exclusive (a.k.a. SysEx) messages
sent to a specific Manufacturer's ID
mostly to allow manufacturer-specific communication (though there are some predefine universal ones)
Also used to implement MIDI Machine Control
Due to variable-length behaviour, terminated with a specific package.

Channel voice

The most central in the music-making sense:

  • NoteOff
1000cccc 0nnnnnnn 0vvvvvvv
(note that NoteOn with a velocity of 0 is basically equivalent to a note off message)
  • NoteOn
1001cccc 0nnnnnnn 0vvvvvvv
where c refers to channel, n to note, and v t velocity
note is C0 to G10 (8Hz..12kHz) in semitone steps, so e.g. middle C is 60
e.g. an 88-key keyboard will use ~three quarters of the full 0..127 range
velocity of 64 is often used when there is no touch sensitivity
  • PitchBend
were V is an unsigned 14-bit integer value (0..16384), and the halfway value 8192 means no pitch bend.
The amount of tone range that the full is chosen by the listening side, apparently often an octave(verify)
the sending side can choose a smaller range by using less of that fairly large integer range

And perhaps

  • Aftertouch is further expression to playing notes.
Few instruments send it, few synths instruments listen to it, but it's nice to use when you have it (also, DAWs typically allow mapping it to something)
On keyboards (that have it) it is usually a force sensor that only does a thing when you lean harder into keys, and isn't particularly related to velocity. It's often also per-channel, i.e. there's just one sensor below all keys.
In some other cases (e.g. sensitive pads) it can be a more of a 'how softly you are letting go', and often also polyphonic (sent for each key, not per channel)
If sensed per key, it is sent in Polyphonic Key Pressure (1010cccc 0nnnnnnn 0vvvvvvv)
If sensed overall, it is sent in Channel Pressure (1101cccc 0vvvvvvv)

  • ControlChange is meant for when the state of a footswitch, pedal, slider, etc (a usually-physical controller) changes
1011cccc 0CCCCCCC 0vvvvvvv
where C is controller number, and v is a value
controller number....
120 through 127 have functions like reset, mute, local control, omni on/off, poly on/off - and are considered channel mode messages, see below
0 through 101ish change how a synth behaves on a specific channel
some for specific controller types controller types (breath, foot)
many to specific synth parameters (portamento, soft, volume, balance, attack, sustain, release, brightness, detune, channel volume, other effect amount)
...except for pitch bend - which has its own message (see above)
6,38, 96,97, 98,99, 100,101 are involved in a more free-form extensible thing, including the RPN and NRPN extensions (which also allow 14-bit values)

  • ProgramChange
1100cccc 0nnnnnnn
change the instrument patch. General Midi has a standard list, not all hardware need follow this.
this idea is extended by ControlChange 0, though it's less stanardized how
on some hardware (e.g. drum machines) it may have other functions



Channel mode

CC messages with controller numbers 120 .. 127 are considered Channel Mode Messages.


120: All Sound Off
121: Reset All Controllers
122: Local Control
basically, local=off says "you, a keyboard+synth, should send notes to MIDI out instead of playing yourself (also still plays what it gets)" (verify)
123: All Notes Off - useful for sequencers, particularly in the context of omni and poly
124: Omni Off
125: Omni On
126: Mono (note: has a parameter)
127: Poly

Omni=on means messages received from all channels are played.

Mono means a new NoteOn should end the previous note

You may want this for portamento/glissando
and makes sense for some instruments, like guitar controllers

More specifically,

Mode 1 (Omni On, Poly) - from all channels
Mode 2 (Omni On, Mono) - from all channels, control one voice
Mode 3 (Omni Off, Poly) - from specific channel, to all voices
Mode 4 (Omni Off, Mono) - from specific channel, to specific voices


Some controllers and DAWs have a 'panic' button used for "argh I have no idea why you are still making sound, please stop it". This sends 123 and/or 120. And sometimes also NoteOff for all notes, in case a sound producer doesn't understand 123.

System Messages

All 1111....

Divided into

System Common Messages (1111000 through 11110111)
SysEx (11110000 (data) 11110111)
System Real-Time Messages (1111000 through 11111111)
all single-byte, no data

There's time/song/tuning stuff is in both these sections, so there's no huge distinction except some scheduling detail (e.g. real-time messages may be sent during SysEx).

SysEx is used for a lot of stuff that fits nowhere else

e.g. device-specific interaction stuff (usually in the manual) that doesn't suit CCs
some parameter upload stuff (e.g. DX7 SysEx)

MIDI monitors may report all of this as SysEx, just because most of it's special-cased control stuff.

SysEx takes the form of

0xF0 (SysEx start)
Manufacturer ID (1 or 3 bytes), helps synths decide whether it should try to read the message [2]
a variable amount of bytes
0xF7 (SysEx end)

On timing, bandwidth, latency

This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)

Serial MIDI is fixed at 31250 bits/second, slow by modern standards. Not too bad and was easy to implement at the time.

Sending a byte (counting start and stop bits) takes 320 microseconds, and since messages are one, two, or three bytes long, so most things arrive in 1 millisecond.

Yet wanting to send, say, 10 messages all at once means the last will by physically put on the wire ~10ms later.

There are a few tricks to alleviate this on serial MIDI, including but not limited to:

  • Running Status skips the first byte of a message if it's the same as the last.
e.g. allowing shortening of a handful of NoteOns, or a bunch of CCs,
  • Note that a running-status NoteOn with velocity 0 is one byte shorter than a NoteOff
and understood as identical same by most synths

The throughput limit rarely matters to human playing, because our timing is never robotically perfect, and saturating the bus with note messages would require playing so fast it wouldn't be musical.

It can start to matter with

MIDI sequencers, which may wish to send a bunch of things exactly on a beat
continuous change of pitch/modulation wheel, polyphonic aftertouch, or other fast CC
but an even slightly clever controller prioritizes note playing higher, so this should not matter
The strongest argument (for something faster) may be Polyphonic Expression (altering parameters per played note), as that is currently often implemented assigning notes and their alterations on channels, round-robin.
again, there are alleviations, but

In USB-MIDI, the data that is transmitted is almost entirely the same, but due to the way it is packed and the higher speeds involved, the latencies don't really add up anymore. (The latency of USB itself is still ~1ms, though, due to the way the OS handles it).

MIDI Sync and timing

Beat clock




Mackie Control Universal (MCU), and Mackie's HUI, and (also audio IO), refers to a physical controller for DAWs (just Logic at first), originally from the late ninties and originally specific to Logic.

These days there are many alternatives to such devices, often with their own (also often proprietary) protocols

MCU/HUI is for a large part just a specific convention on top of MIDI.

The point of this is mostly to have a standard for all the things it wanted, rather than telling you to manually map lots of CCs to specific controls before anything much worked.

Other DAWs and devices have chosen to support this for compatibility/feature reasons.

It's implemented mostly in SysEx. While it was kept closed for years, there's decent documentation available e.g. in logic control, MIDI Implementation section.

MMC (MIDI Machine Control)

MSC (MIDI Show Control)


MVC (MIDI Visual Control)

MIDI Visual Control Specification.pdf

Fragmented notes on mapping

Other stuff

Octave numbering


General MIDI


Scaled Polyphonic MIDI was targeted mainly at ringtones on simpler/earlier mobile phones.

It allows SMF files to say how they should be simplified to play on devices that make only simpler sounds.


MIDI software

MIDI hardware and DIY

More expression, and MPE

MIDI 2.0

See also

See also: