-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
128 lines (99 loc) · 3.68 KB
/
Copy pathcontroller.js
File metadata and controls
128 lines (99 loc) · 3.68 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
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
// This is where your state machines and game logic lives
class Controller {
// This is the state we start with.
constructor() {
this.gameState = "LOAD";
}
// This is called from draw() in sketch.js with every frame
update() {
// STATE MACHINE ////////////////////////////////////////////////
// This is where your game logic lives
/////////////////////////////////////////////////////////////////
switch(this.gameState) {
case "LOAD":
display.clear();
display.setPixel(0, color(250, 0, 0))
if (mixer.state != "LOAD") {
this.gameState = "PLAY";
}
break;
case "PLAY":
// clear screen at frame rate so we always start fresh
display.clear();
// display.setPixel(0, color(0, 250, 0))
display.showPattern(mixer.pattern);
display.showSlider(mixer.stepIndex);
break;
// Not used, it's here just for code compliance
default:
break;
}
}
}
// This function gets called when a key on the keyboard is pressed
function keyPressed() {
// Space bar
// TODO remove overflow to neighbor steps
if (keyCode === 32) {
// drum machine is ready
if (mixer.drumsReady) {
mixer.tap();
}
}
// TODO remove overflow to neighbor steps
// if (key == 'A' || key == 'a') {
// // drum machine is ready
// if (window['drumsReady']) {
// let step = getDrumStepCounter() % getDrumState().patternLength;
// // only allow user input in play mode
// if (step > -1 && step < getDrumState().seedLength) {
// // initialize user input array
// if (!controller.userInput) {
// controller.userInput = _.times(getDrumState().seedLength, i => []);
// }
// controller.userInput[controller.stepIndx] = [controller.defaultInstrument];
// }
// }
// }
// change tempo
if (key == 'p' || key == 'P') {
if (window['drumsReady']) {
setDrumState({ tempo: getDrumState().tempo + 0.5 });
}
}
if (key == 'o' || key == 'O') {
if (window['drumsReady']) {
setDrumState({ tempo: getDrumState().tempo - 0.5 });
}
}
// change instrument
// if (key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9') {
// controller.defaultInstrument = parseInt(key);
// }
// change temperture
if (key == ':' || key == ';') {
if (window['drumsReady']) {
let newTemp = getDrumState().temperature + 0.1 > 2 ? 2.0 : getDrumState().temperature + 0.1;
setDrumState({ temperature: newTemp });
}
}
if (key == 'L' || key == 'l') {
if (window['drumsReady']) {
let newTemp = getDrumState().temperature - 0.1 < 0 ? 0.0 : getDrumState().temperature - 0.1;
setDrumState({ temperature: newTemp });
}
}
// change swing
if (key == '>' || key == '.') {
if (window['drumsReady']) {
let newSwing = getDrumState().swing + 0.25 > 1 ? 1.0 : getDrumState().swing + 0.25;
setDrumState({ swing: newSwing });
}
}
if (key == '<' || key == ',') {
if (window['drumsReady']) {
let newSwing = getDrumState().swing - 0.25 < 0 ? 0.0 : getDrumState().swing - 0.25;
setDrumState({ swing: newSwing });
}
}
}