AnalogTapeModel

Physical modelling signal processing for analog tape recording
Log | Files | Refs | Submodules | README | LICENSE

commit 38c907d0778d0d6fbbdea9bcfc800650696cc482
parent dd3f608f1b3be7cde2f3148181d0bc42c28844fe
Author: jatinchowdhury18 <jatinchowdhury18@gmail.com>
Date:   Sat, 30 Apr 2022 11:51:32 +0100

OversamplingMenu: report oversampling latency and total latency separely (#261)

* OversamplingMenu: report oversampling latency and total latency separately

* Apply clang-format

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Diffstat:
MPlugin/Source/GUI/CMakeLists.txt | 1+
APlugin/Source/GUI/OversamplingMenu.cpp | 47+++++++++++++++++++++++++++++++++++++++++++++++
APlugin/Source/GUI/OversamplingMenu.h | 23+++++++++++++++++++++++
MPlugin/Source/PluginProcessor.cpp | 3++-
4 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/Plugin/Source/GUI/CMakeLists.txt b/Plugin/Source/GUI/CMakeLists.txt @@ -1,6 +1,7 @@ target_sources(CHOWTapeModel PRIVATE AutoUpdating.cpp MyLNF.cpp + OversamplingMenu.cpp SettingsButton.cpp TitleComp.cpp TooltipComp.cpp diff --git a/Plugin/Source/GUI/OversamplingMenu.cpp b/Plugin/Source/GUI/OversamplingMenu.cpp @@ -0,0 +1,47 @@ +#include "OversamplingMenu.h" + +namespace +{ +const StringArray latencyChangeParameters { "loss_onoff", "hyst_onoff", "comp_onoff" }; +} + +OversamplingMenu::OversamplingMenu (OversamplerType& osManager, + AudioProcessorValueTreeState& vtState) : BaseOSMenuType (osManager, vtState), + vts (vtState), + processor (vts.processor) +{ + for (const auto& tag : latencyChangeParameters) + vts.addParameterListener (tag, this); +} + +OversamplingMenu::~OversamplingMenu() +{ + for (const auto& tag : latencyChangeParameters) + vts.removeParameterListener (tag, this); +} + +void OversamplingMenu::parameterChanged (const String&, float) +{ + generateComboBoxMenu(); +} + +void OversamplingMenu::generateComboBoxMenu() +{ + // update menu after parameter change has propagated + Timer::callAfterDelay ( + 50, + [this, safeComp = Component::SafePointer<OversamplingMenu> (this)] { + if (safeComp != nullptr) + { + BaseOSMenuType::generateComboBoxMenu(); + + auto* menu = getRootMenu(); + if (! menu->containsAnyActiveItems()) + return; + + auto totalLatencyMs = ((double) processor.getLatencySamples() / processor.getSampleRate()) * 1000.0; + totalLatencyMs = totalLatencyMs < 0.025 ? 0.0 : totalLatencyMs; + menu->addSectionHeader ("Total Latency: " + juce::String (totalLatencyMs, 3) + " ms"); + } + }); +} diff --git a/Plugin/Source/GUI/OversamplingMenu.h b/Plugin/Source/GUI/OversamplingMenu.h @@ -0,0 +1,23 @@ +#pragma once + +#include <JuceHeader.h> + +using OversamplerType = chowdsp::VariableOversampling<double>; +using BaseOSMenuType = chowdsp::OversamplingMenu<OversamplerType>; + +class OversamplingMenu : public BaseOSMenuType, + private AudioProcessorValueTreeState::Listener +{ +public: + OversamplingMenu (OversamplerType& osManager, AudioProcessorValueTreeState& vtState); + ~OversamplingMenu() override; + + void parameterChanged (const String&, float) override; + void generateComboBoxMenu() override; + +private: + AudioProcessorValueTreeState& vts; + const AudioProcessor& processor; + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OversamplingMenu) +}; diff --git a/Plugin/Source/PluginProcessor.cpp b/Plugin/Source/PluginProcessor.cpp @@ -10,6 +10,7 @@ #include "PluginProcessor.h" #include "GUI/OnOff/PowerButton.h" +#include "GUI/OversamplingMenu.h" #include "GUI/SettingsButton.h" #include "GUI/TitleComp.h" #include "GUI/TooltipComp.h" @@ -301,7 +302,7 @@ AudioProcessorEditor* ChowtapeModelAudioProcessor::createEditor() builder->registerFactory ("TitleComp", &TitleItem::factory); builder->registerFactory ("MixGroupViz", &MixGroupVizItem::factory); builder->registerFactory ("PowerButton", &PowerButtonItem::factory); - builder->registerFactory ("OversamplingMenu", &chowdsp::OversamplingMenuItem<ChowtapeModelAudioProcessor>::factory); + builder->registerFactory ("OversamplingMenu", &chowdsp::OversamplingMenuItem<ChowtapeModelAudioProcessor, OversamplingMenu>::factory); builder->registerFactory ("SettingsButton", &SettingsButtonItem::factory); builder->registerFactory ("InfoComp", &chowdsp::InfoItem<ChowTapeInfoProvider, ChowtapeModelAudioProcessor>::factory);