Created
May 10, 2021 17:43
-
-
Save olilarkin/b48d5261a1a6840773a9312d178c9e30 to your computer and use it in GitHub Desktop.
Randomise parameters from a button click
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" | |
int kMsgTagRandomise = 0; | |
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)); | |
pGraphics->AttachControl(new IVButtonControl(b.GetFromTop(100), SplashClickActionFunc, "Randomise"))->SetAnimationEndActionFunction([&](IControl* pCaller){ | |
// Note: in a non-distributed plugin, it's also OK to do this here, or inside a customised IControl's OnMouseDown()... | |
// RandomiseParamValues(); // loops over all the params and sets them to a random value | |
// SendCurrentParamValuesFromDelegate(); // updates the UI controls linked to parameter values | |
// DirtyParametersFromUI(); // updates the host with the new parameter values | |
// but I prefer to send a message... | |
pCaller->GetDelegate()->SendArbitraryMsgFromUI(kMsgTagRandomise); | |
}); | |
}; | |
#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 | |
bool IPlugEffect::OnMessage(int msgTag, int ctrlTag, int dataSize, const void* pData) | |
{ | |
// and handle here... | |
if (msgTag == kMsgTagRandomise) { | |
RandomiseParamValues(); // loops over all the params and sets them to a random value | |
SendCurrentParamValuesFromDelegate(); // updates the UI controls linked to parameter values | |
DirtyParametersFromUI(); // updates the host with the new parameter values | |
return true; | |
} | |
return false; | |
} |
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" | |
const int kNumPresets = 1; | |
enum EParams | |
{ | |
kGain = 0, | |
kNumParams | |
}; | |
using namespace iplug; | |
using namespace igraphics; | |
class IPlugEffect final : public Plugin | |
{ | |
public: | |
IPlugEffect(const InstanceInfo& info); | |
bool OnMessage(int msgTag, int ctrlTag, int dataSize, const void* pData) override; | |
#if IPLUG_DSP // http://bit.ly/2S64BDd | |
void ProcessBlock(sample** inputs, sample** outputs, int nFrames) override; | |
#endif | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment