Skip to content

Commit

Permalink
engine: fix beat-based Show playback
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Nov 30, 2023
1 parent 435f662 commit 8633690
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
25 changes: 18 additions & 7 deletions engine/src/showrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,18 @@ void ShowRunner::write(MasterTimer *timer)
// check synchronization to beats (if show is beat-based)
if (m_show->tempoType() == Function::Beats)
{
if (timer->isBeat() && beatSynced == false)
beatSynced = true;
//qDebug() << Q_FUNC_INFO << "isBeat:" << timer->isBeat() << ", elapsed beats:" << m_elapsedBeats;

if (timer->isBeat())
{
if (beatSynced == false)
{
beatSynced = true;
qDebug() << "Beat synced";
}
else
m_elapsedBeats += 1000;
}

if (beatSynced == false)
return;
Expand Down Expand Up @@ -212,12 +222,12 @@ void ShowRunner::write(MasterTimer *timer)
Function *f = m_doc->function(sf->functionID());

// this should happen only when a Show is not started from 0
if (m_elapsedTime > funcStartTime)
if (m_elapsedBeats > funcStartTime)
{
functionTimeOffset = m_elapsedTime - funcStartTime;
funcStartTime = m_elapsedTime;
functionTimeOffset = m_elapsedBeats - funcStartTime;
funcStartTime = m_elapsedBeats;
}
if (m_elapsedTime >= funcStartTime)
if (m_elapsedBeats >= funcStartTime)
{
foreach (Track *track, m_show->tracks())
{
Expand Down Expand Up @@ -246,9 +256,10 @@ void ShowRunner::write(MasterTimer *timer)
{
Function *func = m_runningQueue.at(i).first;
quint32 stopTime = m_runningQueue.at(i).second;
quint32 currTime = func->tempoType() == Function::Time ? m_elapsedTime : m_elapsedBeats;

// if we passed the function stop time
if (m_elapsedTime >= stopTime)
if (currTime >= stopTime)
{
// stop the function
func->stop(functionParent());
Expand Down
6 changes: 5 additions & 1 deletion qmlui/js/TimeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ function msToString(ms)
finalTime += ((m < 10) ? "0" + m : m) + ":";
finalTime += ((s < 10) ? "0" + s : s);
if (ms) {
finalTime += "." + ((ms < 10) ? "0" + parseInt(ms) : parseInt(ms));
finalTime += ".";
if (ms < 10) finalTime += "00";
else if (ms < 100) finalTime += "0";

finalTime += parseInt(ms);
}
return finalTime;
}
Expand Down
10 changes: 10 additions & 0 deletions qmlui/showmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ void ShowManager::setTimeDivision(Show::TimeDivision division)
if (division == m_currentShow->timeDivisionType())
return;

if (division == Show::Time)
{
setTimeScale(5.0);
m_currentShow->setTempoType(Function::Time);
}
else
{
setTimeScale(1.0);
m_currentShow->setTempoType(Function::Beats);
}
m_currentShow->setTimeDivisionType(division);
emit timeDivisionChanged(division);

Expand Down

0 comments on commit 8633690

Please sign in to comment.