Skip to content

Commit

Permalink
Merge pull request #28 from JvPeek/develop
Browse files Browse the repository at this point in the history
Fix RTTTL crash
  • Loading branch information
awsdcrafting authored Feb 7, 2024
2 parents 88e7f19 + 4b2a132 commit 8843b25
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/bongocat.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function outroAnimation()
{
mainGainNode.gain.value = 0;
}
if (oscillatorNode)
if (oscillatorNode && synthStarted)
{
oscillatorNode.stop();
synthStarted = false;
Expand Down
32 changes: 17 additions & 15 deletions src/experimental/bongox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -125,14 +126,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
Expand All @@ -144,7 +146,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();
Expand Down Expand Up @@ -185,15 +187,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);
Expand Down Expand Up @@ -241,15 +243,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;
}
}
}
Expand Down

0 comments on commit 8843b25

Please sign in to comment.