Code Wizards

MIDI SysEx Yell Real Loud

As our stage performances become more automated, it becomes challenging to align our disparate systems to know which song is being played. This means that we might need to configure our pedal board, laptop, keyboard, and other software to be aware of each change. At OnSong we believe that the value of software comes when it works together with other software. That’s why we are taking a bold step to invent a protocol that can allow MIDI enabled apps and hardware to listen for changes and react in their own way.

How This Sorcery Works

OnSong can be set to shout out info about the currently selected song with a proprietary system exclusive message. Relax, these messages are easy to decode, so your third-party hardware or software can keep performances in sync. Nobody gets left behind. Well, besides your drummer.

Any gadget hooked up via MIDI to an Android or Apple device runnin’ OnSong can eavesdrop on these messages. Link every computer & doohickey on stage to a network MIDI session & let ’em all gossip. Total chaos, totes worth it.

These System Exclusive messages, aka “SysEx”, are data zoomin’ over MIDI as a 7-bit stream that doesn’t care about channels. We’ll squint at it in hexadecimal “nibbles” so your brain can handle it. NOM NOM NOM.

Nom-Nomming the Song Data

Songs are made of metadata like song title & key. To keep things short (you’re welcome), each name-value pair is separated by a carriage return, or “0D”. The classic move: decode the data into ASCII text, split the string by carriage returns “\r” & start chewin’ through each metadata piece. Nom nom.

For each pair, the first ASCII character you meet tells you the metadata tag type. The song title’s tag, for example, is a capital “S”. So if you run into “SWelcome to OnSong”, the song title is simply “Welcome to OnSong” where “S” announces the type of metadata that follows. The value is ALWAYS a string. Numbers arrive as strings, not as numeric values encoded in data. That way the whole message can be processed as a string once it lands. You’re welcome, LOL.

The order of these tags? Not guaranteed. Deal with it. But we usually put the shorter, popular tags first so stuff processes faster. You’ll see there are ways to request more metadata tags in every message with special SysEx messages. Greedy much?

Chopping It Up, Piece by Piece

First, all SysEx messages begin with an “F0” nibble to indicate that the data that follows is a system exclusive message. The message is likewise terminated with an “F7” nibble. The contents in between carry the message. To avoid conflict, each manufacturer is assigned a Manufacturer ID. That means that directly following the initial SysEx nibble is a series of three other hexadecimal pairs, “00 02 24”. This is the OnSong-specific manufacturer identifier. If you’re planning to listen for OnSong SysEx messages, you’ll want to look for that sequence at the start of the data stream.

The most popular message in OnSong SysEx is the song broadcast. The nibble right after the manufacturer prefix is a carriage return with a hexadecimal value of “0D”. Once you spot it, the rest of the stream up to the terminating “F7” nibble is ASCII encoded string data. Grab the bytes, decode ’em into a string & process to your heart’s content. ZOMG science!

Let’s check out an example, shall we? You might get a MIDI SysEx message that looks like this in hexadecimal. Looks like robot soup, right?

F00002240D4B410D6B430D5438350D74342F340D5357656C636F6D6520546F204F6E536F6E67F7

Let’s break it down, peeps. The F0 (in gray) up front says this is a system exclusive message. The F7 at the end (in gray) says it’s done, finito, KTHXBYE. System exclusive messages usually get processed in packets & nibbles, so once you start reading, keep listenin’ for the F7 as the termination. Don’t wander off.

The OnSong SysEx manufacturer ID is a series of three bytes, shown in teal. Double-check it before you process the rest of the data. Trust, but verify, y’all.

The rest of the message is ASCII-encoded text. The carriage return “0D” in red says a piece of song metadata is about to show up. After the carriage return comes a tag in orange, a single character telling you what kind of value is next. Everything up to the next carriage return “0D” or termination “F7” is ASCII-encoded string data carryin’ the value. Simple. Mostly.

Convert the data from the end of the SysEx manufacturer identifier to the terminating F7 & you get the transposed key, original key, tempo, time signature, & song title in plain text. Heads up: a carriage return shows up first & before each metadata pair. Only data that exists comes back, even if you asked for the tag. Can’t squeeze blood from a turnip:

KA
kC
T85
t4/4
SWelcome To OnSong

Tags You Can Grab (Collect ’Em All)

The tags y’all need most get sent by default, in a particular order. The list below shows every tag we’ve got, defaults first. You’re welcome.

