-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo1.ts
194 lines (156 loc) · 5.68 KB
/
demo1.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
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
186
187
188
189
190
191
192
193
194
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;
class DemoPatterns {
AddPickingPattern_4_1(track, aChord) {
var intRoot = aChord[0];
var intMiddle = aChord[1];
var intFifth = aChord[2];
track.addNote(0, intRoot, beat)
track.addNote(0, intFifth, beat)
track.addNote(0, intMiddle, beat)
track.addNote(0, intFifth, beat)
}
AddPickingPattern_4_2(track, aChord) {
var intRoot = aChord[0];
var intNine = aChord[0] + 2;
var intMiddle = aChord[1];
var intFifth = aChord[2];
var intRoot2 = aChord[0] + 12;
var intNine2 = aChord[0] + 2 + 12;
var intMiddle2 = aChord[1] + 12;
var intFifth2 = aChord[2] + 12;
track.addNote(0, intRoot, beat / 2)
track.addNote(0, intNine, beat / 2)
track.addNote(0, intMiddle, beat / 2)
track.addNote(0, intFifth, beat / 2)
track.addNote(0, intRoot2, beat / 2)
track.addNote(0, intNine2, beat / 2)
track.addNote(0, intMiddle2, beat / 2)
track.addNote(0, intFifth2, beat / 2)
}
AddPickingPattern_4_3(track, aChord) {
var intRoot = aChord[0];
var intMiddle = aChord[1];
var intFifth = aChord[2];
var intRoot2 = aChord[0] + 12;
var intMiddle2 = aChord[1] + 12;
var intFifth2 = aChord[2] + 12;
var list = new Array();
list.push(intRoot);
list.push(intMiddle);
list.push(intFifth);
list.push(intRoot2);
list.push(intMiddle2);
list.push(intFifth2);
var i;
for (i = 0; i < 8; i++) {
var aNote = selectRandom(list);
track.addNote(0, aNote, beat / 2);
}
}
AddPickingPattern_4_4(track, aChord) {
var intRoot = aChord[0] - 24;
track.addNote(0, intRoot, beat * 3)
track.addNote(0, intRoot, beat * 1)
}
AddPickingPattern_4_5(track, aChord) {
var intRoot = aChord[0];
var nine1 = aChord[0] + 2;
var intMiddle = aChord[1];
var intFifth = aChord[2];
var intRoot2 = aChord[0] + 12;
var nine2 = nine1 + 12;
var intMiddle2 = aChord[1] + 12;
var intFifth2 = aChord[2] + 12;
var list = new Array();
list.push(intRoot);
list.push(nine1);
list.push(nine2);
list.push(intMiddle);
list.push(intFifth);
list.push(intRoot2);
list.push(intMiddle2);
list.push(intFifth2);
var i;
for (i = 0; i < 16; i++) {
var aNote = selectRandom(list);
track.addNote(0, aNote, beat / 4);
}
}
}
function demo1() {
var file = new Midi.File();
var chordList = new Array();
chordList.push(makeChord("d4", ChordType.Minor));
chordList.push(makeChord("a4", ChordType.Major));
chordList.push(makeChord("d4", ChordType.Minor));
chordList.push(makeChord("c4", ChordType.Major));
chordList.push(makeChord("f4", ChordType.Major));
chordList.push(makeChord("c4", ChordType.Major));
chordList.push(makeChord("d4", ChordType.Minor));
chordList.push(makeChord("a4", ChordType.Major));
var track = new Midi.Track();
track.setTempo(70);
file.addTrack(track);
let i = 0;
for (i = 0; i < chordList.length; i++) {
track.addNote(9, DrumNotes.BassDrum1, beat);
track.addNote(9, DrumNotes.SnareDrum, beat);
track.addNote(9, DrumNotes.BassDrum1, beat);
track.addNote(9, DrumNotes.SnareDrum, beat);
}
track = new Midi.Track();
file.addTrack(track);
for (i = 0; i < chordList.length; i++) {
track.addNote(9, DrumNotes.ClosedHighHat, beat / 2);
track.addNote(9, DrumNotes.ClosedHighHat, beat / 2);
track.addNote(9, DrumNotes.ClosedHighHat, beat / 2);
track.addNote(9, DrumNotes.ClosedHighHat, beat / 2);
track.addNote(9, DrumNotes.ClosedHighHat, beat / 2);
track.addNote(9, DrumNotes.ClosedHighHat, beat / 2);
track.addNote(9, DrumNotes.ClosedHighHat, beat / 2);
track.addNote(9, DrumNotes.ClosedHighHat, beat / 2);
}
// track ================================================================================
let patterns = new DemoPatterns();
track = new Midi.Track();
file.addTrack(track);
track.setInstrument(8);
track.setTempo(90);
var j = 0;
for (j = 0; j < chordList.length; j++) {
patterns.AddPickingPattern_4_3(track, chordList[j]);
}
// track ================================================================================
track = new Midi.Track();
file.addTrack(track);
track.setInstrument(8);
var j = 0;
for (j = 0; j < chordList.length; j++) {
patterns.AddPickingPattern_4_3(track, chordList[j]);
}
// track ================================================================================
track = new Midi.Track();
file.addTrack(track);
track.setInstrument(8);
for (j = 0; j < chordList.length; j++) {
patterns.AddPickingPattern_4_2(track, chordList[j]);
}
// track ================================================================================
track = new Midi.Track();
file.addTrack(track);
for (j = 0; j < chordList.length; j++) {
patterns.AddPickingPattern_4_4(track, chordList[j]);
}
// track ================================================================================
fs.writeFileSync('test.mid', file.toBytes(), 'binary');
}
demo1();