Fix measure number values and positions

(and remove 2 comments I forgot to remove last time)
This commit is contained in:
Keoiki
2025-09-27 03:57:37 +08:00
committed by Hundrec
parent 533c8f7ede
commit eb40d3bda5
2 changed files with 61 additions and 15 deletions
+52 -5
View File
@@ -469,7 +469,7 @@ class Conductor
this.currentStepTime = FlxMath.roundDecimal((currentTimeChange.beatTime * Constants.STEPS_PER_BEAT)
+ (this.songPosition - currentTimeChange.timeStamp) / stepLengthMs, 6);
this.currentBeatTime = currentStepTime / Constants.STEPS_PER_BEAT;
this.currentMeasureTime = getMeasureTime(songPos);
this.currentMeasureTime = getTimeInMeasures(songPos);
this.currentStep = Math.floor(currentStepTime);
this.currentBeat = Math.floor(currentBeatTime);
this.currentMeasure = Math.floor(currentMeasureTime);
@@ -594,11 +594,11 @@ class Conductor
}
/**
* Calculates the measure time for a given time in milliseconds.
* Given a time in milliseconds, return a time in measures.
* @param ms The time in milliseconds.
* @return The time in measures.
*/
public function getMeasureTime(ms:Float):Float
public function getTimeInMeasures(ms:Float):Float
{
if (timeChanges.length == 0)
{
@@ -639,6 +639,53 @@ class Conductor
}
}
/**
* Given a time in measures and fractional measures, return a time in milliseconds.
* @param measureTime The time in measures.
* @return The time in milliseconds.
*/
public function getMeasureTimeInMs(measureTime:Float):Float
{
if (timeChanges.length == 0)
{
// Assume a constant BPM equal to the forced value.
return measureTime * stepLengthMs * stepsPerMeasure;
}
else
{
var resultMs:Float = 0;
var lastTimeChange:SongTimeChange = timeChanges[0];
var i:Int = -1;
for (timeChange in timeChanges)
{
var currentTimeChangeMeasureTime:Float = getTimeInMeasures(timeChange.timeStamp);
if (measureTime >= currentTimeChangeMeasureTime)
{
// We do NOT want to add the current time change's MEASURE LENGTH to the result, same for if we're inside the song's last time change.
if (measureTime < currentTimeChangeMeasureTime || i == timeChanges.length - 1)
{
// However, we still want this for the ending calculation.
lastTimeChange = timeChange;
break;
}
var currentStepLengthMs:Float = (((Constants.SECS_PER_MIN / lastTimeChange.bpm) * Constants.MS_PER_SEC) * (4 / lastTimeChange.timeSignatureDen)) / Constants.STEPS_PER_BEAT;
var currentStepsPerMeasure:Int = lastTimeChange.timeSignatureNum * Constants.STEPS_PER_BEAT;
resultMs += (currentTimeChangeMeasureTime - getTimeInMeasures(lastTimeChange.timeStamp)) * currentStepLengthMs * currentStepsPerMeasure;
lastTimeChange = timeChange;
}
i++;
}
var remainingStepLengthMs:Float = (((Constants.SECS_PER_MIN / lastTimeChange.bpm) * Constants.MS_PER_SEC) * (4 / lastTimeChange.timeSignatureDen)) / Constants.STEPS_PER_BEAT;
var remainingStepsPerMeasure:Int = lastTimeChange.timeSignatureNum * Constants.STEPS_PER_BEAT;
var remainingFractionalMeasure:Float = (measureTime - getTimeInMeasures(lastTimeChange.timeStamp)) * remainingStepLengthMs * remainingStepsPerMeasure;
resultMs += remainingFractionalMeasure;
return resultMs;
}
}
/**
* Given a time in milliseconds, return a time in steps.
* @param ms The time in milliseconds.
@@ -678,7 +725,7 @@ class Conductor
var resultFractionalStep:Float = (ms - lastTimeChange.timeStamp) / lastStepLengthMs;
resultStep += resultFractionalStep;
return resultStep; // FIX THIS SHIT
return resultStep;
}
}
@@ -720,7 +767,7 @@ class Conductor
var lastStepLengthMs:Float = (((Constants.SECS_PER_MIN / lastTimeChange.bpm) * Constants.MS_PER_SEC) * (4 / lastTimeChange.timeSignatureDen)) / Constants.STEPS_PER_BEAT;
resultMs += (stepTime - lastTimeChange.beatTime * Constants.STEPS_PER_BEAT) * lastStepLengthMs;
return resultMs; // FIX THIS SHIT
return resultMs;
}
}
@@ -49,33 +49,32 @@ class ChartEditorMeasureTicks extends FlxTypedSpriteGroup<FlxSprite>
}
/**
* At time of writing, we only have to manipulate one measure number because we can only see one measure at a time.
* Update all 5 measure numbers, since that's the most we can really see at a time, even if barely.
* Please excuse the horror you're about to witness.
*/
function updateMeasureNumber()
{
var viewTopPosition = 0 - this.y;
var viewHeight = FlxG.height - ChartEditorState.MENU_BAR_HEIGHT - ChartEditorState.PLAYBAR_HEIGHT;
var viewBottomPosition = viewTopPosition + viewHeight;
var currentPixelScrollPositionInMs = Conductor.instance?.getStepTimeInMs((this.chartEditorState?.scrollPositionInPixels + 1) / ChartEditorState.GRID_SIZE);
var measureNumberInViewport = Math.floor(Conductor.instance?.getTimeInMeasures(currentPixelScrollPositionInMs));
for (i in 0...measureNumbers.length)
{
var measureNumber:FlxText = measureNumbers[i];
if (measureNumber == null) continue;
var measureNumberInViewport = Math.floor(viewTopPosition / ChartEditorState.GRID_SIZE / Conductor.instance.stepsPerMeasure) + 1 + i;
var measureNumberPosition = measureNumberInViewport * ChartEditorState.GRID_SIZE * Conductor.instance.stepsPerMeasure;
var measureNumberPosition = Math.floor(Conductor.instance?.getTimeInSteps(Conductor.instance?.getMeasureTimeInMs(measureNumberInViewport +
i)) * ChartEditorState.GRID_SIZE);
measureNumber.y = measureNumberPosition + this.y;
// Show the measure number only if it isn't beneath the end of the note grid.
// Using measureNumber + 1 because the cut-off bar at the bottom is technically a bar, but it looks bad if a measure number shows up there.
if ((measureNumberInViewport + 1) < chartEditorState.songLengthInSteps / Conductor.instance.stepsPerMeasure)
measureNumber.text = '${measureNumberInViewport + 1}';
var fixedMeasureNumberValue = measureNumberInViewport + i + 1;
if (fixedMeasureNumberValue < Math.ceil(Conductor.instance?.getTimeInMeasures(chartEditorState.songLengthInMs)))
measureNumber.text = '${fixedMeasureNumberValue}';
else
measureNumber.text = '';
}
// trace(measureNumber.text + ' at ' + measureNumber.y);
}
public function setHeight(songLengthInPixels:Float):Void