diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index 1e0a706e1..ee963ab48 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -1308,8 +1308,10 @@ void CarlaEngine::transportPlay() noexcept void CarlaEngine::transportPause() noexcept { - pData->timeInfo.playing = false; - pData->time.setNeedsReset(); + if (pData->timeInfo.playing) + pData->time.pause(); + else + pData->time.setNeedsReset(); } void CarlaEngine::transportBPM(const double bpm) noexcept diff --git a/source/backend/engine/CarlaEngineData.cpp b/source/backend/engine/CarlaEngineData.cpp index 45f0b8845..fd14a3dda 100644 --- a/source/backend/engine/CarlaEngineData.cpp +++ b/source/backend/engine/CarlaEngineData.cpp @@ -334,6 +334,8 @@ bool EngineTimeInfo::operator==(const EngineTimeInfo& timeInfo) const noexcept return false; if (! bbt.valid) return true; + if (carla_isNotEqual(timeInfo.bbt.beatsPerBar, bbt.beatsPerBar)) + return false; if (carla_isNotEqual(timeInfo.bbt.beatsPerMinute, bbt.beatsPerMinute)) return false; return true; diff --git a/source/backend/engine/CarlaEngineInternal.cpp b/source/backend/engine/CarlaEngineInternal.cpp index 2a27b54a9..0fe6e33dd 100644 --- a/source/backend/engine/CarlaEngineInternal.cpp +++ b/source/backend/engine/CarlaEngineInternal.cpp @@ -155,6 +155,13 @@ void EngineInternalTime::setNeedsReset() noexcept needsReset = true; } +void EngineInternalTime::pause() noexcept +{ + timeInfo.playing = false; + nextFrame = timeInfo.frame; + needsReset = true; +} + void EngineInternalTime::relocate(const uint64_t frame) noexcept { timeInfo.frame = frame; @@ -187,9 +194,8 @@ void EngineInternalTime::fillEngineTimeInfo(const uint32_t newFrames) noexcept { if (hylia.timeInfo.beat >= 0.0) { - const double beat = hylia.timeInfo.beat; - abs_beat = std::floor(beat); - abs_tick = beat * kTicksPerBeat; + abs_beat = hylia.timeInfo.beat; + abs_tick = abs_beat * kTicksPerBeat; } else { @@ -202,20 +208,21 @@ void EngineInternalTime::fillEngineTimeInfo(const uint32_t newFrames) noexcept #endif { const double min = static_cast(timeInfo.frame) / (sampleRate * 60.0); - abs_tick = min * beatsPerMinute * kTicksPerBeat; - abs_beat = abs_tick / kTicksPerBeat; + abs_beat = min * beatsPerMinute; + abs_tick = abs_beat * kTicksPerBeat; needsReset = false; } - timeInfo.bbt.bar = (int32_t)(std::floor(abs_beat / beatsPerBar) + 0.5); - timeInfo.bbt.beat = (int32_t)(abs_beat - (timeInfo.bbt.bar * beatsPerBar) + 1.5); - timeInfo.bbt.barStartTick = timeInfo.bbt.bar * beatsPerBar * kTicksPerBeat; - ++timeInfo.bbt.bar; + const double bar = std::floor(abs_beat / beatsPerBar); + const double beat = std::floor(std::fmod(abs_beat, beatsPerBar)); + + timeInfo.bbt.bar = static_cast(bar) + 1; + timeInfo.bbt.beat = static_cast(beat) + 1; + timeInfo.bbt.barStartTick = ((bar * beatsPerBar) + beat) * kTicksPerBeat; - //ticktmp = abs_tick - timeInfo.bbt.barStartTick; - ticktmp = abs_tick - (abs_beat * timeInfo.bbt.barStartTick); + ticktmp = abs_tick - timeInfo.bbt.barStartTick; } - else + else if (timeInfo.playing) { ticktmp = tick + (newFrames * kTicksPerBeat * beatsPerMinute / (sampleRate * 60)); @@ -225,16 +232,20 @@ void EngineInternalTime::fillEngineTimeInfo(const uint32_t newFrames) noexcept if (++timeInfo.bbt.beat > beatsPerBar) { + ++timeInfo.bbt.bar; timeInfo.bbt.beat = 1; timeInfo.bbt.barStartTick += beatsPerBar * kTicksPerBeat; - ++timeInfo.bbt.bar; } } } + else + { + ticktmp = tick; + } timeInfo.bbt.beatsPerBar = static_cast(beatsPerBar); timeInfo.bbt.beatsPerMinute = beatsPerMinute; - timeInfo.bbt.tick = (int32_t)(ticktmp + 0.5); + timeInfo.bbt.tick = static_cast(ticktmp); tick = ticktmp; if (transportMode == ENGINE_TRANSPORT_MODE_INTERNAL && timeInfo.playing) @@ -261,9 +272,8 @@ void EngineInternalTime::fillJackTimeInfo(jack_position_t* const pos, const uint { if (hylia.timeInfo.beat >= 0.0) { - const double beat = hylia.timeInfo.beat; - abs_beat = std::floor(beat); - abs_tick = beat * kTicksPerBeat; + abs_beat = hylia.timeInfo.beat; + abs_tick = abs_beat * kTicksPerBeat; } else { @@ -276,20 +286,20 @@ void EngineInternalTime::fillJackTimeInfo(jack_position_t* const pos, const uint #endif { const double min = static_cast(pos->frame) / (sampleRate * 60.0); - abs_tick = min * beatsPerMinute * kTicksPerBeat; - abs_beat = abs_tick / kTicksPerBeat; - needsReset = false; + abs_beat = min * beatsPerMinute; + abs_tick = abs_beat * kTicksPerBeat; } - pos->bar = (int32_t)(std::floor(abs_beat / beatsPerBar) + 0.5); - pos->beat = (int32_t)(abs_beat - (pos->bar * beatsPerBar) + 1.5); - pos->bar_start_tick = pos->bar * beatsPerBar * kTicksPerBeat; - ++pos->bar; + const double bar = std::floor(abs_beat / beatsPerBar); + const double beat = std::floor(std::fmod(abs_beat, beatsPerBar)); + + pos->bar = static_cast(bar) + 1; + pos->beat = static_cast(beat) + 1; + pos->bar_start_tick = ((bar * beatsPerBar) + beat) * kTicksPerBeat; - //ticktmp = abs_tick - pos->bar_start_tick; - ticktmp = abs_tick - (abs_beat * pos->ticks_per_beat); + ticktmp = abs_tick - pos->bar_start_tick; } - else + else if (timeInfo.playing) { ticktmp = tick + (newFrames * kTicksPerBeat * beatsPerMinute / (sampleRate * 60.0)); @@ -299,16 +309,20 @@ void EngineInternalTime::fillJackTimeInfo(jack_position_t* const pos, const uint if (++pos->beat > beatsPerBar) { + ++pos->bar; pos->beat = 1; pos->bar_start_tick += beatsPerBar * kTicksPerBeat; - ++pos->bar; } } } + else + { + ticktmp = tick; + } pos->beats_per_bar = static_cast(beatsPerBar); pos->beats_per_minute = beatsPerMinute; - pos->tick = (int32_t)(ticktmp + 0.5); + pos->tick = static_cast(ticktmp); tick = ticktmp; } diff --git a/source/backend/engine/CarlaEngineInternal.hpp b/source/backend/engine/CarlaEngineInternal.hpp index 9cc95ff2f..e821b9905 100644 --- a/source/backend/engine/CarlaEngineInternal.hpp +++ b/source/backend/engine/CarlaEngineInternal.hpp @@ -124,6 +124,7 @@ public: void enableLink(const bool enable); void setBPM(const double bpm); void setNeedsReset() noexcept; + void pause() noexcept; void relocate(const uint64_t frame) noexcept; private: diff --git a/source/backend/plugin/CarlaPluginLV2.cpp b/source/backend/plugin/CarlaPluginLV2.cpp index 23cb2534c..d5e482c12 100644 --- a/source/backend/plugin/CarlaPluginLV2.cpp +++ b/source/backend/plugin/CarlaPluginLV2.cpp @@ -2846,6 +2846,9 @@ public: bool doPostRt; int32_t rindex; + const double barBeat = static_cast(timeInfo.bbt.beat - 1) + + (static_cast(timeInfo.bbt.tick) / timeInfo.bbt.ticksPerBeat); + // update input ports for (uint32_t k=0; k < pData->param.count; ++k) { @@ -2894,8 +2897,7 @@ public: if (timeInfo.bbt.valid && (fLastTimeInfo.bbt.tick != timeInfo.bbt.tick || fLastTimeInfo.bbt.beat != timeInfo.bbt.beat)) { - fParamBuffers[k] = static_cast(static_cast(timeInfo.bbt.beat) - 1.0 - + (static_cast(timeInfo.bbt.tick) / timeInfo.bbt.ticksPerBeat)); + fParamBuffers[k] = static_cast(barBeat); doPostRt = true; } break; @@ -2967,7 +2969,7 @@ public: lv2_atom_forge_long(&fAtomForge, timeInfo.bbt.bar - 1); lv2_atom_forge_key(&fAtomForge, kUridTimeBarBeat); - lv2_atom_forge_float(&fAtomForge, static_cast(static_cast(timeInfo.bbt.beat) - 1.0 + (static_cast(timeInfo.bbt.tick) / timeInfo.bbt.ticksPerBeat))); + lv2_atom_forge_float(&fAtomForge, static_cast(barBeat)); lv2_atom_forge_key(&fAtomForge, kUridTimeBeat); lv2_atom_forge_double(&fAtomForge, timeInfo.bbt.beat - 1);