-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
166 lines (146 loc) · 5.17 KB
/
index.html
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
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/webmidi"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js"></script>
<style>
.pressed-note {
padding: 20px;
border: 1px solid black;
margin: 15px;
font-size: 20px;
width: auto;
display: inline-flex;
}
.click-me-btn{
height: 100%;
width: 100%;
font-size: 40px;
font-weight: bold;
background-color: white;
border: 5px solid red;
}
</style>
</head>
<body>
<div id="app">
<button
type="button"
@click="showButton = false"
v-if="showButton"
class="click-me-btn"
>Accept Request (Top Left)<br />And Click Me For Sound</button>
<div class="pressed-note" v-for="note in pressedNotes">
<ul>
<li v-for="(value, key) in note">
<b style="text-transform: capitalize;">{{ key }}:</b> {{ value }}
</li>
</ul>
</div>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
play: [],
pressedNotes: [],
playAlong: false,
showButton: true,
stopButtonPressed: false
},
methods: {
playSound(output, id) {
const url = 'sounds/' + id.toString()[0] + '/' + id.toString()[1] + '.mp3'
const a = new Audio(url);
output.sendSysex([0, 32, 41], [2, 13, 7]);
a.play().catch(e => {
if(e.toString().includes('source')) {
output.sendSysex(
[0, 32, 41],
[2, 13, 7, 0, 10, 0, 5, ...`${id}`.split('').map((a) => { return a.charCodeAt(0); })]
);
} else {
output.sendSysex(
[0, 32, 41],
[2, 13, 7, 0, 10, 0, 5, ...':-('.split('').map((a) => { return a.charCodeAt(0); })]
);
}
});
return a
}
},
mounted() {
WebMidi.enable((err) => {
if (err) {
console.log("WebMidi could not be enabled.", err);
}
const input = WebMidi.getInputByName("Launchpad Mini MK3 MIDI 2");
const output = WebMidi.getOutputByName("Launchpad Mini MK3 MIDI 2");
// Set Launchpad into programmer mode
output.sendSysex([0, 32, 41], [2, 13, 14, 1]);
// Reset playAlong LED (92 = MIDI Note) (21 = Green, 0 = Off)
output.sendSysex([0, 32, 41], [2, 13, 3, 0, 92, (this.playAlong ? 21 : 0)]);
// Stop text scrolling
// output.sendSysex([0, 32, 41], [2, 13, 7]);
// Connected Text Scroll
output.sendSysex(
[0, 32, 41],
[2, 13, 7, 0, 10, 0, 21, ...':-)'.split('').map((a) => { return a.charCodeAt(0); })]
);
input.addListener('controlchange', "all",
(e) => {
if(e.controller.number === 92) { // [\/] Button
if(e.value === 127) { // pressed state
this.playAlong = !this.playAlong
// Set playAlong LED on or off
output.sendSysex([0, 32, 41], [2, 13, 3, 0, 92, this.playAlong ? 21 : 0]);
}
}
if(e.controller.number === 19) { // [Stop/Solo/Mute] Button
this.stopButtonPressed = e.value === 127
// Turn LED red or off
output.sendSysex([0, 32, 41], [2, 13, 3, 0, 19, this.stopButtonPressed ? 5 : 0]);
}
console.log("[ControlChange]", e);
}
);
input.addListener('noteoff', "all",
(e) => {
console.log('Note [OFF]', e)
this.pressedNotes = this.pressedNotes.filter((note) => { return note.number !== e.note.number })
if(!this.playAlong) {
this.play[e.note.number].pause() // Stop playback of Audio
delete this.play[e.note.number]
output.playNote(e.note.name + e.note.octave, 1, { duration: 0 }) // Turn off LED
}
}
);
input.addListener('noteon', "all",
(e) => {
console.log('Note [ON]', e)
if(this.stopButtonPressed) {
this.play[e.note.number].pause()
delete this.play[e.note.number]
output.playNote(e.note.name + e.note.octave, 1, { duration: 0 }) // Turn off LED
} else {
var sound = this.playSound(output, e.note.number)
this.pressedNotes.push(e.note)
this.play[e.note.number] = sound
sound.onloadedmetadata = () => {
// Light up the button for the duration of the button press or audio file
output.playNote(e.note.name + e.note.octave, 1,
{
duration: this.playAlong ? sound.duration * 1000 : undefined,
velocity: Math.floor(Math.random() * 127) + 1,
rawVelocity: true
}
);
};
}
}
);
}, true);
}
})
</script>
</body>
</html>