-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.vue
537 lines (509 loc) · 13.6 KB
/
Main.vue
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
/* eslint-disable */
<template>
<main class="page-container">
<div class="daily-call-container">
<div class="daily-call" id="call-wrapper"></div>
</div>
<div class="controls-container">
<div class="main-controls">
<p class="flash-message">
{{ message || "[See incoming changes here]" }}
</p>
<div class="call-controls">
<div class="daily-controls">
<h3>Call controls</h3>
<button class="join-button" @click="joinCall()" :disabled="joined">
Join
</button>
</div>
<div>
<h3>Playback</h3>
<div class="button-container">
<button class="play-button" @click="controlMessage('play')">
<img class="icon-control" :src="playIcon" alt="Play" />
</button>
<button class="stop-button" @click="controlMessage('stop')">
<img class="icon-control" :src="stopIcon" alt="stop" />
</button>
</div>
</div>
</div>
<div class="column-section">
<div>
<h3>Digitone Tracks</h3>
<div class="control-section">
<h4>Mute</h4>
<div class="button-container">
<button @click="controlMessage('muteDN', 1)">1</button>
<button @click="controlMessage('muteDN', 2)">2</button>
<button @click="controlMessage('muteDN', 3)">3</button>
<button @click="controlMessage('muteDN', 4)">4</button>
</div>
</div>
<div class="control-section">
<h4>Unmute</h4>
<div class="button-container">
<button @click="controlMessage('unmuteDN', 1)">1</button>
<button @click="controlMessage('unmuteDN', 2)">2</button>
<button @click="controlMessage('unmuteDN', 3)">3</button>
<button @click="controlMessage('unmuteDN', 4)">4</button>
</div>
</div>
</div>
<div>
<h3>Patterns</h3>
<h4 class="transparent">.</h4>
<div class="button-container">
<button @click="controlMessage('prog1')">1</button>
<button @click="controlMessage('prog2')">2</button>
<button @click="controlMessage('prog3')">3</button>
<button @click="controlMessage('prog4')">4</button>
</div>
</div>
</div>
<h3>Digitakt Tracks</h3>
<div class="control-section">
<h4>Mute</h4>
<div class="button-container">
<button @click="controlMessage('muteDT', 1)">1</button>
<button @click="controlMessage('muteDT', 2)">2</button>
<button @click="controlMessage('muteDT', 3)">3</button>
<button @click="controlMessage('muteDT', 4)">4</button>
<button @click="controlMessage('muteDT', 5)">5</button>
<button @click="controlMessage('muteDT', 6)">6</button>
<button @click="controlMessage('muteDT', 7)">7</button>
<button @click="controlMessage('muteDT', 8)">8</button>
</div>
</div>
<div class="control-section">
<h4>Unmute</h4>
<div class="button-container">
<button @click="controlMessage('unmuteDT', 1)">1</button>
<button @click="controlMessage('unmuteDT', 2)">2</button>
<button @click="controlMessage('unmuteDT', 3)">3</button>
<button @click="controlMessage('unmuteDT', 4)">4</button>
<button @click="controlMessage('unmuteDT', 5)">5</button>
<button @click="controlMessage('unmuteDT', 6)">6</button>
<button @click="controlMessage('unmuteDT', 7)">7</button>
<button @click="controlMessage('unmuteDT', 8)">8</button>
</div>
</div>
</div>
<div class="ranges-container">
<div class="range-container">
<h3>Delay</h3>
<label for="dn-delay-vol">Volume</label>
<input
name="dn-delay-vol"
type="range"
step="1"
min="0"
max="127"
title="delay volume"
@change="controlMessage('delayVol', $event.target.value)"
/>
<label for="dn-delay-fbk">Feedback</label>
<input
name="dn-delay-fbk"
type="range"
step="1"
min="0"
max="65"
title="delay feedback"
@change="controlMessage('delayFbk', $event.target.value)"
/>
<label for="dn-delay-time">Time</label>
<input
name="dn-delay-vol"
type="range"
step="1"
min="0"
max="127"
title="delay time"
@change="controlMessage('delayTime', $event.target.value)"
/>
</div>
<div class="range-container">
<h3>Reverb</h3>
<label for="dt-verb-vol">Volume</label>
<input
name="dt-verb-vol"
type="range"
step="1"
min="0"
max="127"
title="verb volume"
@change="controlMessage('verbVol', $event.target.value)"
/>
<label for="dt-verb-decay">Decay</label>
<input
name="dt-verb-decay"
type="range"
step="1"
min="0"
max="127"
title="verb decay"
@change="controlMessage('verbDecay', $event.target.value)"
/>
<label for="dt-verb-predelay">Predelay</label>
<input
name="dt-verb-vol"
type="range"
step="1"
min="0"
max="127"
title="verb predelay"
@change="controlMessage('verbPredelay', $event.target.value)"
/>
</div>
</div>
</div>
</main>
</template>
<script>
import DailyIframe from "@daily-co/daily-js";
import WebMidi from "webmidi";
import { msgMap } from "../lib/controlMap";
const ROOM_URL = "https://devrel.daily.co/midirtc";
const CALL_OPTIONS = {
url: ROOM_URL,
showLeaveButton: true,
iframeStyle: {
aspectRatio: 16 / 10,
border: "1px solid #e6eaef",
borderRadius: "6px 6px 0 0",
boxShadow: `0 1px 2px rgba(0, 0, 0, 0.02), 0 2px 4px rgba(0, 0, 0, 0.02),
0 4px 8px rgba(0, 0, 0, 0.02), 0 8px 16px rgba(0, 0, 0, 0.02),
0 16px 32px rgba(0, 0, 0, 0.02)`,
},
};
export default {
name: "Main",
data: function() {
return {
devices: [],
outputDN: {},
outputDT: {},
localMidi: false,
participants: [],
localParticipant: {},
callframe: {},
joined: false,
message: "",
playIcon: require("../assets/play-solid.svg"),
stopIcon: require("../assets/stop-solid.svg"),
};
},
mounted: function() {
this.getDevices();
const wrapper = document.getElementById("call-wrapper");
if (wrapper) {
this.callframe = DailyIframe.createFrame(wrapper, CALL_OPTIONS);
this.callframe
.on("joined-meeting", (e) => {
console.log("Event: ", e);
})
.on("participant-joined", (e) => {
console.log("Event: ", e);
if (e.participant.user_id !== this.localParticipant.user_id) {
this.updateParticipants();
}
})
.on("participant-updated", (e) => {
console.log("Event: ", e);
this.updateParticipants();
})
.on("participant-left", (e) => {
console.log("Event: ", e);
this.updateParticipants();
})
.on("left-meeting", (e) => {
console.log("Event: ", e);
this.participants = [];
this.localParticipant;
this.joined = false;
})
.on("app-message", ({ data }) => {
console.log("message: ", data);
this.flashMessage(data.message);
if (this.localMidi) {
this.controlMessage(data.name, data.val);
}
});
}
},
methods: {
joinCall: async function() {
const urlParams = new URLSearchParams(window.location.search);
const token = urlParams.get("token") || "";
this.participants = await this.callframe.join({ token });
this.localParticipant = this.participants.local;
if (!this.localParticipant.owner) {
//hack for remote participants w/ midi devices
this.localMidi = false;
}
this.joined = true;
},
getDevices: function() {
WebMidi.enable((err) => {
if (err) {
console.log("WebMidi could not be enabled.", err);
//todo return here?
} else {
console.log("WebMidi enabled!");
}
this.devices = WebMidi.outputs;
this.outputDT = WebMidi.getOutputByName("Elektron Digitakt");
this.outputDN = WebMidi.getOutputByName("Elektron Digitone");
// TODO add owner check
this.localMidi = this.outputDN ? true : false;
});
},
updateParticipants: async function() {
const participants = await this.callframe.participants();
this.participants = Object.keys(participants).map(
(key) => participants[key]
);
},
flashMessage: function(msg) {
this.message = msg;
setTimeout(() => (this.message = ""), 5000);
},
controlMessage: function(name, val = false) {
if (this.localMidi) {
const device = msgMap[name].device;
console.log("device: ", device);
if (val) {
this[device][msgMap[name].method](
...(msgMap[name].params(val) || "")
);
} else {
this[device][msgMap[name].method](...(msgMap[name].params || ""));
}
} else {
this.callframe.sendAppMessage(
{ name, val, message: msgMap[name].message },
"*"
);
}
},
},
};
</script>
<style>
main.page-container {
display: flex;
width: 100%;
flex: 1;
margin: 12px 48px;
}
.call-wrapper {
display: flex;
margin-bottom: 32px;
}
.controls-container {
width: 50%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.call-controls {
display: flex;
align-items: center;
justify-content: space-between;
}
.call-controls h3 {
margin-bottom: 8px;
margin-top: 0;
}
.column-section {
display: flex;
}
.column-section > div:nth-child(1) {
padding-right: 16px;
}
.column-section > div:nth-child(2) {
padding-left: 16px;
}
.daily-call {
width: 100%;
}
.daily-controls {
display: flex;
flex-direction: column;
}
.daily-call-container {
display: flex;
flex: 1;
width: 100%;
}
.flash-message {
text-align: left;
margin-top: 0;
font-style: italic;
}
h3 {
text-align: left;
font-weight: bold;
margin: 32px 0 16px;
}
h4 {
margin: 8px 0 4px;
text-align: left;
font-weight: normal;
}
.join-button {
background-color: #377758;
}
.join-button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.icon-control {
height: 16px;
padding-top: 2px;
color: #fff;
}
.button-container {
display: flex;
}
.button-container button:nth-child(1) {
background-color: #ade5cf;
}
.button-container button:nth-child(2) {
background-color: #96ddcf;
}
.button-container button:nth-child(3) {
background-color: #81d4d3;
}
.button-container button:nth-child(4) {
background-color: #6bbbcb;
}
.button-container button:nth-child(5) {
background-color: #569bc1;
}
.button-container button:nth-child(6) {
background-color: #4a74ab;
}
.button-container button:nth-child(7) {
background-color: #3e5194;
}
.button-container button:nth-child(8) {
background-color: #32337c;
}
.button-container button:nth-child(9) {
background-color: #342764;
}
.button-container .play-button:nth-child(1) {
background-color: #7dd887;
}
.button-container .stop-button:nth-child(2) {
background-color: #e23039;
}
.main-controls,
.ranges-container {
max-width: 424px;
}
.ranges-container {
display: flex;
width: 100%;
}
.range-container {
display: flex;
flex-direction: column;
flex: 1;
}
input[type="range"] {
max-width: 100%;
-webkit-appearance: none;
height: 16px;
background: rgba(255, 255, 255, 0.6);
border-radius: 5px;
background-image: linear-gradient(#bbebe2, #96ddcf);
margin: 0 8px 16px;
background-repeat: no-repeat;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
height: 20px;
width: 20px;
border-radius: 50%;
background: #52a396;
box-shadow: 0 0 2px 0 #555;
transition: background 0.3s ease-in-out;
}
input[type="range"]::-webkit-slider-runnable-track {
-webkit-appearance: none;
box-shadow: none;
border: none;
background: transparent;
}
.transparent {
color: transparent;
}
iframe {
width: 100%;
height: auto;
}
@media only screen and (max-width: 1025px) {
main.page-container {
flex-direction: column;
}
iframe {
width: 424px;
}
.controls-container {
align-items: flex-start;
}
.call-wrapper {
display: flex;
}
.daily-call {
display: flex;
}
iframe {
margin-right: auto;
margin-bottom: 32px;
}
}
@media only screen and (max-width: 525px) {
main.page-container {
flex-direction: column;
margin: 8px;
}
iframe {
width: 90%;
}
.controls-container,
.main-controls {
width: 90%;
}
.call-controls {
flex-direction: column;
align-items: flex-start;
}
.controls-container {
align-items: flex-start;
}
.column-section {
flex-direction: column-reverse;
}
.column-section > div:nth-child(2) {
padding: 0;
}
.button-container {
flex-wrap: wrap;
}
.button-container button {
margin-bottom: 4px;
}
.transparent {
display: none;
}
h3 {
margin: 16px 0 4px;
}
}
</style>