leonawicz / tabr

R package: tabr. Notation-based and tidy music data analysis and transcription.
https://leonawicz.github.io/tabr/
Other
126 stars 10 forks source link

Using fretboard_plot on guitarChords #27

Closed ratnanil closed 5 years ago

ratnanil commented 5 years ago

I'd like to plot some Chords with fretboard_plot() based on the dataset guitarChords. I prefer to use fretboard_plot() over tab() since the latter only outputs to pdf, and I'd like to display the chords in a markdown file as simply as possible.

Anyway, is it true that the dataset guitarChords is not really optimized for fretboard_plot() or vice versa? What I'm currently doing is something like this:

suppressMessages(library(tabr))
suppressMessages(library(dplyr))
suppressMessages(library(purrr))
suppressMessages(library(stringr))
suppressMessages(library(ggplot2))

guitarChords <- guitarChords %>%
  mutate(
    fretboard2 = map(fretboard,~as.vector(str_split_fixed(.x,";",7))[1:6]),
    mute = map(fretboard2,~.x == "x"),
    fretboard2 = map(fretboard2,~as.integer(ifelse(.x=="x" | .x == "o",0,.x))),
    name = paste0(toupper(root),ifelse(id == "M","",id))
  )
id <- 500
fretboard_plot(6:1,guitarChords$fretboard2[[id]],mute = guitarChords$mute[[id]]) +
  ggtitle(guitarChords$name[id])

Created on 2019-11-04 by the reprex package (v0.3.0)

Is there a better way?

leonawicz commented 5 years ago

Thanks for sharing. Yeah that is not ideal. And no, I didn't make this plotting function with guitarChords in mind; it's more general purpose. As it says in the help docs, "under development and subject to change". Given that, I just improved the function, including fixing some glaring bugs so it works better now when you have a fret range that does not include zero, and took the liberty of changing the name to plot_fretboard. More to your concern, I added a corresponding plot_chord wrapper that is more tailored to individual chord fretboard diagrams like this use case. Going forward you should use that for specific chord diagrams and use plot_fretboard for more general patterns.

See the updated help file for examples and details. plot_chord will take the simple fret notation like xo221o (or x02210). You can also leave off any leading x: (02210). If you have two-digit fret numbers, the simple format won't work but you can use spaces or semicolons (like LilyPond format) such as "x 8 10 10 10 8" or "8;10;10;10;8". For plot_chord muted strings are inferred from the x.

Given that guitarChords is specifically for guitar chords I think it makes sense to have this variant of the function that works with this. No need to convert the concise fretted strings notation into two arbitrary vector sequences yourself as if you were defining a long scale run.