-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
201 lines (172 loc) · 6.1 KB
/
index.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import Synth from './modules/synth.js'
import MixerChannel from './modules/mixer-channel.js'
import MidiRouter from './modules/midi-router.js'
import SampleLoader from './modules/sample-loader.js'
import Slicer from './modules/slicer.js'
import DrumSampler from './modules/drum-sampler.js'
import DelayFX from './modules/delay-fx.js'
import ReverbFX from './modules/reverb-fx.js'
const BEAT_TICKS = 24
window.audioContext = new AudioContext()
console.log("I'M THE ONE AND ONLY DOMINATOR")
document.getElementById('start').addEventListener('click', (ev) => {
window.audioContext.resume()
ev.target.disabled = true
ev.target.innerText = 'BREEEEOOOOOMMM'
window.setTimeout(() => {
ev.target.hidden = true
}, 300)
})
var clockDisplay = document.getElementById('clock')
var cueDisplay = document.getElementById('cueDisplay')
var ticks = 0
var ui = {
clock: () => {
clockDisplay.innerText = ticks
ticks += 1
},
stop: () => {
clockDisplay.innerText = 'STOPPED'
ticks = 0
},
noteOn: (note) => {
cueDisplay.innerText = 'VISUAL CUE ' + note
}
}
function init () {
// TODO: configure correct midi device
var midiInputs = [
new MidiRouter(/DOMinator/, { useClock: true }), // sequencer (mac)
new MidiRouter(/loopMIDI/, { useClock: true }), // sequencer (windows)
new MidiRouter(/LD Output/), // Loop Drop (Matt)
new MidiRouter(/AudioBox/), // Improjam (Jan)
new MidiRouter(/Midi Through Port-0/, { useClock: true }) // Improjam (Jan local)
]
// MIDI Channels for Inst + Send from 1
const drums = new DrumSampler('drums.wav', 35, 63)
drums.config(37, { volume: 0.5 })
drums.config(39, { volume: 0.7 }) // clap
drums.config(48, { volume: 0.7 }) // clap
drums.config(56, { volume: 0.5 })
drums.config(57, { volume: 0.7 })
drums.config(58, { volume: 0.7 })
drums.config(59, { volume: 0.7 })
// congas
drums.config(40, { volume: 0.5 })
drums.config(42, { volume: 0.5 })
drums.config(44, { volume: 0.5 })
drums.config(49, { volume: 0.6 })
drums.config(51, { volume: 0.6 })
drums.config(53, { volume: 0.6 })
// hats
drums.config(41, { chokeGroup: 'h', volume: 0.5 })
drums.config(43, { chokeGroup: 'h', volume: 0.5 })
drums.config(50, { chokeGroup: 'h', volume: 0.5 })
drums.config(52, { chokeGroup: 'h', volume: 0.3 })
drums.config(54, { chokeGroup: 'h', volume: 0.5 })
drums.config(63, { chokeGroup: 'h', volume: 0.5 })
const bass = new Synth()
const lead = new Synth()
const slicer = new Slicer({
ticks: 48 * BEAT_TICKS * 4,
sliceCount: 48 * 2,
startNote: 30
})
const oneshots = new DrumSampler('oneshot.wav', 36, 45)
oneshots.config(36, { chokeGroup: 'p', volume: 1.5 })
oneshots.config(37, { chokeGroup: 'p', volume: 0.5 })
oneshots.config(39, { chokeGroup: 'l' })
oneshots.config(40, { chokeGroup: 'l' })
oneshots.config(41, { chokeGroup: 'l' })
oneshots.config(42, { chokeGroup: 'l' })
oneshots.config(43, { chokeGroup: 'l' })
const reverbFX = new ReverbFX()
const delayFX = new DelayFX()
// MIDI Channels for mixer channels from 8
const drumsChannel = new MixerChannel()
const bassChannel = new MixerChannel({ duckAmount: 0.8 })
const leadChannel = new MixerChannel({ duckAmount: 1, highPass: 100 })
const slicerChannel = new MixerChannel({ duckAmount: 0.8 })
const oneshotsChannel = new MixerChannel({ duckAmount: 0.8 })
const delayChannel = new MixerChannel({ duckAmount: 0.8, highPass: 200, volume: 1.3 })
const reverbChannel = new MixerChannel({ duckAmount: 0.8, highPass: 100 })
// Connect inst/fx to channel strips
const masterOutput = new GainNode(window.audioContext, { gain: 0.5 })
const limiter = new DynamicsCompressorNode(window.audioContext, {
threshold: 0,
knee: 0,
ratio: 20,
attack: 0.005,
release: 0.05
})
const postLimiter = new GainNode(window.audioContext, { gain: 0.8 })
drums.output.connect(drumsChannel.input)
bass.output.connect(bassChannel.input)
lead.output.connect(leadChannel.input)
slicer.output.connect(slicerChannel.input)
oneshots.output.connect(oneshotsChannel.input)
delayFX.output.connect(delayChannel.input)
reverbFX.output.connect(reverbChannel.input)
masterOutput.connect(limiter).connect(postLimiter).connect(window.audioContext.destination)
// connect channel strips to output
;[
drumsChannel, bassChannel, leadChannel, slicerChannel, oneshotsChannel,
delayChannel, reverbChannel
].forEach((ch) => ch.output.connect(masterOutput))
// connect sends
;[
drumsChannel, bassChannel, leadChannel, slicerChannel, oneshotsChannel
].forEach((ch) => {
ch.reverbSend.connect(reverbFX.input)
ch.delaySend.connect(delayFX.input)
})
delayChannel.reverbSend.connect(reverbFX.input)
// MIDI router connections
;[
drums, bass, lead, slicer, oneshots,
reverbFX, delayFX,
drumsChannel, bassChannel, leadChannel, slicerChannel, oneshotsChannel,
reverbChannel, delayChannel,
ui // to display clock info
].forEach((obj, i) => {
midiInputs.forEach(router => {
router.connect(i + 1, obj)
})
})
// Sample loader config
const loader = new SampleLoader()
loader.register('never-forget.wav')
loader.register(drums.sampleNames)
loader.register(oneshots.sampleNames)
// assign samples after all been loaded and decoded
loader.load().then(() => {
slicer.buffer = loader.getBuffer('never-forget.wav')
loader.getBuffers(drums.sampleNames).forEach((buffer, index) => {
drums.setBuffer(index, buffer)
})
loader.getBuffers(oneshots.sampleNames).forEach((buffer, index) => {
oneshots.setBuffer(index, buffer)
})
console.log('LOADED!')
}).catch((e) => console.log(e))
// expose for debugging
window.bass = bass
window.bassChannel = bassChannel
window.slicer = slicer
window.slicerChannel = slicerChannel
window.midiInputs = midiInputs
// expose for debugging
window.drums = drums
window.drumsChannel = drumsChannel
}
async function asyncInit () {
try {
await window.audioContext.audioWorklet.addModule('./worklets/bitcrusher.js?v=1')
console.log('ADD MODULE')
} catch (e) {
console.log(e)
}
console.log('LETS INIT')
init()
}
asyncInit()