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
42Steinberg::uint32 PLUGIN_API IPlugVST3::getTailSamples()
43{
44 return GetTailIsInfinite() ? kInfiniteTail : GetTailSize();
45}
46
47tresult PLUGIN_API IPlugVST3::initialize(FUnknown* context)
48{
49 TRACE
50
51 if (SingleComponentEffect::initialize(context) == kResultOk)
52 {
53 IPlugVST3ProcessorBase::Initialize(this);
54 IPlugVST3ControllerBase::Initialize(this, IsInstrument(), DoesMIDIIn());
55
56 IPlugVST3GetHost(this, context);
58 OnParamReset(kReset);
59
60 return kResultOk;
61 }
62
63 return kResultFalse;
64}
65
66tresult PLUGIN_API IPlugVST3::terminate()
67{
68 TRACE
69
70 return SingleComponentEffect::terminate();
71}
72
73tresult PLUGIN_API IPlugVST3::setBusArrangements(SpeakerArrangement* pInputBusArrangements, int32 numInBuses, SpeakerArrangement* pOutputBusArrangements, int32 numOutBuses)
74{
75 TRACE
76
77 return IPlugVST3ProcessorBase::SetBusArrangements(this, pInputBusArrangements, numInBuses, pOutputBusArrangements, numOutBuses) ? kResultTrue : kResultFalse;
78}
79
80tresult PLUGIN_API IPlugVST3::setActive(TBool state)
81{
82 TRACE
83
84 OnActivate((bool) state);
85 return SingleComponentEffect::setActive(state);
86}
87
88tresult PLUGIN_API IPlugVST3::setupProcessing(ProcessSetup& newSetup)
89{
90 TRACE
91
92 return SetupProcessing(newSetup, processSetup) ? kResultOk : kResultFalse;
93}
94
95tresult PLUGIN_API IPlugVST3::setProcessing(TBool state)
96{
97 Trace(TRACELOC, " state: %i", state);
98
99 return SetProcessing((bool) state) ? kResultOk : kResultFalse;
100}
101
102tresult PLUGIN_API IPlugVST3::process(ProcessData& data)
103{
104 TRACE
105
106 Process(data, processSetup, audioInputs, audioOutputs, mMidiMsgsFromEditor, mMidiMsgsFromProcessor, mSysExDataFromEditor, mSysexBuf);
107 return kResultOk;
108}
109
110tresult PLUGIN_API IPlugVST3::canProcessSampleSize(int32 symbolicSampleSize)
111{
112 return CanProcessSampleSize(symbolicSampleSize) ? kResultTrue : kResultFalse;
113}
114
115tresult PLUGIN_API IPlugVST3::setState(IBStream* pState)
116{
117 TRACE
118
119 return IPlugVST3State::SetState(this, pState) ? kResultOk :kResultFalse;
120}
121
122tresult PLUGIN_API IPlugVST3::getState(IBStream* pState)
123{
124 TRACE
125
126 return IPlugVST3State::GetState(this, pState) ? kResultOk :kResultFalse;
127}
128
129#pragma mark IEditController overrides
130ParamValue PLUGIN_API IPlugVST3::getParamNormalized(ParamID tag)
131{
132 return IPlugVST3ControllerBase::GetParamNormalized(tag);
133}
134
135tresult PLUGIN_API IPlugVST3::setParamNormalized(ParamID tag, ParamValue value)
136{
137 if (IPlugVST3ControllerBase::SetParamNormalized(this, tag, value))
138 return kResultTrue;
139 else
140 return kResultFalse;
141}
142
143IPlugView* PLUGIN_API IPlugVST3::createView(const char* name)
144{
145 if (HasUI() && name && strcmp(name, "editor") == 0)
146 {
147 mView = new ViewType(*this);
148 return mView;
149 }
150
151 return nullptr;
152}
153
154tresult PLUGIN_API IPlugVST3::setEditorState(IBStream* pState)
155{
156 // Currently nothing to do here
157 return kResultOk;
158}
159
160tresult PLUGIN_API IPlugVST3::getEditorState(IBStream* pState)
161{
162 // Currently nothing to do here
163 return kResultOk;
164}
165
166tresult PLUGIN_API IPlugVST3::setComponentState(IBStream* pState)
167{
168 // We get the state through setState so do nothing here
169 return kResultOk;
170}
171
172#pragma mark IMidiMapping overrides
173
174tresult PLUGIN_API IPlugVST3::getMidiControllerAssignment(int32 busIndex, int16 midiChannel, CtrlNumber midiCCNumber, ParamID& tag)
175{
176 if (busIndex == 0 && midiChannel < VST3_NUM_CC_CHANS)
177 {
178 tag = kMIDICCParamStartIdx + (midiChannel * kCountCtrlNumber) + midiCCNumber;
179 return kResultTrue;
180 }
181
182 return kResultFalse;
183}
184
185#pragma mark IInfoListener overrides
186
187Steinberg::tresult PLUGIN_API IPlugVST3::setChannelContextInfos(Steinberg::Vst::IAttributeList* pList)
188{
189 return IPlugVST3ControllerBase::SetChannelContextInfos(pList) ? kResultTrue : kResultFalse;
190}
191
192#pragma mark IPlugAPIBase overrides
193
195{
196 Trace(TRACELOC, "%d", idx);
197 beginEdit(idx);
198}
199
200void IPlugVST3::InformHostOfParamChange(int idx, double normalizedValue)
201{
202 Trace(TRACELOC, "%d:%f", idx, normalizedValue);
203 performEdit(idx, normalizedValue);
204}
205
207{
208 Trace(TRACELOC, "%d", idx);
209 endEdit(idx);
210}
211
213{
214 FUnknownPtr<IComponentHandler> handler(componentHandler);
215 handler->restartComponent(kParamTitlesChanged);
216}
217
218bool IPlugVST3::EditorResize(int viewWidth, int viewHeight)
219{
220 if (HasUI())
221 {
222 if (viewWidth != GetEditorWidth() || viewHeight != GetEditorHeight())
223 mView->Resize(viewWidth, viewHeight);
224
225 SetEditorSize(viewWidth, viewHeight);
226 }
227
228 return true;
229}
230
231#pragma mark IEditorDelegate overrides
232
234{
235 for (int i = 0; i < NParams(); i++)
236 IPlugVST3ControllerBase::SetVST3ParamNormalized(i, GetParam(i)->GetNormalized());
237
238 startGroupEdit();
240 finishGroupEdit();
241}
242
243void IPlugVST3::SendParameterValueFromUI(int paramIdx, double normalisedValue)
244{
245 IPlugVST3ControllerBase::SetVST3ParamNormalized(paramIdx, normalisedValue);
246 IPlugAPIBase::SendParameterValueFromUI(paramIdx, normalisedValue);
247}
248
249void IPlugVST3::SetLatency(int latency)
250{
251 // N.B. set the latency even if the handler is not yet set
252
254
255 if (componentHandler)
256 {
257 FUnknownPtr<IComponentHandler> handler(componentHandler);
258
259 if (handler)
260 {
261 handler->restartComponent(kLatencyChanged);
262 }
263 }
264}
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
bool GetTailIsInfinite() const
int GetTailSize() const
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:212
void SetLatency(int samples) override
Call this if the latency of your plug-in changes after initialization (perhaps from OnReset() ) This ...
Definition: IPlugVST3.cpp:249
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:194
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:200
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:206
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:218
void DirtyParametersFromUI() override
In a distributed VST3 or WAM plugin, if you modify the parameters on the UI side (e....
Definition: IPlugVST3.cpp:233
Shared VST3 processor code.
bool HasUI() const