Skip to content

Commit ec80db5

Browse files
authored
FIX #2645 Better Faux Pickup Support (#4068)
* FIX #2645 Better Faux Pickup Support Changes Made- Added logic to handle non-negative pickup values and support "faux pickups" like 1/3. Ensured notationPickup is called after setting the pickup value. Validated the pickup value before passing it to MeterActions.setPickup to prevent errors. Added input validation for pickup values in flow, ensuring only valid values are processed. * Updating rationalToFraction function to handle all the edge cases for better error handling * Forgot to commit the Syntax error fix * removed warning messgae * removed unnecesarry warning
1 parent eadd178 commit ec80db5

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

js/blocks/MeterBlocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ function setupMeterBlocks(activity) {
13191319
*/
13201320
flow(args, logo, turtle, blk) {
13211321
const arg0 = args[0];
1322-
if (args.length !== 1 || typeof args[0] !== "number") {
1322+
if (args.length !== 1 || typeof args[0] !== "number" || arg0 < 0) {
13231323
activity.errorMsg(NOINPUTERRORMSG, blk);
13241324
return;
13251325
}

js/js-export/export.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ class MusicBlocks {
353353

354354
set PICKUP(value) {
355355
const args = JSInterface.validateArgs("PICKUP", [value]);
356-
Singer.MeterActions.setPickup(args[0], this.turIndex);
356+
const validatedValue = Math.max(0, args[0]);
357+
Singer.MeterActions.setPickup(validatedValue, this.turIndex);
357358
}
358359

359360
get WHOLENOTESPLAYED() {

js/notation.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,6 @@ class Notation {
347347
this._notationStaging[turtle].push("pickup", beat);
348348
this._pickupPOW2[turtle] = true;
349349
} else {
350-
if (this.activity.logo.runningLilypond) {
351-
obj = rationalToFraction(factor);
352-
this.activity.errorMsg(
353-
_("Lilypond cannot process pickup of ") + obj[0] + "/" + obj[1]
354-
);
355-
}
356-
357350
obj = rationalToFraction(1 - factor);
358351
for (let i = 0; i < obj[0]; i++) {
359352
this.activity.logo.updateNotation(["R"], obj[1], turtle, false, "");

js/utils/utils.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,9 @@ readable-fractions/681534#681534
11431143
"3/5"
11441144
11451145
*/
1146+
if (d === 0 || isNaN(d) || !isFinite(d)) {
1147+
return [0, 1];
1148+
}
11461149

11471150
let invert;
11481151
if (d > 1) {
@@ -1154,17 +1157,25 @@ readable-fractions/681534#681534
11541157

11551158
let df = 1.0;
11561159
let top = 1;
1160+
let iterations = 0
1161+
const maxIterations = 10000;
11571162
let bot = 1;
11581163

1159-
while (Math.abs(df - d) > 0.00000001) {
1164+
while (Math.abs(df - d) > 0.00000001 && iterations < maxIterations) {
11601165
if (df < d) {
11611166
top += 1;
11621167
} else {
11631168
bot += 1;
1164-
top = Math.floor(d * bot);
1169+
top = Math.round(d * bot);
11651170
}
11661171

11671172
df = top / bot;
1173+
iterations++;
1174+
}
1175+
1176+
if (iterations === maxIterations) {
1177+
//console.warn("rationalToFraction: Reached iteration limit");
1178+
return [top, bot];
11681179
}
11691180

11701181
if (bot === 0 || top === 0) {

0 commit comments

Comments
 (0)