Skip to content

Commit d78ccf6

Browse files
author
klaus
committed
See NEWS.md
1 parent faba391 commit d78ccf6

File tree

8 files changed

+82
-14
lines changed

8 files changed

+82
-14
lines changed

DESCRIPTION

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: parkR
22
Type: Package
33
Title: Generating monophonic jazz solos for chord sequences
4-
Version: 0.2.2
4+
Version: 0.4.0
55
Authors@R: c(
66
person("Klaus", "Frieler", email = "[email protected]", role = c("aut","cre"))
77
)
@@ -25,6 +25,7 @@ Imports:
2525
tidyr,
2626
stringr,
2727
stats,
28+
tictoc,
2829
tabr
2930
Suggests:
3031
devtools (>= 1.13.6)

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# parkR 0.4.0
2+
3+
* Added export for generated solso to PDF/Lilypond and MIDI via the tabr package
4+
* Fixed lot of bugs
5+
* Added some useful export functions
6+
17
# parkR 0.3.0
28

39
* Renamed create_from_irb and create_from wjd_db

R/chords.R

+16-2
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ fast_parse_chord <- function(chord_label){
316316
tibble(chord = chord_label) %>% left_join(parsed_chords, by = "chord") %>% select(-chord)
317317
}
318318

319+
chord_to_lilypond <- function(chord_labels, lengths = NULL){
320+
321+
chord <- fast_parse_chord(chord_labels)
322+
roots <- str_replace_all(chord$root, "b", "es") %>% str_replace_all("#", "is") %>% tolower() %>% str_replace("ees", "es")
323+
if(is.null(lengths)){
324+
chords <- sprintf("%s:%s", roots, chord$type)
325+
326+
}
327+
else {
328+
chords <- sprintf("%s%d:%s", roots, as.integer(floor(lengths)), chord$type)
329+
}
330+
chords
331+
}
319332
#' get_cdpcx
320333
#'
321334
#' This function transforms a set of (MIDI) pitches given a list of chords into the corresponding Extended Chordal Diatonic Pitch Classes (CDPCX)
@@ -613,8 +626,9 @@ create_leadsheet_from_irb <- function(compid, name = NULL, with_form = F){
613626
#' @export
614627
create_leadsheet_from_wjd_db <- function(compid, name = NULL, with_form = F){
615628
db <- parkR::wjd_chord_db %>%
616-
rename(chord = original) %>%
617-
left_join(parkR::wjd_meta %>% select(title, id, time = signature), by = "id")
629+
rename(chord = original, section = form_name) %>%
630+
left_join(parkR::wjd_meta %>%
631+
select(title, id, composer, date = recordingyear, key, time = signature), by = "id")
618632
create_leadsheet_from_chord_db(db, compid, name, with_form)
619633
}
620634

R/convert.R

+30-6
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ solo_to_mcsv2 <- function(solo_tbl, tempo = 120){
7676
#' @param tempo (double scale) Tempo (bpm) of the generated solo.
7777
#' @return A solo data frame in MCSV2 format
7878
#' @export
79-
solo_to_lilypond <- function(solo_tbl, file = "solo.pdf", key = "c", tempo = 120, ...){
79+
solo_to_lilypond <- function(solo_tbl, file = "solo.pdf", key = "c", tempo = 120, lead_sheet = NULL, ...){
8080
tmp <- solo_tbl %>%
8181
select(-c(type, mlu, phrase_id, chorus_id, chord)) %>%
8282
mutate(
@@ -87,8 +87,18 @@ solo_to_lilypond <- function(solo_tbl, file = "solo.pdf", key = "c", tempo = 120
8787
true_ioi = c(diff(mpos), NA),
8888
end_beat = floor(end_pos / ticks_per_beat) ,
8989
over_beat = beat != end_beat)
90+
#browser()
91+
9092
if(tmp[1,]$beat_pos != 0){
91-
patch_row <- tmp[1,] %>% mutate(pitch = -1, ioi = mpos, mpos = 0, overbeat = F)
93+
patch_row <- tmp[1,] %>% mutate(pitch = -1,
94+
ioi = mpos,
95+
mpos = 0,
96+
bar = 0,
97+
beat = 0, beat_pos = 0,
98+
end_pos = ioi,
99+
true_ioi = 5,
100+
end_beat = floor(ioi / ticks_per_beat),
101+
over_beat = ioi > 4)
92102
tmp <- bind_rows(patch_row, tmp)
93103
}
94104
#browser()
@@ -99,11 +109,17 @@ solo_to_lilypond <- function(solo_tbl, file = "solo.pdf", key = "c", tempo = 120
99109
tmp <- tmp %>%
100110
filter(ioi != true_ioi, mpos != 0) %>%
101111
mutate(pitch = -1,
112+
mpos = mpos + ioi,
102113
ioi = true_ioi - ioi,
103-
beat_pos = (beat_pos + ioi) %% ticks_per_beat) %>%
114+
true_ioi = ioi,
115+
bar = floor(mpos / ticks_per_bar),
116+
beat = floor(mpos / ticks_per_beat) ,
117+
beat_pos = mpos %% ticks_per_beat,
118+
end_pos = mpos + ioi - 1,
119+
end_beat = floor(end_pos / ticks_per_beat) ,
120+
over_beat = beat != end_beat) %>%
104121
mutate(tabr_dur = ioi_to_tabr_dur(ioi)) %>%
105122
bind_rows(tmp)
106-
107123
good_iois <- tmp %>% filter(tabr_dur != "split", !over_beat)
108124
bad_iois <- tmp %>% filter(tabr_dur == "split" | over_beat)
109125

@@ -127,11 +143,19 @@ solo_to_lilypond <- function(solo_tbl, file = "solo.pdf", key = "c", tempo = 120
127143
browser()
128144
}
129145
notes <- sprintf("%s%s", get_tabr_note(tmp$pitch), tmp$tilde)
130-
146+
chord_seq <- NULL
147+
attached_lead_sheet <- attr(solo_tbl, "lead_sheet")
148+
if(!is.null(attached_lead_sheet)){
149+
chord_seq <- setNames(4/attached_lead_sheet$duration, chord_to_lilypond(attached_lead_sheet$chord))
150+
}
151+
if(!is.null(lead_sheet)){
152+
chord_seq <- setNames(4/lead_sheet$duration, chord_to_lilypond(lead_sheet$chord))
153+
}
154+
browser()
131155
tabr::as_music(notes = notes, info = tmp$tabr_dur) %>%
132156
p() %>%
133157
track(tab = F) %>%
134-
score() %>%
158+
score(chord_seq = chord_seq) %>%
135159
tab(file = file, key = key, time = "4/4", tempo = sprintf("4 = %s", tempo))
136160
}
137161

R/interval_grammar.R

+18-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,27 @@ printf <- function(...) print(sprintf(...))
44
messagef <- function(...) if(parkR::parkr_options()$debug) message(sprintf(...))
55

66
#' @export
7-
value_to_vec <- function(value_str){
7+
value_to_vec <- function(value_str, type = c("integer", "character"), collapse = ""){
8+
type <- match.arg(type)
89
vec <- gsub("\\[", "", as.character(value_str))
910
vec <- gsub("\\]", "", vec)
11+
vec <- gsub("[\\{\\(]+", "", vec)
12+
vec <- gsub("[\\}\\)]+", "", vec)
1013
vec <- gsub(" ", "", vec)
11-
as.integer(unlist(strsplit(vec, ",")))
14+
if(type == "integer"){
15+
as.integer(unlist(strsplit(vec, ",")))
16+
ret <- map(strsplit(vec, ","), ~{as.integer(.x)})
17+
if(length(value_str) == 1){
18+
ret <- ret[[1]]
19+
}
20+
}
21+
else {
22+
ret <- strsplit(vec, ",")
23+
if(!is.null(collapse) & !nzchar(collapse)){
24+
ret <- map(ret, ~{paste(.x, collapse = collapse)}) %>% unlist()
25+
}
26+
}
27+
ret
1228
}
1329

1430
# column_to_vector <- function(tbf, col_name) tbf[[col_name]]

data-raw/data_import.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
library(tidyverse)
22
F_blues <- tibble(chord = c("F7","Bb7", "F7", "Cmin7", "F7", "Bb7", "Bb7", "F7", "F7", "Gmin7", "C7", "F7", "F7"),
3-
length_beats = as.integer(c(4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4)))
4-
F_blues <- F_blues %>% mutate(length_ticks = length_beats*4) %>%
3+
duration = as.integer(c(4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4)))
4+
F_blues <- F_blues %>% mutate(length_ticks = duration * 4) %>%
55
mutate(parsed = map(chord, parkR::parse_chord)) %>%
66
tidyr::unnest(cols = parsed)
77
F_blues$onset_ticks <- cumsum(F_blues$length_ticks)

data/F_blues.rda

15 Bytes
Binary file not shown.

man/solo_to_lilypond.Rd

+8-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)