21 ratio = (double)displayLength / (
double)EDITOR_INITIAL_WIDTH();
22 displayLength /= ratio;
28 newlyPopped.resize(dataLength);
33 std::fill(newlyPopped.begin(), newlyPopped.end(), 0);
34 std::fill(notInterpolatedData.begin(), notInterpolatedData.end(), 0);
35 std::fill(newData.begin(), newData.end(), 0);
38 aProcessor.
getTreeState()->addParameterListener(
"bufferLength",
this);
53 jassert(framesPerSecond > 0 && framesPerSecond < 1000);
54 startTimerHz(framesPerSecond);
60 g.setColour(juce::Colours::ghostwhite);
62 g.drawLine(0, h / 2, w, h / 2);
63 g.drawLine(1, 0, 1, h);
66 for (
size_t i = 0; i < 10; i++)
68 float xPos = i * w / 10;
69 float yPos = i * h / 10;
70 g.drawLine(xPos, h / 2 - 8, xPos, h / 2 + 8);
71 g.drawLine(0, yPos, 8, yPos);
75 float fontHeight = g.getCurrentFont().getAscent();
78 auto xText = juce::String(duration, 2);
79 xText.append(
" ms", 3);
82 g.drawLine(w - 95, h - 39, w - 95, h - 39 - fontHeight);
83 g.drawLine(w - 85, h - 39 - fontHeight / 2, w - 95, h - 39 - fontHeight / 2);
84 g.drawLine(w - 85, h - 39, w - 85, h - 39 - fontHeight);
85 g.drawSingleLineText(xText, w - 80, h - 39);
89 g.drawLine(w - 95, h - 19, w - 85, h - 19);
90 g.drawLine(w - 90, h - 19 - fontHeight, w - 90, h - 19);
91 g.drawLine(w - 95, h - 19 - fontHeight, w - 85, h - 19 - fontHeight);
92 g.drawSingleLineText(yText, w - 80, h - 19);
98 g.fillAll(juce::Colours::black);
99 g.setColour(juce::Colours::white);
102 auto area = getLocalBounds();
103 auto h = (float)area.getHeight();
104 auto w = (float)area.getWidth();
113 auto scopeRect = juce::Rectangle<float>{float(0), float(0), w, h};
114 plot(g, scopeRect,
float(1), h / 2);
121void OscilloscopeComponent::parameterChanged(
const juce::String ¶meterID,
float newValue)
129 double dataLength = queueSize / ratio;
130 newlyPopped.resize(dataLength);
133void OscilloscopeComponent::timerCallback()
137 int queueSize = newlyPopped.size();
140 interpolator.process(ratio, notInterpolatedData.data(), newlyPopped.data(), queueSize);
144 std::copy(newlyPopped.data(), newlyPopped.data() + queueSize, newData.begin() +
sampleData.size() - queueSize);
150 subclassSpecificCallback();
Oscilloscope audio processor.
juce::AudioProcessorValueTreeState * getTreeState()
AudioBufferQueue< float > * getAudioBufferQueue()
void paint(juce::Graphics &g) override
void drawGrid(juce::Graphics &g, float w, float h)
OscilloscopeAudioProcessor & audioProcessor
void setFramesPerSecond(int framesPerSecond)
std::vector< float > sampleData
OscilloscopeComponent(OscilloscopeAudioProcessor &aProcessor, int sampleRate, int framesPerSecond)