@@ -66,17 +66,32 @@ chord_definitions[["maj7"]][["scale_weights"]] <- c(1.0, 0.0, 0.0)
66
66
chord_definitions [[" maj7" ]][[" arpeggio" ]] <- c(- 12 , - 8 , - 5 , - 1 , 0 , 4 , 7 , 11 , 12 + 2 , 12 + 6 , 12 + 9 )
67
67
68
68
chord_definitions [[" maj" ]] <- chord_definitions [[" maj7" ]]
69
+ chord_definitions [[" 6" ]] <- chord_definitions [[" maj7" ]]
70
+
69
71
chord_definitions [[" min7" ]][[" scales" ]] <- list (" dorian" = dorian ,
70
72
" aeolian" = aeolian ,
71
73
" melodic_minor" = melodic_minor ,
72
74
" harmonic_minor" = harmonic_minor ,
73
75
" min_7_tetra" = min_7_tetra )
74
- # chord_definitions[["min7"]][["scale_weights"]] <- c(.7, .2, .05, .05)
75
76
chord_definitions [[" min7" ]][[" scale_weights" ]] <- c(1 . , 0.0 , 0.0 , 0.0 , 0.0 )
76
77
chord_definitions [[" min7" ]][[" arpeggio" ]] <- c(- 12 , - 9 , - 5 , - 2 , 0 , 3 , 7 , 10 , 12 + 2 , 12 + 5 , 12 + 9 )
77
78
78
79
chord_definitions [[" min" ]] <- chord_definitions [[" min7" ]]
79
80
81
+ chord_definitions [[" minb6" ]][[" scales" ]] <- list (" aeolian" = aeolian ,
82
+ " harmonic_minor" = harmonic_minor )
83
+ chord_definitions [[" minb6" ]][[" scale_weights" ]] <- c(1 . , 0.0 )
84
+ chord_definitions [[" minb6" ]][[" arpeggio" ]] <- c(- 12 , - 9 , - 5 , - 3 , 0 , 3 , 7 , 8 , 12 + 2 , 12 + 5 )
85
+
86
+ chord_definitions [[" min6" ]][[" arpeggio" ]] <- c(- 12 , - 9 , - 5 , - 4 , 0 , 3 , 7 , 9 , 12 , 12 + 3 )
87
+ chord_definitions [[" min6" ]][[" scales" ]] <- list (" dorian" = dorian )
88
+ chord_definitions [[" min6" ]][[" scale_weights" ]] <- c(1.0 )
89
+
90
+ chord_definitions [[" minmaj7" ]][[" arpeggio" ]] <- c(- 12 , - 9 , - 5 , - 1 , 0 , 3 , 7 , 11 , 12 , 12 + 3 )
91
+ chord_definitions [[" minmaj7" ]][[" scales" ]] <- list (" harmonic_minor" = harmonic_minor )
92
+ chord_definitions [[" minmaj7" ]][[" scale_weights" ]] <- c(1.0 )
93
+
94
+
80
95
chord_definitions [[" 7" ]][[" scales" ]] <- list (" mixolydian" = mixolydian ,
81
96
" mixolydian_sharp11" = mixolydian_sharp11 ,
82
97
" altered" = altered ,
@@ -101,14 +116,8 @@ chord_definitions[["o7"]][["scales"]] <- list("gtht" = gtht,
101
116
" dom_blues" = (major_blues + 6 ) %% 12 )
102
117
# chord_definitions[["o7"]][["scale_weights"]] <- c(.8, .2)
103
118
chord_definitions [[" o7" ]][[" scale_weights" ]] <- c(1.0 , 0.0 , 0.0 , 0.0 )
119
+ chord_definitions [[" o" ]] <- chord_definitions [[" o7" ]]
104
120
105
- chord_definitions [[" min6" ]][[" arpeggio" ]] <- c(- 12 , - 9 , - 5 , - 4 , 0 , 3 , 7 , 9 , 12 , 12 + 3 )
106
- chord_definitions [[" min6" ]][[" scales" ]] <- list (" dorian" = dorian )
107
- chord_definitions [[" min6" ]][[" scale_weights" ]] <- c(1.0 )
108
-
109
- chord_definitions [[" minmaj7" ]][[" arpeggio" ]] <- c(- 12 , - 9 , - 5 , - 1 , 0 , 3 , 7 , 11 , 12 , 12 + 3 )
110
- chord_definitions [[" minmaj7" ]][[" scales" ]] <- list (" harmonic_minor" = harmonic_minor )
111
- chord_definitions [[" minmaj7" ]][[" scale_weights" ]] <- c(1.0 )
112
121
113
122
chord_types <- c(" minmaj7" , " maj7" , " min7" , " min6" ," minb6" , " min" , " maj" , " m7b5" , " o7" , " o" , " 7" , " 6" )
114
123
extensions <- c(" add9" , " add3" , " sus" , " b5" , " alt" , " \\ +" , " 9b" , " 9#" , " 9" , " 11#" , " 11" , " 13b" , " 13" )
@@ -167,7 +176,7 @@ tone_name_to_pc <- Vectorize(function(tone){
167
176
pc <- sharp_pc - 1
168
177
}
169
178
else {
170
- message(sprintf( " Invalid tone %s" , tone ) )
179
+ messagef( " Invalid tone %s" , tone )
171
180
stop()
172
181
return (NA )
173
182
}
@@ -261,7 +270,7 @@ parse_chord <- function(chord_label){
261
270
}
262
271
else {
263
272
messagef(" Parsing %s" , chord_label )
264
- message(sprintf( " Unknown chord type in %s" , chord_label ) )
273
+ messagef( " Unknown chord type in %s" , chord_label )
265
274
stop()
266
275
return (NULL )
267
276
}
@@ -308,6 +317,9 @@ find_best_match_to_chord <- function(int_vector, start_pitch, chord, max_transpo
308
317
int_vector <- value_to_vec(int_vector )
309
318
}
310
319
tmp <- get_scale_pitches(chord , sample = F , return_weights = T )
320
+ if (is.null(tmp )){
321
+ return (integer(0 ))
322
+ }
311
323
scales <- tmp $ scales
312
324
scale_weights <- tmp $ weights
313
325
best_trans <- max_transposition + 1
@@ -335,6 +347,9 @@ weighted_sample <- function(sample_set, weights, size = 1){
335
347
w <- as.integer(round(weights / sum(weights ) * 100 ))
336
348
# print(w)
337
349
# print(sample_set)
350
+ if (is.null(sample_set )){
351
+ browser()
352
+ }
338
353
if (is.null(names(sample_set ))){
339
354
names(sample_set ) <- 1 : length(sample_set )
340
355
}
@@ -358,6 +373,11 @@ get_scale_pitches <- function(chord, min_pitch = 48, max_pitch = 84, sample = T,
358
373
return (NULL )
359
374
}
360
375
}
376
+ if (chord $ type == " NC" ){
377
+ message(" [get_scale_pitches] Found NC chord" )
378
+ return (NULL )
379
+ }
380
+
361
381
# print(chord)
362
382
for (i in 1 : nrow(chord )){
363
383
ct <- chord [i , ]$ type
@@ -455,24 +475,35 @@ unroll_durations <- function(durations){
455
475
tmp
456
476
}
457
477
458
- # ' create_from_irb
478
+ # ' create_leadhseet_chord_db
459
479
# '
460
- # ' This function generates a lead sheet data from parsed iRealBook data (irb),
480
+ # ' This function generates a lead sheet data from parsed chord data frame (irb or wjd_chord_db ),
461
481
# '
462
- # ' @param compid (integer or character scalar) If integer, then id of lead sheet in the iRealBook data (data(irb)), if character, than title of song
482
+ # ' @param db (chord data frame) Chord data frame to use
483
+ # ' @param compid (integer or character scalar) If integer, then id of lead sheet in the chord data, if character, than title of song
463
484
# ' @param name (character scalar) Currently unused
464
485
# ' @param with_form (logical scalar) Flag if form shall be added
465
486
# ' @return A leed sheet data frame
466
487
# ' @export
467
- create_from_irb <- function (compid , name = NULL , with_form = F ){
488
+ create_leadsheet_from_chord_db <- function (db , compid , name = NULL , with_form = F ){
468
489
if (is.character(compid )){
469
- sheet <- parkR :: irb [ tolower(parkR :: irb $ title ) == tolower(compid ),] %> %
490
+ sheet <- db % > % filter( tolower(title ) == tolower(!! compid )) %> %
470
491
select(chord , duration , section , title , time , composer , date , compid , key )
471
492
}
472
493
else {
473
- sheet <- parkR :: irb [parkR :: irb $ compid == compid ,] %> % select(chord , duration , title , time )
494
+ sheet <- db %> % filter(compid == !! compid ) %> % select(chord , duration , title , time )
495
+ }
496
+ if (nrow(sheet ) == 1 ){
497
+ return (NULL )
498
+ }
499
+ if (! nzchar(sheet $ time [1 ])){
500
+ time <- c(" 4" , " 4" )
501
+ }
502
+ else {
503
+ time <- strsplit(sheet $ time [1 ], " /" )[[1 ]]
504
+
474
505
}
475
- time <- strsplit( sheet $ time [ 1 ], " / " )[[ 1 ]]
506
+ # browser()
476
507
period <- as.integer(time [1 ])
477
508
denom <- as.integer(time [2 ])
478
509
if (period == 6 && denom == 8 ){
@@ -486,7 +517,6 @@ create_from_irb <- function(compid, name = NULL, with_form = F){
486
517
mutate(length_ticks = duration * ticks_per_beat ) %> %
487
518
mutate(parsed = purrr :: map(chord , parse_chord )) %> %
488
519
tidyr :: unnest(cols = parsed )
489
-
490
520
sheet $ onset_ticks <- unroll_durations(sheet $ length_ticks )
491
521
sheet $ running_beat <- unroll_durations(sheet $ duration )
492
522
sheet $ beat <- (sheet $ running_beat %% period ) + 1
@@ -504,7 +534,37 @@ create_from_irb <- function(compid, name = NULL, with_form = F){
504
534
sheet %> % set_format(" lead_sheet" )
505
535
}
506
536
507
- # ' create_sheet
537
+
538
+ # ' create_leadsheet_from_irb
539
+ # '
540
+ # ' This function generates a lead sheet data from parsed iRealBook data (irb),
541
+ # '
542
+ # ' @param compid (integer or character scalar) If integer, then id of lead sheet in the iRealBook data (data(irb)), if character, than title of song
543
+ # ' @param name (character scalar) Currently unused
544
+ # ' @param with_form (logical scalar) Flag if form shall be added
545
+ # ' @return A leed sheet data frame
546
+ # ' @export
547
+ create_leadsheet_from_irb <- function (compid , name = NULL , with_form = F ){
548
+ create_leadsheet_from_chord_db(parkR :: irb , compid , name , with_form )
549
+ }
550
+
551
+ # ' create_leadsheet_from_wjd_db
552
+ # '
553
+ # ' This function generates a lead sheet data from parsed WJD chord data (wjd_chord_db),
554
+ # '
555
+ # ' @param compid (integer or character scalar) If integer, then id of lead sheet in the iRealBook data (data(irb)), if character, than title of song
556
+ # ' @param name (character scalar) Currently unused
557
+ # ' @param with_form (logical scalar) Flag if form shall be added
558
+ # ' @return A leed sheet data frame
559
+ # ' @export
560
+ create_leadsheet_from_wjd_db <- function (compid , name = NULL , with_form = F ){
561
+ db <- parkR :: wjd_chord_db %> %
562
+ rename(chord = original ) %> %
563
+ left_join(parkR :: wjd_meta %> % select(title , id , time = signature ), by = " id" )
564
+ create_leadsheet_from_chord_db(db , compid , name , with_form )
565
+ }
566
+
567
+ # ' create_leadsheet
508
568
# '
509
569
# ' This function generates a lead sheet data frame from a vector of chord symbols and beat lengths per chord
510
570
# '
@@ -513,7 +573,7 @@ create_from_irb <- function(compid, name = NULL, with_form = F){
513
573
# ' @param length_beats (integer scalar) length of chord in beats
514
574
# ' @return A leed sheet data frame
515
575
# ' @export
516
- create_sheet <- function (name , chords , length_beats ){
576
+ create_leadsheet <- function (name , chords , length_beats ){
517
577
tmp <- tibble(chord = chords ,
518
578
length_beats = length_beats )
519
579
tmp <- tmp %> % mutate(length_ticks = length_beats * 4 ) %> %
@@ -526,6 +586,37 @@ create_sheet <- function(name, chords, length_beats){
526
586
tmp %> % set_format(" lead_sheet" )
527
587
}
528
588
589
+ # ' simulate_wjd
590
+ # '
591
+ # ' This function simulates a full Weimar Jazz Database, based on lead sheet, chorus counts and tempo
592
+ # '
593
+ # ' @param ids (integer vector) List of ids to create, ids shoudl be in the range 1 to 456, everything else will be ignored
594
+ # ' @return A data frame of generated solos
595
+ # ' @export
596
+ simulate_wjd <- function (ids = 1 : 456 ){
597
+ wjd_meta <- parkR :: wjd_meta %> % mutate(compid = as.integer(factor (id )))
598
+ ids <- as.integer(ids )
599
+ ids <- ids [ids > = 1 ] & ids [ids < = 456 ]
600
+ map_dfr(ids , function (cid ) {
601
+ # messagef("Generating %d...", cid)
602
+ sheet <- create_leadsheet_from_wjd_db(compid = cid )
603
+ if (! is.null(sheet )){
604
+ md <- wjd_meta %> % filter(compid == cid )
605
+ message(sprintf(" (%d): Generating %s with %d choruses" , cid , md $ id , md $ chorus_count ))
606
+ solo <- generate_solo(sheet , n_chorus = md $ chorus_count , tempo = round(md $ avgtempo ))
607
+ if (! is.null(solo )){
608
+ solo <- solo %> %
609
+ mutate(id = md $ id ,
610
+ # compid = md$compid,
611
+ # title = md$title,
612
+ # n_chorus = md$chorus_count,
613
+ # tempo = round(md$avgtempo),
614
+ .before = 1 )
615
+ }
616
+ solo
617
+ }
618
+ })
619
+ }
529
620
parse_wjd_bar <- function (bar_chords , bar_number = 1 ){
530
621
# print(bar_chords)
531
622
elements <- strsplit(bar_chords , " " )[[1 ]]
@@ -598,6 +689,7 @@ signed_mod <- function(x, n = 12){
598
689
r [which(r > n / 2 )] <- r [which(r > n / 2 )] - n
599
690
r
600
691
}
692
+
601
693
create_sheet_from_wjd_changes <- function (changes , form_parts = NULL ){
602
694
purrr :: map2_dfr(changes $ chord_changes ,
603
695
changes $ id ,
@@ -616,6 +708,11 @@ create_sheet_from_wjd_changes <- function(changes, form_parts = NULL){
616
708
617
709
}
618
710
711
+ # ' export
712
+ get_random_chord <- function (chord_db = parkR :: irb ){
713
+ sprintf(" %s%s" , sample(chord_db $ root , 1 ), sample(chord_db $ type , 1 ))
714
+ }
715
+
619
716
expand_chord_changes <- function (split_changes , num_choruses = 1 , max_bar = NULL , with_key_analysis = T ){
620
717
n_ids <- length(unique(split_changes $ id ))
621
718
if (n_ids > 1 ){
0 commit comments