From b2c542bb8f7b4ff80f71fb0f50b5bd12d04c3a20 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 5 Jul 2015 01:06:27 +0200 Subject: [PATCH] carla-lv2: Fix wrong ticksPerBeat value if host doesn't support it --- source/backend/plugin/CarlaPluginLV2.cpp | 6 ++--- source/plugin/carla-lv2.cpp | 33 +++++++++++------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/source/backend/plugin/CarlaPluginLV2.cpp b/source/backend/plugin/CarlaPluginLV2.cpp index 61b9fc362..cc08850fb 100644 --- a/source/backend/plugin/CarlaPluginLV2.cpp +++ b/source/backend/plugin/CarlaPluginLV2.cpp @@ -2807,7 +2807,7 @@ public: break; case LV2_PORT_DESIGNATION_TIME_BAR_BEAT: if ((timeInfo.valid & EngineTimeInfo::kValidBBT) != 0 && (fLastTimeInfo.bbt.tick != timeInfo.bbt.tick || - !carla_isEqual(fLastTimeInfo.bbt.ticksPerBeat, timeInfo.bbt.ticksPerBeat))) + 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)); doPostRt = true; @@ -2880,7 +2880,7 @@ public: 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_key(&fAtomForge, CARLA_URI_MAP_ID_TIME_BEAT); - lv2_atom_forge_double(&fAtomForge, timeInfo.bbt.beat -1); + lv2_atom_forge_double(&fAtomForge, timeInfo.bbt.beat - 1); lv2_atom_forge_key(&fAtomForge, CARLA_URI_MAP_ID_TIME_BEAT_UNIT); lv2_atom_forge_int(&fAtomForge, static_cast(timeInfo.bbt.beatType)); @@ -2892,7 +2892,7 @@ public: lv2_atom_forge_float(&fAtomForge, static_cast(timeInfo.bbt.beatsPerMinute)); lv2_atom_forge_key(&fAtomForge, CARLA_URI_MAP_ID_TIME_TICKS_PER_BEAT); - lv2_atom_forge_double(&fAtomForge, static_cast(timeInfo.bbt.ticksPerBeat)); + lv2_atom_forge_double(&fAtomForge, timeInfo.bbt.ticksPerBeat); } lv2_atom_forge_pop(&fAtomForge, &forgeFrame); diff --git a/source/plugin/carla-lv2.cpp b/source/plugin/carla-lv2.cpp index 2781f672e..1a6856310 100644 --- a/source/plugin/carla-lv2.cpp +++ b/source/plugin/carla-lv2.cpp @@ -192,21 +192,11 @@ public: fBufferSize = 1024; } - fHandle = fDescriptor->instantiate(&fHost); - CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr, false); - carla_zeroStructs(fMidiEvents, kMaxMidiEvents); carla_zeroStruct(fTimeInfo); - // hosts may not send all values, resulting on some invalid data - fTimeInfo.bbt.bar = 1; - fTimeInfo.bbt.beat = 1; - fTimeInfo.bbt.tick = 0; - fTimeInfo.bbt.barStartTick = 0; - fTimeInfo.bbt.beatsPerBar = 4; - fTimeInfo.bbt.beatType = 4; - fTimeInfo.bbt.ticksPerBeat = 960.0; - fTimeInfo.bbt.beatsPerMinute = 120.0; + fHandle = fDescriptor->instantiate(&fHost); + CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr, false); if (fDescriptor->midiIns > 0) fUI.portOffset += fDescriptor->midiIns; @@ -238,6 +228,16 @@ public: fDescriptor->activate(fHandle); carla_zeroStruct(fTimeInfo); + + // hosts may not send all values, resulting on some invalid data + fTimeInfo.bbt.bar = 1; + fTimeInfo.bbt.beat = 1; + fTimeInfo.bbt.tick = 0; + fTimeInfo.bbt.barStartTick = 0; + fTimeInfo.bbt.beatsPerBar = 4; + fTimeInfo.bbt.beatType = 4; + fTimeInfo.bbt.ticksPerBeat = 960.0; + fTimeInfo.bbt.beatsPerMinute = 120.0; } void lv2_deactivate() @@ -312,7 +312,7 @@ public: else carla_stderr("Unknown lv2 ticksPerBeat value type"); - if (fLastPositionData.ticksPerBeat > 0) + if (fLastPositionData.ticksPerBeat > 0.0) fTimeInfo.bbt.ticksPerBeat = fLastPositionData.ticksPerBeat; } @@ -1038,7 +1038,7 @@ private: float beatsPerMinute; int64_t frame; double speed; - int64_t ticksPerBeat; + double ticksPerBeat; Lv2PositionData() : bar(-1), @@ -1048,7 +1048,7 @@ private: beatsPerMinute(0.0f), frame(-1), speed(0.0), - ticksPerBeat(-1) {} + ticksPerBeat(-1.0) {} } fLastPositionData; @@ -1064,7 +1064,6 @@ private: LV2_URID midiEvent; LV2_URID timePos; LV2_URID timeBar; - LV2_URID timeBeat; LV2_URID timeBarBeat; LV2_URID timeBeatsPerBar; LV2_URID timeBeatsPerMinute; @@ -1085,7 +1084,6 @@ private: midiEvent(0), timePos(0), timeBar(0), - timeBeat(0), timeBarBeat(0), timeBeatsPerBar(0), timeBeatsPerMinute(0), @@ -1107,7 +1105,6 @@ private: midiEvent = uridMap->map(uridMap->handle, LV2_MIDI__MidiEvent); timePos = uridMap->map(uridMap->handle, LV2_TIME__Position); timeBar = uridMap->map(uridMap->handle, LV2_TIME__bar); - timeBeat = uridMap->map(uridMap->handle, LV2_TIME__beat); timeBarBeat = uridMap->map(uridMap->handle, LV2_TIME__barBeat); timeBeatUnit = uridMap->map(uridMap->handle, LV2_TIME__beatUnit); timeFrame = uridMap->map(uridMap->handle, LV2_TIME__frame);