low-level MIDI handling

Pulling out your hair? Don't know what to do or where to go? Ask in here.
Forum rules
READ: VSE Board-Wide Rules and Guidelines

If your Help request has been solved, please edit your first post in order to select the Image Topic Icon to let others know your topic has been solved.
Post Reply
User avatar
joeboy
Junior Member
Junior Member
Posts: 102
Joined: Tue Jul 17, 2012 1:22 am
Gear: ax-80, jx-8p, v-synth, monotribe, ПИФ, tx81z, sy35, tg77
Location: 熊本

low-level MIDI handling

Post by joeboy » Wed Jan 20, 2016 1:41 pm

I have a Raspbery Pi running FreeBSD, but I think this is more of a general question about MIDI message encoding, so please keep reading even if you run a different OS.

I have my SY-35 hooked up to the Pi with one of those generic Chinese USB->MIDI devices
I can record some sort of MIDI data to a file by running

Code: Select all

dd if=/dev/umidi0.0 of=/tmp/file bs=1
and playing the keys
(if I engage aftertouch it crashes the connection, but that's another matter entirely)

But when I open that file up, it's a bunch of gibberish. The kind of thing you get when you open a binary package in a text editor: (~P?-~P?^@♦~P3^@=0...)

Question 1: what exactly is that gibberish, and how do I translate it into something more meaningful?

The captured input can be routed back into the synth with:

Code: Select all

dd if=/tmp/file of=/dev/umidi0.0 bs=1
but all the notes play at once without any regard for time.

Question 2: if I wanted to play a midi note on the SY-35 directly from the Pi, in what format would the information need to be passed? What basic system command would I issue?

I'm sorry if this is too specific, but there seem to be a lot of dudes here who know their MIDI, so hopefully somebody might be able to point me in the right direction.

User avatar
joeboy
Junior Member
Junior Member
Posts: 102
Joined: Tue Jul 17, 2012 1:22 am
Gear: ax-80, jx-8p, v-synth, monotribe, ПИФ, tx81z, sy35, tg77
Location: 熊本

Re: low-level MIDI handling

Post by joeboy » Wed Jan 20, 2016 2:01 pm

So continuing to search and twiddle, I found out about the hexdump command.
This is what playing middle C gives me, after running hexdump:

Code: Select all

0000000 fefe fefe fefe fefe fefe 3c90 903a 003c
*
0000010
It looks like something now, but I'm not sure what to try next. I know very little about how data is represented

User avatar
desmond
Active Member
Active Member
Posts: 690
Joined: Tue Oct 11, 2005 12:32 pm
Contact:

Re: low-level MIDI handling

Post by desmond » Wed Jan 20, 2016 8:22 pm

Just look up the MIDI specification online - it will tell you all you need to know about what data types there are, and how they are represented - eg a Note On has a particular value, and is three bytes - the first byte is the Note On message and also the MIDI channel, the second byte is the note number, and the third byte is the velocity.

There's nothing very hard here to understand, it's very straightforward.

User avatar
synthroom
Senior Member
Senior Member
Posts: 876
Joined: Sat Sep 08, 2012 3:16 pm
Real name: Kirk
Gear: Fairlight IIx(!), JP-8, D-50, S-50+550, S-760, JX-3P, JD-800, EII, Emax II, Mini, ARP 2600, P-5 Rev.1, Pro-One, Performer, K1m, K5m, few other things.
Location: pdx
Contact:

Re: low-level MIDI handling

Post by synthroom » Wed Jan 20, 2016 9:48 pm

Just asking - is baud rate important here? Roland D-50s are particular about the data transmittion rate and modern computer/midi interfaces are too fast for the D-50. Perhaps something like that is going on here?
Fairlight IIx (Mid-Life Crisis - cheaper than a Corvette!)
Roland JP-8, D-50, S-50, S-550(2x), S-760(2x), JX-3P, JD-800
EII, Emax II, Minimoog, ARP 2600, P-5 Rev.1 (broken...), Pro-One, Crumar Performer, K1m, K5m, MS-2000B, Virus KC, a few other things.

User avatar
joeboy
Junior Member
Junior Member
Posts: 102
Joined: Tue Jul 17, 2012 1:22 am
Gear: ax-80, jx-8p, v-synth, monotribe, ПИФ, tx81z, sy35, tg77
Location: 熊本

Re: low-level MIDI handling

Post by joeboy » Thu Jan 21, 2016 12:49 pm

desmond wrote:Just look up the MIDI specification online - it will tell you all you need to know about what data types there are, and how they are represented - eg a Note On has a particular value, and is three bytes - the first byte is the Note On message and also the MIDI channel, the second byte is the note number, and the third byte is the velocity.

There's nothing very hard here to understand, it's very straightforward.
I had read up on the basics of MIDI before I started messing around. I was expecting a bunch of ones and zeroes instead of the output I got.
I've since found out about xxd, which does what I'm looking for.
synthroom wrote:Just asking - is baud rate important here? Roland D-50s are particular about the data transmittion rate and modern computer/midi interfaces are too fast for the D-50. Perhaps something like that is going on here?
I don't think so. I was able to play notes on the sy35 after I passed correctly-formatted data

Sorry if this is a dumb thread. I'm learning about binary, raw, and hex data as I go along

User avatar
meatballfulton
Moderator
Moderator
Posts: 5793
Joined: Wed Apr 13, 2005 9:29 pm
Gear: Logic Pro X

Re: low-level MIDI handling

Post by meatballfulton » Thu Jan 21, 2016 12:55 pm

A lot of the MIDI docs show binary rather than hex for some reason. It's a PITA to read binary, esp.since most sequencers and MIDI monitors display in hex and you constantly have to do the conversions.

Have fun.
I listened to Hatfield and the North at Rainbow. They were very wonderful and they made my heart a prisoner.

User avatar
joeboy
Junior Member
Junior Member
Posts: 102
Joined: Tue Jul 17, 2012 1:22 am
Gear: ax-80, jx-8p, v-synth, monotribe, ПИФ, tx81z, sy35, tg77
Location: 熊本

Re: low-level MIDI handling

Post by joeboy » Thu Jan 21, 2016 2:20 pm

I found the 1s and 0s useful for explaining what exactly is in each byte.
In any case, I just would up using the write() function in C, which passes the note-on as hex in this tutorial.

I guess that's really all I need to do for the time being. It's nice how simple UNIX can be.

User avatar
Tidda
Junior Member
Junior Member
Posts: 154
Joined: Sat Sep 16, 2006 5:30 pm

Re: low-level MIDI handling

Post by Tidda » Sat Jan 23, 2016 8:15 pm

joeboy wrote:So continuing to search and twiddle, I found out about the hexdump command.
This is what playing middle C gives me, after running hexdump:

Code: Select all

0000000 fefe fefe fefe fefe fefe 3c90 903a 003c
*
0000010
It looks like something now, but I'm not sure what to try next. I know very little about how data is represented
Your bytes are in the wrong order for translation purposes because of the way your computer stores them in a file. (difference between big and little endian)
So it actually is: fe fe fe fe fe fe fe fe fe fe 90 3c 3a 90 3c 00

fe = active sense message (10x)
90 = note on, on channel 1 for note number ..
3c = middle C, with a velocity of ..
3a = 58 (decimal) followed by another ..
90 = note on, on channel 1 for note number ..
3c = middle C, with a velocity of ..
00 = zero (in this case note off message is implemented as a note on message with value 0)

User avatar
joeboy
Junior Member
Junior Member
Posts: 102
Joined: Tue Jul 17, 2012 1:22 am
Gear: ax-80, jx-8p, v-synth, monotribe, ПИФ, tx81z, sy35, tg77
Location: 熊本

Re: low-level MIDI handling

Post by joeboy » Sun Jan 24, 2016 7:20 am

Thank you for that explanation. It will come in handy when I start thinking about things beyond note-on and note-off.

Right now I'm using srfi-4 in Scheme to send messages to the hardware, and I can just specify integer values for each byte, which is nice.

raito
Newbie
Newbie
Posts: 4
Joined: Sat Dec 26, 2015 3:58 am

Re: low-level MIDI handling

Post by raito » Mon Feb 01, 2016 8:43 pm

A couple of points:

Your notes play back all at once because you're just dumping the file back over MIDI. When you recorded it, the command just kept adding to the file. When you play it back, there's no timing, so it just goes out as fast as it can. MIDI recorders also timestamp the incoming data. I'd recommend looking up the MIDI file specification, and adjusting your programming to add the correct information to the files you save.

Many of the MIDI docs use binary because the MIDI spec starts out with an electrical specification, and works up from there. If you were looking at your MIDI stream with an oscilloscope you'd be doing the conversion the other way.

In theory, MIDI bit rate is 31250/sec. Note that while in this case bit rate is equal to baud rate, that's not the case for all communications. Exceeding that is technically not allowed by the spec, though any unit that insists on it probably isn't being smart.

Scheme huh? I do all my stuff outside work with ANSI Common Lisp.

User avatar
cornutt
Moderator
Moderator
Posts: 2117
Joined: Sun Dec 02, 2007 6:03 am
Gear: 6th
Location: Rocket City USA
Contact:

Re: low-level MIDI handling

Post by cornutt » Sat Feb 13, 2016 9:34 pm

raito wrote: In theory, MIDI bit rate is 31250/sec. Note that while in this case bit rate is equal to baud rate
Not the data bit rate. MIDI uses 8 data bits, 1 start bit and 1 stop bit. So it's 10 baud for every 8 data bits, and you get 3125 data bytes/sec.
Switches, knobs, buttons, LEDs, LCD screens, monitors, keys, mice, jacks, sockets. Now two joysticks!

Post Reply