MCPcopy Create free account
hub / github.com/jerryuhoo/Fire / timerCallback

Method timerCallback

Source/Panels/ControlPanel/Graph Components/WidthGraph.cpp:33–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33void WidthGraph::timerCallback()
34{
35 // Do nothing if the cache image is not valid.
36 if (! pointCloudCache.isValid())
37 return;
38
39 // --- Efficient fade-out implementation ---
40 // 1. Create a graphics context to draw onto our cached image.
41 juce::Graphics g(pointCloudCache);
42
43 // 2. Overlay a semi-transparent dark rectangle on the entire image.
44 // This makes all existing points a little dimmer, simulating a fade-out effect.
45 g.setColour(COLOUR7.withAlpha(0.2f)); // The alpha value controls the fade-out speed.
46 g.fillRect(pointCloudCache.getBounds().reduced(1)); // Use reduced(1) to avoid covering the border.
47
48 // --- Key Step 2: Draw the new points ---
49 // (This part of the code is identical to your original version).
50
51 // Get the latest audio data from the history buffer.
52 historyL = processor.getHistoryArrayL();
53 historyR = processor.getTotalNumInputChannels() == 2 ? processor.getHistoryArrayR() : historyL;
54
55 // Apply coordinate transformations for the goniometer effect.
56 float pi = juce::MathConstants<float>::pi;
57 float rotateAngle = pi / 4.0f;
58 g.addTransform(juce::AffineTransform::scale(-1, -1, getWidth() / 2.0f, getHeight() / 2.0f));
59 g.addTransform(juce::AffineTransform::rotation(rotateAngle, getWidth() / 2.0f, getHeight() / 2.0f));
60
61 // Find the maximum value for normalization.
62 float maxValue = 0.0f;
63 for (int i = 0; i < (int) historyL.size(); i++)
64 {
65 maxValue = std::max({ maxValue, std::abs(historyL[i]), std::abs(historyR[i]) });
66 }
67
68 // Draw the new points.
69 g.setColour(juce::Colours::skyblue);
70 if (maxValue > 0.00001f)
71 {
72 const float scaleFactor = getHeight() / (4.0f * maxValue);
73 // Iterate by 2 for performance, drawing every other point.
74 for (int i = 0; i < (int) historyL.size(); i += 2)
75 {
76 float x = historyL[i] * scaleFactor;
77 float y = historyR[i] * scaleFactor;
78 g.fillRect(getWidth() / 2.0f + x, getHeight() / 2.0f + y, 1.0f, 1.0f);
79 }
80 }
81
82 // Trigger a repaint to show the updated image on screen.
83 repaint();
84}
85
86void WidthGraph::resized()
87{

Callers

nothing calls this directly

Calls 2

getHistoryArrayLMethod · 0.80
getHistoryArrayRMethod · 0.80

Tested by

no test coverage detected