Recently, I was really impressed by Tiago Antao's Abjad-IPython integration which renders Abjad code into PNGs of the Lilypond output. It was recently added to the Abjad repository which is really exciting, you can see an example of this integration below. To further his work and to satisfy my audio interests, I explored two methods of creating dynamically rendered audio of Abjad notation within IPython notebooks.

This is the first method I explored, which was extremely common back in the early 2000s but I knew it would be easy to implement. It relies on the <embed> tag which expects browser plugins to be able to handle the content within the tags. This style of integration is being phased out, as MIDI playback has been removed from the Safari-Quicktime plugin since 10.8. Unfortunately the Web MIDI API is too young for widely accepted usage, so nothing is replacing this old functionality.

This method involves rendering the MIDI file using fluidsynth, and dropping the resulting audio in an <audio> tag using the base64 encoding. For this to work you need to install fluidsynth with your familiar package manager, and Soundfont file to render the MIDI with.

In this example I am using FluidR3 General MIDI, and made the assumption that it is in the same directory as this notebook.

Given how quickly fluidsynth renders audio, I was quite satisfied using it as a permanent solution. Another possible alternative would be client-side rendering using something like MIDI.js, but I ran into difficulties integrating Javascript within IPython (Though I am fairly new to IPython). I think that using base64 encoding to store the file directly in the notebook is probably better than dynamically rendering content anyway.

I am going to try to clean this code up and make a nice repository for it. Thanks for reading this notebook!