mySound = loadSound('vivaldi.mp3');
createCanvas(windowWidth, windowHeight, WEBGL);
playButton = createButton('▶');
playButton.position(width / 2 - 25, height - 80);
playButton.mousePressed(toggleMusic);
playButton.style('background-color', '#000');
playButton.style('color', '#FFF');
playButton.style('border', 'none');
playButton.style('border-radius', '26px');
playButton.style('cursor', 'pointer');
volumeSlider = createSlider(0, 1, 0.5, 0.01);
volumeSlider.position(0, 560);
volumeSlider.style('transform', 'rotate(-90deg)');
volumeSlider.style('width', '130px');
volumeSlider.style('background', '#FFF');
volumeSlider.style('appearance', 'none');
volumeSlider.style('border-radius', '20px');
progressBar = createSlider(0, 1, 0, 0.01);
progressBar.addClass ("slider")
progressBar.position(width / 2 - 150, height - 40);
progressBar.style('width', '320px');
progressBar.style('background', '#FF0000');
progressBar.input(updateMusicPosition);
elapsedTimeText = createDiv('0:00');
elapsedTimeText.position(width / 2 - 170, height - 60);
elapsedTimeText.style('color', '#FFF');
elapsedTimeText.style('font-family', 'Monospace');
durationTimeText = createDiv('0:00');
durationTimeText.position(width / 2 + 130, height - 60);
durationTimeText.style('color', '#FFF');
durationTimeText.style('font-family', 'Monospace');
let spectrum = fft.analyze();
translate(-width / 2, -height / 2, 0);
for (let x = 0; x < cols; x++) {
beginShape(TRIANGLE_STRIP);
for (let y = 0; y < rows; y++) {
let index = floor(map(y, 0, rows, 0, spectrum.length));
let zHeight = map(spectrum[index], 0, 255, -100, 300);
let r = map(spectrum[index], 0, 255, 50, 255);
let g = map(x, 0, cols, 50, 200);
let b = map(y, 0, rows, 50, 255);
vertex(xpos, ypos, zHeight);
vertex(xpos, ypos + spacing, map(spectrum[index + 10] || 0, 0, 255, -100, 300));
mySound.setVolume(volumeSlider.value());
let progress = mySound.currentTime() / mySound.duration();
progressBar.value(progress);
function updateMusicPosition() {
if (mySound.isLoaded()) {
let duration = mySound.duration();
let newPosition = progressBar.value() * duration;
mySound.jump(newPosition);
function updateTimeText() {
let currentTime = mySound.currentTime();
let duration = mySound.duration();
let elapsedMinutes = floor(currentTime / 60);
let elapsedSeconds = floor(currentTime % 60);
elapsedTimeText.html(nf(elapsedMinutes, 2) + ':' + nf(elapsedSeconds, 2));
let remainingTime = duration - currentTime;
let remainingMinutes = floor(remainingTime / 60);
let remainingSeconds = floor(remainingTime % 60);
durationTimeText.html('-' + nf(remainingMinutes, 2) + ':' + nf(remainingSeconds, 2));