Code Wizards
Pop That Song
The onsong:// URL scheme isn’t just for importin’ content into OnSong, y’all. You can ALSO use it to view specific songs in your library. It’s a URL scheme, so it opens OnSong & yanks it to the front if it wasn’t already there. Usin’ split screen or other multitaskin’ wizardry on an iPad? It stays that way. That makes URL open actions perfect if your app lives in just a slice of the iPad screen. Squatters’ rights!
Stuff You Gotta Have, Srsly
The Open Song URL API needs the current version of OnSong. You can join our beta team to get pre-release versions of OnSong & be a guinea pig. Since the onsong:// URL scheme works on EVERY version of OnSong, only keep the beta version installed or your apps will fight like cats in a sack.
Is It In There? LOL
Obviously, to use any of these API calls, the user needs OnSong installed on their device. Duh. So add onsong as a registered URL scheme. Skip this & your app can’t open the OnSong scheme. Web-based apps get a free pass though. Lucky ducks.
Once registered, use the [UIApplication canOpenURL:] method to check if the URL can be opened. If it says false, OnSong isn’t installed & you should show a friendly screen begging the user to go get it. Maybe through an affiliate link? Wanna be an OnSong affiliate partner? Email us & let’s make it rain.
Peek at Song
The simplest action EVER is openin’ a song. OnSong does it by searchin’ for the song title OR the song ID. This uses the base action path & the song querystring parameter. To open the song Be Still, we’d do this:
onsong://open/songs?song=be-still
Or hand over a known unique ID for the song querystring parameter like so. Look at us, rollin’ with the nerds:
onsong://open/songs/?song=85F0CE06-7414-4FFB-BFF0-14D3507A1AA7
Peek at Pile o’ Songs
Collections in OnSong are books, sure, but also the standard stuff like All Songs & Unbound Songs (a.k.a. the island of misfit tunes). You can load All Songs into the song viewer with the collection querystring parameter like this:
onsong://open/songs/?collection=all-songs
Same trick works for books, LOL. Load ’em up:
onsong://open/songs/?collection=christmas-songs
Peek at Set
Sets in OnSong are how you play songs for one specific gig. URL actions let you load an existing set OR make a brand new one. ZOMG, power! We’ll start by simply peekin’ at the current set like this:
onsong://open/songs/?set=current-set
Which Way Is Up?
Loadin’ a set is totes helpful & all, but what if you wanna wander through it? Use the index querystring parameter & stroll through the songs you’re lookin’ at, whether they live in a collection or a set. Wanderlust, unlocked.
Wanna hit the first song? Just toss in the first value, amirite?
onsong://open/songs?index=first
Or, y’know, zip straight to the last song in the viewer. Easy peasy:
onsong://open/songs?index=last
Or whatever, just hop to the next song in the viewer. Srsly, that’s it:
onsong://open/songs?index=next
Or just hit rewind, ya dingus:
onsong://open/songs?index=previous
Or jump to ANY song by its number, but plot twist: we start counting at zero. Because nerds. Want the second song in the set? Do this:
onsong://open/songs?index=1
Yanking Songs
Okay, THIS is where things get kinda crazy, or as developers say, “powerful” (ooooh). We use the same API to load a bunch of songs into the viewer by repeatin’ the song querystring parameter. Then we scoop those songs into the current set, or make a shiny new set. Boom.
Wanna peek at a bunch of songs without savin’ anything? Just repeat the song parameter in the order you want ’em, plus an optional index parameter if you don’t wanna start at the beginnin’ of the set. Commitment issues? We got you:
onsong://open/songs/?song=be-still&song=beautiful-life&song=changes&index=1
To stuff these songs into the set you’re lookin’ at, we hand over the set parameter with the name of the set we wanna create. Easy peasy, amirite?:
onsong://open/songs/?song=be-still&song=beautiful-life&song=changes&set=New+Set
Or shove it into the current set using the current value for the set parameter. ZOMG so fancy:
onsong://open/songs/?song=be-still&song=beautiful-life&song=changes&set=current
Obvs we can also use a name to shove the song into a named set, or flash the set’s unique ID if you happen to know it (you don’t). Here we jam a known song into a known set at spot number four:
onsong://open/songs/?song=85F0CE06-7414-4FFB-BFF0-14D3507A1AA7&index=3&set=8DD5B78C-205A-4F6E-AD09-63711F372BD3
Shipping Songs Out
But how in the bleepin’ world would you know the unique IDs in somebody’s library? Lucky you, the OnSong URL Action API has an export function. Tell the API WHAT to export (song, set, collection) & WHERE to send it. Like so:
onsong://export/songs?collection=current&returnURL=http%3A%2F%2Fmywebsite%2Ecom%2Freceive%3Fdata%3D
In the example above, OnSong grabs the collection currently loaded in the song viewer, makes a list of song content, whips up some Base64 encoded data & tacks it onto your returnURL parameter. Here we used http://mywebsite.com/receive?data= so the data lands at the end of that URL. Obvs you could ALSO make it a URL scheme that opens your app & hands over the song list. Fancy, fancy.
The data gets encoded for easy zippin’ around, but once decoded it’s just a super simple tab-delimited list. The properties live in the first row, & each song gets its own row after that, split by a newline character. So chop it up by newline, then by tabs, & use that first line to figure out what each column is. Spreadsheet party!
We can ALSO pick which properties we wanna export. By default, OnSong coughs up the song’s ID, title & artist. But we could also export the key, transposed key, capo & more. So many shiny toys, srsly.