Make duplicate script compatible with Python 3
[wdl/wdl-ol.git] / IPlugExamples / IPlugEEL / IPlugEEL.cpp
blob02d71f31a97f181a9e063506074692c32a6089b3
1 #include "IPlugEEL.h"
2 #include "IPlug_include_in_plug_src.h"
3 #include "IControl.h"
4 #include "resource.h"
6 const int kNumPrograms = 1;
8 enum EParams
10 kGain = 0,
11 kNumParams
14 enum ELayout
16 kWidth = GUI_WIDTH,
17 kHeight = GUI_HEIGHT,
19 kGainX = 10,
20 kGainY = 10,
21 kKnobFrames = 60
24 void NSEEL_HOSTSTUB_EnterMutex()
26 //TODO: implement
29 void NSEEL_HOSTSTUB_LeaveMutex()
31 //TODO: implement
34 IPlugEEL::IPlugEEL(IPlugInstanceInfo instanceInfo)
35 : IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo), mGain(1.)
37 TRACE;
39 vm = NSEEL_VM_alloc(); // create virtual machine
41 mVmOutput = NSEEL_VM_regvar(vm, "x"); // register a variable into vm to get a value out
43 memset(codetext, 0, 65536);
44 strcpy(codetext, "x=rand(2)-1.;");
46 codehandle = NSEEL_code_compile(vm, codetext, 0); // compile code
48 //arguments are: name, defaultVal, minVal, maxVal, step, label
49 GetParam(kGain)->InitDouble("Gain", 50., 0., 100.0, 0.01, "%");
50 GetParam(kGain)->SetShape(2.);
52 IGraphics* pGraphics = MakeGraphics(this, kWidth, kHeight);
53 pGraphics->AttachPanelBackground(&COLOR_RED);
55 IBitmap knob = pGraphics->LoadIBitmap(KNOB_ID, KNOB_FN, kKnobFrames);
57 pGraphics->AttachControl(new IKnobMultiControl(this, kGainX, kGainY, kGain, &knob));
59 IRECT textRect(5, 70, kWidth-5, kHeight-5);
60 IText textProps(15, &COLOR_BLACK, "Arial", IText::kStyleNormal, IText::kAlignNear, 0, IText::kQualityDefault);
62 mTextControl = new AlgDisplay(this, textRect, &textProps, codetext);
63 pGraphics->AttachControl(mTextControl);
65 AttachGraphics(pGraphics);
67 //MakePreset("preset 1", ... );
68 MakeDefaultPreset((char *) "-", kNumPrograms);
71 IPlugEEL::~IPlugEEL()
73 NSEEL_code_free(codehandle);
74 NSEEL_VM_free(vm);
77 void IPlugEEL::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
79 // Mutex is already locked for us.
81 double* in1 = inputs[0];
82 double* in2 = inputs[1];
83 double* out1 = outputs[0];
84 double* out2 = outputs[1];
86 for (int s = 0; s < nFrames; ++s, ++in1, ++in2, ++out1, ++out2)
88 NSEEL_code_execute(codehandle);
89 *out1 = *mVmOutput * mGain;
90 *out2 = *out1;
94 void IPlugEEL::Reset()
96 TRACE;
97 IMutexLock lock(this);
99 //double sr = GetSampleRate();
102 void IPlugEEL::OnParamChange(int paramIdx)
104 IMutexLock lock(this);
106 switch (paramIdx)
108 case kGain:
109 mGain = GetParam(kGain)->Value() / 100.;
110 break;
112 default:
113 break;