Skip to content

Commit 58342a4

Browse files
author
klaus
committed
On my way to regenerate wjd_tpc
1 parent e81118f commit 58342a4

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

DESCRIPTION

+2-2
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 and more
4-
Version: 0.5.5
4+
Version: 0.5.6
55
Authors@R: c(
66
person("Klaus", "Frieler", email = "[email protected]", role = c("aut","cre"))
77
)
@@ -16,7 +16,7 @@ Depends:
1616
R (>= 3.5.0),
1717
Imports:
1818
tidyverse (>= 1.3.1),
19-
ggplot2,
19+
ggplot2 (>= 3.4.0),
2020
ggthemes,
2121
dplyr,
2222
tibble,

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export(cdpcx_hist)
77
export(chorus_to_mcsv2)
88
export(classify_int_pattern)
99
export(clean_scale)
10+
export(cpc_hist)
1011
export(cpc_plot_solo)
1112
export(create_leadsheet)
1213
export(create_leadsheet_from_chord_db)

R/chords.R

+24-6
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ parse_wjd_form_part <- function(form_part){
740740
}
741741

742742
split_wjd_changes <- function(changes, id = ""){
743-
print(id)
743+
messagef("Splitting chords for %s", id)
744744
lines <- strsplit(changes, "\n")[[1]]
745745
parts <- purrr::map_dfr(lines, parse_wjd_form_part)
746746
#browser()
@@ -758,6 +758,7 @@ split_wjd_changes <- function(changes, id = ""){
758758
bar_number = bar_number + bar_offset) %>%
759759
select(-bar_offset) %>%
760760
mutate(id = id)
761+
#browser()
761762
parts
762763

763764
}
@@ -803,9 +804,13 @@ get_random_chord <- function(chord_db = parkR::irb){
803804

804805
expand_chord_changes <- function(split_changes, num_choruses = 1, max_bar = NULL, with_key_analysis = T){
805806
n_ids <- length(unique(split_changes$id))
807+
messagef("***Expanding %d chord changes", n_ids)
806808
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
809814
}))
810815
}
811816
chorus_length <- max(split_changes$bar_number)
@@ -817,10 +822,11 @@ expand_chord_changes <- function(split_changes, num_choruses = 1, max_bar = NULL
817822
}
818823
if(with_key_analysis){
819824
#browser()
825+
messagef("Enter key analysis (%d, %s)", length(unique(split_changes$id)), unique(split_changes$id))
826+
#print()
820827
ka <- key_analysis(chord_stream = split_changes$original)
821828
if(sum(ka$unique) == nrow(ka)){
822829
split_changes <- bind_cols(split_changes, ka %>% select(local_key, local_scale_degree, tonic, tonic_pc))
823-
824830
}
825831
else{
826832
messagef("Could not find unique key analysis")
@@ -829,9 +835,9 @@ expand_chord_changes <- function(split_changes, num_choruses = 1, max_bar = NULL
829835
}
830836

831837
one_chorus <-
832-
purrr::map_dfr(1:nrow(split_changes),function(row_id){
838+
purrr::map_dfr(1:nrow(split_changes), function(row_id){
833839
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){
835841
t %>% select(-beat_pos) %>% mutate(beat_pos = b)
836842
})
837843
})
@@ -844,6 +850,18 @@ expand_chord_changes <- function(split_changes, num_choruses = 1, max_bar = NULL
844850
multi_choruses
845851
}
846852

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+
}
847865
create_expanded_wjd_chord <- function(changes, num_choruses = NULL, max_bar = NULL, with_key_analysis = F ){
848866
purrr::map2_dfr(changes$chord_changes,
849867
changes$id,

R/harmonic_analysis.R

+7-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ get_intrinsic_scale_degree <- function(chord_label, chord_pos = NULL){
108108
keys <- add_key(keys, "maj", chord)#Ij7
109109
keys <- add_key(keys, "maj", chord, offset = 7)#IVj7
110110
keys <- add_key(keys, "min", chord, offset = 4)#VIbj7
111-
keys <- add_key(keys, "min", chord, offset = -3)#IIIbj7
111+
#keys <- add_key(keys, "min", chord, offset = -3)#IIIbj7
112112
}
113113
if(ctype == "maj"){
114114
keys <- add_key(keys, "X", chord, offset = 5)#V
@@ -144,13 +144,15 @@ get_intrinsic_scale_degree <- function(chord_label, chord_pos = NULL){
144144
}
145145
if(ctype == "7"){
146146
keys <- add_key(keys, "X", chord, offset = +5) #V7
147-
keys <- add_key(keys, "X", chord, offset = -1) #IIb7
147+
if(chord$ext != "sus"){
148+
keys <- add_key(keys, "X", chord, offset = -1) #IIb7
149+
}
148150
if(!nzchar(chord$ext)){
149151
keys <- add_key(keys, "blues", chord, offset = 0) #I7
150152
keys <- add_key(keys, "blues", chord, offset = -5) #IV7
151153
}
152-
keys <- add_key(keys, "min", chord, offset = -8) #VIb7 in minor
153-
#keys <- add_key(keys, "maj", chord, offset = 1)
154+
#keys <- add_key(keys, "min", chord, offset = -8) #VIb7 in minor
155+
keys <- add_key(keys, "maj", chord, offset = 1) #VII7
154156
}
155157
if(ctype == "6"){
156158
keys <- add_key(keys, "maj", chord)#I6
@@ -470,7 +472,7 @@ key_analysis <- function(lead_sheet = NULL, chord_stream = NULL, with_ii_v_filte
470472
if(single_chord){
471473
ret <- chord_stream %>% filter((chord_pc - tonic_pc) %% 12 == 0)
472474
if(nrow(ret) == 0){
473-
chord_stream[1,]
475+
ret <- chord_stream[1,]
474476
}
475477
return(ret %>%
476478
mutate(chord_pos = 1,

man/cdpcx_hist.Rd

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

0 commit comments

Comments
 (0)