Play MIDI files through `mo.audio()`
Hi, I'd like to try out marimo to compose music, but I can't play midi files. For instance,
... will only display a music player with 0:00 / 0:00.
9 Replies
I can look into this today
It looks like .mid is not an audio file (it can contain many audio files). You will likely need to bring in another library for this. quick search led me to https://pypi.org/project/midi2audio/
Hi, MIDI format indeed contains musical instructions rather than sound, requiring a synthesizer or soundfont for playback. In Jupyter, music21 (a Python library for music representation) can display scores with
my_stream.show()
, using an installed software like MuseScore, or play MIDI via my_stream.show('midi')
. I developed Djalgo, a Python package for music composition using Jupyter and music21. As local installation is complex, I’m considering using Pyodide and Marimo on marimo.app. However, I need to solve display issues for both scores and MIDI. I’m considering developing a JavaScript MIDI player and integrating score rendering via e.g. ABCjs to overcome these challenges. However, I couldn't find a way to run JavaScript in Marimo cells, e.g.
if you need to run javascript, we recommend using Anywidget which is a plugin framework that we support: https://anywidget.dev/en/notebooks/counter/
Hi @Myles Scolnick, I played a bit with ABCjs, anywidget and Marimo, but without success. It's working in Jupyter, though. Have I done anything wrong?
`
since you are technically mutating state- we may not be re-rendering this (which is a marimo requirement, no mutating state)
Given this is an any widget, we can possibly handle this like we do with mo.state
Thanks for the tip! But even without state mutation, nothing is displayed.
Maybe that's an issue displaying the svg outcome?
You need to add this might actually be fixed in the latest marimo as well, actually
export default { render };
at the bottom
export default { render };
seems requiredSolution
Wow, magic!!! Thanks++!
Edit: the code with
mo.state
.