When I heard that the score could be displayed on Jupyter, I tried a package called music21. It took a long time to display it on Google Colaboratory, so I will keep it as a memorandum.
By setting the X virtual framebuffer as shown in the code below, the score will be displayed on the Colaboratory as well.
setup.py
#Installation of music21 (common with Jupyter)
!pip install --upgrade music21
!apt-get install musescore
#Virtual framebuffer settings (required settings for Google Colaboratory)
!apt-get install xvfb
!sh -e /etc/init.d/x11-common start
import os
os.putenv('DISPLAY', ':99.0')
!start-stop-daemon --start --pidfile /var/run/xvfb.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1024x768x24 -ac +extension GLX +render -noreset
#Path setting (common with Jupyter)
from music21 import *
us = environment.UserSettings()
us['musescoreDirectPNGPath'] = '/usr/bin/mscore'
us['musicxmlPath'] = '/usr/bin/mscore'
us['directoryScratch'] = '/tmp'
I tried to display the score of "Frog Song".
plot.py
#"Frog Song" in TinyNotation notation
cp = converter.parse('tinyNotation: 4/4 c4 d4 e4 f4 e4 d4 c4 r e4 f4 g4 a4 g4 f4 e4 r c4 r c4 r c4 r c4 r c8 c8 d8 d8 e8 e8 f8 f8 e4 d4 c4 r')
#Display of sheet music
cp.show()
#Piano roll type display
cp.plot()
#Histogram display
cp.plot('histogram', 'pitch')
MIDI playback does not work. It should be audible if it is linked with the Web Audio API or if the device on the local machine is available, and I want to verify it even when I have time.
play.py
#It should be played with the following code on the reference...
cp.show('midi')
If anyone knows, please let me know.
Recommended Posts