From 74b1353dbda5139b439bc5674f67271263cbb3cf Mon Sep 17 00:00:00 2001 From: Oluwatito Ebiwonjumi <31973148+ebiwonjumit@users.noreply.github.com> Date: Mon, 19 Aug 2024 17:02:52 -0500 Subject: [PATCH] Updated the playDuration function --- extensions/BeatBlox/index.js | 105 +++++------------------------------ 1 file changed, 15 insertions(+), 90 deletions(-) diff --git a/extensions/BeatBlox/index.js b/extensions/BeatBlox/index.js index 6c56267..c108044 100644 --- a/extensions/BeatBlox/index.js +++ b/extensions/BeatBlox/index.js @@ -285,102 +285,27 @@ return base + delta; } - function durationToBeats(duration, durationSpecial = ''){ + function durationToBeats(duration, durationSpecial = '') { let playDuration = availableNoteDurations[duration]; - switch (playDuration) { - case 1: - //Whole - playDuration = 4; - break; - case 2: - //Half - playDuration = 2; - break; - case 4: - //Quarter - playDuration = 1; - break; - case 8: - //Eighth - playDuration = 0.5; - break; - case 16: - //Sixteenth - playDuration = 0.25; - break; - case 32: - //Thirty-Secondth - playDuration = 0.125; - break; - case 64: - //Sixty-Fourth - playDuration = 0.0625; - break; - } - if (durationSpecial != '') { + + if (!durationSpecial) { + // For regular durations + return 4 / playDuration; + } else { + // For special durations playDuration = availableNoteDurations[durationSpecial + duration]; - switch (playDuration) { - case (2.0 / 3.0): - // "Dotted Whole" - playDuration = 6; - break; - case (4.0 / 7.0): - // "Dotted Dotted Whole" - playDuration = 7; - break; - case (4.0 / 3.0): - // "Dotted Half" - playDuration = 3; - break; - case (8.0 / 7.0): - // "Dotted Dotted Half" - playDuration = 3.5; - break; - case (8.0 / 3.0): - // "Dotted Quarter" - playDuration = 1.5; - break; - case (16.0 / 7.0): - // "Dotted Dotted Quarter" - playDuration = 1.75; - break; - case (16.0 / 3.0): - // "Dotted Eighth" - playDuration = 0.75; - break; - case (32.0 / 7.0): - // "Dotted Dotted Eighth" - playDuration = 0.875; - break; - case (32.0 / 3.0): - // "Dotted Sixteenth" - playDuration = 0.375; - break; - case (64.0 / 7.0): - // "Dotted Dotted Sixteenth" - playDuration = 0.4375; - break; - case (64.0 / 3.0): - // "Dotted Thirty Secondth" - playDuration = 0.1875; - break; - case (128.0 / 7.0): - // "Dotted Dotted Thirty Secondth" - playDuration = 0.21875; - break; - case (128.0 / 3.0): - // "Dotted SixtyFourth" - playDuration = 0.09375; - break; - case (256.0 / 7.0): - // "Dotted Dotted SixtyFourth" - playDuration = 0.109375; - break; + + if (playDuration === 2/3 || playDuration === 4/7) { + // Dotted Whole and Dotted Dotted Whole + return 4 / (1 - (1 / playDuration)); + } else { + // All other special durations + return 4 / (playDuration * 2); } } - return playDuration; } + async function setTrackEffect(trackName, effectName, level) { const effectType = availableEffects[effectName]; if (!appliedEffects.includes(trackName + effectName)) {