-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay1.2_Workshop.Rmd
69 lines (40 loc) · 1.29 KB
/
Day1.2_Workshop.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
title: "humdrumR workshop, day 1 afternoon."
output: html_notebook
---
```{r}
readHumdrum('ChoralesBH/KernOnly/.*krn') -> bach
readHumdrum('Essen/deutschl/.*/.*krn') -> essen
readHumdrum('MCFlow/.*rap') -> mcflow
readHumdrum('CoCoPops-Billboard/.*hum') -> billboard
subset(billboard, Exclusive == 'harmony') |> removeEmptySpines() -> billboard
billboard <- within(billboard, Harm <- harm(Token))
readHumdrum('TAVERN/.*.krn') -> tavern
```
# Ngrams
Within `with/within` we can use a special syntax to get n-grams.
```{r}
bach <- within(bach, Kern <- kern(Token, simple = TRUE))
with(bach, tally(Token, lag(Token, 1)))
# -> can be written:
with(bach, tally(Token[lag = 0:1]))
with(bach, paste(Token, lag(Token, 1), lag(Token, 2), lag(Token, 3), lag(Token, 4)))
# -> can be written:
with(bach, paste(Token[lag = 0:-4]))
```
# Melodic and Harmonic intervals
We can calculate melodic and harmonic intervals usin `mint()` and `hint()`.
```{r}
within(chorales, mint(Token))
within(chorales, hint(Token))
```
# Time
The `timeline()` function measures duration from the beginning of the piece:
```{r}
within(bach, timeline(Token, pickup = Bar == 0))
```
`count()` is similar...
```{r}
within(chorales, count(Token, beat = tactus(TimeSignature), pickup = Bar == 0))
```
`metlev()`, `metcount()`