I have a ‘musical past’, so this was rather irresistable. For some time I’ve been harbouring an urge to make a solenoid-powered glockenspiel play Rimsky-Korsakoff’s “Flight of the Bumblebee”, which is an amazing piece because it’s so fast.

Solenoids are costly, software isn’t

But that’s a really expensive project (solenoids + a decent glockenspiel) and I haven’t got there yet. Sonic Pi offered me the chance to do it without the costly hardware part. So I got hold of a score arranged for Piano, and started programming it in.

The first thing I did was set some variables for different rhythms, which meant the tempo could be varied by changing just the “speed” variable.

I forgot that, apart from the last three bars, and one quaver each in bars 83 & 95, the entire piece (treble part) is semi-quavers with ALMOST NO RESTS.

One Pi I have can handle speed = 0.4 without mangling the sound. Another needs to be 0.45. Ideally it would be slightly faster. I’m not sure exactly what the limiting factor is, but it’s nice to be able to push the limits and see what you can get away with.

4-5 hours & 1268 lines

It’s a 5 page score and took about 4-5 hours to program in 1268 lines of code. It’s quite a good example too, because there are quite a lot of repeated segments, which gives you a chance to practice loops. This is the first time I’ve ever written anything in Ruby.

Three quarters of the way through, I also realised it would have been more elegant and efficient to make functions for some of the repetitive parts which start at different pitch. That might happen in a future revision.

Repeats are easy

I can remember the feeling, in the school orchestra, when you see those two little dots at the end of a passage. “Oh no, we’ve got to do it all again!” Well in Sonic Pi, you just add a 2.times do before your repeated passage and an end at the end and you’re good to go (you should indent too, for readability).

But for now, sit back and enjoy the Sonic Pi rendition of The Flight of the Bumblebee.

Quite a lot of it was cutting and pasting blocks of 8 as I did a bar at a time.

Hardest part was keeping track, which is why, nearer the end, I started adding bar numbers in comments.

With hindsight, it could be done much more efficiently with functions for each of the main repeating themes, feeding the function the note number to start the sequence at. Although I don’t know how to do functions in Ruby yet, I can’t imagine it’s massively different/harder than Python.

This is great. I had thought of doing the bee before but was put off by the length. well done on your stamina! After an initial play through I made a couple of changes. The speed factor (0.45) is about as low as it will go without the output breaking up with clicks etc. However, if you change the synth to saw_beep by inserting the line
with_synth “saw_beep
after the variable declarations but before the first play command, then this synth is more amenable to playing faster. I was then able to reduce the speed factor to as low as 0.25 with acceptable output, and this gets nearer to the 1 minute duration for the piece, taking 1 min 23 seconds.

[…] Sonic Pi flight of bumblebee video from RasPi.TV: Using Sonic Pi to play flight of the bumblebee on a Raspberry Pi also using an HDMIPi portable Hi-Def screen. This is using the V1 HDMIPi prototype which has HDMI audio broken out to 3.5mm stereo jack. It’s a bit crackly, but that’s Sonic Pi, not the hardware. […]

[…] Rimsky Korsakoff’s Flight of the Bumble Bee for Sonic Pi 2. I know that there is at least one version out there already for Sonic Pi 1, written by Alex Eames of Raspi-TV, which used a single synth, and numerical […]