Skip to content

Commit

Permalink
Updated the playDuration function
Browse files Browse the repository at this point in the history
  • Loading branch information
ebiwonjumit committed Aug 19, 2024
1 parent 805d63c commit 74b1353
Showing 1 changed file with 15 additions and 90 deletions.
105 changes: 15 additions & 90 deletions extensions/BeatBlox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 74b1353

Please sign in to comment.