Debian Codegraph @

plugin/plugingizmo/pluginvst.h

raw
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /***************************************************************************
3 * pluginvst.h
4 *
5 * Mon Feb 8 19:24:39 CET 2016
6 * Copyright 2016 Bent Bisballe Nyeng
7 * [email protected]
8 ****************************************************************************/
9
10 /*
11 * This file is part of PluginGizmo.
12 *
13 * PluginGizmo is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU Lesser General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PluginGizmo is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public License
24 * along with PluginGizmo; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 */
27 #pragma once
28
29 #include <memory>
30
31 #include <plugin.h>
32
33 #include <public.sdk/source/vst2.x/audioeffectx.h>
34 #include <public.sdk/source/vst2.x/aeffeditor.h>
35
36 #if defined(WIN32)
37 #define WIN32_LEAN_AND_MEAN
38 #include <windows.h>
39 #endif // defined(WIN32)
40
41 class PluginVST
42 : public Plugin
43 , public AudioEffectX
44 {
45 public:
46 //! Call this to set up number of inputs/outpus, unique id etc...
47 //! IMPORTANT: This must be called form the constructor.
48 void init() override;
49
50 //! Get current free-wheel mode.
51 bool getFreeWheel() const override;
52
53
54 //! Call this to get current samplerate.
55 float getSamplerate() override;
56
57 //! This method is called by the host when the free-wheel mode changes.
58 virtual void onSamplerateChange(float samplerate) override = 0;
59
60
61 //! Call this to get current frame-size.
62 std::size_t getFramesize() override;
63
64 //! This method is called by the host when the frame-size changes.
65 virtual void onFramesizeChange(std::size_t framesize) override = 0;
66
67
68 //! Call this to get current active state
69 bool getActive() override;
70
71 //! This method is called by the host when the active state changes.
72 virtual void onActiveChange(bool active) override = 0;
73
74
75 //! This method is called by the host to get the current state for storing.
76 virtual std::string onStateSave() override = 0;
77
78 //! This method is called by the host when a new state has been loaded.
79 virtual void onStateRestore(const std::string& config) override = 0;
80
81
82 //! This is method is called by the host to get the current latency.
83 //! \param The latency in samples.
84 float getLatency() override;
85
86 //! Call this method to signal a latency change to the host.
87 //! \param latency The latency in samples.
88 void setLatency(float latency) override;
89
90
91 //! Called by the the host to get the number of audio input channels.
92 //! This must remain constant during the lifespan of the plugin instance.
93 virtual std::size_t getNumberOfAudioInputs() override = 0;
94
95 //! Called by the the host to get the number of audio output channels.
96 //! This must remain constant during the lifespan of the plugin instance.
97 virtual std::size_t getNumberOfAudioOutputs() override = 0;
98
99
100 //! Called by the the host to get the number of midi input channels.
101 //! This must remain constant during the lifespan of the plugin instance.
102 virtual std::size_t getNumberOfMidiInputs() override = 0;
103
104 //! Called by the the host to get the number of midi output channels.
105 //! This must remain constant during the lifespan of the plugin instance.
106 virtual std::size_t getNumberOfMidiOutputs() override = 0;
107
108
109
110 // VST plugin information
111
112 //! Get unique plugin id.
113 std::string getId() override = 0;
114
115 // Functions used to set plugin information for VST
116
117 //! Returns value which is then used by getEffectName
118 std::string getEffectName() override = 0;
119 //! Returns value which is then used by getVendorString
120 std::string getVendorString() override = 0;
121 //! Returns value which is then used by getProductString
122 std::string getProductString() override = 0;
123 //! Returns value which is then used by getPlugCategory
124 PluginCategory getPluginCategory() override = 0;
125
126 //! Fill \e text with a string identifying the effect
127 bool getEffectName(char* name) override;
128
129 //! Fill \e text with a string identifying the vendor
130 bool getVendorString(char* text) override;
131
132 //! Fill \e text with a string identifying the product name
133 bool getProductString(char* text) override;
134
135 //! Specify a category that fits the plug (#VstPlugCategory)
136 virtual VstPlugCategory getPlugCategory() override;
137
138
139 virtual void process(std::size_t pos,
140 const std::vector<MidiEvent>& input_events,
141 std::vector<MidiEvent>& output_events,
142 const std::vector<const float*>& input_samples,
143 const std::vector<float*>& output_samples,
144 std::size_t count) override = 0;
145
146 //
147 // GUI
148 //
149 //! Return true if a GUI implementation is to be used.
150 virtual bool hasGUI() override
151 {
152 return false;
153 }
154
155 //! Create new window.
156 virtual void* createWindow(void *parent) override { return nullptr; }
157
158 //! Destroy window.
159 virtual void onDestroyWindow() override {}
160
161 //! Show window.
162 virtual void onShowWindow() override {}
163
164 //! Hide window.
165 virtual void onHideWindow() override {}
166
167 //! Called regularly by host; process ui events.
168 virtual void onIdle() override {}
169
170 //! Signal new window size to host.
171 void resizeWindow(std::size_t width, std::size_t height) override;
172
173 //! Signal close window event to the host.
174 void closeWindow() override;
175
176 protected:
177 bool active{false};
178
179 void updateLatency();
180 float current_latency{0.0f};
181 float update_latency{0.0f};
182
183 bool free_wheel{true};
184
185 std::vector<MidiEvent> input_events;
186
187 std::size_t pos{0};
188
189 public:
190 PluginVST(audioMasterCallback audioMaster);
191 virtual ~PluginVST();
192
193 // From AudioEffect:
194 void open() override;
195 void close() override;
196 void suspend() override;
197 void resume() override;
198 bool getInputProperties(VstInt32 index, VstPinProperties* props) override;
199 bool getOutputProperties(VstInt32 index, VstPinProperties* props) override;
200
201 // Callbacks:
202 void setSampleRate(float sampleRate) override;
203 void setBlockSize(VstInt32 blockSize) override;
204
205 VstInt32 getChunk(void **data, bool isPreset) override;
206 VstInt32 setChunk(void *data, VstInt32 byteSize, bool isPreset) override;
207
208 // From AudioEffectX:
209 VstInt32 canDo(char* text) override;
210
211 void processReplacing(float** inputs, float** outputs,
212 VstInt32 sampleFrames) override;
213 VstInt32 processEvents(VstEvents *events) override;
214
215 // UI
216 class UI :
217 public AEffEditor
218 {
219 public:
220 UI(PluginVST& plugin_vst);
221
222 bool open(void* ptr) override;
223 void close() override;
224 bool isOpen() override;
225 void idle() override;
226 bool getRect(ERect** rect) override;
227
228 PluginVST& plugin_vst;
229 bool is_open{false};
230
231 ERect rect{0,0,100,100};
232 };
233
234 private:
235 std::shared_ptr<UI> editor;
236 };
237
238 AudioEffect* createEffectInstance(audioMasterCallback audioMaster);