Created
November 14, 2020 20:48
-
-
Save olilarkin/e30ecd677ec8a8a1dcc4b28881be7e02 to your computer and use it in GitHub Desktop.
ILambdaControl Sine Wave animation
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
#include "IPlugEffect.h" | |
#include "IPlug_include_in_plug_src.h" | |
#include "IControls.h" | |
IPlugEffect::IPlugEffect(const InstanceInfo& info) | |
: Plugin(info, MakeConfig(kNumParams, kNumPresets)) | |
{ | |
GetParam(kGain)->InitDouble("Gain", 0., 0., 100.0, 0.01, "%"); | |
#if IPLUG_EDITOR // http://bit.ly/2S64BDd | |
mMakeGraphicsFunc = [&]() { | |
return MakeGraphics(*this, PLUG_WIDTH, PLUG_HEIGHT, PLUG_FPS, GetScaleForScreen(PLUG_WIDTH, PLUG_HEIGHT)); | |
}; | |
mLayoutFunc = [&](IGraphics* pGraphics) { | |
pGraphics->AttachCornerResizer(EUIResizerMode::Scale, false); | |
pGraphics->AttachPanelBackground(COLOR_GRAY); | |
pGraphics->LoadFont("Roboto-Regular", ROBOTO_FN); | |
const IRECT b = pGraphics->GetBounds(); | |
// pGraphics->AttachControl(new ITextControl(b.GetMidVPadded(50), "Hello iPlug 2!", IText(50))); | |
// pGraphics->AttachControl(new IVKnobControl(b.GetCentredInside(100).GetVShifted(-100), kGain)); | |
static std::array<float, 128> yPoints; | |
for (auto i = 0; i<128; i++) { | |
yPoints[i] = 0.5f + (std::sin(0. + i * (6.283185307179586/128.f)) * 0.5f); | |
} | |
pGraphics->AttachControl(new ILambdaControl(b.GetCentredInside(200), | |
[](ILambdaControl* pCaller, IGraphics& g, IRECT& rect) { | |
g.DrawData(COLOR_BLACK, rect, yPoints.data(), 128); | |
std::rotate(yPoints.begin(), yPoints.begin() + 1, yPoints.end()); | |
}, DEFAULT_ANIMATION_DURATION, true /*loop*/, true /*start immediately*/)); | |
}; | |
#endif | |
} | |
#if IPLUG_DSP | |
void IPlugEffect::ProcessBlock(sample** inputs, sample** outputs, int nFrames) | |
{ | |
const double gain = GetParam(kGain)->Value() / 100.; | |
const int nChans = NOutChansConnected(); | |
for (int s = 0; s < nFrames; s++) { | |
for (int c = 0; c < nChans; c++) { | |
outputs[c][s] = inputs[c][s] * gain; | |
} | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment