python music21 port using reticulate
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R
man
.Rbuildignore
.gitignore
.travis.yml
DESCRIPTION
LICENSE
NAMESPACE roxygen2 automatic documentation Oct 13, 2017
README-bach-1.png
README-note-1.png
README.Rmd
README.md try to use pip3 Oct 6, 2018
music21.Rproj

README.md

Travis-CI Build Status

Under development. Please contribute.

music21

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.

Installation

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

music21 object

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()

Example

Show bach chorales

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()

Plot bwv165.6 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.

Print bwv165.6 music (soprano part)

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>