K - Key (the musical kind, not for your door, genius) *
The transposed key of the song, if you flipped on transposition. Fancy pants.
k - Key Before You Butchered It *
This is the key the song started in, before you got your hands on it.
N - Song #1337 *
The song number, if there is one. Spoiler: sometimes there ain’t.
c - CCLI Digits (the legal ones) *
The song’s CCLI number, if it has one. LOL, bureaucracy.
D - How Long Are We Doin’ This? *
How long the song goes on, in seconds. Yawn.
T - Tempo (BPM or bust) *
The song’s tempo in beats per minute (BPM). Faster is not always better, drummers.
t - Beats Per Squiggle *
The time signature of the song, expressed as beats over duration, like 3/4. Math in my music? Ugh.
S - What’s This Jam Called? *
The title of the song. Shockin’, amirite?
A - Awesome Peep
The awesome peep who played the song.
O - Capo
The capo on the song, if you turned that on. Look at you, fancy.
C - Copy-Wrong? Copy-Right.
The copyright info, because lawyers gotta eat too.
B - Your Jam Drawers
The books the song hangs out in, separated by the tab character. Tab it like it’s hot.
E - Magic Words
Magic words that describe the song. Thrillin’.
F - Flow (go with it)
How the song flows, like the order it goes in. Mind-blowin’.
I - The One & Only ID
The special ID OnSong uses to keep track of stuff. Don’t lose it.
L - Stuff
The whole bleepin’ text of the song. All of it. Srsly.
l - Lyrics (the words you keep forgetting)
The lyrics, minus the chords. Sing it, don’t strum it.

Askin’ Nicely for Tags & Mooore Metadata

Only the tags with an asterisk up there come back by default. Need more? Fine, beg for them with MIDI SysEx messages & the OnSong protocol. We’ll wait.

First, nosey much? You can ask which tags are supported with a question mark “?”, or “3F” in hexadecimal, right after the manufacturer identifier. Turned into a hexadecimal data stream, the system exclusive message looks like this. Pretty, right?

F00002243FF7

This coughs up a list of tags starting with an exclamation mark “!” operator, or “21” in hexadecimal, meanin’ the next bit is a string of characters about the tags to be returned. This system exclusive message would return “!KkNcDTtS” after the prefix & looks like this:

F0000224214B6B4E6344547453F7

Missing a tag? Slap on the plus “+” operator, or “2B” if you’re a hexadecimal show-off. Wanna eavesdrop on copyright & artist? Tack “+CA” on after the prefix but before the termination. Easy peasy, amirite?

F00002242B4341F7

Removin’ tags is just as easy with the minus “-” operator, or “2D” in hexadecimal. To ditch the copyright & artist tags we just added, send this. Poof. Gone.

F00002242D4341F7

Not recommended (srsly, don’t), but you can also just dictate your tags with the equals “=” operator, or “3D” in hexadecimal. This might break how other apps behave. LOL oops. To listen to EVERYTHING “KkNcDTtSAOCBEFIlL”, send this and hope for the best:

F00002243D4B6B4E6344547453414F43424546496C4CF7

Super important: don’t assume metadata shows up in any particular order, because you can shuffle the order of metadata that comes back. Surprise! Chaos!

Politely Beggin’ for Song Info

MIDI broadcast sends a system exclusive message every time a song changes, but maybe you want the current song’s info right now, like when you first start listenin’. Just build an OnSong SysEx & send it. OnSong hears you & replies with the standard broadcast of the currently selected songs. So polite.

To do this, send the usual SysEx start & end bytes with the manufacturer ID, then an “@” symbol or “40” in hexadecimal. Here’s an example. Try not to break it.

F000022440F7

Or you can demand specific keys by tackin’ them on after the “@” symbol. Want lyrics & flow? Do it in hexadecimal where 6C is a lowercase “L” and 46 is an uppercase “F”. Yes, case matters. Welcome to computers!

F0000224406C46F7

Wanna grab everything? Fire off an asterisk after the at symbol, like this in hexadecimal. Greedy much?

F0000224402AF7

Showtime, Baby

Pro tip: if your app needs crazy low latency/overhead, process the stream as it arrives & pluck out this info “just in time” by checkin’ each “nibble”, and when a carriage return “0D” shows up, peek at the next nibble to see if you want the value. Only process it when you find it. Lazy genius, amirite?

Signin’ Up for the SysEx Party

Normally OnSong users have to manually flip on MIDI SysEx broadcast in settings. Boring! You can register your app with OnSong to enable MIDI SysEx broadcast messages instead. Build a URL in your app & open it. OnSong pops open & registers your app for broadcast. Here’s an example on registering an app for broadcast MIDI. Copy-paste responsibly:

onsong://midi/broadcast/enable

This example uses the “onsong” URL scheme with the MIDI host. It tells OnSong we’re messin’ with MIDI broadcast by switchin’ on the source app. Even with broadcasting turned off in settings, OnSong sends MIDI SysEx anyway. Sneaky, sneaky.

When you’re done listenin’, you can yank your app off the broadcastin’ apps list. Just make a URL like this & open it in your app. Don’t forget. We’ll know.

onsong://midi/broadcast/disable

No app? No prob. Toss your unique app ID on the end of the URL as the last parameter. Easy peasy.

onsong://midi/broadcast/enable/com.domain.name
onsong://midi/broadcast/disable/com.domain.name

Also, you can use OnSong system exclusive messages to turn on broadcast. Use a greater than or less than symbol after the manufacturer identifier to enable or disable it, then give your service a name. To enable MIDI broadcast for “My App”, send this in hexadecimal. ZOMG so easy:

F00002243E4D7920417070F7

See the data after that red symbol? That’s ASCII-encoded text for “My App”. It asks the user nicely to allow access. To shut access off, send the same message with a less than symbol, like this. Door’s closed, buddy.

F00002243C4D7920417070F7