Under development. Please contribute.
The goal of music21
is to have an pipe-able API of music21 python library. It uses RStudio's excellent reticulate
package in the backend.
In practice, music21
is more limited than the python library. However, it is really easy to run any functions from music21
inside R.
music21
package is based on the music21
python library. On Ubuntu:
sudo apt-get install python-pip
sudo pip install pip --upgrade
sudo pip install music21
You can install music21
from github with:
# install.packages("devtools")
devtools::install_github("jtrecenti/music21")
To use the plot
and view
methods, you'll also have to install lilypond
:
sudo apt-get install lilypond
library(music21)
music21
#> Module(music21)
music21
object stores the python module. It is possible to run any function from it just by using $
, treating it as a Reference Class object.
note <- music21$note$Note("C#")
note
<music21.note.Note C#>
note %>%
plot()
get_composer("bach") %>%
head()
#> [1] "/usr/local/lib/python2.7/dist-packages/music21/corpus/bach/bwv1.6.mxl"
#> [2] "/usr/local/lib/python2.7/dist-packages/music21/corpus/bach/bwv10.7.mxl"
#> [3] "/usr/local/lib/python2.7/dist-packages/music21/corpus/bach/bwv101.7.mxl"
#> [4] "/usr/local/lib/python2.7/dist-packages/music21/corpus/bach/bwv102.7.mxl"
#> [5] "/usr/local/lib/python2.7/dist-packages/music21/corpus/bach/bwv103.6.mxl"
#> [6] "/usr/local/lib/python2.7/dist-packages/music21/corpus/bach/bwv104.6.mxl"
Let's get one of these paths and read:
bach_music <- get_composer("bach")[61] %>%
read_music()
Now let's plot the music!
bach_music %>%
plot()
In RStudio, you can use the view
function to see the music inside viewer pane.
bach_music[[1]]
#> {0.0} <music21.instrument.Instrument P1: Soprano: Instrument 1>
#> {0.0} <music21.stream.Measure 0 offset=0.0>
#> {0.0} <music21.clef.TrebleClef>
#> {0.0} <music21.key.Key of G major>
#> {0.0} <music21.meter.TimeSignature 4/4>
#> {0.0} <music21.note.Note G>
#> {1.0} <music21.stream.Measure 1 offset=1.0>
#> {0.0} <music21.note.Note G>
#> {1.0} <music21.note.Note F#>
#> {2.0} <music21.note.Note E>
#> {2.5} <music21.note.Note F#>
#> {3.0} <music21.note.Note G>
#> {3.5} <music21.note.Note A>
#> {5.0} <music21.stream.Measure 2 offset=5.0>
#> {0.0} <music21.note.Note B>
#> {0.5} <music21.note.Note C>
#> {1.0} <music21.note.Note A>
#> {2.0} <music21.note.Note G>
#> {3.0} <music21.note.Note G>
#> {9.0} <music21.stream.Measure 3 offset=9.0>
#> {0.0} <music21.note.Note G>
#> {1.0} <music21.note.Note A>
#> {1.5} <music21.note.Note G>
#> {2.0} <music21.note.Note F#>
#> {2.5} <music21.note.Note E>
#> {3.0} <music21.note.Note D>
#> {13.0} <music21.stream.Measure 4 offset=13.0>
#> {0.0} <music21.note.Note G>
#> {2.0} <music21.note.Note F#>
#> {3.0} <music21.note.Note F#>
#> {17.0} <music21.stream.Measure 5 offset=17.0>
#> {0.0} <music21.layout.SystemLayout>
#> {0.0} <music21.note.Note G>
#> {1.0} <music21.note.Note G>
#> {2.0} <music21.note.Note A>
#> {3.0} <music21.note.Note B>
#> {21.0} <music21.stream.Measure 6 offset=21.0>
#> {0.0} <music21.note.Note A>
#> {2.0} <music21.note.Note A>
#> {3.0} <music21.note.Note B>
#> {25.0} <music21.stream.Measure 7 offset=25.0>
#> {0.0} <music21.note.Note C>
#> {1.0} <music21.note.Note B>
#> {2.0} <music21.note.Note A>
#> {3.0} <music21.note.Note B>
#> {3.5} <music21.note.Note C>
#> {29.0} <music21.stream.Measure 8 offset=29.0>
#> {0.0} <music21.note.Note A>
#> {2.0} <music21.note.Note G>
#> {3.0} <music21.bar.Barline style=final>