MIDI. Documentation is one thing, implementation the other. O_o - Page 1
Forum section: electronics / projects

author: Yansi
author_rank: Super Contributor
timestamp: December 22, 2018, 10:54:06 pm
content: Hello,I am currently working on some project incorporating a MIDI interface. I am new to MIDI, never have worked with this stuff, so please bear with me.First, I need a documentation. If I could sum up my few minutes of googling around, this is the best (well, the only one usable) "documentation" of the MIDI interface:https://www.nyu.edu/classes/bello/FMT_files/9_MIDI_code.pdfI could find within that time frame.Then there is the "midi.org", where the full documentation is nowhere to be found, apart from numerous links to "pay them and then send whatever data you want through the MIDI interface". There goes the standard.Currently, I have a HW that should receive MIDI from a keyboard/controller. I have one such keys available, currently hooked up to my HW, trying to figure out what happens within the MIDI line.From what I see, is nowhere near what I have expected, based on the "documentation" above.Here I present the byte sequence I have recorded from my keyboard:Pressing a key (G#3 in the middle of the keys - according to the "documentation") produces this sequence: 7F B0 7B 0090 44 7F7BReleasing the key produces 00 00 44.What the hell?!!!Pressing the key next to the right, produces 7F B0 7B 0090 45 7F7B, release does 00 00 45So okay, I can see the control byte 90, telling channel 0 to start a note 45 with maximum velocity of 7F. But that is the only thing that makes sense. What's the rest of the rubbish? O_oThe note cut sequence of double zeros does not make any sense, according to the "documentation".Is this some non-standard implementation? Or am I reading the doc wrong? Or are the keys really a piece of junk?Thank you for any insight.Y.//EDIT: I can also see a B0 control byte, telling me a controller has changed, in this case a controller 7B to 00. You know, fun is, that I have found controller 7B is typically "all notes off" button. I don't understand a shit this keyboard is telling me.

