Created
December 23, 2020 13:06
-
-
Save olilarkin/dc1fa0861de1a5e3a20c55efd4128c93 to your computer and use it in GitHub Desktop.
Visualize modulation
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" | |
class ModIVControl : public IVKnobControl { | |
public: | |
ModIVControl(const IRECT& bounds, int paramIdx) | |
: IVKnobControl(bounds, paramIdx) | |
{ | |
} | |
void DrawWidget(IGraphics& g) override | |
{ | |
float widgetRadius; // The radius out to the indicator track arc | |
if(mWidgetBounds.W() > mWidgetBounds.H()) | |
widgetRadius = (mWidgetBounds.H()/2.f); | |
else | |
widgetRadius = (mWidgetBounds.W()/2.f); | |
const float cx = mWidgetBounds.MW(), cy = mWidgetBounds.MH(); | |
widgetRadius -= (mTrackSize/2.f); | |
IRECT knobHandleBounds = mWidgetBounds.GetCentredInside((widgetRadius - mTrackToHandleDistance) * 2.f ); | |
const float angle = mAngle1 + (static_cast<float>(GetValue()) * (mAngle2 - mAngle1)); | |
mAnchorAngle = angle; | |
DrawIndicatorTrack(g, (mData.vals[0]) + angle, cx, cy, widgetRadius); | |
DrawPressableShape(g, /*mShape*/ EVShape::Ellipse, knobHandleBounds, mMouseDown, mMouseIsOver, IsDisabled()); | |
DrawPointer(g, angle, cx, cy, knobHandleBounds.W() / 2.f); | |
} | |
void OnMsgFromDelegate(int msgTag, int dataSize, const void* pData) override | |
{ | |
if (!IsDisabled() && msgTag == ISender<>::kUpdateMessage) | |
{ | |
IByteStream stream(pData, dataSize); | |
int pos = 0; | |
pos = stream.Get(&mData, pos); | |
SetDirty(false); | |
} | |
} | |
public: | |
ISenderData<> mData; | |
}; | |
IPlugEffect::IPlugEffect(const InstanceInfo& info) | |
: Plugin(info, MakeConfig(kNumParams, kNumPresets)) | |
{ | |
mLFO.SetPolarity(true); | |
GetParam(kParam1)->InitDouble("Gain", 0., 0., 100.0, 0.01, "%"); | |
GetParam(kParamModDepth)->InitPercentage("Depth"); | |
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); | |
auto bounds = pGraphics->GetBounds(); | |
pGraphics->AttachControl(new ModIVControl(bounds.GetCentredInside(100).GetHShifted(-100), kParam1), kCtrlTagLFODisplay); | |
pGraphics->AttachControl(new IVKnobControl(bounds.GetCentredInside(100).GetHShifted(100), kParamModDepth)); | |
}; | |
} | |
void IPlugEffect::ProcessBlock(sample** inputs, sample** outputs, int nFrames) | |
{ | |
const int nChans = NOutChansConnected(); | |
auto lfo = 0.f; | |
auto depth = GetParam(kParamModDepth)->Value(); | |
for (int s = 0; s < nFrames; s++) { | |
lfo = mLFO.Process(1.f) * depth; | |
for (int c = 0; c < nChans; c++) { | |
outputs[c][s] = inputs[c][s]; | |
} | |
} | |
ISenderData lfoVal(kCtrlTagLFODisplay, 1, 0); | |
lfoVal.vals[0] = lfo; | |
mLFOSender.PushData(lfoVal); | |
} | |
void IPlugEffect::OnIdle() | |
{ | |
mLFOSender.TransmitData(*this); | |
} |
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
#pragma once | |
#include "IPlug_include_in_plug_hdr.h" | |
#include "LFO.h" | |
#include "ISender.h" | |
const int kNumPresets = 1; | |
enum EParams | |
{ | |
kParam1 = 0, | |
kParamModDepth, | |
kNumParams | |
}; | |
enum ECtrlTags | |
{ | |
kCtrlTagLFODisplay = 0 | |
}; | |
using namespace iplug; | |
using namespace igraphics; | |
class IPlugEffect final : public Plugin | |
{ | |
public: | |
IPlugEffect(const InstanceInfo& info); | |
void ProcessBlock(sample** inputs, sample** outputs, int nFrames) override; | |
void OnIdle() override; | |
LFO<> mLFO; | |
ISender<> mLFOSender; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment