09/22/2013

music hack day NYC

This past weekend I went on a limb and flew up to NYC for Music Hack Day 2013, which was held at Spotify's offices in the Flatiron District. Since I just got done learning all about LibSpotify/CocoaLibSpotify I figured why not? My dad used some of his skymiles and I flew up on Wednesday afternoon, right after class. I stayed in an AirBnB in Brooklyn (thanks Julian!), and kind of explored around NYC Thursday and Friday morning. I tried not to be too much of a tourist, which means that I did everything I could except Times Square (I had been there on a marching band trip years earlier).

The first thing I did after landing at LGA is watch Jon Stewart's pizza rant against Donald Trump, and just picked a random place to go before taking a train directly there. I think I went to Lombardi's in Little Italy. I checked into my room for the night, and then got tickets for the Rockefeller Center, trying to get there right for sunset. A few subway mishaps later, and I just barely missed it, but it was beautiful regardless. I think the Rock was a good choice, you could see the Empire State from it, which was pretty neat.

image

The next morning I was pretty bad at getting out of bed. I had stayed up pretty late watching people play chess at Bryant Park and wandering around. I got over to their offices early enough to eat a bagel right around the corner. I made the mistake of asking for it toasted, only to be met with a scoff "Sir, all of our bagels are baked fresh." It was hot because it had came out of the oven just seconds earlier. Delicious. I went to their lobby possibly too early, everyone was still working, and they told me to just hang out in the reception area. I had some physics online assignments to do anyway. The receptionist was a little rude (read: I work for a super popular software company pretentious), but it probably was my fault for showing up an hour early.

Hanging out early worked out nicely though, I met some interesting people, and some of the representatives from the companies that were giving out prizes. I met Paul Lamere, from the EchoNest, who (I didn't know at the time) runs the Music Machinery blog. I'd seen his website show up a few times on HN and had really enjoyed his stuff. Before we were let into the work area he told me about what the EchoNest did and, it sounded really interesting.

So, before long, everyone was hacking away. I worked from about 6pm to midnight trying to create something that would attempt to correlate weather to your listening history, but Spotify doesn't have any publicly available history information, so I had to resort to getting playlist information, at which point I realized the analysis was going to be quite contrived. I had lots of trouble getting free hourly weather information without paying. Wunderground had a good API, but the free rate limit was very low, and the batch request endpoint was pretty limited as well.

So, I remembered something I had done earlier where I made an iPhone app to control a computer running Spotify, so I thought I could just swap it around, have an app-less iPhone controlling an iPad that has an app using CocoaLibSpotify. The ideas got flowing (something about those expensive juice drinks Spotify had in their fridges) and I realized I could make it pretty with album art showing the queue, and I could pull some information about the songs that people were queuing up from EchoNest. I figured I'd plot these onto some sort of graph so I people could see how the party was progressing. To top it all off I figured I'd have everyone text in what they wanted to play, and then allow an "admin" to control the music (skipping, play/pause, and volume).

This was exciting. I knew there was an iPad up for grabs from the EchoNest, and Twilio was handing out prizes for the best use of their API, so, I thought I had a good conglomeration. I figured I had a fighting chance since half the people who started that afternoon only showed up for some free beer before abandoning their project and leaving. Over the next 8 hours, I descended into callback hell, since I was moving so fast, working with APIs I hadn't ever really had lots of experience with. I'd say this is probably the most sprawl-y code I've ever written. This is pure, unadulterated irresponsibility.

image

I mean, but, it worked. I think the github page I threw up says it best, "Please don't look at this. Please don't look at this. This code is terrible, motivated by 12 hours at a standing desk from around midnight to noon with a brief napping stint on a hard carpet floor."

Logistically, most everything happens server side. I didn't want to have interactions with the EchoNest in two places, so the server that's responding to Twilio does most of everything. It takes the song or artist or whatever the user texted in, and tries to do a search on the EchoNest for the track (you can also text "top R. Kelly" and it will play R. Kelly's top track) and then just takes the top result. The EchoNest keeps track of foreign library keys, so you can grab the Spotify URI directly from them so the song can be located using the Spotify API. The server then packages this URI up, along with the data for the song before sending it off to the iPad. I tracked danceability, tempo, and energy (which are all sort of contrived anyway, but whatever).

After all this was done, all I had to do was make the iPad app look sorta pretty. I threw CorePlot in there and learned how to use their stuff in 30 minutes, which made the plotting really easy. I averaged together the each point of data and displayed them on the left of the graph in the same color as the data line. I quickly threw together an automatic scrolling view DPContinuousImageScrollView for song+artist titles that were too long for the screen, I just hand the UILabel off as a UIImage to my view and it deals with scrolling it off the page. Then, for the kicker I placed big album art at the bottom of the screen in a scroll view so you can see what's coming up next. Done.

image

The EchoNest has a taste-profile API, which lets you throw a bunch of songs into a playlist, for which it determines a user's tastes and then can provide song recommendations (along with some other data). In the last hour I was attempting to assemble all of the party's songs into a taste profile so that any of the party attendees could text in "gamble" and it would queue up the EchoNest's next recommendation. Thanks to how crazy my node code was.... it was a pipe dream. It also would have been cool to get something working where I used the names that everyone texted in to kind of have a "wall of shame" for the people who were submitting songs that deviated the most from the taste profile, or were too far from the average tempo or something. Or maybe a "wall of fame" for the best songs.

The demo was very stressful. I basically got up on the stage and said "Well, I know this is bad practice, and I deserve everything I get for this, but, please try and break my hack." I didn't know of a better way to show off what it could do. I threw up a big cell phone number in a sticky, and told people to have fun. People had been playing "What Does the Fox Say?" over and over through the speakers in the offices, lots of copies of that song were requested. But everything ended up working really well, to my surprise. I ended up winning the iPad from the EchoNest and an Sparkfun Arduino starting kit from Twilio, so overall, for my first solo hackathon, I think things went really well.

image

The rest of the weekend was lots of fun too. I had met two designers during the course of the night, and since I had been too busy coding I hadn't had time to scope out where I was staying Saturday night. They told me I was welcome to crash with them in their hotel. And crash I did.

Sunday I woke up again, way too late. I spent the day touring the 9/11 Memorial (the hotel was right around the corner) and then had enough time to walk Central Park from end to end. Unfortunately I didn't have enough time to get one more bagel or some more pizza, but I suppose I'll just have to wait till next time.