options(crayon.enabled = TRUE)
sgr_wrap <- function(x, options){
  paste0("<pre class=\"r-output\"><code>", fansi::sgr_to_html(x = htmltools::htmlEscape(x)), "</code></pre>")
}
knitr::knit_hooks$set(output = sgr_wrap)
knitr::opts_chunk$set(
  collapse = TRUE, comment = "#>", message = FALSE, warning = FALSE, error = FALSE, tidy = FALSE, out.width = "100%"
)
library(tabr)
library(dplyr)

The plot_fretboard() function can be used to create general fretboard diagrams directly in R using ggplot and plot_chord() specifically produces single chord diagrams, but this vignette shows how to create a standalone chord chart using LilyPond. Instead of using tab() to render a score to pdf that may contain a chord chart at the top of the first page, you can use render_chordchart(). This function creates the necessary LilyPond file and sends it to LilyPond for final rendering.

Prepare chords

For consistency, render_chordchart() takes chord input in the same way that score() does, as a named character vector. The chords and their names are in the same format.

Filter the guitarChords dataset down to chords:

library(dplyr)

chords <- filter(
  guitarChords, 
  root %in% c("c", "f") & 
    id %in% c("7", "M7", "m7") &
    !grepl("#", notes) & root_fret <= 12
  ) |>
  arrange(root, id)

chords <- setNames(chords$fretboard, chords$lp_name)
head(chords)

Render chord chart

The filtering above results in 41 chords. The size of the fretboard diagrams is increased below with size = 2. Like lilypond() and the render_* functions that wrap around it for rendering music scores, render_chordchart() also takes the header and paper named list arguments. Once the named chord vector is ready, rendering the chord chart is as simple as the following.

hdr <- list(
  title = "Dominant 7th, major 7th and minor 7th chords",
  subtitle = "C and F root"
)
render_chordchart(chords, "out.png", 2, hdr, list(textheight = 175))

The chord chart template must be kept to one page.



leonawicz/tabr documentation built on Sept. 24, 2023, 2:49 p.m.