-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
testpattern4.js
59 lines (45 loc) · 1.7 KB
/
testpattern4.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
const Pattern = require('./pattern/pattern.class.js');
const output = require('./midi/output.js');
const recorder = require('./midi/recorder.js');
const RecordedPattern = require('./pattern/recordedpattern.class.js');
const fs = require('fs');
global.startTime = Date.now();
global.bpm = 110;
global.currentBeat = () =>
((Date.now() -
global.startTime)/
(60*1000)
) * global.bpm;
const midi = require('midi');
const chord = (new class extends Pattern {
constructor() {
super(output);
this.channel = 2;
this.velocity = 127;
}
async play(notes, duration) {
await this.waitForBeat(Math.round(global.currentBeat()));
notes.forEach(note => this.playNote(note, duration));
};
});
const Arpeggiator = new require('./pattern/playable/arpeggiato1.js');
const pattern = new Arpeggiator(output);
const DrumPattern = require('./pattern/playable/drumpattern.js');
const drums = new DrumPattern(output);
const BasePattern = require('./pattern/playable/basepattern.js');
const base = new BasePattern(output);
// recorder('./recordings/recording4.json');
(async function() {
try {
new RecordedPattern(output, JSON.parse(fs.readFileSync('./recordings/recording2.json'))
.map(e => {
e[1][2] /= 3;
return e;
})).play();
new RecordedPattern(output, JSON.parse(fs.readFileSync('./recordings/recording3.json'))).play();
new RecordedPattern(output, JSON.parse(fs.readFileSync('./recordings/recording4.json'))).play();
} catch(e) {}
while(true) {
await drums.play('baseandhihats');
}
})();