-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeys.js
133 lines (128 loc) · 3.43 KB
/
keys.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
/* Controls keyboard input interpretation
* as well as implements and sets the keybindings
* that control the program */
//When a key is pressed, figure out which sound should
//be played. Set the "shot" button in the bottom left
//hand corner to the current note.
KeyIn = (e) => {
if(!inCommandMode) {
curNote=e.note[1]+curOct*12;
document.getElementById("shot").innerHTML=curNote;
if(e.note[0]) {
if(inRecordMode) addNote(curNote);
synth.send([0x90+curMidi,curNote,100]);
} else {
if(inRecordMode) endNote(curNote);
synth.send([0x80+curMidi,curNote,0]);
}
if(curMidi==9){
let w=synth.drummap[curNote-35];
//ViewParam(w);
}
}
}
//Keybindings for normal mode/music mode.
const normalEvents = {
"Shift":(e) => {
//Sustain on Shift
document.getElementById("sus").checked=true;
Sustain(true);
}, ";":(e) => {
utter("Command Mode", voiceIndex);
inCommandMode=true;
}, "ArrowUp":(e) => {
e.preventDefault();
//Ascend octaves on up arrow in normal/music mode.
const octs = [-2, -1, 0, 1, 2];
curOct=octs[(octs.indexOf(curOct)+1)%octs.length];
}, "ArrowDown":(e) => {
e.preventDefault();
//Descend octaves on down arrow in normal/music mode.
const octs = [2, 1, 0, -1, -2];
curOct=octs[(octs.indexOf(curOct)+1)%octs.length];
}
}
//Keybindings for command mode
const commandEvents = {
";":(e) => {
utter("Music Mode", voiceIndex);
inCommandMode=false;
}, "v":(e) => {
if(enableVoiceChange) {
voiceIndex=(voiceIndex+1)%(window.speechSynthesis.getVoices().length);
utter("Changed voice", voiceIndex);
enableVoiceChange = false;
}
}, "o":(e) => {
utter("Open Midi File", voiceIndex);
openMidiFile();
}, "r":(e) => {
//Toggle instrument recording in command modr
if(document.querySelector(".stop").disabled) {
utter("Begin Recording Instruments", voiceIndex);
inRecordMode = true;
document.querySelector(".record").click();
inCommandMode=false;
} else {
utter("Stop Instrument Recording", voiceIndex);
inRecordMode = false;
createTrack();
document.querySelector(".stop").click();
inCommandMode=true;
}
}, "j":(e) => {
changeTrackUp();
}, "k":(e) => {
changeTrackDown();
}, "d":(e) => {
if(tracks.length) {
document.querySelector("#track_list").removeChild(document.querySelector("#track_list").children[curTrackIndex])
delTrack(curTrackIndex);
}
}, "h":(e) => {
if(curProg) {
ProgChange(curProg-1);
utter(`${synth.getTimbreName(0, curProg)}`, voiceIndex);
} else {
utter("No prior instruments", voiceIndex);
}
}, "l":(e) => {
ProgChange(curProg+1);
utter(`${synth.getTimbreName(0, curProg)}`, voiceIndex);
}, "x":(e) => {
utter("Exporting Song", voiceIndex);
exportSong();
}, "m":(e) => {
if(useMic) {
utter("Mic Recording Off", voiceIndex);
useMic = false;
reloadRecorder();
} else {
utter("Mic Recording On", voiceIndex);
useMic = true;
reloadRecorder();
}
}
}
//Bind the handlers to event types.
BindKeys = () => {
//Keydown events
document.addEventListener("keydown", (e) => {
if(!inCommandMode) {
if(e.key in normalEvents) normalEvents[e.key](e);
} else {
if(e.key in commandEvents) commandEvents[e.key](e);
}
if(e.key == "f")
document.querySelector("#kb").focus();
});
document.addEventListener("keyup", (e) => {
if(e.keyCode==16){
document.getElementById("sus").checked=false;
Sustain(false);
} else if (e.key == "v") {
if(inCommandMode)
enableVoiceChange = true;
}
});
}