#include "WaveformDisplay.h" namespace serum { void WaveformDisplay::paint (juce::Graphics& g) { const auto b = getLocalBounds().toFloat(); g.setColour (juce::Colours::black.withAlpha (0.4f)); g.fillRoundedRectangle (b, 4.0f); g.setColour (theme::outline); g.drawRoundedRectangle (b.reduced (0.5f), 4.0f, 1.0f); const float midY = b.getCentreY(); g.setColour (theme::outline); g.drawLine (b.getX() + 4.0f, midY, b.getRight() - 4.0f, midY, 1.0f); if (wtLib == nullptr || ! enabled) return; const Wavetable& wt = wtLib->getTable (wave); if (! wt.isValid()) return; const int n = 512; juce::Path path; path.startNewSubPath (b.getX() + 4.0f, midY); for (int i = 0; i <= n; ++i) { const float phase = (float) i / (float) n; const float sample = wt.readSafe (wtPos * 255.0f, phase); const float x = b.getX() + 4.0f + ((float) i / (float) n) * (b.getWidth() - 8.0f); const float y = midY - sample * (b.getHeight() * 0.42f); if (i == 0) path.startNewSubPath (x, y); else path.lineTo (x, y); } g.setColour (theme::accent); g.strokePath (path, juce::PathStrokeType (1.5f)); } } // namespace serum