mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
Metronome fix
do not call now() multiple times to avoid time difference between calls.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user