TapeScope.cpp (2310B)
1 #include "TapeScope.h" 2 3 using namespace foleys; 4 5 namespace 6 { 7 constexpr int rmsMS = 5000; // rms window milliseconds 8 constexpr float xPad = 3.0f; 9 } // namespace 10 11 void TapeScope::setNumChannels (int newNumChannels) { numChannels = newNumChannels; } 12 13 void TapeScope::prepareToPlay (double newSampleRate, int samplesPerBlockExpected) 14 { 15 MagicOscilloscope::prepareToPlay (newSampleRate, samplesPerBlockExpected); 16 inputSource.setupSource (numChannels, newSampleRate, rmsMS, rmsMS); 17 outputSource.setupSource (numChannels, newSampleRate, rmsMS, rmsMS); 18 } 19 20 void TapeScope::pushSamplesIO (const AudioBuffer<float>& buffer, AudioType type) 21 { 22 switch (type) 23 { 24 case Input: 25 inputSource.pushSamples (buffer); 26 return; 27 28 case Output: 29 outputSource.pushSamples (buffer); 30 MagicOscilloscope::pushSamples (buffer); 31 } 32 } 33 34 void TapeScope::createPlotPaths (Path& path, Path& filledPath, Rectangle<float> bounds, MagicPlotComponent& component) 35 { 36 // plot normal scope, with no fill 37 MagicOscilloscope::createPlotPaths (path, filledPath, bounds, component); 38 filledPath.clear(); 39 40 // get strings for I/O dB meters 41 auto getDBString = [] (const MagicLevelSource& source, AudioType type) -> String 42 { 43 String prefix = type == Input ? "IN: " : "OUT: "; 44 auto dBVal = Decibels::gainToDecibels (source.getRMSvalue (0), -80.0f); 45 return prefix + String (dBVal, 1) + " dB"; 46 }; 47 48 String inputMeter = getDBString (inputSource, Input); 49 String outputMeter = getDBString (outputSource, Output); 50 51 // draw label text 52 const auto b = bounds.toFloat(); 53 const auto labelHeight = b.getProportion (Rectangle<float> { 0.0f, 0.2f }).getHeight(); 54 const auto fontHeight = labelHeight * 0.9f; 55 const auto font = Font (fontHeight); 56 57 auto drawLabel = [b, &filledPath, labelHeight, font] (const String& textStr, float x) 58 { 59 auto width = font.getStringWidthFloat (textStr); 60 x = x < b.getCentreX() ? x : x - width; 61 62 GlyphArrangement text; 63 text.addFittedText (font, textStr, x, b.getY(), width, labelHeight, Justification::left, 1); 64 text.createPath (filledPath); 65 }; 66 67 drawLabel (inputMeter, b.getX() + xPad); 68 drawLabel (outputMeter, b.getRight() - xPad); 69 }