Skip to content

Instantly share code, notes, and snippets.

@olilarkin
Created August 7, 2022 22:15
Show Gist options
  • Select an option

  • Save olilarkin/30792ef02a883953286d291775dc1898 to your computer and use it in GitHub Desktop.

Select an option

Save olilarkin/30792ef02a883953286d291775dc1898 to your computer and use it in GitHub Desktop.

Revisions

  1. olilarkin created this gist Aug 7, 2022.
    46 changes: 46 additions & 0 deletions IPlugEffect.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #include "IPlugEffect.h"
    #include "IPlug_include_in_plug_src.h"
    #include "IControls.h"

    IPlugEffect::IPlugEffect(const InstanceInfo& info)
    : iplug::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 ILambdaControl(b.GetCentredInside(100),
    [](ILambdaControl* pCaller, IGraphics&g, IRECT& r) {
    g.PathClear();
    g.PathTransformTranslate(r.MW(), r.MH());
    g.PathTransformScale(0.5f);
    g.PathTransformRotate(pCaller->GetAnimationProgress() * 90.0f);
    g.PathTransformTranslate(-r.MW(), -r.MH());
    g.PathRect(r);
    g.PathFill(COLOR_RED);
    }, 500));
    };
    #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