-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.js
169 lines (134 loc) · 4.5 KB
/
mod.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
const scribble = require('scribbletune');
const length = 32 * 16;
const twos = [...Array(length).keys()].map((a) => a + 1).filter((a) => a % 2 === 0);
const threes = [...Array(length).keys()].map((a) => a + 1).filter((a) => a % 3 === 0);
const fives = [...Array(length).keys()].map((a) => a + 1).filter((a) => a % 5 === 0);
const sevens = [...Array(length).keys()].map((a) => a + 1).filter((a) => a % 7 === 0);
const fours = [...Array(length).keys()].map((a) => a + 1).filter((a) => a % 8 === 1);
const eights = [...Array(length).keys()].map((a) => a + 1).filter((a) => a % 8 === 1);
const altEights = [...Array(length).keys()].map((a) => a + 1).filter((a) => (a - 4) % 8 === 1);
// Basic Pattern
const finalBasic = Array.from(
new Set(
threes
.concat(fives)
.concat(sevens)
.sort((a, b) => a - b)
)
)
.map((a, i) => (i % 2 === 0 ? null : a))
.filter((a) => !!a);
const basicPattern = [...Array(length).keys()].map((a) => (finalBasic.includes(a + 1) ? 'x' : '-')).join('');
console.log('Basic:');
console.log(basicPattern);
// Create a clip that plays the middle C
const basic = scribble.clip({
notes: 'c4',
pattern: basicPattern,
});
// Render a MIDI file of this clip
scribble.midi(basic, 'basic.mid');
// Kick Pattern
const kickAccents = Array.from(new Set(fives.concat(sevens).sort((a, b) => a - b)))
.map((a, i) => (i % 2 === 0 ? null : a))
.filter((a) => !!a);
const kickFinal = Array.from(new Set(eights.concat(kickAccents).sort((a, b) => a - b)));
const kickPattern = [...Array(length).keys()]
.map((a) => {
if (kickFinal.includes(a + 1)) {
if ((a + 5) % 8 === 1) {
return '-';
}
return 'x';
}
return '-';
})
.join('');
console.log('Kick:');
console.log(kickPattern);
// Create a clip that plays the middle C
const kick = scribble.clip({
notes: 'c4',
pattern: kickPattern,
accent: 'x-------',
});
// Render a MIDI file of this clip
scribble.midi(kick, 'kick.mid');
// Snare Pattern
const snareAccents = Array.from(new Set(fives.concat(sevens).sort((a, b) => a - b)))
.map((a, i) => (i % 2 === 1 ? null : a))
.filter((a) => !!a);
const snareFinal = Array.from(new Set(altEights.concat(snareAccents).sort((a, b) => a - b)));
const snarePattern = [...Array(length).keys()]
.map((a) => {
if (snareFinal.includes(a + 1)) {
if ((a + 4) % 8 === 1) {
return '-';
}
return 'x';
}
return '-';
})
.join('');
console.log('Snare:');
console.log(snarePattern);
// Create a clip that plays the middle C
const snare = scribble.clip({
notes: 'c4',
pattern: snarePattern,
accent: '----x---',
});
// Render a MIDI file of this clip
scribble.midi(snare, 'snare.mid');
// Hats
// const finalhats = Array.from(new Set(threes.concat(twos).sort((a, b) => a - b)))
// .map((a, i) => (i % 2 === 1 ? null : a))
// .filter((a) => !!a)
// .filter((a) => a % 4 !== 1);
// const hatsPattern = [...Array(length).keys()].map((a) => (finalhats.includes(a + 1) ? 'x' : '-')).join('');
// console.log('Hats:');
// console.log(hatsPattern);
// Create a clip that plays the middle C
const hats = scribble.clip({
notes: 'c4',
pattern: '--x-',
accent: '--x-',
});
// Render a MIDI file of this clip
scribble.midi(hats, 'hats.mid');
// Bass
const finalBass = Array.from(new Set(finalBasic.concat(fours).sort((a, b) => a - b)));
const bassPattern = [...Array(length).keys()].map((a) => (finalBass.includes(a + 1) ? 'x' : '-')).join('');
console.log('Bass:');
console.log(bassPattern);
// Create a clip that plays the middle C
const bass = scribble.clip({
notes: ['c4', 'f4', 'd4', 'g4'],
pattern: bassPattern,
});
// Render a MIDI file of this clip
scribble.midi(bass, 'bass.mid');
// Arp
const finalArp = finalBass;
const arpPattern = [...Array(length).keys()].map((a) => (finalArp.includes(a + 1) ? 'xxxxxxx-' : '-------')).join('');
console.log('Arp:');
console.log(arpPattern);
// Create a clip that plays the middle C
const arp = scribble.clip({
notes: scribble.arp({ chords: 'Cmaj7-4 Fmaj7-4 Dmin7-4 Gmaj7-4', order: '0123210', subdiv: '16n' }),
pattern: arpPattern,
});
// Render a MIDI file of this clip
scribble.midi(arp, 'arp.mid');
// Chords
const finalChord = finalBass;
const chordPattern = [...Array(length).keys()].map((a) => (finalChord.includes(a + 1) ? 'x' : '-')).join('');
console.log('Chord:');
console.log(chordPattern);
// Create a clip that plays the middle C
const chord = scribble.clip({
notes: ['CM', 'FM', 'Dm', 'GM'],
pattern: chordPattern,
});
// Render a MIDI file of this clip
scribble.midi(chord, 'chord.mid');