Skip to content

Instantly share code, notes, and snippets.

@olilarkin
Last active July 14, 2021 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olilarkin/02a0618cde48f80e22f329513c044e5c to your computer and use it in GitHub Desktop.
Save olilarkin/02a0618cde48f80e22f329513c044e5c to your computer and use it in GitHub Desktop.
Storing and Restoring the plugin editor scaling
#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));
};
#endif
}
bool IPlugEffect::SerializeState(IByteChunk& chunk) const
{
// good idea to serialize plugin version number here, to handle old state in future versions if nessecary
SerializeEditorState(chunk);
SerializeParams(chunk);
return true;
}
int IPlugEffect::UnserializeState(const IByteChunk& chunk, int startPos)
{
// see above
int pos = UnserializeEditorState(chunk, startPos);
pos = UnserializeParams(chunk, pos);
return pos;
}
#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
#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);
#if IPLUG_DSP // http://bit.ly/2S64BDd
void ProcessBlock(sample** inputs, sample** outputs, int nFrames) override;
#endif
bool SerializeState(IByteChunk& chunk) const override;
int UnserializeState(const IByteChunk& chunk, int startPos) override;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment