From 768f357bdcd8bdc34e1851b62cd6febf95baff26 Mon Sep 17 00:00:00 2001 From: scisneromam Date: Wed, 7 Feb 2024 18:02:57 +0100 Subject: [PATCH 1/2] fix: Crash by trying to stop synth while none is playing --- src/bongocat.js | 2 +- src/experimental/bongox.js | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/bongocat.js b/src/bongocat.js index c20c7d7..2751a52 100644 --- a/src/bongocat.js +++ b/src/bongocat.js @@ -243,7 +243,7 @@ function outroAnimation() { mainGainNode.gain.value = 0; } - if (oscillatorNode) + if (oscillatorNode && synthStarted) { oscillatorNode.stop(); synthStarted = false; diff --git a/src/experimental/bongox.js b/src/experimental/bongox.js index 37ab2a8..fa39e8f 100644 --- a/src/experimental/bongox.js +++ b/src/experimental/bongox.js @@ -125,14 +125,15 @@ function rtttl(song) let splits = notes.split(":"); // we do not use song names at the moment - let name = "" - if (splits.length >= 3) { - name = splits.shift() - name = name.trim() + let name = ""; + if (splits.length >= 3) + { + name = splits.shift(); + name = name.trim(); } - - let regex = /(?:(\w)=(\d+))|(?:(\d+)?(a#|ab|a|b|h|c#|c|db|d|eb|e#|e|fb|f#|f|gb|g#|g|p)(\d)?(\.)?)/gi; //rtttl notation converted to regex + + let regex = /(?:(\w)=(\d+))|(?:(\d+)?(a#|ab|a|b|h|c#|c|db|d#|d|eb|e#|e|fb|f#|f|gb|g#|g|p)(\.)?(\d)?(\.)?)/gi; //rtttl notation converted to regex //groups: //0 = complete capture //1 = key @@ -144,7 +145,7 @@ function rtttl(song) let time = 1; //current time in seconds let playbacks = []; prepareSynth("square"); - playbacks.push(preparePlaybackObject(setInstrument, 0, "nokia3210")) + playbacks.push(preparePlaybackObject(setInstrument, 0, "nokia3210")); while (splits.length > 0) { let notes = splits.shift(); @@ -185,15 +186,15 @@ function rtttl(song) } } let noteLength = 240 / bpm / noteDuration; - if (note[6]) + if (note[5] || note[7]) { noteLength *= 1.5; } let noteOctave = octave; //noteOctave = 1 - if (note[5]) + if (note[6]) { - let numberValue = Math.floor(Number(note[5])); + let numberValue = Math.floor(Number(note[6])); if (numberValue && !Number.isNaN(numberValue)) { noteOctave = clamp(numberValue, 0, 8); @@ -241,15 +242,15 @@ function rtttl(song) let noteFrequency = noteFreq[noteOctave][noteStr]; if (noteFrequency) { - let paws = ["paw-left", "paw-right"] - let rnd = 0 + (Math.random() > 0.95) - playbacks.push(preparePlaybackObject(setPaw, time*1000, paws[rnd], bpm * (noteDuration / 4))) + let paws = ["paw-left", "paw-right"]; + let rnd = 0 + (Math.random() > 0.95); + playbacks.push(preparePlaybackObject(setPaw, time * 1000, paws[rnd], bpm * (noteDuration / 4))); //playSynthSound(noteFrequency, time) playbacks.push(preparePlaybackObject(playSynthSound, 0, noteFrequency, time)); - time += noteLength / 10 * 8 + time += noteLength / 10 * 8; //muteSynth(time) playbacks.push(preparePlaybackObject(muteSynth, 0, time)); - time += noteLength / 10 * 2 + time += noteLength / 10 * 2; } } } From 4b2a13205ff54548d201f4e2f5b87f01976dc270 Mon Sep 17 00:00:00 2001 From: scisneromam Date: Wed, 7 Feb 2024 18:04:19 +0100 Subject: [PATCH 2/2] feat: Parse _ as # in rtttl notation --- src/experimental/bongox.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/experimental/bongox.js b/src/experimental/bongox.js index fa39e8f..d61ed07 100644 --- a/src/experimental/bongox.js +++ b/src/experimental/bongox.js @@ -117,6 +117,7 @@ const noteFreq = createNoteTable(); function rtttl(song) { let notes = song.notes; + notes = notes.replaceAll("_", "#"); let username = song.performer; console.log("Playing RTTTL", notes, "for", username); let duration = 4;