@@ -740,7 +740,7 @@ parse_wjd_form_part <- function(form_part){
740
740
}
741
741
742
742
split_wjd_changes <- function (changes , id = " " ){
743
- print( id )
743
+ messagef( " Splitting chords for %s " , id )
744
744
lines <- strsplit(changes , " \n " )[[1 ]]
745
745
parts <- purrr :: map_dfr(lines , parse_wjd_form_part )
746
746
# browser()
@@ -758,6 +758,7 @@ split_wjd_changes <- function(changes, id = ""){
758
758
bar_number = bar_number + bar_offset ) %> %
759
759
select(- bar_offset ) %> %
760
760
mutate(id = id )
761
+ # browser()
761
762
parts
762
763
763
764
}
@@ -803,9 +804,13 @@ get_random_chord <- function(chord_db = parkR::irb){
803
804
804
805
expand_chord_changes <- function (split_changes , num_choruses = 1 , max_bar = NULL , with_key_analysis = T ){
805
806
n_ids <- length(unique(split_changes $ id ))
807
+ messagef(" ***Expanding %d chord changes" , n_ids )
806
808
if (n_ids > 1 ){
807
- return (purrr :: map_dfr(ids , function (i ){
808
- expand_chord_changes(split_changes %> % filter(id == i ))
809
+ return (purrr :: map_dfr(unique(split_changes $ id ), function (i ){
810
+ # messagef("### Recursive for %s", i)
811
+ tmp <- expand_chord_changes(split_changes %> % filter(id == i ))
812
+ # messagef("### Recursive return for %s", i)
813
+ tmp
809
814
}))
810
815
}
811
816
chorus_length <- max(split_changes $ bar_number )
@@ -817,10 +822,11 @@ expand_chord_changes <- function(split_changes, num_choruses = 1, max_bar = NULL
817
822
}
818
823
if (with_key_analysis ){
819
824
# browser()
825
+ messagef(" Enter key analysis (%d, %s)" , length(unique(split_changes $ id )), unique(split_changes $ id ))
826
+ # print()
820
827
ka <- key_analysis(chord_stream = split_changes $ original )
821
828
if (sum(ka $ unique ) == nrow(ka )){
822
829
split_changes <- bind_cols(split_changes , ka %> % select(local_key , local_scale_degree , tonic , tonic_pc ))
823
-
824
830
}
825
831
else {
826
832
messagef(" Could not find unique key analysis" )
@@ -829,9 +835,9 @@ expand_chord_changes <- function(split_changes, num_choruses = 1, max_bar = NULL
829
835
}
830
836
831
837
one_chorus <-
832
- purrr :: map_dfr(1 : nrow(split_changes ),function (row_id ){
838
+ purrr :: map_dfr(1 : nrow(split_changes ), function (row_id ){
833
839
t <- split_changes [row_id ,]
834
- purrr :: map_dfr(seq(t $ beat_pos , t $ beat_pos + t $ duration - 1 ), function (b ){
840
+ purrr :: map_dfr(seq(t $ beat_pos , t $ beat_pos + t $ duration - 1 ), function (b ){
835
841
t %> % select(- beat_pos ) %> % mutate(beat_pos = b )
836
842
})
837
843
})
@@ -844,6 +850,18 @@ expand_chord_changes <- function(split_changes, num_choruses = 1, max_bar = NULL
844
850
multi_choruses
845
851
}
846
852
853
+ create_wjd_local_key_annotations <- function (data = jazzodata :: wjd_meta ){
854
+ map_dfr(unique(data $ id ), function (i ){
855
+ tmp <- data %> % filter(id == i )
856
+ parkR ::: create_expanded_wjd_chord(tmp %> % select(id , chord_changes ),
857
+ num_choruses = tmp %> % pull(chorus_count ),
858
+ with_key_analysis = T )
859
+
860
+ }) %> %
861
+ mutate(melid = as.integer(factor (id )),
862
+ beat_id = sprintf(" %s_%s_%s" , melid , beat_pos , bar_number ))
863
+
864
+ }
847
865
create_expanded_wjd_chord <- function (changes , num_choruses = NULL , max_bar = NULL , with_key_analysis = F ){
848
866
purrr :: map2_dfr(changes $ chord_changes ,
849
867
changes $ id ,
0 commit comments