Learn R Programming

tabr (version 0.4.0)

plot_music: Plot sheet music snippet with LilyPond

Description

These functions are wrappers around the render_music_* functions. They abstract the process of rendering a sheet music snippet to png and loading the rendered image back into R to be displayed as a plot in an open graphics device or inserted into an R markdown code chunk.

Usage

plot_music(
  music,
  clef = "treble",
  tab = FALSE,
  tuning = "standard",
  string_names = NULL,
  header = NULL,
  paper = NULL,
  colors = NULL,
  res = 300
)

plot_music_tc(music, header = NULL, paper = NULL, colors = NULL, res = 300)

plot_music_bc(music, header = NULL, paper = NULL, colors = NULL, res = 300)

plot_music_tab( music, clef = NA, tuning = "standard", string_names = NULL, header = NULL, paper = NULL, colors = NULL, res = 300 )

plot_music_guitar( music, tuning = "standard", string_names = NULL, header = NULL, paper = NULL, colors = NULL, res = 300 )

plot_music_bass( music, tuning = "bass", string_names = FALSE, header = NULL, paper = NULL, colors = NULL, res = 300 )

Arguments

music

a music object.

clef

character, include a music staff with the given clef. NA to suppress. See track for details.

tab

logical, include tablature staff. NA to suppress. See track.

tuning

character, string tuning, only applies to tablature. See track.

string_names

label strings at beginning of tab staff. NULL (default) for non-standard tunings only, TRUE or FALSE for force on or off completely.

header

a named list of arguments passed to the header of the LilyPond file. See lilypond details.

paper

a named list of arguments for the LilyPond file page layout. See lilypond details.

colors

a named list of LilyPond element color global overrides. See lilypond for details.

res

numeric, resolution, png only. Defaults to 300.

Value

a plot

Details

While these functions abstract away the details of the process, this is not the same as making the plot completely in R. R is only displaying the intermediary png file. LilyPond is required to engrave the sheet music.

For R markdown you can alternatively render the png using the corresponding render_music_* function and then place it in the document explicitly using knitr::include_graphics. Transparency is not relevant to these wrapper functions since they are used only for plotting, not for overlays on existing. See render_music for more details.

See Also

render_music, phrase, track, score, lilypond, tab

Examples

Run this code
# NOT RUN {
x <- "a,4;5*5 b,4- c4 cgc'e'~4 cgc'e'1 e'4;2 c';3 g;4 c;5 ce'1;51"
x <- as_music(x)

y <- "a,,4;3*5 b,,4- c,4 c,g,c~4 c,g,c1 c4;1 g,;2 c,;3 g,;2 c,c1;31"
y <- as_music(y)

# }
# NOT RUN {
if(tabr_options()$lilypond != ""){ # requires LilyPond installation
  plot_music(x)
  plot_music(x, "treble_8", tab = TRUE)

  plot_music_tc(x)
  plot_music_bc(x)

  plot_music_tab(x)
  plot_music_guitar(x)
  plot_music_bass(y)
}
# }

Run the code above in your browser using DataLab