Closed cifkao closed 7 months ago
I did create a custom Jupyter 'display' object tonight that seems to work fine in local "trusted" Jupyter notebooks, for both web-hosted midi files and local midi files, without the need to spawn a separate web server.
I can share the code later after I clean it up a bit -- after I re-locate and attribute the person (Tony Hirst?) who posted the code on which I based mine.
On Colab, it will only work for web-hosted midi files, otherwise you get the usual CORS errors. Same with logging the player to WandB. ( I may see if any WandB engineers want to help with that.)
Here goes!
I'll attach an example Jupyter notebook .ipynb file if it'll let me. I'd be happy to send this as a PR to doc/
somewhere:
...ok then here's a link to a Colab! Note however that the second part with the local file viz won't work on Colab: https://colab.research.google.com/drive/1a5xTPgH31icTt1_kUkqGF_J0GTYoHFW7?usp=sharing
Just updated the Colab to show an example with WandB logging, which already worked for remote midi file urls without the new object. Active project link: https://wandb.ai/drscotthawley/html-midi-player?workspace=user-drscotthawley
If WandB support is able to help with referencing logged midi files,...? 🔥
@drscotthawley This is cool!
For Colab & WandB, could you encode the MIDI file as an object URL and somehow pass that into the iframe? Not sure if the player will accept an object URL directly or if you will have to decode it into a NoteSequence
object.
@cifkao Great minds think alike! Indeed, encoding it as a data object url was the thing that occurred to me earlier today and what enabled everything else to work.
I made a simple pip-installable package at https://github.com/drscotthawley/midi-player
Take a look in the examples/
directory where there's a notebook that can run from anywhere. I've immortalized your name in stylers.py
for your "Advanced" example code.
Happy to keep making changes and improvements.
...although what I really should do is now stop fiddling with this, and get back to the task for which I really wanted the player -- to use it to help me track & debug my training code! lol
That's amazing! I think I can now close this issue thanks to you!
So far I have not succeeded in including the player in Jupyter notebooks. I tried including the library using a RequireJS call like here, but I get an error about a "mismatched anonymous
define()
" like here. Maybe the bundle is in a format that RequireJS cannot work with?