Skip to content

Commit 830afcb

Browse files
author
klaus
committed
Making nice
1 parent ceeadd7 commit 830afcb

30 files changed

+144
-165
lines changed

.Rbuildignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
^.*\.Rproj$
22
^\.Rproj\.user$
3+
.travis.yml
4+
^Makefile
5+
data_raw

DESCRIPTION

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
Package: sologenerator
1+
Package: parkR
22
Type: Package
3-
Title: Generate monophonic jazz solos for chord sequences
3+
Title: Generates monophonic jazz solos for chord sequences
44
Version: 0.1.0
5-
Author: NN
6-
Maintainer: NN <[email protected]>
5+
Authors@R: c(
6+
person("Klaus", "Frieler", email = "[email protected]", role = c("aut","cre"))
7+
)
8+
Maintainer: Klaus Frieler <[email protected]>
79
Description: Generates jazz solos using Weimar Bebop Alphabet atoms and midlevel units based on the Weimar Jazz Database.
8-
License: MIT
10+
License: MIT + file LICENSE
911
Encoding: UTF-8
12+
URL: https://github.com/klausfrieler/parkR
13+
BugReports: https://github.com/klausfrieler/parkR/issues
1014
LazyData: true
1115
Depends:
1216
R (>= 3.5.0),
1317
Imports:
1418
tidyverse (>= 1.2.1),
1519
ggplot2,
20+
ggthemes,
1621
dplyr,
1722
tibble,
1823
purrr,
24+
purrrlyr,
25+
tidyr,
1926
stringr,
2027
stats
2128
Suggests:

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
This project is licensed under the terms of the MIT license.
22

33
YEAR: 2021
4-
COPYRIGHT HOLDER: NN
4+
COPYRIGHT HOLDER: Klaus Frieler

NAMESPACE

+4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export(solo_to_mcsv2)
1313
export(write_mcsv2)
1414
import(dplyr)
1515
import(ggplot2)
16+
import(ggthemes)
17+
import(purrr)
18+
import(purrrlyr)
1619
import(stringr)
1720
import(tibble)
21+
import(tidyr)
1822
importFrom(stats,chisq.test)
1923
importFrom(utils,write.table)

NEWS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# sologenerator 0.1.0
1+
# parkR 0.1.0
22

33
Initial version.
44

R/chords.R

