Jamba C++ API  5.1.1
PluginFactory.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 pongasoft
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  *
16  * @author Yan Pujante
17  */
18 
19 #pragma once
20 
21 #include <string>
22 #include <functional>
23 #include <vector>
24 
25 #include <pluginterfaces/base/funknown.h>
26 #include <pluginterfaces/base/ipluginbase.h>
27 #include <pluginterfaces/vst/ivstaudioprocessor.h>
28 #include <pluginterfaces/vst/ivstcomponent.h>
29 #include <public.sdk/source/main/pluginfactory.h>
30 
31 // SDK 3.7.1 renamed the old define so restoring it to avoid backward incompatibilities
32 #define EXPORT_FACTORY SMTG_EXPORT_SYMBOL
33 
34 namespace pongasoft::VST {
35 
70 {
71 public:
82  template<typename RTProcessorClass, typename GUIControllerClass>
83  static Steinberg::IPluginFactory* GetVST3PluginFactory(const std::string& iVendor,
84  const std::string& iURL,
85  const std::string& iEmail,
86  const std::string& iPluginName,
87  const std::string& iPluginVersion,
88  const std::string& iSubCategories,
89  void *iContext = nullptr)
90  {
91  return createFactory<RTProcessorClass, GUIControllerClass>(iVendor,
92  iURL,
93  iEmail,
94  iPluginName,
95  iPluginVersion,
96  iSubCategories,
97  iContext,
98  static_cast<Steinberg::int32>(Steinberg::Vst::kDistributable));
99  }
100 
109  template<typename RTProcessorClass, typename GUIControllerClass>
110  static Steinberg::IPluginFactory* GetNonDistributableVST3PluginFactory(const std::string& iVendor,
111  const std::string& iURL,
112  const std::string& iEmail,
113  const std::string& iPluginName,
114  const std::string& iPluginVersion,
115  const std::string& iSubCategories,
116  void *iContext = nullptr)
117  {
118  return createFactory<RTProcessorClass, GUIControllerClass>(iVendor,
119  iURL,
120  iEmail,
121  iPluginName,
122  iPluginVersion,
123  iSubCategories,
124  iContext,
125  0); // non distributable
126  }
127 
128 
129 private:
130  // createFactory
131  template<typename RTProcessorClass, typename GUIControllerClass>
132  static Steinberg::IPluginFactory* createFactory(const std::string& iVendor,
133  const std::string& iURL,
134  const std::string& iEmail,
135  const std::string& iPluginName,
136  const std::string& iPluginVersion,
137  const std::string& iSubCategories,
138  void *iContext,
139  int32 iProcessorFlags);
140 };
141 
142 //------------------------------------------------------------------------
143 // JambaPluginFactory::GetVST3PluginFactory
144 //------------------------------------------------------------------------
145 template<typename RTClass, typename GUIClass>
146 Steinberg::IPluginFactory *JambaPluginFactory::createFactory(std::string const &iVendor,
147  std::string const &iURL,
148  std::string const &iEmail,
149  std::string const &iPluginName,
150  std::string const &iPluginVersion,
151  std::string const &iSubCategories,
152  void *iContext,
153  int32 iProcessorFlags)
154 {
155  // implementation note: this code was essentially copied from the macros coming from the SDKs and adapted this way:
156  // 1) do not use Steinberg::gPluginFactory global variable
157  // 2) do not use any static variables (which end up being small memory leaks)
158  Steinberg::PFactoryInfo factoryInfo(iVendor.c_str(),
159  iURL.c_str(),
160  iEmail.c_str(),
161  Steinberg::Vst::kDefaultFactoryFlags);
162 
163  // wrapping in a unique_ptr to make sure it gets destroyed if the method does not end properly
164  auto factory = std::make_unique<Steinberg::CPluginFactory>(factoryInfo);
165 
166  // processor
167  {
168  Steinberg::TUID lcid = INLINE_UID_FROM_FUID(RTClass::UUID());
169  Steinberg::PClassInfo2 component{lcid,
170  Steinberg::PClassInfo::kManyInstances,
171  kVstAudioEffectClass,
172  iPluginName.c_str(),
173  iProcessorFlags,
174  iSubCategories.c_str(),
175  nullptr,
176  iPluginVersion.c_str(),
177  kVstVersionString};
178 
179  factory->registerClass(&component, RTClass::createInstance, iContext);
180  }
181 
182  // controller
183  {
184  Steinberg::TUID lcid = INLINE_UID_FROM_FUID(GUIClass::UUID());
185  Steinberg::PClassInfo2 component{lcid,
186  Steinberg::PClassInfo::kManyInstances,
187  kVstComponentControllerClass,
188  (iPluginName + "Controller").c_str(),
189  0,
190  nullptr,
191  nullptr,
192  iPluginVersion.c_str(),
193  kVstVersionString};
194 
195  factory->registerClass(&component, GUIClass::createInstance, iContext);
196  }
197 
198  // here we can release the pointer as it becomes the responsibility of the caller to manage its
199  // lifecycle
200  return factory.release();
201 }
202 
203 
204 }
static Steinberg::IPluginFactory * GetVST3PluginFactory(const std::string &iVendor, const std::string &iURL, const std::string &iEmail, const std::string &iPluginName, const std::string &iPluginVersion, const std::string &iSubCategories, void *iContext=nullptr)
Main method to create the factory for the plugin.
Definition: PluginFactory.h:83
static Steinberg::IPluginFactory * createFactory(const std::string &iVendor, const std::string &iURL, const std::string &iEmail, const std::string &iPluginName, const std::string &iPluginVersion, const std::string &iSubCategories, void *iContext, int32 iProcessorFlags)
Definition: PluginFactory.h:146
The purpose of this class is to make it easier and safer to create the plugin factory.
Definition: PluginFactory.h:69
Definition: Clock.h:23
static Steinberg::IPluginFactory * GetNonDistributableVST3PluginFactory(const std::string &iVendor, const std::string &iURL, const std::string &iEmail, const std::string &iPluginName, const std::string &iPluginVersion, const std::string &iSubCategories, void *iContext=nullptr)
This flavor of this API lets you create a plugin that is not declared distributable.
Definition: PluginFactory.h:110