Skip to content

Instantly share code, notes, and snippets.

@leonawicz
Created December 4, 2018 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonawicz/42e8e32726ff1db24f83cabb51b85d61 to your computer and use it in GitHub Desktop.
Save leonawicz/42e8e32726ff1db24f83cabb51b85d61 to your computer and use it in GitHub Desktop.
Example guitar arrangement using R code
title <- "Devil in me"
composer <- "Words and music by Gin Wigmore"
performer <- "Gin Wigmore"
album <- "Gravel and Wine"
subtitle <- paste("From the album", album, "by", performer)
arranger <- "Arranged by Matthew Leonawicz"
copyright <- "2011 Island Records"
tagline <- paste(arranger, Sys.Date())
# CHORDS
# strummed chords
d1 <- "d3a3d4f4"
f1 <- "f2c3f3a3c4f4"
g1 <- "g2d3g3b_3d4g4"
a1 <- "a2e3a3c#4e4"
b_1 <- "b_2f3b_3d4f4"
c1 <- "c3e3g3c4e4"
b_2 <- "b_3d4f4b_4"
c2 <- "c4e4g4c5"
f2 <- "c4f4a4c5"
d2 <- "d4f4a4"
f3 <- "c4f4a4"
g2 <- "d4g4b_4"
# chord diagrams
chord_names <- c("d:m", "f", "g:m", "a", "b_", "c", "s", "b_", "c", "f", "d:m", "f/c", "g:m/d")
chord_positions <- c("xxo231", "133211", "355333", "xo222o", "x13331", "x32o1o", NA, "xx8766", "xx(10)988", "xx(10)(10)(10)8", "xxx765", "xxx565", "xxx786")
# chord sequence
intro <- rep(c(1:3, 1), each = 2)
verse <- list(c(rep(rep(1:3, each = 2), 2), rep(1:2, each = 2), 3, 4), c(rep(1:3, each = 2), rep(1:2, each = 2), 3, 4))
chorus <- c(5:6, 2:1, 5:6)
interlude <- list(rep(1:2, each = 2), rep(c(1, 2, 1, 2, 1, 5, 1, 4), each = 2))
ending <- c(7, 1)
measures <- length(c(intro, unlist(verse), rep(chorus, 3), unlist(interlude), ending))
chord_seq <- rep(1, measures)
names(chord_seq) <- chord_names[c(intro, verse[[1]], chorus, interlude[[1]], verse[[2]], chorus, interlude[[2]], chorus, ending)]
chords <- chord_set(chord_positions, chord_names)
# GUITAR 1
# melody
txt <- c("Guitar 1 w/ tremolo. Guitars 3 and 4 rhythm figures played during intro.",
"Add guitar 3 intro rhythm figure during intro lead repeat.",
"Add guitar 4 intro rhythm figure until chorus.",
"Guitar solo. Add guitar 3 during solo.")
p1 <- purrr::map(txt[1:2], ~p("r a2 c3 f3 d3 a3 f3 b3~ b3~ b3", glue(notate("4", .x), "8*6 16^ 16 2..^"), "x 5 5 4 4 3 4 3 3 3"))
p2 <- p("r a3 c4 d4 a3 f4 d4 g4~ g4~ g4", "4 8*6 16^ 16 2.^", "x 4 3 3 4 2 3 2 2 2")
p2b <- gsub("\\.", "\\.\\.", p2)
p3 <- p("f4 g4 a3 c4 d4 f4 d4~ d4", "8 2 8*4 1 1", "2 2 4 3 3 2 3 3")
p4 <- glue(dup("r1", 5), p("r g3~ g3 r d3~ d3 r c5 c5 a4 r r r f4 d4~ d4 r r c5 a4~ a4 r r",
"4 2. 1 4 2. 1 2.. 16 16 1 1 1 4. 2 8 1 2 8 4 8 1 1 1",
"x 4 4 x 5 5 x 1 1 2 x*3 3*3 x x 1 2 2 x x"))
p5a <- p(glue(b_2, c2, f2, d2), "1*4", "4s*3 3s")
p5 <- purrr::map(1:2, ~glue(volta(p5a, .x), p(glue(b_2, c2), "1 1", "4s 4s")))
p6 <- p("r f4 d4 f4~ f4 r r a4c5 a4 r d5~g5~ d5g5 r a4 f4 d4 a3 r a4c5 c5 a4 f4 r d5g5 r",
glue("4. 4 4 8 1 2 8 4. 1 2. 4 1 4. 8 4 4 1", notate(4, txt[3]), "4. 4 8 1 4 2. 1"),
"x 3*4 x x 21 2 x 21 21 x 2 3 3 4 x 21 1 2 3 x 21 x")
p7 <- glue(volta(p5a, 2), p(glue(b_2, tie(c2), c2, d1), "1*4", dup("4s", 4)))
# solo
solo <- glue(
p("d3 c3 d3~ d3 a2 c3 d3 g3 a3 g3 f3~ f3 d4 f4 c5 a4 a3 f3",
glue(notate("2.", txt[4]), "8*6 8- 8- 8 8 2- 8 4 8 2 4 4"), "5*7 4*5 3 2 1 1 3 4"),
p("d3 d3 c3 d3~ d3 a2 c3 d3 g3 a3 g3 f3~ f3 r f4*5 e4",
"2 4 8*6 8- 8- 8 8 2 8*4 2 4 4", "5*8 4*5 x 2*6"),
p("d4 d4 c4 d4~ d4 f4 a3 c4 d4 c4 b_3 b_3 c4 d4~ d4 a3 f3",
"2 4 8*6 4 4 2 4 8 8 2 4 4", "3*5 2 4 3 3 3 4 4 3*4 4"),
p("d3 d3 c3 d3~ d3 a2 c3 d3 g3 a3 g3 a3~ a3 e4a4*4 e4a4e5*11 r",
"2 4 8*6 8- 8- 8 8 2- 16*14 2 8", "5*8 4*3 3 3 32*4 3s*11 x")
)
track1 <- track(glue(p1[[1]], p2, p3, p4, p5[[1]], p1[[2]], p2b, p6, p5[[2]], solo, p7))
# GUITAR 2
# rhythm
f <- function(notes, strings, n = 1) pct(p(dup(notes, 8), "8 8x 8*3 8x 8 8", dup(strings, 8)), n - 1)
p1a <- glue(f(d1, "4s", 2), f(f1, "6s", 2), f(g1, "6s", 2))
p1 <- glue(p1a, f(d1, "4s"), p(d1, "1]", "4s"))
p2 <- glue(p1a, p1a, f(d1, "4s", 2), f(f1, "6s", 2), f(g1, "6s"), p(dup(a1, 8), dup(8, 8), dup("5s", 8)))
p3a <- glue(f(b_1, "5s"), f(c1, "5s"), f(f1, "6s"), f(d1, "4s"))
p3 <- glue(volta(p3a, silent = TRUE), f(b_1, "5s"), p(c1, "1]", "5s"), f(d1, "4s", 2), f(f1, "6s"), p(f1, "1]", "6s"))
p4 <- glue(f(d1, "4s", 2), f(f1, "6s", 2), f(g1, "6s", 2), f(d1, "4s", 2), f(f1, "6s", 2), f(g1, "6s"), p(dup(a1, 8), dup(8, 8), dup("5s", 8)))
p5 <- glue(volta(p3a, 2, silent = TRUE), f(b_1, "5s"), p(c1, "1]", "5s"))
p6 <- glue(dup(glue(f(d1, "4s", 2), f(f1, "6s", 2)), 2), f(d1, "4s", 2), f(b_1, "5s", 2), f(d1, "4s", 2), f(a1, "5s", 2))
p7 <- glue(volta(p3a, 2, silent = TRUE), f(b_1, "5s"), p(glue(c1, "r r"), "1] 1 1", "5s x x"))
track2 <- track(glue(p1, p2, p3, p4, p5, p6, p7))
# GUITAR 3
f <- function(notes, n = 1) pct(p(glue("r", notes, "r", notes, "r"), "4 8] 4 8] 4", "x 3s x 3s x"), n - 1)
p1a <- glue(f(d2, 2), f(f3, 2), f(g2, 2), f(d2), p(glue(d2, "r"), "8] 2..", "3s x"))
p1b <- glue(f(d2, 2), f(f3), f(f3))
track3 <- track(p1a)
# GUITAR 4
f <- function(notes, n = 1) pct(p(glue(notes, "r", notes, "r"), "8] 4 8] 2", "54 x 54 x"), n - 1)
p1 <- glue(f("d3a3", 2), f("f3c4", 2), f("g3d4", 2), f("d3a3", 1), p(glue("d3a3 r"), "4 2.", "54 x"))
track4 <- track(p1)
# Generate tablature
song <- score(trackbind(track1, track2, track3, track4), chords, chord_seq)
header <- list(title = title, composer = composer, subtitle = subtitle, album = album, arranger = arranger, copyright = copyright, tagline = tagline)
outlily <- paste0(performer, " - ", title, ".ly")
outfile <- gsub(".ly", ".pdf", outlily)
lilypond(song, outlily, key = "dm", time = "4/4", tempo = "4 = 120", header)
tab(song, outfile, key = "dm", time = "4/4", tempo = "4 = 120", header)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment