-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPadHitProcessor.js
More file actions
57 lines (54 loc) · 2.02 KB
/
Copy pathPadHitProcessor.js
File metadata and controls
57 lines (54 loc) · 2.02 KB
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
const PadMidiSender = require("./PadMidiSender");
const SimPadControlSender = require("./SimPadControlSender");
const { clipState } = require("./constants");
module.exports = class PadHitProcessor {
#state;
#padMidiSender;
#simPadControlSender;
constructor({ state, colours }) {
this.#state = state;
this.#padMidiSender = new PadMidiSender({ state, colours });
this.#simPadControlSender = new SimPadControlSender({ state, colours });
}
process(padId, outlet) {
const currentState = this.#state.get(`pads::${padId}::state`);
let nextState = currentState;
switch (currentState) {
// if the pad that was hit has no clip associated, do nothing
case clipState.EMPTY:
post(`Clip ${padId} is empty\n`);
break;
// if the clip associated to the pad that was hit…
// was stopped, trigger it
case clipState.STOPPED:
nextState = clipState.TRIGGERED;
post(`Clip ${padId} has been triggered\n`);
break;
// if the clip associated to the pad that was hit…
// was triggered, leave it stopped, revoke the trigger
case clipState.TRIGGERED:
nextState = clipState.STOPPED;
post(`Clip ${padId} is stopped (trigger revoked)\n`);
break;
// if the clip associated to the pad that was hit…
// was playing, schedule it to stop
case clipState.PLAYING:
nextState = clipState.STOPPING;
post(`Clip ${padId} is stopping\n`);
break;
// if the clip associated to the pad that was hit…
// was scheduled to stop, let it continue to play, revoke the previous stop
case clipState.STOPPING:
nextState = clipState.PLAYING;
post(`Clip ${padId} is playing (stop revoked)\n`);
break;
default:
}
post(`state ${currentState} -> ${nextState}\n`);
if (nextState !== currentState) {
this.#state.replace(`pads::${padId}::state`, nextState);
this.#padMidiSender.send(padId, outlet);
this.#simPadControlSender.send(padId, outlet);
}
}
};