-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
149 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
|
||
WavetableComponent::WavetableComponent() | ||
{ | ||
} | ||
|
||
WavetableComponent::~WavetableComponent() | ||
{ | ||
} | ||
|
||
//============================================================================== | ||
|
||
void WavetableComponent::setParams (WTOscillator::Params params_) | ||
{ | ||
if (! almostEqual (params.pw, params_.pw)) | ||
{ | ||
params = params_; | ||
repaint(); | ||
} | ||
} | ||
|
||
void WavetableComponent::setWavetables (juce::OwnedArray<BandLimitedLookupTable>* bllt_) | ||
{ | ||
bllt = bllt_; | ||
needsUpdate = true; | ||
repaint(); | ||
} | ||
|
||
void WavetableComponent::paint (juce::Graphics& g) | ||
{ | ||
if (needsUpdate && bllt) | ||
{ | ||
needsUpdate = false; | ||
|
||
auto numTables = std::min (32, bllt->size()); | ||
for (auto i = 0; i < numTables; i++) | ||
paths.add (createWavetablePath (float (i) / numTables)); | ||
} | ||
|
||
g.setColour (findColour (waveColourId, true)); | ||
for (auto& p : paths) | ||
g.strokePath (p, juce::PathStrokeType (0.75f)); | ||
|
||
g.setColour (findColour (activeWaveColourId, true)); | ||
g.strokePath (createWavetablePath (params.pw), juce::PathStrokeType (0.75f)); | ||
} | ||
|
||
juce::Path WavetableComponent::createWavetablePath (float wtPos) | ||
{ | ||
constexpr auto samples = 256; | ||
|
||
juce::AudioSampleBuffer buf (2, samples); | ||
|
||
{ | ||
WTOscillator osc; | ||
|
||
auto hz = 44100.0f / samples; | ||
auto note = getMidiNoteFromHertz (hz); | ||
auto p = params; | ||
|
||
p.pw = wtPos; | ||
|
||
osc.setSampleRate (44100.0); | ||
osc.setWavetable (*bllt); | ||
osc.noteOn (0.0f); | ||
osc.process (note, p, buf); | ||
} | ||
|
||
juce::Path p; | ||
|
||
auto w = float (getWidth()); | ||
auto h = float (getHeight()); | ||
|
||
auto data = buf.getReadPointer (0); | ||
|
||
auto xSpread = 0.5f; | ||
auto yScale = -(1.0f / 4.5f); | ||
auto dx = std::min (w, h); | ||
|
||
auto xSlope = (dx * 1.5f * (1.0f - xSpread)) / float (samples); | ||
auto ySlope = xSlope / 4.0f; | ||
|
||
auto xOffset = (dx * xSpread) * wtPos; | ||
auto yOffset = (dx * xSpread) - xOffset; | ||
|
||
xOffset += (w - dx * xSpread - samples * xSlope) / 2.0f; | ||
yOffset += (h - dx * xSpread - samples * ySlope) / 2.0f; | ||
|
||
p.startNewSubPath (xOffset, data[0] * yScale * dx + yOffset); | ||
|
||
for (auto s = 1; s < samples; s++) | ||
{ | ||
p.lineTo (xOffset, data[s] * yScale * dx + yOffset); | ||
|
||
xOffset += xSlope; | ||
yOffset += ySlope; | ||
} | ||
|
||
return p; | ||
} | ||
//------------------------------------------------------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
/** Draws a wavetable | ||
*/ | ||
class WavetableComponent : public juce::Component | ||
{ | ||
public: | ||
WavetableComponent(); | ||
~WavetableComponent() override; | ||
|
||
enum ColourIds | ||
{ | ||
lineColourId = 0x3331e10, | ||
backgroundColourId = 0x3331e11, | ||
waveColourId = 0x3331e12, | ||
activeWaveColourId = 0x3331f13, | ||
}; | ||
|
||
//============================================================================== | ||
void paint (juce::Graphics& g) override; | ||
void setParams (WTOscillator::Params params); | ||
void setWavetables (juce::OwnedArray<BandLimitedLookupTable>*); | ||
|
||
private: | ||
juce::Path createWavetablePath (float pos); | ||
|
||
juce::OwnedArray<BandLimitedLookupTable>* bllt = nullptr; | ||
WTOscillator::Params params; | ||
juce::Array<juce::Path> paths; | ||
bool needsUpdate = false; | ||
|
||
//============================================================================== | ||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WavetableComponent) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters