block by timelyportfolio d986116e741bfa85601c

Musical Notation in R with V8 and Verovio

Full Screen

Why?

I’m not sure why, but I guess because we can now with V8 and the emscriptenized Verovio. If you have any reason to need musical notation in SVG format in R, you will love this.

Code

library(V8)
library(htmltools)
library(pipeR)

ct = new_context("window")
# make a phony addEventListener function
ct$eval("window.addEventListener = function(){}")
# get the javascript
ct$source("http://rism-ch.github.io/verovio/javascript/verovio-toolkit.js")
# get a reference to the toolkit
ct$eval(
  "
  var vrvToolkit = new verovio.toolkit();
"
)
# assign data this way to avoid escaped character problems
ct$assign(  
  'data'
  ,"@clef:G-2\n\
    @keysig:xFCGD\n\
    @timesig:3/8\n\
    @data:'6B/{8B+(6B''E'B})({AFD})/{6.E3G},8B-/({6'EGF})({FAG})({GEB})/"
)

# get our svg
ct$eval(
  "
  vrvToolkit.renderData( 
    data,
    JSON.stringify({ inputFormat: 'pae' })
  );
"
) %>>%
  (
    tagList(
      tags$h1("Make Music in R with "
        ,tags$a(href = "https://www.opencpu.org/posts/v8-release-0-5/", "V8")
        ," and "
        ,tags$a(href = "http://rism-ch.github.io/verovio/index.xhtml","Verovio")
      )  
      ,HTML( . )
    )
  ) %>>%
  html_print %>>% ~ hf

Thanks @jeroenooms for V8 and @sckott/ROpenSci for gistr.

code.R