commit b19789057482088bd3f7db1ca76de4868fc73f0d
parent b55eb970bd9c9cffe9f6297e32cb7ce39fb8f751
Author: jatinchowdhury18 <[email protected]>
Date: Wed, 4 Nov 2020 23:15:48 -0800
Add I/O meters to oscilloscope (#106)
Co-authored-by: jatinchowdhury18 <[email protected]>
Diffstat:
6 files changed, 107 insertions(+), 5 deletions(-)
diff --git a/Plugin/CHOWTapeModel.jucer b/Plugin/CHOWTapeModel.jucer
@@ -30,6 +30,8 @@
<FILE id="YzAgWK" name="MixGroupViz.h" compile="0" resource="0" file="Source/GUI/MixGroupViz.h"/>
<FILE id="IgOtsG" name="MyLNF.cpp" compile="1" resource="0" file="Source/GUI/MyLNF.cpp"/>
<FILE id="pj6eEc" name="MyLNF.h" compile="0" resource="0" file="Source/GUI/MyLNF.h"/>
+ <FILE id="yy3bQ7" name="TapeScope.cpp" compile="1" resource="0" file="Source/GUI/TapeScope.cpp"/>
+ <FILE id="zDg8Lf" name="TapeScope.h" compile="0" resource="0" file="Source/GUI/TapeScope.h"/>
<FILE id="WfCYvA" name="TitleComp.cpp" compile="1" resource="0" file="Source/GUI/TitleComp.cpp"/>
<FILE id="aoz8GN" name="TitleComp.h" compile="0" resource="0" file="Source/GUI/TitleComp.h"/>
<FILE id="oFI05X" name="TooltipComp.cpp" compile="1" resource="0" file="Source/GUI/TooltipComp.cpp"/>
diff --git a/Plugin/Source/GUI/Assets/gui.xml b/Plugin/Source/GUI/Assets/gui.xml
@@ -41,7 +41,7 @@
<View background-color="00000000" flex-grow="0.33"/>
</View>
<Plot source="scope" plot-color="FFEAA92C" padding="0" background-color="33000000"
- plot-decay="0.0" plot-fill-color="00000000"/>
+ plot-decay="0.0" plot-fill-color="FFFFFFFF"/>
</View>
<View padding="0" margin="" background-color="" lookAndFeel="">
<View flex-direction="column" margin="5" padding="" background-color="FF31323A">
diff --git a/Plugin/Source/GUI/TapeScope.cpp b/Plugin/Source/GUI/TapeScope.cpp
@@ -0,0 +1,67 @@
+#include "TapeScope.h"
+
+using namespace foleys;
+
+namespace
+{
+ constexpr int rmsMS = 5000; // rms window milliseconds
+ constexpr float xPad = 3.0f;
+}
+
+void TapeScope::prepareToPlay (int numChannels, double newSampleRate, int samplesPerBlockExpected)
+{
+ MagicOscilloscope::prepareToPlay (newSampleRate, samplesPerBlockExpected);
+ inputSource.setupSource (numChannels, newSampleRate, rmsMS, rmsMS);
+ outputSource.setupSource (numChannels, newSampleRate, rmsMS, rmsMS);
+}
+
+void TapeScope::pushSamples (const AudioBuffer<float>& buffer, AudioType type)
+{
+ switch (type)
+ {
+ case Input:
+ inputSource.pushSamples (buffer);
+ return;
+
+ case Output:
+ outputSource.pushSamples (buffer);
+ MagicOscilloscope::pushSamples (buffer);
+ }
+}
+
+void TapeScope::createPlotPaths (Path& path, Path& filledPath, Rectangle<float> bounds, MagicPlotComponent& component)
+{
+ // plot normal scope, with no fill
+ MagicOscilloscope::createPlotPaths (path, filledPath, bounds, component);
+ filledPath.clear();
+
+ // get strings for I/O dB meters
+ auto getDBString = [] (const MagicLevelSource& source, AudioType type) -> String
+ {
+ String prefix = type == Input ? "IN: " : "OUT: ";
+ auto dBVal = Decibels::gainToDecibels (source.getRMSvalue (0), -80.0f);
+ return prefix + String (dBVal, 1) + " dB";
+ };
+
+ String inputMeter = getDBString (inputSource, Input);
+ String outputMeter = getDBString (outputSource, Output);
+
+ // draw label text
+ const auto b = bounds.toFloat();
+ const auto labelHeight = b.getProportion (Rectangle<float> { 0.0f, 0.2f }).getHeight();
+ const auto fontHeight = labelHeight * 0.9f;
+ const auto font = Font (fontHeight);
+
+ auto drawLabel = [b, &filledPath, labelHeight, font] (const String& textStr, float x)
+ {
+ auto width = font.getStringWidthFloat (textStr);
+ x = x < b.getCentreX() ? x : x - width;
+
+ GlyphArrangement text;
+ text.addFittedText (font, textStr, x, b.getY(), width, labelHeight, Justification::left, 1);
+ text.createPath (filledPath);
+ };
+
+ drawLabel (inputMeter, b.getX() + xPad);
+ drawLabel (outputMeter, b.getRight() - xPad);
+}
diff --git a/Plugin/Source/GUI/TapeScope.h b/Plugin/Source/GUI/TapeScope.h
@@ -0,0 +1,30 @@
+#ifndef TAPESCOPE_H_INCLUDED
+#define TAPESCOPE_H_INCLUDED
+
+#include <JuceHeader.h>
+
+class TapeScope : public foleys::MagicOscilloscope
+{
+public:
+ TapeScope() = default;
+ ~TapeScope() = default;
+
+ enum AudioType
+ {
+ Input,
+ Output,
+ };
+
+ void prepareToPlay (int numChannels, double sampleRate, int samplesPerBlockExpected);
+ void pushSamples (const AudioBuffer<float>& buffer, AudioType type);
+
+ void createPlotPaths (Path& path, Path& filledPath, Rectangle<float> bounds, foleys::MagicPlotComponent& component) override;
+
+private:
+ foleys::MagicLevelSource inputSource;
+ foleys::MagicLevelSource outputSource;
+
+ JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TapeScope)
+};
+
+#endif // TAPESCOPE_H_INCLUDED
diff --git a/Plugin/Source/PluginProcessor.cpp b/Plugin/Source/PluginProcessor.cpp
@@ -37,7 +37,7 @@ ChowtapeModelAudioProcessor::ChowtapeModelAudioProcessor()
for (int ch = 0; ch < 2; ++ch)
lossFilter[ch].reset (new LossFilter (vts));
- scope = magicState.createAndAddObject<foleys::MagicOscilloscope> ("scope");
+ scope = magicState.createAndAddObject<TapeScope> ("scope");
flutter.initialisePlots (magicState);
LookAndFeel::setDefaultLookAndFeel (&myLNF);
@@ -161,7 +161,7 @@ void ChowtapeModelAudioProcessor::prepareToPlay (double sampleRate, int samplesP
flutter.prepareToPlay (sampleRate, samplesPerBlock);
outGain.prepareToPlay (sampleRate, samplesPerBlock);
- scope->prepareToPlay (sampleRate, samplesPerBlock);
+ scope->prepareToPlay (getMainBusNumInputChannels(), sampleRate, samplesPerBlock);
dryWet.setDryWet (*vts.getRawParameterValue ("drywet") / 100.0f);
dryWet.reset();
@@ -215,6 +215,8 @@ void ChowtapeModelAudioProcessor::processBlock (AudioBuffer<float>& buffer, Midi
dryBuffer.makeCopyOf (buffer, true);
inGain.processBlock (buffer, midiMessages);
+ scope->pushSamples (buffer, TapeScope::AudioType::Input);
+
toneControl.processBlockIn (buffer);
hysteresis.processBlock (buffer, midiMessages);
toneControl.processBlockOut (buffer);
@@ -231,7 +233,7 @@ void ChowtapeModelAudioProcessor::processBlock (AudioBuffer<float>& buffer, Midi
outGain.processBlock (buffer, midiMessages);
dryWet.processBlock (dryBuffer, buffer);
- scope->pushSamples (buffer);
+ scope->pushSamples (buffer, TapeScope::AudioType::Output);
}
void ChowtapeModelAudioProcessor::latencyCompensation()
diff --git a/Plugin/Source/PluginProcessor.h b/Plugin/Source/PluginProcessor.h
@@ -22,6 +22,7 @@
#include "Presets/PresetManager.h"
#include "GUI/MyLNF.h"
#include "GUI/AutoUpdating.h"
+#include "GUI/TapeScope.h"
#include "MixGroups/MixGroupsController.h"
//==============================================================================
@@ -90,7 +91,7 @@ private:
AudioBuffer<float> dryBuffer;
foleys::MagicProcessorState magicState { *this, vts };
- foleys::MagicPlotSource* scope = nullptr;
+ TapeScope* scope = nullptr;
PresetManager presetManager;
MyLNF myLNF;