Skip to content

Commit 6fa4eef

Browse files
authored
added the block highlight minimum time threshold (#5726)
* added the highlight minimum time threshold * ran prettier on turtle_singer.js and changed the minimum threshold to 400ms * formatting commit
1 parent d7ef119 commit 6fa4eef

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

js/logo.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
2727
Queue, Logo, LogoDependencies, DEFAULTVOLUME, PREVIEWVOLUME, DEFAULTDELAY,
2828
OSCVOLUMEADJUSTMENT, TONEBPM, TARGETBPM, TURTLESTEP, NOTEDIV,
29+
MIN_HIGHLIGHT_DURATION_MS,
2930
NOMICERRORMSG, NANERRORMSG, NOSTRINGERRORMSG, NOBOXERRORMSG,
3031
NOACTIONERRORMSG, NOINPUTERRORMSG, NOSQRTERRORMSG,
3132
ZERODIVIDEERRORMSG, EMPTYHEAPERRORMSG, INVALIDPITCH, POSNUMBER,
@@ -1529,6 +1530,10 @@ class Logo {
15291530
// Highlight the current block
15301531
logo.activity.blocks.highlight(blk, false);
15311532
logo._currentlyHighlightedBlock = blk;
1533+
// Force stage update so highlight is visible when blocks were shown during execution
1534+
if (logo.activity.stage) {
1535+
logo.activity.stage.update();
1536+
}
15321537
}
15331538
}
15341539

@@ -1670,15 +1675,22 @@ class Logo {
16701675
logo._unhighlightStepQueue[turtle] = blk;
16711676
} else {
16721677
if (!tur.singer.suppressOutput && tur.singer.justCounting.length === 0) {
1678+
const unhighlightDelay = Math.max(
1679+
logo.turtleDelay + tur.waitTime,
1680+
MIN_HIGHLIGHT_DURATION_MS
1681+
);
16731682
setTimeout(() => {
16741683
if (logo.activity.blocks.visible) {
16751684
logo.activity.blocks.unhighlight(blk);
16761685
// Clear the currently highlighted block if it was this one
16771686
if (logo._currentlyHighlightedBlock === blk) {
16781687
logo._currentlyHighlightedBlock = null;
16791688
}
1689+
if (logo.activity.stage) {
1690+
logo.activity.stage.update();
1691+
}
16801692
}
1681-
}, logo.turtleDelay + tur.waitTime);
1693+
}, unhighlightDelay);
16821694
}
16831695
}
16841696
}
@@ -1703,6 +1715,10 @@ class Logo {
17031715
tur.unhighlightQueue.push(logo.deps.utils.last(tur.parentFlowQueue));
17041716
} else if (tur.unhighlightQueue.length > 0) {
17051717
// The child flow is finally complete, so unhighlight.
1718+
const unhighlightDelay = Math.max(
1719+
logo.turtleDelay,
1720+
MIN_HIGHLIGHT_DURATION_MS
1721+
);
17061722
setTimeout(() => {
17071723
if (logo.activity.blocks.visible) {
17081724
const unhighlightBlock = tur.unhighlightQueue.pop();
@@ -1711,10 +1727,13 @@ class Logo {
17111727
if (logo._currentlyHighlightedBlock === unhighlightBlock) {
17121728
logo._currentlyHighlightedBlock = null;
17131729
}
1730+
if (logo.activity.stage) {
1731+
logo.activity.stage.update();
1732+
}
17141733
} else {
17151734
tur.unhighlightQueue.pop();
17161735
}
1717-
}, logo.turtleDelay);
1736+
}, unhighlightDelay);
17181737
}
17191738
}
17201739
}

js/logoconstants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
exported
88
DEFAULTVOLUME, PREVIEWVOLUME, DEFAULTDELAY,
99
OSCVOLUMEADJUSTMENT, TONEBPM, TARGETBPM, TURTLESTEP, NOTEDIV,
10+
MIN_HIGHLIGHT_DURATION_MS,
1011
NOMICERRORMSG, NANERRORMSG, NOSTRINGERRORMSG, NOBOXERRORMSG,
1112
NOACTIONERRORMSG, NOINPUTERRORMSG, NOSQRTERRORMSG,
1213
ZERODIVIDEERRORMSG, EMPTYHEAPERRORMSG, INVALIDPITCH, POSNUMBER,
@@ -25,6 +26,8 @@ const TONEBPM = 240; // seems to be the default
2526
const TARGETBPM = 90; // what we'd like to use for beats per minute
2627
const TURTLESTEP = -1; // run in step-by-step mode
2728
const NOTEDIV = 8; // number of steps to divide turtle graphics
29+
/** Minimum time (ms) to keep a block highlighted during execution so users can see which block is active. */
30+
const MIN_HIGHLIGHT_DURATION_MS = 400;
2831

2932
// These error messages don't need translation since they are
3033
// converted into artwork w/o text.
@@ -59,6 +62,7 @@ const exportsObj = {
5962
TARGETBPM,
6063
TURTLESTEP,
6164
NOTEDIV,
65+
MIN_HIGHLIGHT_DURATION_MS,
6266
NOMICERRORMSG,
6367
NANERRORMSG,
6468
NOSTRINGERRORMSG,

js/turtle-singer.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/*
1919
global
2020
21-
DEFAULTVOLUME, TARGETBPM, TONEBPM, frequencyToPitch, last,
21+
DEFAULTVOLUME, TARGETBPM, TONEBPM, MIN_HIGHLIGHT_DURATION_MS, frequencyToPitch, last,
2222
pitchToFrequency, getNote, isCustomTemperament, getStepSizeUp,
2323
getStepSizeDown, numberToPitch, pitchToNumber, rationalSum,
2424
noteIsSolfege, getSolfege, SOLFEGENAMES1, SOLFEGECONVERSIONTABLE,
@@ -2479,12 +2479,16 @@ class Singer {
24792479
// After the note plays, clear the embedded graphics and notes queue.
24802480
tur.singer.embeddedGraphics[blk] = [];
24812481

2482-
// Ensure note value block unhighlights after note plays.
2482+
// Ensure note value block unhighlights after note plays (minimum duration so highlight is visible).
2483+
const highlightDurationMs = Math.max(beatValue * 1000, MIN_HIGHLIGHT_DURATION_MS);
24832484
setTimeout(() => {
24842485
if (activity.blocks.visible && blk in activity.blocks.blockList) {
24852486
activity.blocks.unhighlight(blk);
2487+
if (activity.stage) {
2488+
activity.stage.update();
2489+
}
24862490
}
2487-
}, beatValue * 1000);
2491+
}, highlightDurationMs);
24882492
};
24892493

24902494
if (last(tur.singer.inNoteBlock) !== null || noteInNote) {

0 commit comments

Comments
 (0)