Developers
MIDI SysEx Broadcast
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 It Works
OnSong can be configured t’ broadcast information about th’ currently selected song usin’ a proprietary system exclusive message. But don’t ye worry, matey, these messages be easy t’ decode an’ allow OnSong t’ transmit information that third-party hardware or software can use t’ keep performances in sync.
Any device that can be connected via MIDI t’ an Android or Apple device runnin’ OnSong can listen fer these messages. Fer instance, ye could link all computers an’ devices on stage t’ a network MIDI session so that all th’ crew’s software can listen fer these messages. Arrr!
These System Exclusive messages, or “SysEx”, be data sent over th’ MIDI protocol as a 7-bit data stream that be not specific t’ a channel. We’ll take a look at this data stream in hexadecimal “nibbles” t’ help ye understand how t’ process th’ stream, ye scallywag!
Parsin’ Song Data
Songs be comprised o’ metadata such as th’ song title an’ key. Fer th’ sake o’ brevity, each o’ these name-value metadata pairs be delimited by a carriage return, or “0D”. A common way t’ handle this then be t’ take th’ data an’ decode it into ASCII text, split th’ string by carriage returns “\r” an’ start processin’ each metadata component. Avast!
Fer each pair, th’ type o’ th’ metadata tag be indicated by th’ first ASCII character that be encountered. Fer instance, th’ song title’s tag be a capital “S”. This means that if ye encounter “SWelcome to OnSong”, th’ title o’ th’ song be simply “Welcome to OnSong” where “S” declares th’ type o’ metadata that follows. Th’ value o’ th’ metadata pair be always a string. This means that numeric values be delivered as strings an’ not numeric values encoded in data. This allows th’ entire message t’ be processed as a string once received, matey!
Th’ order o’ these tags be not guaranteed, but generally we want th’ shorter an’ more commonly used tags t’ come first in th’ stream t’ allow fer faster processin’. Ye’ll see that there be ways t’ request more metadata tag t’ be included in each message with special SysEx messages. Ahoy!
Breakin’ It Down
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.
Th’ most common message used by OnSong SysEx be th’ song broadcast. Th’ nibble directly after th’ manufacturer prefix be a carriage return which has a hexadecimal value o’ “0D”. Once this be encountered, th’ rest o’ th’ stream up until th’ terminatin’ “F7” nibble be ASCII encoded string data. This means that ye can take th’ bytes o’ data an’ decode them into a string fer further processin’.
Avast! Let’s take a look at an example. Ye may receive a MIDI SysEx message that looks like th’ followin’ in hexadecimal:
F00002240D4B410D6B430D5438350D74342F340D5357656C636F6D6520546F204F6E536F6E67F7
Let’s take a look at what this means. Th’ F0 (in gray) in th’ beginnin’ indicates that this be a system exclusive message. Th’ F7 at th’ end (in gray) indicates that th’ message be finished. Th’ system exclusive message be typically processed in packets an’ nibbles so once ye begin readin’ it, ye must then listen fer th’ F7 as th’ termination.
Th’ OnSong SysEx manufacturer identifier be a series o’ three bytes an’ be displayed in teal. This should be confirmed in order t’ process th’ rest o’ th’ data usin’ this protocol, ye scallywag.
Th’ rest o’ th’ message can be read as ASCII-encoded text. Th’ carriage return “0D” displayed in red indicates a piece o’ metadata about th’ song be about t’ be encountered. After th’ carriage return be a tag shown in orange that be a single character indicatin’ th’ type o’ value that comes next. Th’ rest up until th’ next carriage return “0D” or termination “F7” be an ASCII-encoded string data that carries th’ value.
If we convert th’ data from th’ end o’ th’ SysEx manufacturer identifier t’ th’ terminatin’ F7, ye get th’ transposed key, original key, tempo, time signature, an’ song title in plain text. Note that a carriage return be encountered first an’ afore each metadata pair. Only data that be available be returned even if th’ tag be requested:
KA
kC
T85
t4/4
SWelcome To OnSong
Available Tags
Th’ most commonly needed tags be sent by default an’ in a particular order. Th’ list below shows all available tags, with th’ default ones listed first, savvy?
- K - Key *
- Arrr, this be th’ transposed key o’ th’ song, if transposition be enabled.
- k - Original Key *
- Arrr, this be th’ original key o’ th’ song.
- N - Song Number *
- This be th’ song number, if available.
- c - CCLI Number *
- This be th’ song’s CCLI number, if available.
- D - Duration *
- Th’ duration o’ th’ song in seconds.
- T - Tempo *
- Th’ tempo o’ th’ song in beats per minute (BPM).
- t - Time Signature *
- Th’ time signature o’ th’ song as expressed as th’ number o’ beats over th’ duration like 3/4.
- S - Song Title *
- Th’ title o’ th’ song.
- A - Artist
- Th’ artist that performed th’ song, matey.
- O - Capo
- Th’ capo applied t’ th’ song, if enabled.
- C - Copyright
- Th’ copyright information fer th’ song.
- B - Books
- Th’ books in which th’ song belongs as delimited by th’ tab character, matey.
- E - Keywords
- Th’ keywords fer th’ song.
- F - Flow
- Th’ flow o’ th’ song such as th’ song’s order, like chartin’ a course.
- I - Unique Identifier
- Th’ unique identifier used by OnSong.
- L - Content
- Th’ full textual content o’ th’ song.
- l - Lyrics
- Th’ lyrics o’ th’ song by removin’ chords, savvy?
Queryin’ Tags an’ Requestin’ More Metadata
Only th’ tags denoted with an asterisk in th’ list above be returned by default. However, if yer application requires other tags, ye can request them by sendin’ MIDI SysEx messages usin’ th’ OnSong protocol. Arrr!
First, ye can query which tags be currently supported usin’ a question mark “?”, or “3F” in hexadecimal, after th’ manufacturer identifier. When converted t’ a hexadecimal data stream, th’ system exclusive message looks like this:
F00002243FF7
This will return a list o’ tags prefaced by an exclamation mark “!” operator, or “21” in hexadecimal, that indicates th’ followin’ data be a string containin’ characters related t’ th’ tags t’ be returned. This system exclusive message would return “!KkNcDTtS” after th’ prefix an’ looks like this:
F0000224214B6B4E6344547453F7
T’ add a tag that be missin’, ye can use th’ plus “+” operator, or “2B” in hexadecimal. Fer instance, ye can request t’ listen t’ copyright an’ artist by appendin’ “+CA” after th’ prefix, but afore th’ termination, savvy?
F00002242B4341F7
Ye can just as easily remove tags usin’ th’ minus “-” operator, or “2D” in hexadecimal. T’ remove th’ copyright an’ artist tags we’ve just added, send this:
F00002242D4341F7
Arrr, while not recommended, ye can also just set th’ tags ye want usin’ th’ equals “=” operator, or “3D” in hexadecimal. This could affect how other apps sail th’ seas. T’ listen fer everythin’ “KkNcDTtSAOCBEFIlL”, ye could send th’ followin’:
F00002243D4B6B4E6344547453414F43424546496C4CF7
Blimey, it be important t’ note that yer application should not assume that metadata will be in any particular order because ye can alter th’ order o’ metadata returned in this manner.
Requestin’ Song Information
While MIDI broadcast will send a system exclusive message each time a song changes, ye may want t’ request th’ current song’s information such as when ye first start listenin’ fer broadcast messages. T’ do this, ye form an OnSong SysEx an’ send it. OnSong will hear this an’ respond with th’ standard broadcast with th’ currently selected songs, savvy?
T’ do this, ye send th’ typical SysEx startin’ an’ endin’ bytes along with th’ manufacturer ID an’ followed by an “@” symbol or “40” in hexadecimal. Here’s an example, matey:
F000022440F7
Alternatively, ye can request OnSong t’ send specific keys by appendin’ those keys after th’ “@” symbol. Fer instance, t’ request lyrics an’ flow, ye could do this in hexadecimal where 6C be a lowercase “L” an’ 46 be an uppercase “F”:
F0000224406C46F7
Ye can also request everythin’ by sendin’ an asterisk after th’ at symbol like this in hexadecimal:
F0000224402AF7
Performance
Note, if ye be writin’ an application that requires very low latency/overhead, ye can process th’ stream as it arrives an’ extract this information in a “just in time” method by evaluatin’ each “nibble” an’ when each carriage return “0D” be found, look at th’ followin’ nibble t’ determine if ye require th’ value, only processin’ th’ value once encountered. Blimey!
Registerin’ fer Broadcast SysEx
Typically, OnSong users would need t’ manually enable MIDI SysEx broadcast usin’ a setting. However ye can register yer app with OnSong t’ enable MIDI SysEx broadcast messages. T’ do this, ye will form a URL in yer app an’ open it. This will cause th’ OnSong app t’ open an’ th’ broadcast settings t’ register yer app. Here be an example on how t’ register an app fer broadcast MIDI:
onsong://midi/broadcast/enable
This example uses th’ “onsong” URL scheme with th’ MIDI host. It tells OnSong that we be affectin’ th’ broadcast status o’ MIDI by enablin’ th’ source app. Even with broadcastin’ disabled in settings, OnSong will send MIDI SysEx, matey!
When ye be done listenin’, ye can remove yer app from th’ broadcastin’ apps list. T’ do this ye would create a URL like th’ followin’ an’ open it in yer app:
onsong://midi/broadcast/disable
If ye be not usin’ an app, ye can also pass yer unique app identifier in th’ URL as th’ last parameter:
onsong://midi/broadcast/enable/com.domain.name
onsong://midi/broadcast/disable/com.domain.name
Additionally, ye can use OnSong system exclusive messages t’ enable broadcast. T’ do this, ye use a greater than or less than symbol after th’ manufacturer identifier t’ enable or disable broadcast. After these symbols, ye must provide an identifier fer yer service. T’ enable MIDI broadcast fer “My App” ye would send in hexadecimal:
F00002243E4D7920417070F7
Note that th’ data after th’ symbol shown in red be ASCII-encoded text fer “My App”. This prompts th’ user t’ allow access. T’ disable access, ye would send th’ same message with a less than symbol like this:
F00002243C4D7920417070F7