-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
1827 lines (1609 loc) · 70.7 KB
/
index.html
File metadata and controls
1827 lines (1609 loc) · 70.7 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
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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Begin Jekyll SEO tag v2.7.1 -->
<title>ACE-Step 1.5: Pushing the Boundaries of Open-Source Music Generation</title>
<meta name="generator" content="Jekyll v3.9.0">
<meta property="og:title" content="ACE-Step 1.5: Pushing the Boundaries of Open-Source Music Generation">
<meta property="og:locale" content="en_US">
<meta name="twitter:card" content="summary">
<!-- End Jekyll SEO tag -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#5D59FF">
<link rel="stylesheet" href="style.css">
<style>
/* Lyrics toggle section */
.lyrics-toggle {
border: 1px solid #dee2e6;
border-radius: 8px;
margin-top: 0;
overflow: hidden;
}
.lyrics-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 20px;
background-color: #f8f9fa;
cursor: pointer;
font-weight: 600;
}
.toggle-icon {
transition: transform 0.3s ease;
}
.lyrics-toggle.expanded .toggle-icon {
transform: rotate(180deg);
}
.lyrics-body {
padding: 0;
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease, padding 0.3s ease;
}
.lyrics-toggle.expanded .lyrics-body {
padding: 20px;
max-height: 300px;
/* Reduced height to encourage scrolling */
overflow-y: auto;
/* Add vertical scrolling */
overflow-x: auto;
/* Add horizontal scrolling when content is too wide */
}
/* Ensure pre element doesn't expand beyond container */
.lyrics-body pre {
white-space: pre-wrap;
word-wrap: break-word;
overflow-x: auto;
margin: 0;
/* Remove default margin to ensure first line is visible */
display: block;
/* Ensure block display */
text-align: left;
/* Ensure left alignment */
max-width: 100%;
/* Constrain to container width */
}
/* Constrain lyrics toggle container */
.lyrics-toggle {
max-width: 100%;
box-sizing: border-box;
}
/* Toggle all button styling */
.toggle-all-button {
background-color: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 4px;
padding: 8px 16px;
font-weight: 600;
cursor: pointer;
transition: background-color 0.2s ease;
}
.toggle-all-button:hover {
background-color: #e9ecef;
}
/* Fixed toggle button container */
.fixed-toggle-container {
position: fixed;
top: 20px;
right: 20px;
z-index: 1000;
background-color: rgba(255, 255, 255, 0.9);
padding: 5px;
border-radius: 4px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
/* Play button for individual tracks */
.track-play-btn {
background-color: #5D59FF;
color: white;
border: none;
border-radius: 50%;
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
cursor: pointer;
transition: all 0.2s ease;
}
.track-play-btn:hover {
background-color: #4A46E3;
}
.track-play-btn.playing {
background-color: #4A46E3;
}
/* Global player bar styling */
#global-player {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background-color: #333;
border-top: 1px solid #222;
padding: 10px 20px;
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
gap: 15px;
z-index: 1000;
transform: translateY(100%);
transition: transform 0.3s ease;
height: 80px;
}
#global-player.visible {
transform: translateY(0);
}
.player-track-info {
flex: 0 0 250px;
display: flex;
align-items: center;
color: #fff;
}
.track-details {
display: flex;
flex-direction: column;
justify-content: center;
width: 180px;
overflow: hidden;
}
.player-track-title {
font-weight: bold;
font-size: 18px;
margin-bottom: 3px;
color: #fff;
max-width: 180px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.player-track-genre {
font-size: 12px;
color: #888;
text-transform: uppercase;
max-width: 180px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* Add scrolling animation for long text */
.player-track-title.scrolling,
.player-track-genre.scrolling {
text-overflow: clip;
position: relative;
display: inline-block;
padding-right: 10px;
/* Add some space at the end */
animation: marquee 10s linear infinite;
animation-delay: 1s;
/* Delay before starting */
}
/* Animation for scrolling text */
@keyframes marquee {
0%,
15% {
transform: translateX(0);
}
/* Pause at the beginning */
85%,
100% {
transform: translateX(calc(-100% + 180px));
}
/* Stop when text is at the end of container */
}
/* Different animation speeds based on content length */
.player-track-title.scrolling.length-medium,
.player-track-genre.scrolling.length-medium {
animation-duration: 15s;
}
.player-track-title.scrolling.length-long,
.player-track-genre.scrolling.length-long {
animation-duration: 20s;
}
/* Ensure the animation stays within the container */
.track-details {
position: relative;
overflow: hidden;
}
.player-controls {
display: flex;
align-items: center;
gap: 15px;
}
.player-btn {
background: none;
border: none;
cursor: pointer;
font-size: 18px;
color: #fff;
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
transition: background-color 0.2s ease;
}
.player-btn:hover {
background-color: #333;
}
.player-btn.active {
color: #fff;
}
.mode-indicator {
font-size: 10px;
vertical-align: super;
margin-left: 2px;
}
.player-play-btn {
background-color: transparent;
color: white;
border-radius: 50%;
width: 40px;
height: 40px;
}
.player-play-btn:hover {
background-color: #333;
}
.player-progress-container {
flex-grow: 1;
height: 4px;
background-color: #444;
border-radius: 2px;
cursor: pointer;
position: relative;
}
.player-progress-bar {
height: 100%;
background-color: #fff;
border-radius: 2px;
width: 0%;
position: relative;
}
.player-progress-handle {
width: 12px;
height: 12px;
background-color: #fff;
border-radius: 50%;
position: absolute;
top: 50%;
right: -6px;
transform: translateY(-50%);
cursor: grab;
}
.player-time-display {
font-size: 14px;
color: #fff;
min-width: 80px;
text-align: right;
font-family: monospace;
}
/* Add padding to the bottom of the page to account for the player */
body {
padding-bottom: 80px;
}
/* Extra controls styling */
.player-extra-controls {
display: flex;
align-items: center;
gap: 10px;
margin-left: 10px;
}
</style>
</head>
<body data-new-gr-c-s-check-loaded="14.1001.0" data-gr-ext-installed="">
<!-- Include the audio loader script -->
<script src="audio-loader.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
// This will hold our music samples data organized by sections
let musicSampleSections = {};
// This will hold the flattened list of all samples
let musicSamples = [];
// Initialize the AudioLoader
const audioLoader = new AudioLoader({
username: 'ace-step',
repo: 'ace-step-v1.5.github.io',
releaseTag: '',
useJsDelivr: true,
// Use mp3 first since opus may not be available
formatPreference: ['mp3', 'flac']
});
// Function to load the samples data from the JSON file
async function loadSamplesData() {
try {
// Fetch the samples data from the JSON file
const response = await fetch('samples_data.json');
if (!response.ok) {
throw new Error(`Failed to fetch samples data: ${response.status}`);
}
// Parse the JSON response
musicSampleSections = await response.json();
// Generate the table rows
generateTableRows(['GeneralSongs'], 'baseline-quality');
// Hidden sections - commented out
// generateTableRows(['Controlability-retake', 'Controlability-repaint', 'Controlability-edit'], 'controlability');
// generateTableRows(['Application-Lyric2Vocal', 'Text2Sample', 'RapMachine'], 'application');
// Initialize mode indicators
document.querySelector('#player-shuffle-btn .mode-indicator').textContent = '';
document.querySelector('#player-repeat-btn .mode-indicator').textContent = '';
// Update the toggle all button text to match initial state (all collapsed)
document.getElementById('toggle-all-lyrics').textContent = 'Expand All Lyrics';
// Add click event listeners to all lyrics toggle headers
document.querySelectorAll('.lyrics-header').forEach(function (header) {
header.addEventListener('click', function () {
// Toggle the 'expanded' class on the parent element
this.parentElement.classList.toggle('expanded');
});
});
// Update the flattened list of all samples
musicSamples = Object.values(musicSampleSections).flat();
musicSamples.forEach(sample => {
fetchTextAndUpdate(`raw/samples/${sample.directory}/${sample.fileName}.txt`, `${sample.id}-lyrics`);
fetchTextAndUpdate(`raw/samples/${sample.directory}/${sample.fileName}_prompt.txt`, `${sample.id}-prompt`);
});
// Add event listeners to play buttons after table is generated
addPlayButtonListeners();
} catch (error) {
console.error('Error loading samples data:', error);
}
}
// Start loading the samples data
loadSamplesData();
// Generate table rows dynamically by section
function generateTableRows(sectionIds, select_id) {
// function generateTableRows() {
// Make sure we're using the latest flattened list
musicSamples = Object.values(musicSampleSections).flat();
// const tbody = document.querySelector('table tbody');
const tbody = document.querySelector(`tbody#${select_id}`);
tbody.innerHTML = ''; // Clear existing content
// Process each section
Object.entries(musicSampleSections).forEach(([sectionId, samples]) => {
if (!sectionIds.includes(sectionId)) {
return;
}
// Create section header row
const sectionRow = document.createElement('tr');
const sectionCell = document.createElement('td');
sectionCell.colSpan = 3;
sectionCell.className = 'section-header';
sectionCell.id = sectionId;
// Style the section header
sectionCell.style.backgroundColor = '#f0f0f0';
sectionCell.style.padding = '10px';
sectionCell.style.fontWeight = 'bold';
sectionCell.style.fontSize = '1.2em';
sectionCell.style.textAlign = 'center';
// Set section title based on ID
let sectionTitle = sectionId;
if (sectionId === 'GeneralSongs') {
sectionTitle = '';
}
// Clear existing content
sectionCell.textContent = '';
// Create title element with more prominent styling
const titleElement = document.createElement('div');
titleElement.textContent = sectionTitle;
titleElement.style.marginBottom = '15px';
titleElement.style.fontSize = '1.3em';
titleElement.style.fontWeight = 'bold';
titleElement.style.color = '#333';
titleElement.style.letterSpacing = '1px';
sectionCell.appendChild(titleElement);
// Add note div based on section ID with distinct styling
const noteDiv = document.createElement('div');
noteDiv.style.borderLeft = '4px solid #097EFF';
noteDiv.style.paddingLeft = '15px';
noteDiv.style.marginBottom = '10px';
noteDiv.style.textAlign = 'left';
noteDiv.style.fontSize = '0.85em';
noteDiv.style.color = '#606c71';
noteDiv.style.backgroundColor = '#f8f9fa';
noteDiv.style.padding = '8px 15px';
noteDiv.style.borderRadius = '0 4px 4px 0';
const noteTitle = document.createElement('p');
noteTitle.style.fontWeight = 'bold';
noteTitle.style.marginBottom = '8px';
noteTitle.style.color = '#097EFF';
noteTitle.style.fontSize = '1em';
noteTitle.style.borderBottom = '1px solid #dee2e6';
noteTitle.style.paddingBottom = '4px';
noteTitle.textContent = 'Note:';
noteDiv.appendChild(noteTitle);
// Add the note div to the section cell if it has content
if (noteDiv.childNodes.length > 1) {
sectionCell.appendChild(noteDiv);
}
sectionRow.appendChild(sectionCell);
tbody.appendChild(sectionRow);
// Helper function to add note items
function addNoteItem(parent, text) {
const noteItem = document.createElement('p');
noteItem.style.margin = '0 0 6px 0';
noteItem.style.lineHeight = '1.4';
noteItem.style.textIndent = '-12px';
noteItem.style.paddingLeft = '12px';
noteItem.textContent = '- ' + text;
parent.appendChild(noteItem);
}
// Add samples for this section
samples.forEach(sample => {
const row = document.createElement('tr');
// First column - Prompt
const promptCell = document.createElement('td');
promptCell.className = 'tg-0lax';
promptCell.style.width = '500px';
const promptSpan = document.createElement('span');
promptSpan.id = `${sample.id}-prompt`;
promptSpan.textContent = 'Loading prompt...';
promptCell.appendChild(promptSpan);
// Second column - Lyrics toggle
const lyricsCell = document.createElement('td');
lyricsCell.style.verticalAlign = 'top';
lyricsCell.style.width = '800px'; /* Same width as Caption column */
lyricsCell.style.maxWidth = '800px'; /* Prevent expansion */
lyricsCell.style.position = 'relative'; /* For proper positioning of child elements */
const lyricsToggle = document.createElement('div');
lyricsToggle.className = 'lyrics-toggle'; // Remove 'expanded' to collapse by default
const lyricsHeader = document.createElement('div');
lyricsHeader.className = 'lyrics-header';
lyricsHeader.textContent = 'Lyrics';
switch (sample.id) {
case 'dark-atmospheric':
lyricsHeader.textContent = 'Chinese';
break;
case 'electro-house':
lyricsHeader.textContent = 'Chinese';
break;
case 'folk-rnb-female':
lyricsHeader.textContent = 'Chinese';
break;
case 'french-pop':
lyricsHeader.textContent = 'French';
break;
case 'german-dance':
lyricsHeader.textContent = 'German';
break;
case 'hip-house':
lyricsHeader.textContent = 'Chinese';
break;
case 'italian-folk':
lyricsHeader.textContent = 'Italian';
break;
case 'jpop':
lyricsHeader.textContent = 'Japanese';
break;
case 'kpop':
lyricsHeader.textContent = 'Korean';
break;
case 'mandopop':
lyricsHeader.textContent = 'Chinese';
break;
case 'portuguese-pop':
lyricsHeader.textContent = 'Portuguese';
break;
case 'russian-folk':
lyricsHeader.textContent = 'Russian';
break;
case 'spanish-song':
lyricsHeader.textContent = 'Spanish';
break;
}
const toggleIcon = document.createElement('span');
toggleIcon.className = 'toggle-icon';
toggleIcon.textContent = '▼';
lyricsHeader.appendChild(toggleIcon);
const lyricsBody = document.createElement('div');
lyricsBody.className = 'lyrics-body';
lyricsBody.style.display = 'flex';
lyricsBody.style.flexDirection = 'column';
lyricsBody.style.alignItems = 'flex-start';
const lyricsPre = document.createElement('pre');
lyricsPre.id = `${sample.id}-lyrics`;
lyricsPre.textContent = 'Loading lyrics...';
lyricsPre.style.alignSelf = 'flex-start';
lyricsBody.appendChild(lyricsPre);
lyricsToggle.appendChild(lyricsHeader);
lyricsToggle.appendChild(lyricsBody);
lyricsCell.appendChild(lyricsToggle);
// Third column - Audio player
const audioCell = document.createElement('td');
audioCell.className = 'tg-0lax';
audioCell.style.width = '60px'; /* Reduced from 500px to be closer to play button size */
// Create a play button for this track
const playButton = document.createElement('button');
playButton.innerHTML = '▶'; // Play icon
playButton.className = 'track-play-btn';
// Store track data as attributes (without src - we'll get it dynamically)
playButton.dataset.directory = sample.directory;
playButton.dataset.fileName = sample.fileName;
playButton.dataset.id = sample.id;
playButton.dataset.title = sample.fileName.replace(/_/g, ' ');
// Add the play button to the cell
audioCell.appendChild(playButton);
// We don't need this line anymore since we're appending the audioWrapper instead
// Add all cells to the row
row.appendChild(promptCell);
row.appendChild(lyricsCell);
row.appendChild(audioCell);
// Add the row to the table
tbody.appendChild(row);
});
});
}
// Function to fetch text from file and update element
async function fetchTextAndUpdate(filePath, elementId) {
try {
const response = await fetch(filePath);
if (!response.ok) {
throw new Error(`Failed to fetch ${filePath}: ${response.status}`);
}
const text = await response.text();
const element = document.getElementById(elementId);
if (element) {
element.textContent = text;
}
} catch (error) {
console.error('Error fetching text:', error);
const element = document.getElementById(elementId);
if (element) {
element.textContent = 'No Lyrics';
}
}
}
// Toggle all lyrics functionality
const toggleAllButton = document.getElementById('toggle-all-lyrics');
let allExpanded = false; // Start with all collapsed
toggleAllButton.addEventListener('click', function () {
const lyricsToggles = document.querySelectorAll('.lyrics-toggle');
if (allExpanded) {
// Collapse all
lyricsToggles.forEach(toggle => {
toggle.classList.remove('expanded');
});
toggleAllButton.textContent = 'Expand All Lyrics';
} else {
// Expand all
lyricsToggles.forEach(toggle => {
toggle.classList.add('expanded');
});
toggleAllButton.textContent = 'Collapse All Lyrics';
}
// Toggle the state
allExpanded = !allExpanded;
// If we're collapsing all, make sure to re-expand the currently playing track
if (!allExpanded && currentTrackIndex >= 0) {
const track = musicSamples[currentTrackIndex];
const lyricsElement = document.getElementById(`${track.id}-lyrics`);
if (lyricsElement) {
const lyricsToggle = lyricsElement.closest('.lyrics-toggle');
if (lyricsToggle) {
lyricsToggle.classList.add('expanded');
}
}
}
});
// Global Player Implementation
const globalPlayer = document.getElementById('global-player');
const globalAudio = document.getElementById('global-audio');
const playerPlayBtn = document.getElementById('player-play-btn');
const playerPrevBtn = document.getElementById('player-prev-btn');
const playerNextBtn = document.getElementById('player-next-btn');
const playerShuffleBtn = document.getElementById('player-shuffle-btn');
const playerRepeatBtn = document.getElementById('player-repeat-btn');
const playerProgressContainer = document.querySelector('.player-progress-container');
const playerProgressBar = document.querySelector('.player-progress-bar');
const playerProgressHandle = document.querySelector('.player-progress-handle');
const playerTimeDisplay = document.querySelector('.player-time-display');
const playerTrackTitle = document.querySelector('.player-track-title');
const playerTrackGenre = document.querySelector('.player-track-genre');
const playerAlbumArt = document.getElementById('player-album-art');
// Player state
let currentTrackIndex = -1;
let isShuffleMode = false;
let isRepeatMode = false;
let playQueue = [];
// Format time function (converts seconds to MM:SS format)
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = Math.floor(seconds % 60);
return `${minutes}:${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`;
}
// Update the play queue based on shuffle mode
function updatePlayQueue() {
if (isShuffleMode) {
// Create a shuffled queue excluding the current track
const availableTracks = [...Array(musicSamples.length).keys()].filter(i => i !== currentTrackIndex);
// Shuffle the available tracks
for (let i = availableTracks.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[availableTracks[i], availableTracks[j]] = [availableTracks[j], availableTracks[i]];
}
// Put the current track at the beginning if it's valid
if (currentTrackIndex >= 0) {
playQueue = [currentTrackIndex, ...availableTracks];
} else {
playQueue = availableTracks;
}
} else {
// Sequential mode - just create an array from 0 to the number of tracks
playQueue = [...Array(musicSamples.length).keys()];
// If we have a current track, rotate the queue so it starts from the next track
if (currentTrackIndex >= 0) {
const currentIndex = playQueue.indexOf(currentTrackIndex);
playQueue = [...playQueue.slice(currentIndex), ...playQueue.slice(0, currentIndex)];
}
}
}
// Function to update all track buttons to show correct play/pause state
function updateTrackButtons() {
document.querySelectorAll('.track-play-btn').forEach(button => {
const sampleId = button.dataset.id;
const trackIndex = musicSamples.findIndex(s => s.id === sampleId);
if (trackIndex === currentTrackIndex && !globalAudio.paused) {
button.innerHTML = '❚❚'; // Pause icon
button.classList.add('playing');
} else {
button.innerHTML = '▶'; // Play icon
button.classList.remove('playing');
}
});
}
// Function to scroll to the lyrics of the current track and expand only that one
function scrollToCurrentTrackLyrics() {
if (currentTrackIndex >= 0) {
// First collapse all lyrics
document.querySelectorAll('.lyrics-toggle').forEach(toggle => {
toggle.classList.remove('expanded');
});
// Then expand only the current track's lyrics
const track = musicSamples[currentTrackIndex];
const lyricsElement = document.getElementById(`${track.id}-lyrics`);
if (lyricsElement) {
// Make sure the lyrics toggle is expanded
const lyricsToggle = lyricsElement.closest('.lyrics-toggle');
if (lyricsToggle) {
lyricsToggle.classList.add('expanded');
}
// Scroll to the lyrics with a small delay to allow expansion
setTimeout(() => {
lyricsElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
}, 300);
}
}
}
// Play a specific track
async function playTrack(index) {
if (index >= 0 && index < musicSamples.length) {
currentTrackIndex = index;
const track = musicSamples[index];
// Update player UI
playerTrackTitle.textContent = track.fileName.replace(/_/g, ' ');
playerTrackGenre.textContent = track.id.replace(/-/g, ' ');
// Check if text is too long and apply scrolling if needed
setTimeout(() => {
// For track title
playerTrackTitle.classList.remove('scrolling', 'length-medium', 'length-long');
const titleText = playerTrackTitle.textContent;
playerTrackTitle.setAttribute('data-content', titleText); // Set content for ::after
if (playerTrackTitle.scrollWidth > playerTrackTitle.clientWidth) {
playerTrackTitle.classList.add('scrolling');
// Calculate ratio to determine animation speed
const ratio = playerTrackTitle.scrollWidth / playerTrackTitle.clientWidth;
if (ratio >= 2) {
playerTrackTitle.classList.add('length-long');
} else if (ratio >= 1.5) {
playerTrackTitle.classList.add('length-medium');
}
}
// For track genre
playerTrackGenre.classList.remove('scrolling', 'length-medium', 'length-long');
const genreText = playerTrackGenre.textContent;
playerTrackGenre.setAttribute('data-content', genreText); // Set content for ::after
if (playerTrackGenre.scrollWidth > playerTrackGenre.clientWidth) {
playerTrackGenre.classList.add('scrolling');
// Calculate ratio to determine animation speed
const ratio = playerTrackGenre.scrollWidth / playerTrackGenre.clientWidth;
if (ratio >= 2) {
playerTrackGenre.classList.add('length-long');
} else if (ratio >= 1.5) {
playerTrackGenre.classList.add('length-medium');
}
}
}, 50); // Small timeout to ensure text is rendered
// Generate random colorful SVG as album art
const getRandomColor = () => {
const letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
};
// Create a random music-themed SVG
const bgColor = getRandomColor();
const fgColor = getRandomColor();
const svgPatterns = [
// Music note pattern
`<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200">
<rect width="200" height="200" fill="${bgColor}"/>
<path d="M80 30 L80 130 Q80 150 60 150 Q40 150 40 130 Q40 110 60 110 Q70 110 80 120 M120 50 L120 110 Q120 130 100 130 Q80 130 80 110 Q80 90 100 90 Q110 90 120 100" stroke="${fgColor}" stroke-width="8" fill="none"/>
</svg>`,
// Equalizer pattern
`<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200">
<rect width="200" height="200" fill="${bgColor}"/>
<rect x="40" y="40" width="20" height="120" fill="${fgColor}"/>
<rect x="80" y="80" width="20" height="80" fill="${fgColor}"/>
<rect x="120" y="20" width="20" height="140" fill="${fgColor}"/>
<rect x="160" y="60" width="20" height="100" fill="${fgColor}"/>
</svg>`,
// Vinyl record pattern
`<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200">
<rect width="200" height="200" fill="${bgColor}"/>
<circle cx="100" cy="100" r="80" fill="${fgColor}"/>
<circle cx="100" cy="100" r="30" fill="${bgColor}"/>
<circle cx="100" cy="100" r="10" fill="${fgColor}"/>
</svg>`
];
// Select a random SVG pattern
const randomSvg = svgPatterns[Math.floor(Math.random() * svgPatterns.length)];
// Convert SVG to data URL
const svgDataUrl = 'data:image/svg+xml;base64,' + btoa(randomSvg);
playerAlbumArt.src = svgDataUrl;
playerAlbumArt.style.display = 'block';
playerAlbumArt.style.backgroundColor = 'transparent';
// Show loading indicator
playerPlayBtn.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6 fill-primary"><path d="M12 4V2A10 10 0 0 0 2 12h2a8 8 0 0 1 8-8z"><animateTransform attributeName="transform" type="rotate" from="0 12 12" to="360 12 12" dur="1s" repeatCount="indefinite"/></path></svg>'; // Loading icon
try {
// Get optimized audio URL using AudioLoader
const audioUrl = await audioLoader.getAudioUrl(track.directory, track.fileName);
// Set audio source and play
globalAudio.src = audioUrl;
await globalAudio.play();
playerPlayBtn.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6 fill-primary"><path d="M8 19c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2s-2 .9-2 2v10c0 1.1.9 2 2 2zm8-2V7c0-1.1-.9-2-2-2s-2 .9-2 2v10c0 1.1.9 2 2 2s2-.9 2-2z"></path></svg>'; // Pause icon
globalPlayer.classList.add('visible'); // Show the player
updateTrackButtons(); // Update all track buttons
scrollToCurrentTrackLyrics(); // Scroll to the lyrics
// Log which format is being used
console.log(`Playing ${track.fileName} from: ${audioUrl}`);
} catch (error) {
console.error('Error playing audio:', error);
playerPlayBtn.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6 fill-primary"><path d="M8 6.82v10.36c0 .79.87 1.27 1.54.84l8.14-5.18a1 1 0 0 0 0-1.69L9.54 5.98A.998.998 0 0 0 8 6.82z"></path></svg>'; // Reset to play icon
}
// Update play queue
updatePlayQueue();
}
}
// Play the next track in the queue
function playNextTrack() {
if (playQueue.length > 0) {
// If repeat mode is on and we're at the end, play the current track again
if (isRepeatMode && globalAudio.ended) {
globalAudio.currentTime = 0;
globalAudio.play()
.then(() => {
updateTrackButtons();
});
return;
}
// Find the current track index in the queue
let currentQueueIndex = -1;
if (currentTrackIndex >= 0) {
currentQueueIndex = playQueue.indexOf(currentTrackIndex);
}
// Get the next track index
let nextQueueIndex = (currentQueueIndex + 1) % playQueue.length;
let nextTrackIndex = playQueue[nextQueueIndex];
// Play the next track
playTrack(nextTrackIndex);
} else if (musicSamples.length > 0) {
// If queue is empty but we have samples, initialize and play the first track
updatePlayQueue();
if (playQueue.length > 0) {
playTrack(playQueue[0]);
}
}
}
// Play the previous track
function playPreviousTrack() {
if (playQueue.length > 0) {
// Move the last track to the front
const prevIndex = playQueue.pop();
playQueue.unshift(prevIndex);
// And also move the current first track to the front (which is now second)
const currentIndex = playQueue.shift();
playQueue.unshift(currentIndex);
// Play the previous track
playTrack(prevIndex);
}
}
// Function to add event listeners to track play buttons
function addPlayButtonListeners() {
document.querySelectorAll('.track-play-btn').forEach(button => {
button.addEventListener('click', function () {
// Find the index of this sample in the current musicSamples array
const sampleId = this.dataset.id;
const trackIndex = musicSamples.findIndex(s => s.id === sampleId);
// If this is the currently playing track, toggle play/pause
if (trackIndex === currentTrackIndex && globalAudio.src) {
if (globalAudio.paused) {
globalAudio.play()
.then(() => {
playerPlayBtn.innerHTML = '❚❚'; // Pause icon
updateTrackButtons();
});
} else {
globalAudio.pause();
playerPlayBtn.innerHTML = '▶'; // Play icon
updateTrackButtons();
}
} else {
// Show loading indicator on the button
this.innerHTML = '⏳️'; // Loading icon
// Otherwise play the new track
playTrack(trackIndex);
}
});
});
}
// Play/Pause button click event
playerPlayBtn.addEventListener('click', function () {
if (globalAudio.paused) {
if (globalAudio.src) {
globalAudio.play()
.then(() => {
playerPlayBtn.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6 fill-primary"><path d="M8 19c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2s-2 .9-2 2v10c0 1.1.9 2 2 2zm8-2V7c0-1.1-.9-2-2-2s-2 .9-2 2v10c0 1.1.9 2 2 2s2-.9 2-2z"></path></svg>'; // Pause icon
updateTrackButtons();
});
} else if (playQueue.length > 0) {
// If no track is loaded but we have a queue, play the first track
playTrack(playQueue[0]);
}
} else {
globalAudio.pause();
playerPlayBtn.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6 fill-primary"><path d="M8 6.82v10.36c0 .79.87 1.27 1.54.84l8.14-5.18a1 1 0 0 0 0-1.69L9.54 5.98A.998.998 0 0 0 8 6.82z"></path></svg>'; // Play icon
updateTrackButtons();
}
});
// Previous track button click event
playerPrevBtn.addEventListener('click', playPreviousTrack);