from abjad import * %load_ext abjad.ext.ipython pitch_numbers = 4 * [0, 2, 4, 9, 7] duration = Duration(1, 8) notes = scoretools.make_notes(pitch_numbers, duration) staff = Staff(notes) show(staff) import os import tempfile from abjad.tools import systemtools, topleveltools tmpdir = tempfile.mkdtemp() agent = topleveltools.persist(staff) result = agent.as_midi(tmpdir + os.sep + 'out.mid') midi_file_path, format_time, render_time = result from IPython.display import HTML from base64 import b64encode midi_file = open(midi_file_path, "rb").read() midi_encoded = b64encode(midi_file) embed_tag = ''.format(midi_encoded) HTML(data=embed_tag) import os import tempfile from abjad.tools import systemtools, topleveltools tmpdir = tempfile.mkdtemp() agent = topleveltools.persist(staff) result = agent.as_midi(tmpdir + os.sep + 'out.mid') midi_file_path, format_time, render_time = result soundfont = 'FluidR3_GM.sf2' tmpaudio = tmpdir + os.sep + 'out.ogg' cmd = 'fluidsynth -nli -r 48000 -o synth.cpu-cores=2 -T oga -F %s %s %s' % (tmpaudio, soundfont, midi_file_path) result = systemtools.IOManager.spawn_subprocess(cmd) from IPython.display import HTML from base64 import b64encode audio_file = open(tmpaudio, "rb").read() audio_encoded = b64encode(audio_file) audio_tag = '