author: Yansi
author_rank: Super Contributor
timestamp: December 22, 2018, 11:59:24 pm
content: So half issue solved. I needed to get myself a bit of rest too see the mistake: There was a tiny memory leakage, corrupting the receive buffer. (That's what gets created, where X-mass gets mixed with a pile of assembly language on an old system, where there is no debug possibility, neither writing a software monitor routine - UART already taken by the MIDI. Ugh!)So in fact the note on sequence as sent by the keyboard looks like this:C0 16B0 7B 0090 44 7F, note cut isB0 7B 00. Makes much more sense now!So it is telling me before each note, what sound bank is used - ugh, why? It is enough to tell once for all successive notes on that channel, isn't it?What is infuriating, is that B0 7B 00 sequence, used to tell "All not stop" simulating a (non existent) "all notes off" button.So indeed, some retarded moron nut-fucker has programmed the MIDI interface on this keyboard. This explains why I was not able to use the keyboard with a PC, it was behaving weird. Now we know why!Even if it would work like this, it would not play in polyphony, only one note at a time. Am I getting that correct?But the question remains - is this sequence something common within MIDI instruments? Should I make my HW compatible with such setup? Or is this complete exotic rubbish, where someone didn't do his one job right?Thanks

author: hamster_nz
author_rank: Super Contributor
timestamp: December 23, 2018, 12:18:01 am
content: Why be so angry at a protocol? As far as protocols go, MIDI is actually OK, considering it is from the 1980s....

author: Yansi
author_rank: Super Contributor
timestamp: December 23, 2018, 12:37:15 am
content: Well I am not angry at the protocol itself really, I get easily pissed of by websites like the MIDI organization has. I think it is pretty obvious to look for standards directly at the place where it comes from, however the midi.org site is of no help. I could find third party publications way easier. Even the SD card or USB specs can be downloaded quite easily, not to mention the RFCs for ethernet and such.But this is a bit offtopic.Yes, the data received were corrupted. Now receiveing correctly, as above. Yet the keyboard is producing I'd say a non-standard output.

author: hamster_nz
author_rank: Super Contributor
timestamp: December 23, 2018, 01:27:32 am
content: Good info is athttp://www.personal.kent.edu/~sbirch/Music_Production/MP-II/MIDI/midi_protocol.htm... Or you might need to do what we did in the 80s and buy a book. It is just that it it so old it predates the Internet (as we know it)

author: Rerouter
author_rank: Super Contributor
timestamp: December 23, 2018, 01:36:14 am
content: Its more likely that its similar to the J1939 Canbus protocol in the terms that the standard is behind a paywall and they tack on new functionality every now and then requiring a purchase of the newer standard,The unknown data is not following some escape character or similar? other protocols from the same era had commands that would escape out say a bulk transfer of data that didn't match the protocol.

author: oPossum
author_rank: Super Contributor
timestamp: December 23, 2018, 07:04:40 am
content: Quote from: Yansi on December 22, 2018, 10:54:06 pmIf you need a compact and complete MIDI parser in C, here is one I wrote a while ago.Code:// MIDI message handler function typedeftypedef void(*pfnMIDI)(unsigned cmd, unsigned d1, unsigned d2);// Dummy function for unhandled and undefined MIDI messagesstatic void midiNone(unsigned cmd, unsigned d1, unsigned d2) {}static const pfnMIDI mf = { // --- Array of MIDI function pointers// - System CommonmidiNone,// F0 Sysex beginmidiNone,// F1 Quarter framemidiNone,// F2 Song positionmidiNone,// F3 Song selectmidiNone,// F4 UndefinedmidiNone,// F5 UndefinedmidiNone,// F6 Tune requestmidiNone,// F7 Sysex end// - VoicemidiNone,// 8x Note offmidiNone,// 9x Note onmidiNone,// Ax AftertouchmidiNone,// Bx ControllermidiNone,// Cx Program changemidiNone,// Dx Channel aftertouchmidiNone,// Ex Pitch bendmidiNone,// Sysex data (system common)// - System Real TimemidiNone,// F8 ClockmidiNone,// F9 TickmidiNone,// FA StartmidiNone,// FB ContinuemidiNone,// FC StopmidiNone,// FD UndefinedmidiNone,// FE Active sensemidiNone// FF Reset};void parse_midi(unsigned c) {static const unsigned mis = { 4, 5, 6, 5, 0, 0, 0, 0, 2, 2, 2, 2, 1, 1, 2 };static unsigned state = 0, rs, d1, channel;static unsigned channel_mask = 0x0001;if(c & 0x80) {channel = c & 0x0F;if(c <= 0xEF) {if(channel_mask & (1 << channel)) {rs = c;state = mis[rs >> 4];} else state = 0;} else if(c <= 0xF7) {rs = c;state = mis;if(state < 5) mf(c, 0, 0);} else {mf[channel + 8](c, 0, 0);channel = rs & 0x0F;}} else switch(state) {case 1: mf[rs >> 4](rs, c, 0); break;case 3:mf[rs >> 4](rs, d1, c);state = 2; break;case 5:mf(rs, c, 0); state = 0; break;case 7:mf(rs, d1, c);state = 0; break;case 4:mf(rs, c, 0); break;case 2: case 6: d1 = c; ++state; break;}}One project it was used in was MIDI message display via NTSC video. Also used for a few MIDI software synths.

author: jeroen79
author_rank: Frequent Contributor
timestamp: December 23, 2018, 04:45:55 pm
content: Quote from: Yansi on December 23, 2018, 12:37:15 amI didn't find it hard to get the specification from midi.org.The did want me to register but after tyat everything was downloadable for free.https://www.midi.org/specifications

author: Yansi
author_rank: Super Contributor
timestamp: December 23, 2018, 05:38:39 pm
content: You seem to be done fast searching, could you please point me to a single (PDF) file covering the protocol?

author: diyaudio
author_rank: Frequent Contributor
timestamp: December 23, 2018, 05:57:12 pm
content: Quote from: oPossum on December 23, 2018, 07:04:40 amreally cool.

author: jeroen79
author_rank: Frequent Contributor
timestamp: December 23, 2018, 07:06:20 pm
content: Quote from: Yansi on December 23, 2018, 05:38:39 pmRight here:https://www.midi.org/specificationsLike I said, they want you to register but it is free.