Skip to content

Instantly share code, notes, and snippets.

@olilarkin
Created June 7, 2020 11:39
Show Gist options
  • Save olilarkin/8de0ac90f771acdefd0cf5b665fa37ec to your computer and use it in GitHub Desktop.
Save olilarkin/8de0ac90f771acdefd0cf5b665fa37ec to your computer and use it in GitHub Desktop.
#include "IPlugEffect.h"
#include "IPlug_include_in_plug_src.h"
#include "IControls.h"
#include "IWebViewControl.h"
#include "json.hpp"
using json = nlohmann::json;
IPlugEffect::IPlugEffect(const InstanceInfo& info)
: Plugin(info, MakeConfig(kNumParams, kNumPrograms))
{
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_HEIGHT));
};
mLayoutFunc = [&](IGraphics* pGraphics) {
pGraphics->AttachCornerResizer(EUIResizerMode::Scale, false);
pGraphics->AttachPanelBackground(COLOR_GRAY);
pGraphics->LoadFont("Roboto-Regular", ROBOTO_FN);
const IRECT b = pGraphics->GetBounds().GetPadded(-20.f);
auto readyFunc = [](IWebViewControl* pCaller){
pCaller->LoadHTML(R"(<p>This is a web view</p><button onclick='IPlugSendMsg({"msg":"SAMFUI"})'>Change IGraphics bgcolor</button>)");
};
auto msgFunc = [](IWebViewControl* pCaller, const char* json){
auto j = json::parse(json, nullptr, false);
pCaller->GetUI()->GetBackgroundControl()->As<IPanelControl>()->SetPattern(IColor::GetRandomColor());
};
pGraphics->AttachControl(new IWebViewControl(b.FracRectHorizontal(0.5), true, readyFunc, msgFunc, "C:\\Users\\oli\\Dev\\iPlug2\\Examples\\IPlugEffect\\WebView2Loader.dll", "C:\\Users\\oli\\Dev\\iPlug2\\Examples\\IPlugEffect\\"), 0);
auto setColors = [pGraphics](int cell, IColor color) {
WDL_String jsStr, colorStr;
color.ToColorCodeStr(colorStr);
jsStr.SetFormatted(256, "document.body.style.background = \"%s\";", colorStr.Get());
pGraphics->GetControlWithTag(0)->As<IWebViewControl>()->EvaluateJavaScript(jsStr.Get());
};
pGraphics->AttachControl(new ITextControl(b.FracRectHorizontal(0.5, true), "This is UI in IGraphics"));
pGraphics->AttachControl(new IVColorSwatchControl(b.FracRectHorizontal(0.5, true).GetFromTop(20.f), "", setColors, DEFAULT_STYLE, IVColorSwatchControl::ECellLayout::kVertical, {kBG}, { "Change <body> bgcolor" }));
pGraphics->AttachControl(new IVButtonControl(b.FracRectHorizontal(0.5, true).GetFromBottom(50.f).GetCentredInside(100, 50), SplashClickActionFunc, "Load URL"))->SetAnimationEndActionFunction([pGraphics](IControl* pCaller){
pGraphics->GetControlWithTag(0)->As<IWebViewControl>()->LoadURL("https://iplug2.github.io");
});
};
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment