Tuesday, September 25, 2012

Henrik’s Awesome Playlist Generator

I'm afraid this is going to be a very long and technical text about one of my greatest passion in the Dolce Trio daily work (besides the playing of course) – generating a good playlist for our gigs. The task at hand is quite substantial, and it is only through trying and thinking about it many times that I've finally arrived at a satisfactory result. We have around 150 pieces, 110 being “classical” and 40 belonging to the “pop/other”-stack, incorporating such musical highlights of the last century as Disney hits, evergreens, Abba's, tangos, musicals, Swedish waltzes, Celine Dion and Andrea Bocelli duets etc. etc., that we get good response for playing and that we also feel nice to spice up the classical repertoire with (see excerpt)


So the challenge is this, expressed through the following objectives:
  •      Make a playlist that incorporates all of our pieces, so that we play through everything before starting over in order to get as less tired of the pieces as possible. 150 pieces = around 9h music, 3h playing/day => 3 days before starting over.
  •      Make a new playlist every week in order to not get tired of the pieces by playing them in the same order every time.
On our last contract we made the playlist by hand once a week, and being three persons in the trio it was a workload of about one hour every third week. As you will see I have put a lot of more work into this than I would have with the old system, but the principle is that of instead of inventing the wheel every time, I'm building a wheel factory. Moreover, putting 150 pieces in order by hand may result in a good order from the start, but it is inevitable that you forget one or two, or ten, and to check for leftovers would take nearly as much time as making it in the first place.

Anyway, I had an idea that I would be able to do this with a little help from my computer. And in order for you to understand how that is done, dear reader, I need to explain how our repertoire works in the first place.

Every piece has a number. The original numbering, when we first got on the ship last year, was from 1 – 75 (classical) and 1 – 52 (pop/other). Of these 127 we were able to play about half because we hadn't have time to rehearse or practice all of them. But throughout the contract we did just that, and in the end we managed to play around 100 of them I think. Whenever any of us arranged a new piece for the trio we just squeezed it in as for example 52b, between 52 and 53. The classical stack is ordered by composer and title and the pop stack only by title. Thus, 1 (classical) is Albinoni's Adagio and 75c is Verdi's “Slave choir”. Anyway, the fundamental idea with the playlist is that we have all these numbers in a row on a piece of paper next to our music when we're playing, and we never need to decide in the moment what the next piece is going to be (trust me, it isn't easy with three stubborn musicians). But of course we allow ourselves to deviate from the playlist whenever we feel like it.

Now, there are two more criteria for the perfect playlist. First, regarding the numbering and practicality of the gig:
  •      There shouldn't be less than three pieces from any binder.
With our increased repertoire this is a new problem since there's no room for all music in one binder. We have three binders of music each (the piano binders are fuller but still amount to the same number) – pop/other obviously, and two for the classical: composers A-L and M-V. When we have one binder on the music stand the other two are on the floor, and switching the binders back and forth all the time is not only a wearisome task but also a greater risk for the wellbeing of the instruments, should they fall over and break in the process.

So, when all this is clear to you, dear reader that is still with me, you probably think that it wouldn't be hard at all just to randomize the order with an algorithm of three pieces from binder 1, three pieces from binder 2 and three pieces from binder 3. But here is where the real challenge begins, to be in compliance with the last criterion.
  •      The order of pieces should have an inner coherence of succession, variation and dramaturgy, and should reflect the exterior atmosphere of the performance situation in its mood.
Now we have to do some real thinking. Well, you don't have to because I have and I'm sharing with you. This isn't really any different from the fact that all major classical works with several movements have a succession of characters for the movements that passes from fast to slow and from slow to fast. So what we have done is putting a number to every piece corresponding to its mood/tempo, from 1 to 4 like the following:

1 being really slow, like “Air on a G” string by Bach;
2 being a bit more moving, like “Salut d’Amour” by Elgar;
3 being quite active but not too much, like Schubert's “Moment musiceaux”;
4 being a real show-off piece like Brahms' Hungarian dance no. 5.

The same goes for the pop songs except there are no songs as slow as 1. Now, after sorting the repertoire like this in Excel, there are only two tools that you need: sorting on several levels and the randomize function. A big thanks to my friend Attila who helped my on the right track here. Starting with the randomize function, if you type in =SLUMP() in Excel (Swedish) it generates a figure between 0 and 1. If you do that to every row entry and then sort the data according to those figures you get a totally randomized order. But we don't want that, no, we want a randomized order with some rules applied. Here is where the sorting on different levels comes in. We need to sort first on the 1-4 character number, and then on the randomized numbers. So now we have a list of all 1’s, all 2’s, all 3’s and all 4’s, and also sorted by binder 1, 2 and 3 of course, in a random order. Now this is the fun part: coming up with the algorithm for the perfect order. I've tried a few and I'm not sure I'm there yet but it gets better and better. Just to explain: the algorithm for a three-movement typical classical sonata would be (4-1-4) or (4-2-4), following the fast-slow-fast model. And for the trio to indicate which binder I'm writing 1(X-X-X) for classical binder 1, 2(X-X-X) for binder 2 and P(X-X-X) for the pop/other binder.

But before we can come up with an order algorithm we need to look closely at the last part of the criterion above: “The order of the pieces … should reflect the exterior atmosphere of the performance situation in its mood”. The exterior atmosphere of the performance situation for us is this: people eating and enjoying their dinner, talking to each other and occasionally listening, and the later the evening goes the louder they become and the less they listen. So the algorithm needs to be in two parts: one for the first sets when it's quiet enough to play slow pieces, and on for the later sets when it's too noisy to play quiet pieces but feels right to play active ones. In Dolce terms they are known as “Hour of death” and “Party”.

I'm now going to reveal our current algorithm, even though it might be regarded as a corporate secret, but I doubt there's any rival out there that's going to profit on this on our behalf, so here it goes.

Calm: 1(2-3-1) 2(2-3-1) P(2-3-2)
Party: 1(3-4-2) 2(3-4-2) P(3-4-2/3)

Oh, isn't that beautiful.

The only thing left to do now is to sort the pieces data as described above, fill in X.Y in another column for every piece, Y being the place of the group in the algorithm and X being 1 through 7 for the calm part and 11 through 17 for the party part (which is easy to do in excel, you just type the first two for each group and then pull down to get the rest automatically), save that column for later generation (“the wheel”), sort the data according to the new column, copy the column of the numbers of the pieces, now in right order, to Word as text only, replace all enters with dashes, and after a final touch it looks something like this:





Coincidently (you would think) almost all pieces in our repertoire made it to the list, fulfilling the first requirement, because we happen to have proportionally twice as many 2’s and 3’s as 1’s and 4’s. Only a few pop songs didn't come out even but they can be thrown in “manually” at the gig. And whenever we feel the noise is too loud for the Calm part of the list we just switch to Party mode and the next day we continue where we left, thus letting us play our entire repertoire in a perfect order of succession and variation and with not too many binder changes.

If you are still with me dear reader, well done, you made it through. Now you can enjoy our playing in a dimension you didn't know before. Not a musical or artistic one, but the mathematical-programming-theoretical-playlist-generation dimension!
Congratulations.

/Henrik

No comments:

Post a Comment