+8-8
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,9 @@ shift_pc_set <- function(pc_set, shift){
422422
}
423423
find_best_matching_scale <- function(pitch_set, root = pitch_set[1]){
424424
if(is.list(pitch_set)){
425-
print((pitch_set))
425+
#print((pitch_set))
426426
pitch_set <- purrr::reduce(pitch_set, union)
427-
print(sort(pitch_set))
427+
#print(sort(pitch_set))
428428
}
429429
candidates <- purrr::map_int(scales, function(x) length(intersect(shift_pc_set(x, root), pitch_set))) %>% sort(decreasing = T)
430430
best = candidates[candidates == max(candidates)]
@@ -441,7 +441,7 @@ blues <- tibble(chord = c("F7","Bb7", "F7", "Cmin7", "F7", "Bb7", "Bb7", "F7",
441441
length_beats = as.integer(c(4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4)))
442442
blues <- blues %>% mutate(length_ticks = length_beats*4) %>%
443443
mutate(parsed = purrr::map(chord, parse_chord)) %>%
444-
unnest(cols = parsed)
444+
tidyr::unnest(cols = parsed)
445445
blues$onset_ticks <- cumsum(blues$length_ticks)
446446
blues$onset_ticks <- blues$onset_ticks - blues$onset_ticks[1]
447447
blues$beat <- (floor(blues$onset_ticks/4) %%4 ) + 1
@@ -464,11 +464,11 @@ unroll_durations <- function(durations){
464464
#' @export
465465
create_from_irb <- function(compid, name = NULL, with_form = F){
466466
if(is.character(compid)){
467-
sheet <- sologenerator::irb[tolower(sologenerator::irb$title) == tolower(compid),] %>%
467+
sheet <- parkR::irb[tolower(parkR::irb$title) == tolower(compid),] %>%
468468
select(chord, duration, section, title, time, composer, date, compid, key)
469469
}
470470
else {
471-
sheet <- sologenerator::irb[sologenerator::irb$compid == compid,] %>% select(chord, duration, title, time)
471+
sheet <- parkR::irb[parkR::irb$compid == compid,] %>% select(chord, duration, title, time)
472472
}
473473
time <- strsplit(sheet$time[1], "/")[[1]]
474474
period <- as.integer(time[1])
@@ -483,7 +483,7 @@ create_from_irb <- function(compid, name = NULL, with_form = F){
483483
sheet %>%
484484
mutate(length_ticks = duration * ticks_per_beat) %>%
485485
mutate(parsed = purrr::map(chord, parse_chord)) %>%
486-
unnest(cols = parsed)
486+
tidyr::unnest(cols = parsed)
487487

488488
sheet$onset_ticks <- unroll_durations(sheet$length_ticks)
489489
sheet$running_beat <- unroll_durations(sheet$duration)
@@ -516,7 +516,7 @@ create_sheet <- function(name, chords, length_beats){
516516
length_beats = length_beats)
517517
tmp <- tmp %>% mutate(length_ticks = length_beats * 4) %>%
518518
mutate(parsed = purrr::map(chord, parse_chord)) %>%
519-
unnest(cols = c(parsed))
519+
tidyr::unnest(cols = c(parsed))
520520
tmp$onset_ticks <- cumsum(tmp$length_ticks)
521521
tmp$onset_ticks <- tmp$onset_ticks- tmp$onset_ticks[1]
522522
tmp$beat <- (floor(tmp$onset_ticks/4) %% 4 ) + 1
@@ -644,7 +644,7 @@ expand_chord_changes <- function(split_changes, num_choruses = 1, max_bar = NULL
644644
one_chorus <-
645645
purrr::map_dfr(1:nrow(split_changes),function(row_id){
646646
t <- split_changes[row_id,]
647-
purrr:::map_dfr(seq(t$beat_pos, t$beat_pos + t$duration-1), function(b){
647+
purrr::map_dfr(seq(t$beat_pos, t$beat_pos + t$duration-1), function(b){
648648
t %>% select(-beat_pos) %>% mutate(beat_pos = b)
649649
})
650650
})

R/data.R

+16-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@ NULL
1919
#' @docType data
2020
NULL
2121

22+
#' wba_mla
23+
#'
24+
#' Database of WBA atoms and midlevel units (MLUs)
25+
#' @name wba_mla
26+
#' @docType data
27+
NULL
28+
2229

2330
#' successor_dist
2431
#'
2532
#' First order Markov transitions of WBA atoms
26-
#' @name WBA_df
33+
#' @name successor_dist
2734
#' @docType data
2835
NULL
2936

@@ -43,11 +50,18 @@ NULL
4350

4451
#' length_dist
4552
#'
46-
#' Disbtribution of phrase lengths and relative phrase positions
53+
#' Disbtribution of number of phrases over WJD solos
4754
#' @name length_dist
4855
#' @docType data
4956
NULL
5057

58+
#' phrase_length_dist
59+
#'
60+
#' Disbtribution of phrase lengths and relative phrase positions
61+
#' @name phrase_length_dist
62+
#' @docType data
63+
NULL
64+
5165
#' F_blues
5266
#'
5367
#' Sample lead sheet of a sinple 12-bar jazz blues in F

R/imports.R

+12
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,21 @@ NULL
77
#' @import ggplot2
88
NULL
99

10+
#' @import ggthemes
11+
NULL
12+
1013
#' @import stringr
1114
NULL
1215

16+
#' @import purrr
17+
NULL
18+
19+
#' @import purrrlyr
20+
NULL
21+
22+
#' @import tidyr
23+
NULL
24+
1325

1426
#' @importFrom stats chisq.test
1527
NULL

R/interval_grammar.R

+21-23
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ vec_to_value <- function(int_vec){
4545
sprintf("[%s]", paste(int_vec, collapse=","))
4646
}
4747

48-
add_overlaps <- function(data, type=c("all", "pre", "post")) {
48+
add_overlaps <- function(data, type = c("all", "pre", "post")) {
4949
data <- data %>%
50-
mutate(pre_over = data.table::shift(data$end, type="lag")- data$start + 1)
50+
mutate(pre_over = dplyr::lag(data$end)- data$start + 1)
5151
data <- data %>%
52-
mutate(post_over = data.table::shift(data$pre_over, type="lead"))
52+
mutate(post_over = dplyr::lead(data$pre_over))
5353
if(type[1] == "all"){
5454
return(data)
5555
}
@@ -156,7 +156,7 @@ make_rle_df <- function(data, var){
156156
values_from_positions <- function(int_vector, data){
157157
values <- purrrlyr::by_row(data,
158158
function(x) vec_to_value(int_vector[x$start:x$end])) %>%
159-
unnest(cols = c(.out)) %>%
159+
tidyr::unnest(cols = c(.out)) %>%
160160
as.data.frame()
161161

162162
values[, ".out"]
@@ -165,7 +165,7 @@ values_from_positions <- function(int_vector, data){
165165
directions_from_positions <- function(int_vector, data){
166166
values <- purrrlyr::by_row(data,
167167
function(x) sign(sum(int_vector[x$start:x$end]))) %>%
168-
unnest(cols = c(.out)) %>%
168+
tidyr::unnest(cols = c(.out)) %>%
169169
as.data.frame()
170170

171171
values[, ".out"]
@@ -279,7 +279,7 @@ find_scales <- function(int_vector){
279279
###### second approach#######
280280
#types <- purrrlyr::by_row(scales,
281281
# function(x) classify_scale(int_vector[x$start:x$end])) %>%
282-
# unnest(cols = c(.out)) %>%
282+
# tidyr::unnest(cols = c(.out)) %>%
283283
# as.data.frame()
284284
#scales$type <- types[, ".out"]
285285

@@ -315,9 +315,6 @@ find_arpeggios <- function(int_vector){
315315
tmp
316316
}
317317

318-
by_row_result_to_vec <- function(by_row_result_tbl){
319-
by_row_result_tbl %>% select(cols = c(.out)) %>% unlist()
320-
}
321318

322319
find_chords <- function(int_vector){
323320
arp_int_vector <- sign(int_vector)*get_arp_int_from_int(int_vector)
@@ -344,11 +341,11 @@ find_chords <- function(int_vector){
344341
}
345342

346343
find_trills <- function(int_vector){
347-
sum_vector <- int_vector + data.table::shift(int_vector, 1, type="lead")
344+
sum_vector <- int_vector + dplyr::lead(int_vector, 1)
348345
zero_crossings <- intersect(which(sum_vector == 0),
349-
which(abs(int_vector) %in% c(1,2)))
346+
which(abs(int_vector) %in% c(1, 2)))
350347
#print(zero_crossings)
351-
trills<-get_rle_df(sum_vector) %>% filter(value == 0, length>0, start %in% zero_crossings)
348+
trills<-get_rle_df(sum_vector) %>% filter(value == 0, length > 0, start %in% zero_crossings)
352349
if(nrow(trills) == 0){
353350
return(NULL)
354351
}
@@ -373,22 +370,22 @@ find_trills <- function(int_vector){
373370
stringsAsFactors=F)
374371
}
375372

376-
find_bigram <- function(int_vector, bigram, value="F"){
377-
bigrams <- paste(int_vector, data.table::shift(int_vector, 1, type="lead"), sep=" ")
373+
find_bigram <- function(int_vector, bigram, value = "F"){
374+
bigrams <- paste(int_vector, dplyr::lead(int_vector, 1), sep = " ")
378375
bigram <- paste(bigram, collapse=" ")
379376
pos <- which(bigrams == bigram)
380377
if(length(pos) == 0){
381378
return(NULL)
382379
}
383-
values <- values_from_positions(int_vector, data.frame(start=pos, end=pos+1))
384-
directions <- directions_from_positions(int_vector, data.frame(start=pos, end=pos+1))
380+
values <- values_from_positions(int_vector, data.frame(start = pos, end = pos+1))
381+
directions <- directions_from_positions(int_vector, data.frame(start = pos, end = pos + 1))
385382
data.frame(length = 2,
386383
type = "F",
387384
value = values,
388385
direction = directions,
389386
start = pos,
390387
end = pos + 1,
391-
stringsAsFactors=F)
388+
stringsAsFactors = F)
392389
}
393390

394391
find_approaches <- function(int_vector){
@@ -546,7 +543,7 @@ remove_rows <- function(data, rows){
546543
data[left_over,]
547544
}
548545

549-
remove_redundants <- function(data, debug=F){
546+
remove_redundants <- function(data, debug = F){
550547
to_remove <- which(data$length == 2 &
551548
data$pre_over == 1 &
552549
data$post_over == 1 & data$type %in% c("F", "T"))
@@ -883,8 +880,9 @@ get_class_code_raw <- function(data, type = c("full", "reduced", "short", "exten
883880
}
884881

885882
compare_freq <- function(data1, data2, type="F"){
886-
tt <- bind_rows(tibble(source = 1, value=data1[data1$type == type,]$value),
887-
tibble(source = 2, value=data2[data2$type == type,]$value))
883+
tt <- bind_rows(
884+
tibble(source = 1, value=data1[data1$type == type,]$value),
885+
tibble(source = 2, value=data2[data2$type == type,]$value))
888886
#print(tt)
889887
tt$value <- factor(tt$value)
890888
tt1 <- table(tt[tt$source == 1,]$value)
@@ -902,7 +900,7 @@ hash_wba_dataframe <- function(data){
902900
too_long <- TRUE
903901
print(sprintf("Too long by %d", tl))
904902
}
905-
hashes <- by_row(data, function(x){
903+
hashes <- purrrlyr::by_row(data, function(x){
906904
hash_wba(x$type, x$direction, x$length)}) %>%
907905
select(cols = c(.out)) %>%
908906
unlist() %>%
@@ -932,8 +930,8 @@ find_wba <- function(x, debug = F){
932930
resolve_overlaps(debug = debug)
933931
}
934932

935-
recalc_pattern_classes <- function(){
936-
patterns <- lapply(unique(master$value), pattern_to_vec)
933+
recalc_pattern_classes <- function(data){
934+
patterns <- lapply(unique(data$value), pattern_to_vec)
937935
patterns_classes <- purrr::map(patterns,
938936
function(x) data.frame(pattern = vec_to_value(x),
939937
find_wba(x)))

R/output.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#' This function write a MCSV2 formated data fraem to a file
44
#'
55
#' @param data (data frame) MCSV2 formatted solo data.frame
6-
#' @param fname (character scale) path to write to.
6+
#' @param fname (character scalar) file path to write to.
77
#' @export
88
write_mcsv2 <- function(data, fname){
99
header <- strsplit("onset;duration;period;division;bar;beat;tatum;beat_duration;signature;pitch;phrase_id;phrase_begin", ";") %>% unlist()

0 commit comments

Comments
 (0)