Skip to content

Instantly share code, notes, and snippets.

@olilarkin
Last active March 6, 2021 20:05
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/5fddce683cf31e75ad93855f55841c76 to your computer and use it in GitHub Desktop.
Save olilarkin/5fddce683cf31e75ad93855f55841c76 to your computer and use it in GitHub Desktop.
Basic VU meter hookup
#include "IPlugEffect.h"
#include "IPlug_include_in_plug_src.h"
#include "IControls.h"
constexpr int kNumVUFrames = 100;
IPlugEffect::IPlugEffect(const InstanceInfo& info)
: Plugin(info, MakeConfig(kNumParams, kNumPresets))
{
GetParam(kGain)->InitDouble("Gain", 0., 0., 100.0, 0.01, "%");
mMakeGraphicsFunc = [&]() {
return MakeGraphics(*this, PLUG_WIDTH, PLUG_HEIGHT, PLUG_FPS);
};
mLayoutFunc = [&](IGraphics* pGraphics) {
pGraphics->AttachPanelBackground(COLOR_GRAY);
pGraphics->AttachControl(new IBitmapControl(100, 100, pGraphics->LoadBitmap(VU2X_FN, kNumVUFrames)), kCtrlTagVUMeter);
};
}
void IPlugEffect::OnIdle()
{
SendControlValueFromDelegate(kCtrlTagVUMeter, mLevel.load());
}
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];
}
}
mLevel.store(outputs[0][0]);
}
#pragma once
#include "IPlug_include_in_plug_hdr.h"
const int kNumPresets = 1;
constexpr int kCtrlTagVUMeter = 0;
enum EParams
{
kGain = 0,
kNumParams
};
using namespace iplug;
using namespace igraphics;
class IPlugEffect final : public Plugin
{
public:
IPlugEffect(const InstanceInfo& info);
void OnIdle() override;
void ProcessBlock(sample** inputs, sample** outputs, int nFrames) override;
std::atomic<float> mLevel;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment