iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IPlugVST3.cpp
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#include <cstdio>
12
13#include "pluginterfaces/base/ustring.h"
14#include "pluginterfaces/base/ibstream.h"
15#include "pluginterfaces/vst/ivstparameterchanges.h"
16#include "pluginterfaces/vst/ivstevents.h"
17#include "pluginterfaces/vst/ivstmidicontrollers.h"
18
19#include "IPlugVST3.h"
20
21using namespace iplug;
22using namespace Steinberg;
23using namespace Vst;
24
25#include "IPlugVST3_Parameter.h"
26
27#pragma mark - IPlugVST3 Constructor/Destructor
28
29IPlugVST3::IPlugVST3(const InstanceInfo& info, const Config& config)
30: IPlugAPIBase(config, kAPIVST3)
31, IPlugVST3ProcessorBase(config, *this)
32, IPlugVST3ControllerBase(parameters)
33, mView(nullptr)
34{
35 CreateTimer();
36}
37
38IPlugVST3::~IPlugVST3() {}
39
40#pragma mark AudioEffect overrides
41
42tresult PLUGIN_API IPlugVST3::initialize(FUnknown* context)
43{
44 TRACE
45
46 if (SingleComponentEffect::initialize(context) == kResultOk)
47 {
48 IPlugVST3ProcessorBase::Initialize(this);
49 IPlugVST3ControllerBase::Initialize(this, IsInstrument(), DoesMIDIIn());
50
51 IPlugVST3GetHost(this, context);
53 OnParamReset(kReset);
54
55 return kResultOk;
56 }
57
58 return kResultFalse;
59}
60
61tresult PLUGIN_API IPlugVST3::terminate()
62{
63 TRACE
64
65 return SingleComponentEffect::terminate();
66}
67
68tresult PLUGIN_API IPlugVST3::setBusArrangements(SpeakerArrangement* pInputBusArrangements, int32 numInBuses, SpeakerArrangement* pOutputBusArrangements, int32 numOutBuses)
69{
70 TRACE
71
72 return IPlugVST3ProcessorBase::SetBusArrangements(this, pInputBusArrangements, numInBuses, pOutputBusArrangements, numOutBuses) ? kResultTrue : kResultFalse;
73}
74
75tresult PLUGIN_API IPlugVST3::setActive(TBool state)
76{
77 TRACE
78
79 OnActivate((bool) state);
80 return SingleComponentEffect::setActive(state);
81}
82
83tresult PLUGIN_API IPlugVST3::setupProcessing(ProcessSetup& newSetup)
84{
85 TRACE
86
87 return SetupProcessing(newSetup, processSetup) ? kResultOk : kResultFalse;
88}
89
90tresult PLUGIN_API IPlugVST3::setProcessing(TBool state)
91{
92 Trace(TRACELOC, " state: %i", state);
93
94 return SetProcessing((bool) state) ? kResultOk : kResultFalse;
95}
96
97tresult PLUGIN_API IPlugVST3::process(ProcessData& data)
98{
99 TRACE
100
101 Process(data, processSetup, audioInputs, audioOutputs, mMidiMsgsFromEditor, mMidiMsgsFromProcessor, mSysExDataFromEditor, mSysexBuf);
102 return kResultOk;
103}
104
105tresult PLUGIN_API IPlugVST3::canProcessSampleSize(int32 symbolicSampleSize)
106{
107 return CanProcessSampleSize(symbolicSampleSize) ? kResultTrue : kResultFalse;
108}
109
110tresult PLUGIN_API IPlugVST3::setState(IBStream* pState)
111{
112 TRACE
113
114 return IPlugVST3State::SetState(this, pState) ? kResultOk :kResultFalse;
115}
116
117tresult PLUGIN_API IPlugVST3::getState(IBStream* pState)
118{
119 TRACE
120
121 return IPlugVST3State::GetState(this, pState) ? kResultOk :kResultFalse;
122}
123
124#pragma mark IEditController overrides
125ParamValue PLUGIN_API IPlugVST3::getParamNormalized(ParamID tag)
126{
127 return IPlugVST3ControllerBase::GetParamNormalized(tag);
128}
129
130tresult PLUGIN_API IPlugVST3::setParamNormalized(ParamID tag, ParamValue value)
131{
132 if (IPlugVST3ControllerBase::SetParamNormalized(this, tag, value))
133 return kResultTrue;
134 else
135 return kResultFalse;
136}
137
138IPlugView* PLUGIN_API IPlugVST3::createView(const char* name)
139{
140 if (HasUI() && name && strcmp(name, "editor") == 0)
141 {
142 mView = new ViewType(*this);
143 return mView;
144 }
145
146 return nullptr;
147}
148
149tresult PLUGIN_API IPlugVST3::setEditorState(IBStream* pState)
150{
151 // Currently nothing to do here
152 return kResultOk;
153}
154
155tresult PLUGIN_API IPlugVST3::getEditorState(IBStream* pState)
156{
157 // Currently nothing to do here
158 return kResultOk;
159}
160
161tresult PLUGIN_API IPlugVST3::setComponentState(IBStream* pState)
162{
163 // We get the state through setState so do nothing here
164 return kResultOk;
165}
166
167#pragma mark IMidiMapping overrides
168
169tresult PLUGIN_API IPlugVST3::getMidiControllerAssignment(int32 busIndex, int16 midiChannel, CtrlNumber midiCCNumber, ParamID& tag)
170{
171 if (busIndex == 0 && midiChannel < VST3_NUM_CC_CHANS)
172 {
173 tag = kMIDICCParamStartIdx + (midiChannel * kCountCtrlNumber) + midiCCNumber;
174 return kResultTrue;
175 }
176
177 return kResultFalse;
178}
179
180#pragma mark IInfoListener overrides
181
182Steinberg::tresult PLUGIN_API IPlugVST3::setChannelContextInfos(Steinberg::Vst::IAttributeList* pList)
183{
184 return IPlugVST3ControllerBase::SetChannelContextInfos(pList) ? kResultTrue : kResultFalse;
185}
186
187#pragma mark IPlugAPIBase overrides
188
190{
191 Trace(TRACELOC, "%d", idx);
192 beginEdit(idx);
193}
194
195void IPlugVST3::InformHostOfParamChange(int idx, double normalizedValue)
196{
197 Trace(TRACELOC, "%d:%f", idx, normalizedValue);
198 performEdit(idx, normalizedValue);
199}
200
202{
203 Trace(TRACELOC, "%d", idx);
204 endEdit(idx);
205}
206
208{
209 FUnknownPtr<IComponentHandler> handler(componentHandler);
210 handler->restartComponent(kParamTitlesChanged);
211}
212
213bool IPlugVST3::EditorResize(int viewWidth, int viewHeight)
214{
215 if (HasUI())
216 {
217 if (viewWidth != GetEditorWidth() || viewHeight != GetEditorHeight())
218 mView->Resize(viewWidth, viewHeight);
219
220 SetEditorSize(viewWidth, viewHeight);
221 }
222
223 return true;
224}
225
226#pragma mark IEditorDelegate overrides
227
229{
230 for (int i = 0; i < NParams(); i++)
231 IPlugVST3ControllerBase::SetVST3ParamNormalized(i, GetParam(i)->GetNormalized());
232
233 startGroupEdit();
235 finishGroupEdit();
236}
237
238void IPlugVST3::SendParameterValueFromUI(int paramIdx, double normalisedValue)
239{
240 IPlugVST3ControllerBase::SetVST3ParamNormalized(paramIdx, normalisedValue);
241 IPlugAPIBase::SendParameterValueFromUI(paramIdx, normalisedValue);
242}
243
244void IPlugVST3::SetLatency(int latency)
245{
246 // N.B. set the latency even if the handler is not yet set
247
249
250 if (componentHandler)
251 {
252 FUnknownPtr<IComponentHandler> handler(componentHandler);
253
254 if (handler)
255 {
256 handler->restartComponent(kLatencyChanged);
257 }
258 }
259}
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
Definition: IPlugAPIBase.h:43
virtual void DirtyParametersFromUI() override
In a distributed VST3 or WAM plugin, if you modify the parameters on the UI side (e....
virtual void OnHostIdentified()
Implement this to do something specific when IPlug becomes aware of the particular host that is hosti...
Definition: IPlugAPIBase.h:69
virtual void SetLatency(int latency)
Call this if the latency of your plug-in changes after initialization (perhaps from OnReset() ) This ...
bool IsInstrument() const
bool DoesMIDIIn() const
virtual void OnActivate(bool active)
Override OnActivate() which should be called by the API class when a plug-in is "switched on" by the ...
Shared VST3 controller code.
void InformHostOfParameterDetailsChange() override
Implemented by the API class, call this if you update parameter labels and hopefully the host should ...
Definition: IPlugVST3.cpp:207
void SetLatency(int samples) override
Call this if the latency of your plug-in changes after initialization (perhaps from OnReset() ) This ...
Definition: IPlugVST3.cpp:244
void BeginInformHostOfParamChange(int idx) override
Implemented by the API class, called by the UI (or by a delegate) at the beginning of a parameter cha...
Definition: IPlugVST3.cpp:189
void InformHostOfParamChange(int idx, double normalizedValue) override
Implemented by the API class, called by the UI via SetParameterValue() with the value of a parameter ...
Definition: IPlugVST3.cpp:195
void EndInformHostOfParamChange(int idx) override
Implemented by the API class, called by the UI (or by a delegate) at the end of a parameter change ge...
Definition: IPlugVST3.cpp:201
bool EditorResize(int viewWidth, int viewHeight) override
Implementations call into the APIs resize hooks returns a bool to indicate whether the DAW or plugin ...
Definition: IPlugVST3.cpp:213
void DirtyParametersFromUI() override
In a distributed VST3 or WAM plugin, if you modify the parameters on the UI side (e....
Definition: IPlugVST3.cpp:228
Shared VST3 processor code.
bool HasUI() const