Skip to content

Commit

Permalink
fix: freeze when opening new score while running
Browse files Browse the repository at this point in the history
  • Loading branch information
philippekocher committed Nov 6, 2023
1 parent 31cb0c0 commit a7ff1fe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Source/Scheduler/Polytempo_Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ enum Polytempo_EventType

eventType_Tick,
eventType_Beat,
eventType_Marker, // 4
eventType_Marker,

eventType_Start,
eventType_Stop,
eventType_Pause,

eventType_GotoMarker,
eventType_GotoTime, // 9
eventType_GotoTime,
eventType_TempoFactor,

eventType_LoadImage,
eventType_AddRegion,
eventType_AddSection,

eventType_Image, // 14
eventType_Image,
eventType_AppendImage,
eventType_Text,
eventType_Progressbar,
Expand Down
21 changes: 15 additions & 6 deletions Source/Scheduler/Polytempo_ScoreScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,27 @@ void Polytempo_ScoreScheduler::executeInit()
#ifdef USING_SCORE
void Polytempo_ScoreScheduler::setScore(Polytempo_Score* theScore)
{
// set new score
newScore = theScore;

// reset / delete everything that belongs to an old score
if(engine->isRunning()) {
Polytempo_EventScheduler::getInstance()->deletePendingEvents();
engine->stop();
engine->kill();
}
Polytempo_EventScheduler::getInstance()->deletePendingEvents();
engine->kill();
}
else swapScores();
}

void Polytempo_ScoreScheduler::swapScores()
{
if (score == newScore) return;

Polytempo_EventScheduler::getInstance()->scheduleEvent(Polytempo_Event::makeEvent(eventType_DeleteAll));
Polytempo_EventScheduler::getInstance()->scheduleEvent(Polytempo_Event::makeEvent(eventType_TempoFactor, 1.0));

// set new score
score = theScore;
engine->setScore(theScore);
score = newScore;
engine->setScore(score);

executeInit();

Expand Down
2 changes: 2 additions & 0 deletions Source/Scheduler/Polytempo_ScoreScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Polytempo_ScoreScheduler : public Polytempo_EventObserver
--------------------------------------- */
#ifdef USING_SCORE
void setScore(Polytempo_Score* score_);
void swapScores();
#endif
int getScoreTime();

Expand All @@ -55,5 +56,6 @@ class Polytempo_ScoreScheduler : public Polytempo_EventObserver

#ifdef USING_SCORE
Polytempo_Score* score = nullptr;
Polytempo_Score* newScore = nullptr;
#endif
};
2 changes: 2 additions & 0 deletions Source/Scheduler/Polytempo_ScoreSchedulerEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ void Polytempo_NetworkEngine::run()
scoreScheduler->gotoTime(lastDownbeat);
shouldReturnToLastDownbeat = false;
}

if(killed) MessageManager::callAsync([this]() { scoreScheduler->swapScores(); });

Polytempo_NetworkApplication* const app = dynamic_cast<Polytempo_NetworkApplication*>(JUCEApplication::getInstance());
if (app->quitApplication) app->applicationShouldQuit();
Expand Down

0 comments on commit a7ff1fe

Please sign in to comment.