-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
265 lines (241 loc) · 7.07 KB
/
index.html
File metadata and controls
265 lines (241 loc) · 7.07 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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Launchpad Sound Mapper</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #121212;
color: white;
text-align: center;
padding: 20px;
}
#midi-keys {
display: grid;
grid-template-columns: repeat(80, 50px);
grid-gap: 5px;
justify-content: center;
margin-top: 20px;
}
.key {
width: 50px;
height: 50px;
background-color: #444;
border: 1px solid #666;
border-radius: 5px;
line-height: 50px;
text-align: center;
color: white;
}
.key.active {
background-color: #935AF6;
}
.key.assigned {
background-color: #3BA55C;
}
#audio-list {
margin-top: 20px;
max-width: 500px;
margin-left: auto;
margin-right: auto;
background: #1c1c1c;
padding: 15px;
border-radius: 8px;
}
.audio-item {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
background: #444;
padding: 5px 10px;
border-radius: 5px;
}
.audio-item button {
margin-left: 5px;
background: #935AF6;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
padding: 5px;
}
.audio-item button.delete {
background: #FF4C4C;
}
</style>
</head>
<body>
<h1>Launchpad Sound Mapper</h1>
<div id="midi-keys" style="display: none;">
<!-- Visualisatie van toetsen -->
<div class="key" id="key-36">36</div>
<div class="key" id="key-37">37</div>
<!-- Voeg meer toetsen toe hier -->
</div>
<div>
<p>Selected Key: <span id="selected-key">Nothing</span></p>
<input type="file" id="file-input" accept="audio/*">
</div>
<div id="audio-list">
<h3>Uploaded Audio's</h3>
<div id="audio-items"></div>
</div>
<p id="status">Status: Not Connected</p>
<script>
const keys = document.querySelectorAll('.key');
const statusDisplay = document.getElementById('status');
const selectedKeyDisplay = document.getElementById('selected-key');
const fileInput = document.getElementById('file-input');
const audioList = document.getElementById('audio-items');
let keySounds = JSON.parse(localStorage.getItem('keySounds')) || {}; // Geluiden opgeslagen per toets
let keySettings = JSON.parse(localStorage.getItem('keySettings')) || {}; // Modus opgeslagen per toets
let activeAudios = {}; // Huidig actieve audios bijhouden
let selectedKey = null;
let midiOutput = null;
// Initialiseer knoppen en audios
function initialize() {
Object.keys(keySounds).forEach((key) => {
lightUpKeyPermanently(parseInt(key));
addAudioToList(key, keySounds[key].name);
});
}
initialize();
// Controleer of Web MIDI API beschikbaar is
if (navigator.requestMIDIAccess) {
navigator.requestMIDIAccess().then(onMIDISuccess, onMIDIFailure);
} else {
alert('Web MIDI API wordt niet ondersteund in deze browser.');
}
// Callback voor succesvolle toegang tot MIDI
function onMIDISuccess(midiAccess) {
statusDisplay.textContent = 'Status: Connected';
const inputs = midiAccess.inputs.values();
const outputs = midiAccess.outputs.values();
for (let output of outputs) {
midiOutput = output;
break;
}
for (let input of inputs) {
input.onmidimessage = onMIDIMessage;
}
}
// Callback voor mislukte toegang tot MIDI
function onMIDIFailure() {
statusDisplay.textContent = 'Status: Unable to access MIDI devices.';
}
// Verwerk MIDI-berichten
function onMIDIMessage(message) {
const [status, key, velocity] = message.data;
if (status === 144 && velocity > 0) { // Note On
if (keySounds[key]) {
playSound(key);
} else {
selectKey(key);
}
}
}
// Selecteer een toets
function selectKey(key) {
selectedKey = key;
selectedKeyDisplay.textContent = key;
}
// Upload geluid en koppel aan toets
fileInput.addEventListener('change', (event) => {
if (selectedKey === null) {
alert('First select a key by pressing it.');
return;
}
const file = event.target.files[0];
if (file) {
const url = URL.createObjectURL(file);
keySounds[selectedKey] = { url, name: file.name };
keySettings[selectedKey] = keySettings[selectedKey] || { mode: 'overlap' };
localStorage.setItem('keySounds', JSON.stringify(keySounds));
localStorage.setItem('keySettings', JSON.stringify(keySettings));
addAudioToList(selectedKey, file.name);
lightUpKeyPermanently(selectedKey);
alert(`Sound linked to key ${selectedKey}`);
}
});
// Voeg geluid toe aan lijst
function addAudioToList(key, name) {
const item = document.createElement('div');
item.classList.add('audio-item');
item.innerHTML = `
<span>Key ${key}: ${name}</span>
<select class="mode-select">
<option value="overlap">Repeat</option>
<option value="start-stop">Start/Stop</option>
</select>
<button class="reassign">Reassign</button>
<button class="delete">Delete</button>
`;
const modeSelect = item.querySelector('.mode-select');
modeSelect.value = keySettings[key]?.mode || 'overlap';
modeSelect.addEventListener('change', () => updateMode(key, modeSelect.value));
item.querySelector('.reassign').addEventListener('click', () => reassignKey(key));
item.querySelector('.delete').addEventListener('click', () => deleteKey(key, item));
audioList.appendChild(item);
}
// Update de modus van een toets
function updateMode(key, mode) {
keySettings[key].mode = mode;
localStorage.setItem('keySettings', JSON.stringify(keySettings));
}
// Hertoewijs een toets
function reassignKey(key) {
selectedKey = key;
selectedKeyDisplay.textContent = key;
alert(`Key ${key} selected to reassign a sound.`);
}
// Verwijder een toets
function deleteKey(key, item) {
delete keySounds[key];
delete keySettings[key];
localStorage.setItem('keySounds', JSON.stringify(keySounds));
localStorage.setItem('keySettings', JSON.stringify(keySettings));
stopLight(key);
audioList.removeChild(item);
}
// Speel geluid af
function playSound(key) {
const mode = keySettings[key]?.mode || 'overlap';
if (mode === 'overlap') {
// Herhaalmodus: speel geluid opnieuw af, ook als het al speelt
const audio = new Audio(keySounds[key].url);
audio.play();
} else if (mode === 'start-stop') {
// Start/Stop-modus: speel af of stop geluid
if (activeAudios[key]) {
activeAudios[key].pause();
activeAudios[key].currentTime = 0;
delete activeAudios[key];
} else {
const audio = new Audio(keySounds[key].url);
audio.play();
activeAudios[key] = audio;
// Verwijder uit actieve lijst wanneer het geluid klaar is
audio.addEventListener('ended', () => {
delete activeAudios[key];
});
}
}
}
// Verlicht toets permanent op de Launchpad
function lightUpKeyPermanently(key) {
if (midiOutput) {
midiOutput.send([144, key, 60]);
}
}
// Zet het licht van een toets uit
function stopLight(key) {
if (midiOutput) {
midiOutput.send([128, key, 0]);
}
}
</script>
</body>
</html>