/
tabr-chordchart.Rmd
65 lines (51 loc) · 2.54 KB
/
tabr-chordchart.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
title: "Render chord charts"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Render chord charts}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
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:
* whose root note is either C or F
* the chords is either a 7th, major 7th, or minor 7th
* the chords do not contain sharps
* and the fret number of the root note is no higher than 12
```{r 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.
```{r chordchart, eval=FALSE}
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))
```
<p><img src="https://github.com/leonawicz/tabr/blob/master/data-raw/vignette-pngs/ex36.png?raw=true" class="centerimg" width="100%"></p>
The chord chart template must be kept to one page.