diff --git a/server.js b/server.js index 77fa71c..c7b6575 100644 --- a/server.js +++ b/server.js @@ -175,7 +175,7 @@ fastify.post("/entry", async function (request, reply) { const client = new Client(server); //create unique folder ==> timestamp + uuid - const folder = await client.createFolder("Storage/public/sound-parade/" + moment().tz('Asia/Seoul').format('YYYYMMDD-HHmmss - ') + uuidv1()); + const folder = await client.createFolder("Storage/public/sound-parade/" + moment().tz('Asia/Seoul').format('YYYYMMDD-HHmmss-') + uuidv1()); if (converted) { const file = await folder.createFile("audio.mp3", await fs.readFile(tmpdir + '/converted.mp3')); } else { diff --git a/src/pages/parade.html b/src/pages/parade.html index 5bfd08b..e2517f7 100644 --- a/src/pages/parade.html +++ b/src/pages/parade.html @@ -56,9 +56,10 @@ fr = 20; } frameRate(fr); - // - silence = (await AudioImport("./audio/_silence.wav")).toDestination(); - clap = (await AudioImport("./audio/clap01.mp3")).toDestination(); + + //p5 'draw()' doesn't work if user is not looking at the tab. + noLoop(); + // --> use custom looper. } // @@ -66,9 +67,12 @@ var intro; var ready; // - socket.on("connect", function() { + socket.on("connect", async function() { console.log("connected!"); + // + silence = (await AudioImport("./audio/_silence.wav")).toDestination(); + clap = (await AudioImport("./audio/clap01.mp3")).toDestination(); //TESTING... fixed to room 1. // myroom = 1; @@ -127,8 +131,8 @@ } }); - var fading_factor = 0.3; //30% - //var fading_factor = 0.5; //50% + //var fading_factor = 0.3; //30% + var fading_factor = 0.5; //50% socket.on("post", async function(post) { console.log(post); @@ -159,7 +163,7 @@ var img = createImg(object.src, object.alt, "", async function(im) { //로딩이 끝나면, start! var pv = new Tone.PanVol(0, -99).toDestination(); - var snd = (await AudioImport(object.audio)); + var snd = await AudioImport(object.audio); // NOTE: url with spaces didn't work here. snd.connect(pv).start(); snd.loop = true; @@ -222,60 +226,70 @@ }); - function draw() { - for (var i = arr.length - 1; i >= 0; i -= 1) { - var bundle = arr[i]; - var img = bundle.img; - var showtime = parseFloat(img.attribute("data-showtime")); - var type = img.attribute("data-type"); - var x = img.position().x; - var y = img.position().y; - y = y + random(-1, 1); - x = x - windowWidth / (fr * showtime); + //p5 'draw()' doesn't work if user is not looking at the tab. + // --> custom looper is ok. + var looper; + (looper = function(timeout) { + setTimeout(async function() { // - if (type == "icon") { - img.style("z-index", "-1"); - } - 3; + for (var i = arr.length - 1; i >= 0; i -= 1) { + var bundle = arr[i]; + var img = bundle.img; + var showtime = parseFloat(img.attribute("data-showtime")); + var type = img.attribute("data-type"); + var x = img.position().x; + var y = img.position().y; + y = y + random(-1, 1); + x = x - windowWidth / (fr * showtime); - img.position(x, y); - var pan = (x / windowWidth) * 2 - 1; + // + if (type == "icon") { + img.style("z-index", "-1"); + } + 3; - //panning - var snd = bundle.sound; - var pv = bundle.panvol; - if (x >= -bundle.width && x < windowWidth) { - pan = ((x + bundle.width) / (windowWidth + bundle.width)) * 2 - 1; - pv.pan.value = pan; - pv.volume.value = 0;//(dB) - } else { - var range; - var knob; - if (x >= windowWidth) { - range = windowWidth * fading_factor - knob = x - windowWidth; - pv.pan.value = 1; - pv.volume.value = (1 - (knob / range)) * 99; - } else if (x < -bundle.width) { - range = windowWidth * fading_factor - knob = (x + bundle.width) * -1; - pv.pan.value = -1; - pv.volume.value = (1 - (knob / range)) * 99; + img.position(x, y); + var pan = (x / windowWidth) * 2 - 1; + + //panning + var snd = bundle.sound; + var pv = bundle.panvol; + if (x >= -bundle.width && x < windowWidth) { + pan = ((x + bundle.width) / (windowWidth + bundle.width)) * 2 - 1; + pv.pan.value = pan; + pv.volume.value = 0;//(dB) + } else { + var range; + var knob; + if (x >= windowWidth) { + range = windowWidth * fading_factor + knob = x - windowWidth; + pv.pan.value = 1; + pv.volume.value = knob / range * -20; + } else if (x < -bundle.width) { + range = windowWidth * fading_factor + knob = (x + bundle.width) * -1; + pv.pan.value = -1; + pv.volume.value = knob / range * -20; + } + } + + //remove with sound fade-out + var exit_x = -bundle.width - windowWidth * fading_factor; + if (x < exit_x) { + img.remove(); + snd.stop(); + delete snd; + delete pv; + arr.splice(i, 1); } } + // - //remove with sound fade-out - var exit_x = -bundle.width - windowWidth * fading_factor; - if (x < exit_x) { - img.remove(); - snd.stop(); - delete snd; - delete pv; - arr.splice(i, 1); - } - } - } + looper(1000/fr); + }, timeout); + })(1000/fr); // function randomvoiceplay() { // (looper = function(timeout) {