-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo3.ts
94 lines (64 loc) · 2.53 KB
/
demo3.ts
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
var fs = require('fs');
var Midi = require('jsmidgen');
var Util = require('jsmidgen').Util;
import mm = require('./MusicMaker')
var beat = 128;
var DrumNotes = mm.DrumNotes;
var selectRandom = mm.SelectRandom;
var makeChord = mm.MakeChord;
var addRhythmPattern = mm.AddRhythmPattern;
var ChordType = mm.ChordType;
function demo3() {
var file = new Midi.File();
var track;
var j;
track = new Midi.Track();
track.setTempo(80);
file.addTrack(track);
for (j = 0; j < 8; j++) {
var scale1 = mm.MakeScale("a5", mm.ScaleType.Blues, 1);
var i;
for (i = 0; i < 4 * 4 * 2; i++) {
var velocity = Math.floor(Math.random() * 100);
var currentNote = mm.SelectRandom(scale1);
track.addNote(0, currentNote, beat / 2, 0, velocity)
}
}
track = new Midi.Track();
file.addTrack(track);
for (j = 0; j < 8; j++) {
track.addChord(0, mm.MakeChord("a4", ChordType.Major), beat * 4);
track.addChord(0, mm.MakeChord("g4", ChordType.Major), beat * 4);
track.addChord(0, mm.MakeChord("f4", ChordType.Major), beat * 4);
track.addChord(0, mm.MakeChord("e4", ChordType.Major), beat * 4);
}
track = new Midi.Track();
file.addTrack(track);
mm.Repeat(8, function () {
track.addNote(0, "a2", beat * 3);
track.addNote(0, "a2", beat);
track.addNote(0, "g2", beat * 3);
track.addNote(0, "g2", beat);
track.addNote(0, "f2", beat * 3);
track.addNote(0, "f2", beat);
track.addNote(0, "e2", beat * 3);
track.addNote(0, "e2", beat);
})
track = new Midi.Track();
file.addTrack(track);
mm.Repeat(8, function () {
mm.AddRhythmPattern(track, "x---|---x|x---|---x", mm.DrumNotes.BassDrum1);
})
track = new Midi.Track();
file.addTrack(track);
mm.AddRhythmPattern(track, "----|x---|----|x---", mm.DrumNotes.SnareDrum);
mm.AddRhythmPattern(track, "----|x---|----|x--x", mm.DrumNotes.SnareDrum);
mm.AddRhythmPattern(track, "----|x---|----|x---", mm.DrumNotes.SnareDrum);
mm.AddRhythmPattern(track, "----|x---|---x|x---", mm.DrumNotes.SnareDrum);
mm.AddRhythmPattern(track, "----|x---|----|x---", mm.DrumNotes.SnareDrum);
mm.AddRhythmPattern(track, "----|x---|----|x--x", mm.DrumNotes.SnareDrum);
mm.AddRhythmPattern(track, "----|x---|---x|x---", mm.DrumNotes.SnareDrum);
mm.AddRhythmPattern(track, "----|x---|----|x---", mm.DrumNotes.SnareDrum);
fs.writeFileSync('test.mid', file.toBytes(), 'binary');
}
demo3();