-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
testpattern2.js
185 lines (158 loc) · 4.88 KB
/
testpattern2.js
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
const Pattern = require('./pattern/pattern.class.js');
const midi = require('midi');
global.startTime = Date.now();
global.bpm = 120;
// Set up a new output.
const output = new midi.output();
let outputIndex;
for(var n=0;n<output.getPortCount(); n++) {
if(output.getPortName(n) === 'virtual1') {
outputIndex = n;
}
}
output.openPort(outputIndex);
const pattern1 = new class extends Pattern {
constructor() {
super(output);
}
async play() {
this.setChannel(1);
this.velocity = 127;
while(true) {
this.playNote('c3', 1);
this.playNote('g#3', 1);
await this.waitForBeat(1);
this.playNote('e3', 1);
this.playNote('g#3', 1);
await this.waitForBeat(2);
this.playNote('g#3', 1);
await this.waitForBeat(2.5);
this.playNote('c3', 1);
await this.waitForBeat(3);
this.playNote('g#3', 1);
this.playNote('e3', 1);
await this.waitForBeat(4);
this.offset+=4;
}
}
};
const pattern2 = new class extends Pattern {
constructor() {
super(output);
}
async play() {
this.channel = 2;
this.velocity = 50;
while(true) {
await this.waitForBeat(0);
this.playNote('c6', 0.5);
this.playNote('d#6', 0.5);
this.playNote('g6', 0.5);
await this.waitForBeat(1.3);
this.playNote('c6', 0.5);
this.playNote('f6', 0.5);
this.playNote('g6', 0.5);
await this.waitForBeat(3);
this.playNote('c6', 0.5);
this.playNote('d6', 0.5);
this.playNote('g6', 0.5);
await this.waitForBeat(8);
this.offset+=8;
}
}
};
const pattern3 = new class extends Pattern {
constructor() {
super(output);
}
async play() {
this.channel = 3;
this.velocity = 100;
await this.waitForBeat(0);
this.playNote('c3', 0.5);
await this.waitForBeat(0.5);
this.playNote('c4', 0.25);
await this.waitForBeat(2.5);
this.playNote('c3', 0.25);
await this.waitForBeat(2.75);
this.playNote('c4', 0.25);
await this.waitForBeat(3.5);
this.playNote('c3', 0.15);
await this.waitForBeat(4);
this.playNote('c3', 0.5);
await this.waitForBeat(4.5);
this.playNote('a#3', 0.25);
await this.waitForBeat(6.5);
this.playNote('c3', 0.25);
await this.waitForBeat(6.75);
this.playNote('a#3', 0.25);
await this.waitForBeat(7.5);
this.playNote('c4', 0.5);
await this.waitForBeat(8);
}
};
const pattern4 = new class extends Pattern {
constructor() {
super(output);
}
async play() {
this.channel = 3;
this.velocity = 100;
await this.waitForBeat(0);
this.playNote('g#2', 0.5);
await this.waitForBeat(0.5);
this.playNote('g#3', 0.25);
await this.waitForBeat(2.5);
this.playNote('g#2', 0.25);
await this.waitForBeat(2.75);
this.playNote('g#3', 0.25);
await this.waitForBeat(3.5);
this.playNote('g#2', 0.15);
await this.waitForBeat(4);
this.playNote('g2', 0.5);
await this.waitForBeat(4.5);
this.playNote('g3', 0.25);
await this.waitForBeat(6.5);
this.playNote('g2', 0.25);
await this.waitForBeat(6.75);
this.playNote('g3', 0.25);
await this.waitForBeat(7.5);
this.playNote('g2', 0.5);
await this.waitForBeat(8);
}
};
pattern1.play();
pattern2.play();
(async function() {
pattern4.offset = 8;
while(true) {
console.log('pattern 3');
await pattern3.play();
pattern3.offset += 16;
console.log('pattern 4');
await pattern4.play();
pattern4.offset += 16;
}
})();
(new class extends Pattern {
constructor() {
super(output);
this.stepsperbeat = 4;
this.offset = 16;
}
async play() {
const notes = [0, 2, 3, 7, 12, 7, 3, 2];
let ndx = 0;
while(true) {
await this.waitForStep(ndx++);
this.velocity = Math.floor(Math.random() * 64 + 16);
const note = this.toNoteNumber('c5') + notes[ndx%notes.length];
this.note(note, 1 / this.stepsperbeat);
(async () => {
await this.waitForStep(ndx + 2);
this.velocity = Math.floor(this.velocity * (2/3));
this.note(note+12, 1 / this.stepsperbeat * 2);
})();
};
}
}).play();