-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualizer.js
More file actions
48 lines (40 loc) · 1.35 KB
/
Visualizer.js
File metadata and controls
48 lines (40 loc) · 1.35 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
class Visualizer {
constructor(container, imageFile) {
this.container = container;
this.imageFile = imageFile;
this.speed = container.clientHeight * 0.008;
this.am = new AnimationManager();
let config = {
releasedPrefix: "assets/buttons_released",
pressedPrefix: "assets/buttons_pressed",
pluckedPrefix: "assets/buttons_plucked",
postfix: ".png"
}
this.buttons = new FretButtons(container, config, this.speed, this.am);
this.listener = new window.keypress.Listener();
this._initKeyListeners();
let n = new Neck(container, imageFile, this.speed, this.am);
}
changeState(buttonNo, state) {
this.buttons.changeState(button, state);
}
_buildListener(key, button) {
let my_scope = this;
return {
"keys": key,
"prevent_repeat": true,
"on_keydown": function() {
this.buttons.changeState(button, "plucked");
},
"on_keyup": function(e) {
this.buttons.changeState(button, "released");
},
"this": my_scope
};
}
_initKeyListeners() {
this.listener.register_many(["a", "s", "d", "f", "g"].map((key,n)=>{
return this._buildListener(key,n);
}));
}
}