Metronome fix

do not call now() multiple times to avoid time difference between calls.
This commit is contained in:
Bruno Herbelin
2022-03-13 23:13:32 +01:00
parent 0b12c5a169
commit e0676c66a0
2 changed files with 26 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
/*
/*
* This file is part of vimix - video live mixer
*
* **Copyright** (C) 2019-2022 Bruno Herbelin <bruno.herbelin@gmail.com>
@@ -403,7 +403,6 @@ bool Control::init()
void Control::update()
{
// read joystick buttons
int num_buttons = 0;
const unsigned char *state_buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &num_buttons );
@@ -438,6 +437,21 @@ void Control::update()
}
}
// draft : react to metronome
// int p = (int) Metronome::manager().phase();
// static bool bip = false;
// static int t = 2;
// if (!bip) {
// if (p + 1 == t){
// g_print("bip");
// bip = true;
// }
// }
// else {
// if (p + 1 != t){
// bip = false;
// }
// }
}
void Control::listen()
@@ -943,7 +957,7 @@ std::string Control::inputLabel(uint id)
}
else if ( id >= INPUT_CUSTOM_FIRST && id <= INPUT_CUSTOM_LAST )
{
label = std::string( "Custom ") + std::to_string(id - INPUT_CUSTOM_FIRST);
}
return label;

View File

@@ -59,10 +59,10 @@ namespace ableton
return sessionState.beatAtTime(now(), mQuantum);
}
std::chrono::microseconds timeNextBeat() const
std::chrono::microseconds timeNextBeat(std::chrono::microseconds now) const
{
auto sessionState = mLink.captureAppSessionState();
double beat = ceil(sessionState.beatAtTime(now(), mQuantum));
double beat = ceil(sessionState.beatAtTime(now, mQuantum));
return sessionState.timeAtBeat(beat, mQuantum);
}
@@ -72,11 +72,11 @@ namespace ableton
return sessionState.phaseAtTime(now(), mQuantum);
}
std::chrono::microseconds timeNextPhase() const
std::chrono::microseconds timeNextPhase(std::chrono::microseconds now) const
{
auto sessionState = mLink.captureAppSessionState();
double phase = ceil(sessionState.phaseAtTime(now(), mQuantum));
double beat = ceil(sessionState.beatAtTime(now(), mQuantum));
double phase = ceil(sessionState.phaseAtTime(now, mQuantum));
double beat = ceil(sessionState.beatAtTime(now, mQuantum));
return sessionState.timeAtBeat(beat + (mQuantum-phase), mQuantum);
}
@@ -223,12 +223,14 @@ void Metronome::restart()
std::chrono::microseconds Metronome::timeToBeat()
{
return engine_.timeNextBeat() - engine_.now();
std::chrono::microseconds now = engine_.now();
return engine_.timeNextBeat( now ) - now;
}
std::chrono::microseconds Metronome::timeToPhase()
{
return engine_.timeNextPhase() - engine_.now();
std::chrono::microseconds now = engine_.now();
return engine_.timeNextPhase( now ) - now;
}
void delay(std::function<void()> f, std::chrono::microseconds us)