@@ -146,7 +146,7 @@ get_arp_int_from_int <- function(x){
146
146
return (sapply(x , get_arp_int_from_int ))
147
147
}
148
148
x <- x [1 ]
149
- if (! is.na(x ) && abs(x ) > = 3 ){
149
+ if (! is.na(x ) && abs(x ) > = 3 ){
150
150
return (TRUE )
151
151
}
152
152
return (FALSE )
@@ -203,7 +203,7 @@ make_rle_df <- function(data, var){
203
203
}
204
204
205
205
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 ])})
207
207
}
208
208
209
209
directions_from_positions <- function (int_vector , data ){
@@ -355,24 +355,34 @@ find_arpeggios <- function(int_vector){
355
355
356
356
357
357
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 )
359
359
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 ))
363
371
}
372
+ browser()
373
+
364
374
tmp $ type <- " J"
365
375
tmp $ value <- values_from_positions(int_vector , tmp )
366
376
triads <- ! as.logical(
367
377
unlist(
368
378
lapply(
369
379
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 )))
371
381
)
372
382
)
373
383
)
374
384
# print(triads)
375
- if (length(triads ) > 0 && sum(triads )){
385
+ if (length(triads ) > 0 && sum(triads )){
376
386
tmp [triads ,]$ type <- " A"
377
387
}
378
388
tmp
@@ -693,7 +703,7 @@ fuse_row_pair <- function(data, row_index){
693
703
694
704
resolve_row_pair <- function (data , row_index ){
695
705
# browser()
696
- if (row_index < 1 || row_index > nrow(data )){
706
+ if (row_index < 1 || row_index > nrow(data )){
697
707
stop(" Invalid row index" )
698
708
}
699
709
# pat1 <- data[row_index,]$pattern
0 commit comments