-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSequence.mjs
57 lines (48 loc) · 1.05 KB
/
Sequence.mjs
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
// class Note {
// constructor(frequency, velocity, timeStamp) {
// this.frequency = frequency;
// this.velocity = velocity;
// this.timeStamp = timeStamp;
// }
// }
export default class Sequence {
constructor(length) {
console.log('Sequence created')
/* holds Events
{
frequency: 0..127 or 0..16383,
velocity: 0..127 or 0..1
timeStamp: something relative to the start of the audio context time
}
*/
this.length = length;
this.events = [];
this.counter = 0;
}
accumClock() {
// console.log(this.counter);
// console.log(this.readEvent());
// accummulate the internal count
this.counter = (this.counter + 1) % this.length;
}
readEvent() {
// read the next event
return this.events[this.counter];
}
addEvent(ev) {
this.events.push(ev);
}
removeEvent() {
this.events.splice(idx, 1);
}
//
setAllEvents(seq) {
this.events = seq;
}
printSequence() {
console.log(this.events);
}
playEvent(idx) {
console.log(this.events[idx]);
}
}