Skip to content

Commit

Permalink
[skip ci] another corner case
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Feb 24, 2023
1 parent c5aa567 commit b1c96a6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
7 changes: 6 additions & 1 deletion Breeder/BR_EnvelopeUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2961,10 +2961,15 @@ void CalculateSplitMiddlePoints (double* time1, double* time2, double* bpm1, dou
WritePtr(bpm2, val2);
}

void InitTempoMap ()
bool InitTempoMap ()
{
if (!CountTempoTimeSigMarkers(NULL))
{
SetTempoTimeSigMarker(NULL, -1, 0, -1, -1, GetProjectSettingsTempo(NULL, NULL), 0, 0, false);
return true;
}
else
return false;
}

void RemoveTempoMap ()
Expand Down
2 changes: 1 addition & 1 deletion Breeder/BR_EnvelopeUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ double CalculateMeasureAtPosition (double startBpm, double endBpm, double timeLe
double CalculatePositionAtMeasure (double startBpm, double endBpm, double timeLen, double targetMeasure);
void CalculateMiddlePoint (double* middleTime, double* middleBpm, double measure, double startTime, double endTime, double startBpm, double endBpm);
void CalculateSplitMiddlePoints (double* time1, double* time2, double* bpm1, double* bpm2, double splitRatio, double measure, double startTime, double middleTime, double endTime, double startBpm, double middleBpm, double endBpm);
void InitTempoMap (); // will make sure there's at least one point in tempo map (we can't manipulate tempo map's chunk (i.e. insert new points) if there isn't at least one point in tempo map)
bool InitTempoMap (); // will make sure there's at least one point in tempo map (we can't manipulate tempo map's chunk (i.e. insert new points) if there isn't at least one point in tempo map)
void RemoveTempoMap ();
void UnselectAllTempoMarkers ();
void UpdateTempoTimeline (); // UpdateTimeline() isn't enough after changing tempo points through chunk - call this instead
28 changes: 18 additions & 10 deletions Breeder/BR_Tempo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,21 @@ static HCURSOR MoveGridCursor (COMMAND_T* ct, int window)
*/
static bool EnsureTempoSet(int id)
{
char debugStr[256];
snprintf(debugStr, sizeof(debugStr), "EnsureTempoSet: id: %d\n", id);
OutputDebugString(debugStr);

double timeposOut, beat, bpm;
int measure, num, den;
bool linear;
GetTempoTimeSigMarker(NULL, id, &timeposOut, &measure, &beat, &bpm, &num, &den, &linear);
//TODO is there any way to tell whether bpm has already been explicitly set by this point?
SetTempoTimeSigMarker(NULL, id, timeposOut, measure, beat, bpm, num, den, linear);
return true;
if(GetTempoTimeSigMarker(NULL, id, &timeposOut, &measure, &beat, &bpm, &num, &den, &linear))
{
SetTempoTimeSigMarker(NULL, id, timeposOut, measure, beat, bpm, num, den, linear);
//TODO is there any way to tell whether bpm has already been explicitly set by this point?
return true;
}
else
return false;
}

static void MoveGridToMouse (COMMAND_T* ct)
Expand All @@ -367,16 +375,16 @@ static void MoveGridToMouse (COMMAND_T* ct)
s_lastPosition = 0;

// Make sure tempo map already has at least one point created (for some reason it won't work if creating it directly in chunk)
if (cmd != MOVE_CLOSEST_TEMPO_MOUSE)
{
InitTempoMap();
g_didTempoMapInit = true;
}
g_didTempoMapInit = InitTempoMap();

g_moveGridTempoMap = new (nothrow) BR_Envelope(GetTempoEnv());

// Make sure previous point is editable via g_moveGridTempoMap.
if (g_moveGridTempoMap && cmd != MOVE_CLOSEST_TEMPO_MOUSE)
// FIXME in MOVE_CLOSEST_TEMPO_MOUSE, we need the prev point relative to
// the closest point to be matched, not relative to the mouse.
// eg., 4/4 12bpm <cursor>
// ^--this needs tempo
if (g_moveGridTempoMap && g_moveGridTempoMap->CountPoints())
{
// ensure previous point's bpm is explicitly set, otherwise changes won't register in BR_Envelope.
if(EnsureTempoSet(g_moveGridTempoMap->FindPrevious(PositionAtMouseCursor(true))))
Expand Down

0 comments on commit b1c96a6

Please sign in to comment.