-
Notifications
You must be signed in to change notification settings - Fork 0
/
tg.ck
121 lines (95 loc) · 2.11 KB
/
tg.ck
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//basic timing operations abbreviated
public class TimeGrid {
dur beat;
dur meas;
dur sect;
int nbeat;
int nmeas;
//phase and magnitude of offset
float measPhase;
dur measOffset;
fun void set(dur mybeat, int nb, int nm) {
mybeat => beat;
nb => nbeat;
beat*nbeat => meas;
nm => nmeas;
meas*nmeas => sect;
}
//sync to beat
fun void sync() {
beat - (now % beat) => now;
}
fun void sync(dur T) {
T - (now % T) => now;
}
//how long to sync to this duration
fun dur syncDur(dur T) {
return (T - (now % T));
}
//minimum time
fun dur tmin(dur a, dur b) {
return (a < b) ? a : b;
}
//get beat in relation to section
fun int guess() {
//this approach would not count sections
//return ((now % sect) / beat) $ int;
//this approach is completely global
return (now / beat) $ int;
}
//get the mod rhythm
fun int bmod(int r) {
return (r%nbeat);
}
fun int mmod(int r) {
return (r/nbeat%nmeas);
}
fun int smod(int r) {
return (r/nbeat/nmeas);
}
//section markers
int g;
int b;
int m;
int s;
int i;
int j; //for anything, really
int c; //counter in measure
int d; //counter in section
//events for stuff
Event newMeas;
Event newSect;
//update markers
fun int up() {
guess() => g;
//experimental
if ( b-bmod(g)>0 ) { //if b decreases
0=>c;
newMeas.broadcast();
}
else c++;
//TODO: make a c but for the measure
if ( m-mmod(g)>0 ) { //if m decreases
0 => d;
newSect.broadcast();
}
else d++;
bmod(g) => b;
mmod(g) => m;
smod(g) => s;
i++;
return true;
}
//update the markers of another timeGrid
fun int up( TimeGrid tg ) {
this.up();
b => tg.b;
m => tg.m;
s => tg.s;
g => tg.g;
c => tg.c;
i => tg.i;
j => tg.j;
return true;
}
}