From 3850a2bb20dfcc26be0a695fe9d5f5ca5f88d334 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 2 Nov 2021 18:30:05 +0000 Subject: [PATCH] AudioPlayHead: Update wrappers to use new FrameRate type --- .../AAX/juce_AAX_Wrapper.cpp | 92 ++++++++++++++----- .../AU/juce_AU_Wrapper.mm | 35 ++++--- .../AU/juce_AUv3_Wrapper.mm | 35 ++++--- .../RTAS/juce_RTAS_Wrapper.cpp | 30 +++--- .../VST/juce_VST_Wrapper.cpp | 52 +++++------ .../VST3/juce_VST3_Wrapper.cpp | 47 +--------- 6 files changed, 158 insertions(+), 133 deletions(-) diff --git a/modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp b/modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp index 30732f16b8..ecbc4dbdb4 100644 --- a/modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/AAX/juce_AAX_Wrapper.cpp @@ -681,6 +681,31 @@ namespace AAXClasses JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JuceAAX_GUI) }; + // Copied here, because not all versions of the AAX SDK define all of these values + enum JUCE_AAX_EFrameRate : std::underlying_type_t + { + JUCE_AAX_eFrameRate_Undeclared = 0, + JUCE_AAX_eFrameRate_24Frame = 1, + JUCE_AAX_eFrameRate_25Frame = 2, + JUCE_AAX_eFrameRate_2997NonDrop = 3, + JUCE_AAX_eFrameRate_2997DropFrame = 4, + JUCE_AAX_eFrameRate_30NonDrop = 5, + JUCE_AAX_eFrameRate_30DropFrame = 6, + JUCE_AAX_eFrameRate_23976 = 7, + JUCE_AAX_eFrameRate_47952 = 8, + JUCE_AAX_eFrameRate_48Frame = 9, + JUCE_AAX_eFrameRate_50Frame = 10, + JUCE_AAX_eFrameRate_5994NonDrop = 11, + JUCE_AAX_eFrameRate_5994DropFrame = 12, + JUCE_AAX_eFrameRate_60NonDrop = 13, + JUCE_AAX_eFrameRate_60DropFrame = 14, + JUCE_AAX_eFrameRate_100Frame = 15, + JUCE_AAX_eFrameRate_11988NonDrop = 16, + JUCE_AAX_eFrameRate_11988DropFrame = 17, + JUCE_AAX_eFrameRate_120NonDrop = 18, + JUCE_AAX_eFrameRate_120DropFrame = 19 + }; + static void AAX_CALLBACK algorithmProcessCallback (JUCEAlgorithmContext* const instancesBegin[], const void* const instancesEnd); static Array activeProcessors; @@ -1047,31 +1072,54 @@ namespace AAXClasses info.ppqLoopStart = (double) loopStartTick / 960000.0; info.ppqLoopEnd = (double) loopEndTick / 960000.0; - info.editOriginTime = 0; - info.frameRate = AudioPlayHead::fpsUnknown; - - AAX_EFrameRate frameRate; - int32_t offset; - - if (transport.GetTimeCodeInfo (&frameRate, &offset) == AAX_SUCCESS) + std::tie (info.frameRate, info.editOriginTime) = [&transport] { - double framesPerSec = 24.0; + AAX_EFrameRate frameRate; + int32_t offset; - switch (frameRate) + if (transport.GetTimeCodeInfo (&frameRate, &offset) != AAX_SUCCESS) + return std::make_tuple (FrameRate(), 0.0); + + const auto rate = [&] { - case AAX_eFrameRate_Undeclared: break; - case AAX_eFrameRate_24Frame: info.frameRate = AudioPlayHead::fps24; break; - case AAX_eFrameRate_25Frame: info.frameRate = AudioPlayHead::fps25; framesPerSec = 25.0; break; - case AAX_eFrameRate_2997NonDrop: info.frameRate = AudioPlayHead::fps2997; framesPerSec = 30.0 * 1000.0 / 1001.0; break; - case AAX_eFrameRate_2997DropFrame: info.frameRate = AudioPlayHead::fps2997drop; framesPerSec = 30.0 * 1000.0 / 1001.0; break; - case AAX_eFrameRate_30NonDrop: info.frameRate = AudioPlayHead::fps30; framesPerSec = 30.0; break; - case AAX_eFrameRate_30DropFrame: info.frameRate = AudioPlayHead::fps30drop; framesPerSec = 30.0; break; - case AAX_eFrameRate_23976: info.frameRate = AudioPlayHead::fps23976; framesPerSec = 24.0 * 1000.0 / 1001.0; break; - default: break; - } + switch ((JUCE_AAX_EFrameRate) frameRate) + { + case JUCE_AAX_eFrameRate_24Frame: return FrameRate().withBaseRate (24); + case JUCE_AAX_eFrameRate_23976: return FrameRate().withBaseRate (24).withPullDown(); - info.editOriginTime = offset / framesPerSec; - } + case JUCE_AAX_eFrameRate_25Frame: return FrameRate().withBaseRate (25); + + case JUCE_AAX_eFrameRate_30NonDrop: return FrameRate().withBaseRate (30); + case JUCE_AAX_eFrameRate_30DropFrame: return FrameRate().withBaseRate (30).withDrop(); + case JUCE_AAX_eFrameRate_2997NonDrop: return FrameRate().withBaseRate (30).withPullDown(); + case JUCE_AAX_eFrameRate_2997DropFrame: return FrameRate().withBaseRate (30).withPullDown().withDrop(); + + case JUCE_AAX_eFrameRate_48Frame: return FrameRate().withBaseRate (48); + case JUCE_AAX_eFrameRate_47952: return FrameRate().withBaseRate (48).withPullDown(); + + case JUCE_AAX_eFrameRate_50Frame: return FrameRate().withBaseRate (50); + + case JUCE_AAX_eFrameRate_60NonDrop: return FrameRate().withBaseRate (60); + case JUCE_AAX_eFrameRate_60DropFrame: return FrameRate().withBaseRate (60).withDrop(); + case JUCE_AAX_eFrameRate_5994NonDrop: return FrameRate().withBaseRate (60).withPullDown(); + case JUCE_AAX_eFrameRate_5994DropFrame: return FrameRate().withBaseRate (60).withPullDown().withDrop(); + + case JUCE_AAX_eFrameRate_100Frame: return FrameRate().withBaseRate (100); + + case JUCE_AAX_eFrameRate_120NonDrop: return FrameRate().withBaseRate (120); + case JUCE_AAX_eFrameRate_120DropFrame: return FrameRate().withBaseRate (120).withDrop(); + case JUCE_AAX_eFrameRate_11988NonDrop: return FrameRate().withBaseRate (120).withPullDown(); + case JUCE_AAX_eFrameRate_11988DropFrame: return FrameRate().withBaseRate (120).withPullDown().withDrop(); + + case JUCE_AAX_eFrameRate_Undeclared: break; + } + + return FrameRate(); + }(); + + const auto effectiveRate = rate.getEffectiveRate(); + return std::make_tuple (rate, effectiveRate != 0.0 ? offset / effectiveRate : 0.0); + }(); // No way to get these: (?) info.isRecording = false; @@ -2377,7 +2425,7 @@ namespace AAXClasses jassert (pluginIds.size() > 0); #endif } -} +} // namespace AAXClasses void AAX_CALLBACK AAXClasses::algorithmProcessCallback (JUCEAlgorithmContext* const instancesBegin[], const void* const instancesEnd) { diff --git a/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm b/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm index 23d9bd5c51..8557bceed9 100644 --- a/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm +++ b/modules/juce_audio_plugin_client/AU/juce_AU_Wrapper.mm @@ -1091,22 +1091,27 @@ public: info.ppqPositionOfLastBarStart = 0; info.isRecording = false; - switch (lastTimeStamp.mSMPTETime.mType) + info.frameRate = [this] { - case kSMPTETimeType2398: info.frameRate = AudioPlayHead::fps23976; break; - case kSMPTETimeType24: info.frameRate = AudioPlayHead::fps24; break; - case kSMPTETimeType25: info.frameRate = AudioPlayHead::fps25; break; - case kSMPTETimeType30Drop: info.frameRate = AudioPlayHead::fps30drop; break; - case kSMPTETimeType30: info.frameRate = AudioPlayHead::fps30; break; - case kSMPTETimeType2997: info.frameRate = AudioPlayHead::fps2997; break; - case kSMPTETimeType2997Drop: info.frameRate = AudioPlayHead::fps2997drop; break; - case kSMPTETimeType60: info.frameRate = AudioPlayHead::fps60; break; - case kSMPTETimeType60Drop: info.frameRate = AudioPlayHead::fps60drop; break; - case kSMPTETimeType5994: - case kSMPTETimeType5994Drop: - case kSMPTETimeType50: - default: info.frameRate = AudioPlayHead::fpsUnknown; break; - } + switch (lastTimeStamp.mSMPTETime.mType) + { + case kSMPTETimeType2398: return FrameRate().withBaseRate (24).withPullDown(); + case kSMPTETimeType24: return FrameRate().withBaseRate (24); + case kSMPTETimeType25: return FrameRate().withBaseRate (25); + case kSMPTETimeType30Drop: return FrameRate().withBaseRate (30).withDrop(); + case kSMPTETimeType30: return FrameRate().withBaseRate (30); + case kSMPTETimeType2997: return FrameRate().withBaseRate (30).withPullDown(); + case kSMPTETimeType2997Drop: return FrameRate().withBaseRate (30).withPullDown().withDrop(); + case kSMPTETimeType60: return FrameRate().withBaseRate (60); + case kSMPTETimeType60Drop: return FrameRate().withBaseRate (60).withDrop(); + case kSMPTETimeType5994: return FrameRate().withBaseRate (60).withPullDown(); + case kSMPTETimeType5994Drop: return FrameRate().withBaseRate (60).withPullDown().withDrop(); + case kSMPTETimeType50: return FrameRate().withBaseRate (50); + default: break; + } + + return FrameRate(); + }(); if (CallHostBeatAndTempo (&info.ppqPosition, &info.bpm) != noErr) { diff --git a/modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm b/modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm index 344dac4299..5ecc29be03 100644 --- a/modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm +++ b/modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm @@ -1003,22 +1003,27 @@ public: info.timeInSamples = (int64) (lastTimeStamp.mSampleTime + 0.5); info.timeInSeconds = info.timeInSamples / getAudioProcessor().getSampleRate(); - switch (lastTimeStamp.mSMPTETime.mType) + info.frameRate = [this] { - case kSMPTETimeType2398: info.frameRate = AudioPlayHead::fps23976; break; - case kSMPTETimeType24: info.frameRate = AudioPlayHead::fps24; break; - case kSMPTETimeType25: info.frameRate = AudioPlayHead::fps25; break; - case kSMPTETimeType2997: info.frameRate = AudioPlayHead::fps2997; break; - case kSMPTETimeType2997Drop: info.frameRate = AudioPlayHead::fps2997drop; break; - case kSMPTETimeType30Drop: info.frameRate = AudioPlayHead::fps30drop; break; - case kSMPTETimeType30: info.frameRate = AudioPlayHead::fps30; break; - case kSMPTETimeType60Drop: info.frameRate = AudioPlayHead::fps60drop; break; - case kSMPTETimeType60: info.frameRate = AudioPlayHead::fps60; break; - case kSMPTETimeType5994: - case kSMPTETimeType5994Drop: - case kSMPTETimeType50: - default: info.frameRate = AudioPlayHead::fpsUnknown; break; - } + switch (lastTimeStamp.mSMPTETime.mType) + { + case kSMPTETimeType2398: return FrameRate().withBaseRate (24).withPullDown(); + case kSMPTETimeType24: return FrameRate().withBaseRate (24); + case kSMPTETimeType25: return FrameRate().withBaseRate (25); + case kSMPTETimeType30Drop: return FrameRate().withBaseRate (30).withDrop(); + case kSMPTETimeType30: return FrameRate().withBaseRate (30); + case kSMPTETimeType2997: return FrameRate().withBaseRate (30).withPullDown(); + case kSMPTETimeType2997Drop: return FrameRate().withBaseRate (30).withPullDown().withDrop(); + case kSMPTETimeType60: return FrameRate().withBaseRate (60); + case kSMPTETimeType60Drop: return FrameRate().withBaseRate (60).withDrop(); + case kSMPTETimeType5994: return FrameRate().withBaseRate (60).withPullDown(); + case kSMPTETimeType5994Drop: return FrameRate().withBaseRate (60).withPullDown().withDrop(); + case kSMPTETimeType50: return FrameRate().withBaseRate (50); + default: break; + } + + return FrameRate(); + }(); double num; NSInteger den; diff --git a/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp b/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp index 702ed46d4d..99defb774e 100644 --- a/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp @@ -23,6 +23,7 @@ ============================================================================== */ +#include #include #include "../utility/juce_CheckSettingMacros.h" @@ -756,21 +757,24 @@ public: info.ppqLoopStart = 0; info.ppqLoopEnd = 0; - double framesPerSec = 24.0; - - switch (fTimeCodeInfo.mFrameRate) + info.frameRate = [this] { - case ficFrameRate_24Frame: info.frameRate = AudioPlayHead::fps24; break; - case ficFrameRate_25Frame: info.frameRate = AudioPlayHead::fps25; framesPerSec = 25.0; break; - case ficFrameRate_2997NonDrop: info.frameRate = AudioPlayHead::fps2997; framesPerSec = 30.0 * 1000.0 / 1001.0; break; - case ficFrameRate_2997DropFrame: info.frameRate = AudioPlayHead::fps2997drop; framesPerSec = 30.0 * 1000.0 / 1001.0; break; - case ficFrameRate_30NonDrop: info.frameRate = AudioPlayHead::fps30; framesPerSec = 30.0; break; - case ficFrameRate_30DropFrame: info.frameRate = AudioPlayHead::fps30drop; framesPerSec = 30.0; break; - case ficFrameRate_23976: info.frameRate = AudioPlayHead::fps23976; framesPerSec = 24.0 * 1000.0 / 1001.0; break; - default: info.frameRate = AudioPlayHead::fpsUnknown; break; - } + switch (fTimeCodeInfo.mFrameRate) + { + case ficFrameRate_24Frame: return FrameRate().withBaseRate (24); + case ficFrameRate_23976: return FrameRate().withBaseRate (24).withPullDown(); + case ficFrameRate_25Frame: return FrameRate().withBaseRate (25); + case ficFrameRate_30NonDrop: return FrameRate().withBaseRate (30); + case ficFrameRate_30DropFrame: return FrameRate().withBaseRate (30).withDrop(); + case ficFrameRate_2997NonDrop: return FrameRate().withBaseRate (30).withPullDown(); + case ficFrameRate_2997DropFrame: return FrameRate().withBaseRate (30).withPullDown().withDrop(); + } - info.editOriginTime = fTimeCodeInfo.mFrameOffset / framesPerSec; + return FrameRate(); + }(); + + const auto effectiveRate = info.frameRate.getEffectiveRate(); + info.editOriginTime = effectiveRate != 0.0 ? fTimeCodeInfo.mFrameOffset / effectiveRate : 0.0; return true; } diff --git a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp index 82bae5249d..91414d2636 100644 --- a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp @@ -633,39 +633,39 @@ public: info.ppqPosition = (ti->flags & Vst2::kVstPpqPosValid) != 0 ? ti->ppqPos : 0.0; info.ppqPositionOfLastBarStart = (ti->flags & Vst2::kVstBarsValid) != 0 ? ti->barStartPos : 0.0; - if ((ti->flags & Vst2::kVstSmpteValid) != 0) + std::tie (info.frameRate, info.editOriginTime) = [ti] { - AudioPlayHead::FrameRateType rate = AudioPlayHead::fpsUnknown; - double fps = 1.0; + if ((ti->flags & Vst2::kVstSmpteValid) == 0) + return std::make_tuple (FrameRate(), 0.0); - switch (ti->smpteFrameRate) + const auto rate = [&] { - case Vst2::kVstSmpte239fps: rate = AudioPlayHead::fps23976; fps = 24.0 * 1000.0 / 1001.0; break; - case Vst2::kVstSmpte24fps: rate = AudioPlayHead::fps24; fps = 24.0; break; - case Vst2::kVstSmpte25fps: rate = AudioPlayHead::fps25; fps = 25.0; break; - case Vst2::kVstSmpte2997fps: rate = AudioPlayHead::fps2997; fps = 30.0 * 1000.0 / 1001.0; break; - case Vst2::kVstSmpte30fps: rate = AudioPlayHead::fps30; fps = 30.0; break; - case Vst2::kVstSmpte2997dfps: rate = AudioPlayHead::fps2997drop; fps = 30.0 * 1000.0 / 1001.0; break; - case Vst2::kVstSmpte30dfps: rate = AudioPlayHead::fps30drop; fps = 30.0; break; + switch (ti->smpteFrameRate) + { + case Vst2::kVstSmpte24fps: return FrameRate().withBaseRate (24); + case Vst2::kVstSmpte239fps: return FrameRate().withBaseRate (24).withPullDown(); - case Vst2::kVstSmpteFilm16mm: - case Vst2::kVstSmpteFilm35mm: fps = 24.0; break; + case Vst2::kVstSmpte25fps: return FrameRate().withBaseRate (25); + case Vst2::kVstSmpte249fps: return FrameRate().withBaseRate (25).withPullDown(); - case Vst2::kVstSmpte249fps: fps = 25.0 * 1000.0 / 1001.0; break; - case Vst2::kVstSmpte599fps: fps = 60.0 * 1000.0 / 1001.0; break; - case Vst2::kVstSmpte60fps: fps = 60; break; + case Vst2::kVstSmpte30fps: return FrameRate().withBaseRate (30); + case Vst2::kVstSmpte30dfps: return FrameRate().withBaseRate (30).withDrop(); + case Vst2::kVstSmpte2997fps: return FrameRate().withBaseRate (30).withPullDown(); + case Vst2::kVstSmpte2997dfps: return FrameRate().withBaseRate (30).withPullDown().withDrop(); - default: jassertfalse; // unknown frame-rate.. - } + case Vst2::kVstSmpte60fps: return FrameRate().withBaseRate (60); + case Vst2::kVstSmpte599fps: return FrameRate().withBaseRate (60).withPullDown(); - info.frameRate = rate; - info.editOriginTime = ti->smpteOffset / (80.0 * fps); - } - else - { - info.frameRate = AudioPlayHead::fpsUnknown; - info.editOriginTime = 0; - } + case Vst2::kVstSmpteFilm16mm: + case Vst2::kVstSmpteFilm35mm: return FrameRate().withBaseRate (24); + } + + return FrameRate(); + }(); + + const auto effectiveRate = rate.getEffectiveRate(); + return std::make_tuple (rate, effectiveRate != 0.0 ? ti->smpteOffset / (80.0 * effectiveRate) : 0.0); + }(); info.isRecording = (ti->flags & Vst2::kVstTransportRecording) != 0; info.isPlaying = (ti->flags & (Vst2::kVstTransportRecording | Vst2::kVstTransportPlaying)) != 0; diff --git a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp index 8853bdd14f..0598384c99 100644 --- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp @@ -2741,51 +2741,14 @@ public: info.frameRate = [&] { if ((processContext.state & Vst::ProcessContext::kSmpteValid) == 0) - return fpsUnknown; + return FrameRate(); - const auto interpretFlags = [&] (FrameRateType basicRate, - FrameRateType pullDownRate, - FrameRateType dropRate, - FrameRateType pullDownDropRate) - { - switch (processContext.frameRate.flags & (Vst::FrameRate::kPullDownRate | Vst::FrameRate::kDropRate)) - { - case Vst::FrameRate::kPullDownRate | Vst::FrameRate::kDropRate: - return pullDownDropRate; - - case Vst::FrameRate::kPullDownRate: - return pullDownRate; - - case Vst::FrameRate::kDropRate: - return dropRate; - } - - return basicRate; - }; - - switch (processContext.frameRate.framesPerSecond) - { - case 24: - return interpretFlags (fps24, fps23976, fps24, fps23976); - - case 25: - return interpretFlags (fps25, fps25, fps25, fps25); - - case 30: - return interpretFlags (fps30, fps2997, fps30drop, fps2997drop); - - case 60: - return interpretFlags (fps60, fps60, fps60drop, fps60drop); - } - - return fpsUnknown; + return FrameRate().withBaseRate ((int) processContext.frameRate.framesPerSecond) + .withDrop ((processContext.frameRate.flags & Vst::FrameRate::kDropRate) != 0) + .withPullDown ((processContext.frameRate.flags & Vst::FrameRate::kPullDownRate) != 0); }(); - const auto baseFps = (double) processContext.frameRate.framesPerSecond; - const auto effectiveFps = (processContext.frameRate.flags & Vst::FrameRate::kPullDownRate) != 0 - ? baseFps * 1000.0 / 1001.0 - : baseFps; - info.editOriginTime = (double) processContext.smpteOffsetSubframes / (80.0 * effectiveFps); + info.editOriginTime = (double) processContext.smpteOffsetSubframes / (80.0 * info.frameRate.getEffectiveRate()); return true; }