Jamba C++ API  4.5.0
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/pluginfactoryvst3.h>
30 
31 namespace pongasoft::VST {
32 
67 {
68 public:
79  template<typename RTProcessorClass, typename GUIControllerClass>
80  static Steinberg::IPluginFactory* GetVST3PluginFactory(const std::string& iVendor,
81  const std::string& iURL,
82  const std::string& iEmail,
83  const std::string& iPluginName,
84  const std::string& iPluginVersion,
85  const std::string& iSubCategories,
86  void *iContext = nullptr);
87 };
88 
89 //------------------------------------------------------------------------
90 // JambaPluginFactory::GetVST3PluginFactory
91 //------------------------------------------------------------------------
92 template<typename RTClass, typename GUIClass>
93 Steinberg::IPluginFactory *JambaPluginFactory::GetVST3PluginFactory(std::string const &iVendor,
94  std::string const &iURL,
95  std::string const &iEmail,
96  std::string const &iPluginName,
97  std::string const &iPluginVersion,
98  std::string const &iSubCategories,
99  void *iContext)
100 {
101  // implementation note: this code was essentially copied from the macros coming from the SDKs and adapted this way:
102  // 1) do not use Steinberg::gPluginFactory global variable
103  // 2) do not use any static variables (which end up being small memory leaks)
104  Steinberg::PFactoryInfo factoryInfo(iVendor.c_str(),
105  iURL.c_str(),
106  iEmail.c_str(),
107  Steinberg::Vst::kDefaultFactoryFlags);
108 
109  // wrapping in a unique_ptr to make sure it gets destroyed if the method does not end properly
110  auto factory = std::make_unique<Steinberg::CPluginFactory>(factoryInfo);
111 
112  // processor
113  {
114  Steinberg::TUID lcid = INLINE_UID_FROM_FUID(RTClass::UUID());
115  Steinberg::PClassInfo2 component{lcid,
116  Steinberg::PClassInfo::kManyInstances,
117  kVstAudioEffectClass,
118  iPluginName.c_str(),
119  static_cast<Steinberg::int32>(Steinberg::Vst::kDistributable),
120  iSubCategories.c_str(),
121  nullptr,
122  iPluginVersion.c_str(),
123  kVstVersionString};
124 
125  factory->registerClass(&component, RTClass::createInstance, iContext);
126  }
127 
128  // controller
129  {
130  Steinberg::TUID lcid = INLINE_UID_FROM_FUID(GUIClass::UUID());
131  Steinberg::PClassInfo2 component{lcid,
132  Steinberg::PClassInfo::kManyInstances,
133  kVstComponentControllerClass,
134  (iPluginName + "Controller").c_str(),
135  0,
136  nullptr,
137  nullptr,
138  iPluginVersion.c_str(),
139  kVstVersionString};
140 
141  factory->registerClass(&component, GUIClass::createInstance, iContext);
142  }
143 
144  // here we can release the pointer as it becomes the responsibility of the caller to manage its
145  // lifecycle
146  return factory.release();
147 }
148 
149 
150 }
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:93
The purpose of this class is to make it easier and safer to create the plugin factory.
Definition: PluginFactory.h:66
Definition: Clock.h:23