From 1839f914384930905954fc0ca85ed5a9499b2096 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Tue, 1 Jun 2021 17:18:25 +0200 Subject: [PATCH] Set fifth click to reset screen --- voicegardens/static/voicegardens.js | 35 +++++++++++++++++------------ 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/voicegardens/static/voicegardens.js b/voicegardens/static/voicegardens.js index 051a4d0..b7d324d 100644 --- a/voicegardens/static/voicegardens.js +++ b/voicegardens/static/voicegardens.js @@ -11,7 +11,7 @@ var _canvas; var offlineRecordingDuration = 3000; // Offline limits for hardware considerations -var offlineLimits = 4; +var offlineLimits = 5; // URL which exposes the archive saving API end-point var archiveUrl = window.location + "add-to-archive"; @@ -87,7 +87,7 @@ function gardenOfflineLimits() { /** * Ensure shapes stay within limits **/ - if (shapes.length < offlineLimits) return; + if (shapes.length < offlineLimits) return false; for (let i = 0; i < shapes.length; i++) { let shape = shapes[i]; @@ -97,6 +97,8 @@ function gardenOfflineLimits() { while (shapes.length > 0) { shapes.pop(); } + + return true; } function sendToArchive() { @@ -583,18 +585,23 @@ function draw() { // generate a new shape after a sound recording if (newSoundJustRecorded === true) { - // build a new copy of the recording to store on the shape object - let soundBlob = recording.getBlob(); - let data = new p5.File(soundBlob); - let sound = new p5.SoundFile(data, function () { - let amp = sound.getPeaks(1)[0] * 100; - let dur = sound.duration(); - let shape = new GeneratedShape(sound, amp, dur); - gardenOfflineLimits(); - shape.sound(); - shapes.push(shape); - sendToArchive(); - }); + let limits = gardenOfflineLimits(); + console.log("limits are:"); + console.log(limits); + if (limits === false) { + console.log("making another one!"); + // build a new copy of the recording to store on the shape object + let soundBlob = recording.getBlob(); + let data = new p5.File(soundBlob); + let sound = new p5.SoundFile(data, function () { + let amp = sound.getPeaks(1)[0] * 100; + let dur = sound.duration(); + let shape = new GeneratedShape(sound, amp, dur); + shape.sound(); + shapes.push(shape); + sendToArchive(); + }); + } newSoundJustRecorded = false; }