-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
563 lines (527 loc) · 22.6 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
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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
<!doctype html>
<html lang="fr" class="w-100 h-100">
<head>
<meta charset="utf-8">
<title>💻</title>
<!-- Bootstrap -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- Bootstrap Icons -->
<link href="bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
<style>
body {
padding-top: 54px;
}
#camera-list .modal-body video {
width: 100%;
transform: rotateY(180deg);
}
#chroma-picker .modal-body video,
#chroma-picker .modal-body canvas {
width: 100%;
transform: rotateY(180deg);
cursor: crosshair;
}
</style>
</head>
<body class="w-100">
<!-- Caméras -->
<div class="modal" id="camera-list">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Caméras</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Fermer"></button>
</div>
<div class="modal-body d-flex"></div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">Fermer</button>
</div>
</div>
</div>
</div>
<!-- Clé chromatique -->
<div class="modal" id="chroma-picker">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Clé chromatique</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Fermer"></button>
</div>
<div class="modal-body d-flex"></div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">Fermer</button>
</div>
</div>
</div>
</div>
<!-- Propriétés d'une chanson -->
<div class="modal" id="song-properties">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Propriétés</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Fermer"></button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label>Artiste</label>
<input id="song-artist" class="form-control"></input>
</div>
<div class="form-group mt-2">
<label>Titre</label>
<input id="song-title" class="form-control"></input>
</div>
<div id="song-cdg" style="display:none;">
<div class="form-group mt-2">
<label>Audio</label>
<input id="song-cdg-audio" class="form-control" readonly disabled></input>
<!--audio controls muted id="song-cdg-audio" class="w-100"></audio-->
</div>
<div class="form-group mt-2">
<label>Paroles</label>
<input id="song-cdg-lyrics" class="form-control" readonly disabled></input>
<!--canvas id="song-cdg-lyrics" class="w-100"></canvas-->
</div>
<div class="form-group mt-2">
<label>Taille</label>
<div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="song-cdg-height" value="50%" id="song-cdg-height-50" required disabled>
<label class="form-check-label" for="song-cdg-height-50">50 %</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="song-cdg-height" value="75%" id="song-cdg-height-75" required disabled>
<label class="form-check-label" for="song-cdg-height-75">75 %</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="song-cdg-height" value="100%" id="song-cdg-height-100" required disabled>
<label class="form-check-label" for="song-cdg-height-100">100 %</label>
</div>
</div>
</div>
</div>
<div class="form-group mt-2" id="song-karafun" style="display:none;">
<label>Vidéo</label>
<video muted loop id="song-karafun-video" class="w-100" style="cursor:crosshair;"></video>
<div class="d-flex justify-content-between">
<span id="song-karafun-colors"></span>
<button id="song-karafun-pause" type="button" class="btn border" style="width:50px;height:50px;">
<i class="bi-pause-fill"></i>
</button>
</div>
</div>
<div class="form-group mt-2" id="song-singking" style="display:none;">
<label>Vidéo</label>
<video muted id="song-singking-video" class="w-100"></video>
</div>
<div id="song-background" class="form-group mt-2" style="display:none;">
<label>Arrière-plan</label>
<input class="form-control"></input>
</div>
<div id="song-icon" class="form-group mt-2" style="display:none;">
<label>Pochette</label>
<input class="form-control"></input>
</div>
<button type="submit" class="d-none">Bouton caché mais nécessaire</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Annuler</button>
<button type="button" class="btn btn-primary">Enregistrer</button>
</div>
</div>
</div>
</div>
<!-- Nouvelle chanson -->
<div class="modal" id="new-song">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Téléchargement</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Fermer"></button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label>Artiste</label>
<input id="new-artist" class="form-control" required></input>
</div>
<div class="form-group mt-2">
<label>Titre</label>
<input id="new-title" class="form-control" required></input>
</div>
<div class="form-group mt-2">
<label>URL</label>
<input id="new-video" class="form-control" required></input>
</div>
<div class="form-group mt-2">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="new-video-type" value="karafun" id="new-video-karafun" required>
<label class="form-check-label" for="new-video-karafun">Karafun</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="new-video-type" value="singking" id="new-video-singking" required>
<label class="form-check-label" for="new-video-singking">Sing King</label>
</div>
</div>
<button type="submit" class="d-none">Bouton caché mais nécessaire</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Annuler</button>
<button type="button" class="btn btn-primary">Télécharger</button>
</div>
</div>
</div>
</div>
<!-- Barre de navigation -->
<nav class="navbar navbar-expand-md navbar-light fixed-top bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Karaokéké</a>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Rechercher" aria-label="Rechercher">
<button class="btn btn-outline-success" type="submit"><i class="bi-search"></i></button>
</form>
</div>
</nav>
<!-- Barres d'outils -->
<div class="btn-group-vertical position-fixed" role="toolbar" style="top:56px;margin:12px;">
<div class="btn-group-vertical mb-2" role="group">
<button type="button" class="btn btn-light" id="toolbar-camera" data-bs-toggle="modal" data-bs-target="#camera-list" disabled><i class="bi-camera-video"></i></button>
<button type="button" class="btn btn-light" id="toolbar-chroma" data-bs-toggle="modal" data-bs-target="#chroma-picker" disabled><i class="bi-eyedropper"></i></button>
</div>
<div class="btn-group-vertical mb-2" role="group">
<button type="button" class="btn btn-light" id="toolbar-new-song" data-bs-toggle="modal" data-bs-target="#new-song"><i class="bi-cloud-plus"></i></button>
</div>
<div class="btn-group-vertical mb-2" role="group">
<button type="button" class="btn btn-danger" id="toolbar-stop"><i class="bi-stop-fill"></i></button>
</div>
<div class="btn-group-vertical" role="group">
<input type="checkbox" class="btn-check" id="toolbar-fx-mirror-vertical" autocomplete="off">
<label class="btn btn-outline-secondary" for="toolbar-fx-mirror-vertical"><i class="bi-symmetry-vertical"></i></label>
<input type="checkbox" class="btn-check" id="toolbar-fx-mirror-horizontal" autocomplete="off">
<label class="btn btn-outline-secondary" for="toolbar-fx-mirror-horizontal"><i class="bi-symmetry-horizontal"></i></label>
<input type="checkbox" class="btn-check" id="toolbar-fx-rotate" autocomplete="off">
<label class="btn btn-outline-secondary" for="toolbar-fx-rotate"><i class="bi-arrow-clockwise"></i></label>
</div>
</div>
<!-- Liste des chansons -->
<ul id="songs" class="list-group list-group-flush w-75 mx-auto"></ul>
<!-- Toasts -->
<div class="toast-container position-fixed bottom-0 end-0 p-3"></div>
<script type="module">
import {PAD} from "./js/data.js";
import * as file from "./js/file.js";
import * as media from "./js/media.js";
import Camera from "./js/camera.js";
import VideoChroma from "./js/video-chroma.js";
import Properties from "./js/song-properties.js";
import Wizard from "./js/song-wizard.js";
const DEFAULT_CAMERA_RATIO = 16/9;
const DEFAULT_CHROMA_KEY = "#00ff00";
const DEFAULT_SPLASH = "backgrounds/nyan_cat.webm";
let songs = [];
let selection = [];
let confirm_reload = false;
let toasts = document.querySelector ('.toast-container');
function toast_message (background, icon, title, message)
{
console.log ('toast', title, message);
let i = document.createElement ('i');
i.classList.add (icon, 'me-2');
let strong = document.createElement ('strong');
strong.classList.add ('me-auto');
strong.innerHTML = title;
let button = document.createElement ('button');
button.type = 'button';
button.classList.add ('btn-close', 'btn-close-white');
button.setAttribute ('data-bs-dismiss', 'toast');
let header = document.createElement ('div');
header.classList.add ('toast-header', background, 'text-white');
header.append (i, strong, button);
let body = document.createElement ('div');
body.className = 'toast-body';
body.innerHTML = message;
let toast = document.createElement ('div');
toast.className = 'toast';
//toast.setAttribute ('data-bs-autohide', false);
toast.append (header, body);
toasts.append (toast);
let t = new bootstrap.Toast (toast);
t.show ();
}
function toast_success (title, m)
{
toast_message ('bg-success', 'bi-check-circle', title, m);
}
function toast_error (title, m)
{
toast_message ('bg-danger', 'bi-exclamation-octagon', title, m);
}
//setTimeout (() => {toast_success ('Test', 'test'); setTimeout (() => {toast_error ('Test', 'test');}, 2000);}, 2000);
// Propriétés d'une chanson.
let properties = new Properties ('song-properties',
(song, message) => {
toast_success (song.artist + ' - ' + song.title, message);
song_list ();
},
(song, error) => {
toast_error (song.artist + ' - ' + song.title, error);
});
// Téléchargement d'une nouvelle vidéo.
let wizard = new Wizard ('new-song',
song => {
toast_success (song.artist + ' - ' + song.title, 'Téléchargement terminé');
songs.push (song);
songs = songs.sort (file.ORDER ());
song_list ();
},
(song, error) => {
toast_error (song.artist + ' - ' + song.title, error);
});
function song_item_icon (song)
{
if (! song.icon)
return 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='
if (/^https?:\/\//.test (song.icon))
return song.icon;
return 'songs/' + song.id + '/' + song.icon;
}
function song_item (song)
{
let img = document.createElement ('img');
img.className = 'm-1 bg-secondary';
img.width = 50;
img.height = 50;
img.src = song_item_icon (song);
img.onclick = () => karaoke.postMessage ({type: 'play', song});
let title = document.createElement ('div');
title.innerHTML = song.title;
let artist = document.createElement ('div');
artist.className = 'text-secondary';
artist.innerHTML = song.artist;
let text = document.createElement ('div');
text.className = 'd-flex flex-column flex-grow-1 m-1';
text.append (title, artist);
let warning = document.createElement ('i');
warning.className = 'bi-exclamation-triangle text-warning';
warning.style.display = song.warning ? 'block' : 'none';
let settings = document.createElement ('button');
settings.className = 'btn';
settings.innerHTML = '<i class="bi-three-dots"></i>';
settings.onclick = () => properties.show (song);
let li = document.createElement ('li');
li.className = 'list-group-item d-flex flex-row align-items-center';
li.append (img, text, warning, settings);
return li;
}
function song_list ()
{
console.log ('song_list');
let list = document.getElementById ('songs');
list.innerHTML = '';
selection.forEach (song => {
list.append (song_item (song));
});
}
function ASCII (s)
{
return s.normalize ('NFD').replace (/\p{Diacritic}/gu, '').toLowerCase ();
}
function search (e)
{
let f = e.target;
//window.scrollTo ({top: 0, behavior: 'instant'});
let q = ASCII (f.querySelector ('input').value);
let r = new RegExp ('\\b' + q);
let t = str => r.test (ASCII (str));
selection = songs.filter (song => t (song.title) || t (song.artist));
song_list ();
return false;
}
{
let f = document.querySelector ('nav form');
f.onsubmit = search;
}
function load_config ()
{
return fetch ("config.json").then (r => r.json ());
}
function enumerate_cameras (ratio)
{
return Camera.ENUMERATE (ratio);
}
// Fenêtre secondaire.
let karaoke = window.open ('karaoke.html', 'Karaoke');
if (karaoke != null)
{
// Settings.
load_config ().then (config => {
console.log (config);
let ratio = config.ratio ?? DEFAULT_CAMERA_RATIO;
let splash = config.splash ?? DEFAULT_SPLASH;
function post_splash ()
{
console.log ('splash', splash);
karaoke.postMessage ({type: 'splash', splash});
}
post_splash ();
// Webcam.
enumerate_cameras (ratio).then (cameras => {
function post_camera ()
{
console.log ('post_camera');
let constraints = cameras [camera_index].constraints;
let chroma_key = chroma_keys [camera_index];
karaoke.postMessage ({type: 'camera', constraints, 'chroma-key': chroma_key});
}
function post_chroma_key ()
{
let chroma_key = chroma_keys [camera_index];
karaoke.postMessage ({type: 'chroma-key', 'chroma-key': chroma_key});
}
function camera_button_size ()
{
switch (cameras.length)
{
case 1: return '100%';
case 3: return '33%';
default: return '50%';
}
}
// Clés chromatiques.
let chroma_keys = PAD (config['chroma-keys'], cameras.length, DEFAULT_CHROMA_KEY);
console.log (chroma_keys);
// Caméra par défaut.
let camera_index = 0;
// Ajout des caméras à la fenêtre de sélection.
let camera_modal = document.getElementById ('camera-list');
let camera_modal_body = document.querySelector ('.modal-body');
// Dès que la fenêtre s'affiche...
camera_modal.addEventListener ('show.bs.modal', e => {
camera_modal_body.innerHTML = '';
cameras.forEach ((c, k) => {
c.video.play ();
c.video.onclick = () => {
let items = Array.from (camera_modal_body.querySelectorAll ('div'));
items [camera_index].classList.toggle ('border-secondary');
items [camera_index].classList.toggle ('border-danger');
camera_index = k;
post_camera ();
items [camera_index].classList.toggle ('border-secondary');
items [camera_index].classList.toggle ('border-danger');
};
let item = document.createElement ('div');
let color = k == camera_index ? 'border-danger' : 'border-secondary';
item.classList.add ('m-2', 'border', 'border-5', color);
item.style.lineHeight = 0;
item.style.width = camera_button_size ();
item.appendChild (c.video);
camera_modal_body.appendChild (item);
});
});
// Activation des boutons liés aux caméras.
document.querySelector ('#toolbar-camera').disabled = false;
document.querySelector ('#toolbar-chroma').disabled = false;
// Fenêtre de dialogue.
let modal = document.getElementById ('chroma-picker');
let body = modal.querySelector ('.modal-body');
// Dès que la fenêtre s'affiche...
modal.addEventListener ('show.bs.modal', e => {
let video = cameras [camera_index].video;
// Démarrage de la vidéo.
video.play ();
// Création du filtre "chroma-key".
let chroma = new VideoChroma (video, chroma_keys [camera_index]);
// Rafraîchissement de l'aperçu.
let request = null;
let animate = () => {
chroma.draw ();
request = requestAnimationFrame (animate);
};
animate ();
// Gestion du clic sur la vidéo.
video.onclick = media.ONCLICK (video, rgb => {
console.log ('onclick', rgb);
chroma_keys [camera_index] = rgb;
chroma.chroma_key = rgb;
post_chroma_key ();
});
// Ajout des éléments.
let div1 = document.createElement ('div');
div1.classList.add ('m-2');
div1.appendChild (video);
div1.style.width = "50%";
let div2 = document.createElement ('div');
div2.classList.add ('m-2');
div2.appendChild (chroma.canvas);
div2.style.width = "50%";
body.append (div1, div2);
// Suppression des éléments à la fermeture.
let listener = () => {
//console.log ('hidden.bs.modal');
cancelAnimationFrame (request);
body.removeChild (div1);
body.removeChild (div2);
chroma.dispose ();
};
modal.addEventListener ('hidden.bs.modal', listener, {once: true});
});
// Caméra à la demande.
window.addEventListener ('message', e => {
switch (e.data)
{
case 'ready':
post_camera ();
post_splash ();
break;
}
});
});
});
file.FETCH ('songs.php').
then (data => {
songs = data;
selection = data;
song_list ();
});
{
let button = document.getElementById ('toolbar-stop');
button.onclick = () => karaoke.postMessage ({type: 'stop'});
}
{
let input = document.getElementById ('toolbar-fx-mirror-vertical');
input.onchange = () => karaoke.postMessage ({type: 'mirror-vertical', mirror: input.checked});
}
{
let input = document.getElementById ('toolbar-fx-mirror-horizontal');
input.onchange = () => karaoke.postMessage ({type: 'mirror-horizontal', mirror: input.checked});
}
{
let input = document.getElementById ('toolbar-fx-rotate');
input.onchange = () => karaoke.postMessage ({type: 'rotate', rotate: input.checked});
}
}
window.onbeforeunload = e => {
if (confirm_reload)
{
e.returnValue = "Interrompre le karaoké ?";
e.preventDefault ();
}
}
</script>
<div class="text-center">
<a href="https://www.youtube.com/user/karafunfr/videos" target="_blank">KaraFun France</a>
<span>•</span>
<a href="https://www.youtube.com/user/karafun/videos" target="_blank">KaraFun</a>
<span>•</span>
<a href="https://www.youtube.com/c/singkingkaraoke/videos" target="_blank">Sing King</a>
<span>•</span>
<a href="https://www.youtube.com/channel/UCObchMolWdiUqpdjUGRPUcA/videos" target="_blank">Sing Now!</a>
<span>•</span>
<a href="https://www.youtube.com/user/KaraokeOnVEVO/videos" target="_blank">Karaoke on Vevo</a>
</div>
</body>
</html>