Skip to content

Commit 1fdf58d

Browse files
author
klaus
committed
Improved arpgeggio WBA to contain direction change
1 parent 1e63535 commit 1fdf58d

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

DESCRIPTION

+1-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 and more
4-
Version: 0.5.7
4+
Version: 0.5.8
55
Authors@R: c(
66
person("Klaus", "Frieler", email = "[email protected]", role = c("aut","cre"))
77
)

R/interval_grammar.R

+19-9
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ get_arp_int_from_int <- function(x){
146146
return(sapply(x, get_arp_int_from_int))
147147
}
148148
x <- x[1]
149-
if(!is.na(x) && abs(x) >=3 ){
149+
if(!is.na(x) && abs(x) >= 3 ){
150150
return(TRUE)
151151
}
152152
return(FALSE)
@@ -203,7 +203,7 @@ make_rle_df <- function(data, var){
203203
}
204204

205205
values_from_positions <- function(int_vector, data){
206-
map2_chr(data$start, data$end, ~{vec_to_value(int_vector[.x:.y])})
206+
map2_chr(data$start, data$end, ~{vec_to_value(int_vector[.x : .y])})
207207
}
208208

209209
directions_from_positions <- function(int_vector, data){
@@ -355,24 +355,34 @@ find_arpeggios <- function(int_vector){
355355

356356

357357
find_chords <- function(int_vector){
358-
arp_int_vector <- sign(int_vector)*get_arp_int_from_int(int_vector)
358+
arp_int_vector <- sign(int_vector) * get_arp_int_from_int(int_vector)
359359
tmp <- get_rle_df(arp_int_vector)
360-
tmp <- tmp %>% filter(value > 0, length>1)
361-
if(nrow(tmp) == 0){
362-
return(NULL)
360+
tmp2 <- tmp %>% filter(value != 0, length > 1)
361+
if(nrow(tmp2) == 0){
362+
iv <- int_vector[int_vector != 0] %>% cumsum()
363+
iv <- iv %% 12 %>% sort() %>% diff()
364+
if(length(setdiff(iv, c(3, 4))) != 0){
365+
return(NULL)
366+
}
367+
tmp <- tibble(length = length(int_vector),
368+
direction = sign(cumsum(int_vector)[-1]),
369+
start = 1,
370+
end = length(int_vector))
363371
}
372+
browser()
373+
364374
tmp$type <- "J"
365375
tmp$value <- values_from_positions(int_vector, tmp)
366376
triads<- !as.logical(
367377
unlist(
368378
lapply(
369379
tmp$value,
370-
function(x) length(setdiff(unique(abs(value_to_vec(x))), c(3,4)))
380+
function(x) length(setdiff(unique(abs(value_to_vec(x))), c(3, 4)))
371381
)
372382
)
373383
)
374384
#print(triads)
375-
if(length(triads) >0 && sum(triads)){
385+
if(length(triads) > 0 && sum(triads)){
376386
tmp[triads,]$type <- "A"
377387
}
378388
tmp
@@ -693,7 +703,7 @@ fuse_row_pair <- function(data, row_index){
693703

694704
resolve_row_pair <- function(data, row_index){
695705
#browser()
696-
if(row_index <1 || row_index > nrow(data)){
706+
if(row_index < 1 || row_index > nrow(data)){
697707
stop("Invalid row index")
698708
}
699709
#pat1 <- data[row_index,]$pattern

0 commit comments

Comments
 (0)