Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
6.9KB

  1. //------------------------------------------------------------------------
  2. // Project : VST SDK
  3. //
  4. // Category : Common Base Classes
  5. // Filename : public.sdk/source/main/pluginfactoryvst3.h
  6. // Created by : Steinberg, 01/2004
  7. // Description : Standard Plug-in Factory
  8. //
  9. //-----------------------------------------------------------------------------
  10. // LICENSE
  11. // (c) 2017, Steinberg Media Technologies GmbH, All Rights Reserved
  12. //-----------------------------------------------------------------------------
  13. // Redistribution and use in source and binary forms, with or without modification,
  14. // are permitted provided that the following conditions are met:
  15. //
  16. // * Redistributions of source code must retain the above copyright notice,
  17. // this list of conditions and the following disclaimer.
  18. // * Redistributions in binary form must reproduce the above copyright notice,
  19. // this list of conditions and the following disclaimer in the documentation
  20. // and/or other materials provided with the distribution.
  21. // * Neither the name of the Steinberg Media Technologies nor the names of its
  22. // contributors may be used to endorse or promote products derived from this
  23. // software without specific prior written permission.
  24. //
  25. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  26. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  27. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  28. // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  29. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  30. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  32. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  33. // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  34. // OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //-----------------------------------------------------------------------------
  36. #pragma once
  37. #include "pluginterfaces/base/ipluginbase.h"
  38. namespace Steinberg {
  39. //------------------------------------------------------------------------
  40. /** Default Class Factory implementation.
  41. \ingroup sdkBase
  42. \see \ref classFactoryMacros */
  43. //------------------------------------------------------------------------
  44. class CPluginFactory : public IPluginFactory3
  45. {
  46. public:
  47. //------------------------------------------------------------------------
  48. CPluginFactory (const PFactoryInfo& info);
  49. virtual ~CPluginFactory ();
  50. //------------------------------------------------------------------------
  51. /** Registers a Plug-in class with classInfo version 1, returns true for success. */
  52. bool registerClass (const PClassInfo* info,
  53. FUnknown* (*createFunc)(void*),
  54. void* context = 0);
  55. /** Registers a Plug-in class with classInfo version 2, returns true for success. */
  56. bool registerClass (const PClassInfo2* info,
  57. FUnknown* (*createFunc)(void*),
  58. void* context = 0);
  59. /** Registers a Plug-in class with classInfo Unicode version, returns true for success. */
  60. bool registerClass (const PClassInfoW* info,
  61. FUnknown* (*createFunc)(void*),
  62. void* context = 0);
  63. /** Check if a class for a given classId is already registered. */
  64. bool isClassRegistered (const FUID& cid);
  65. //------------------------------------------------------------------------
  66. DECLARE_FUNKNOWN_METHODS
  67. //---from IPluginFactory------
  68. tresult PLUGIN_API getFactoryInfo (PFactoryInfo* info) SMTG_OVERRIDE;
  69. int32 PLUGIN_API countClasses () SMTG_OVERRIDE;
  70. tresult PLUGIN_API getClassInfo (int32 index, PClassInfo* info) SMTG_OVERRIDE;
  71. tresult PLUGIN_API createInstance (FIDString cid, FIDString _iid, void** obj) SMTG_OVERRIDE;
  72. //---from IPluginFactory2-----
  73. tresult PLUGIN_API getClassInfo2 (int32 index, PClassInfo2* info) SMTG_OVERRIDE;
  74. //---from IPluginFactory3-----
  75. tresult PLUGIN_API getClassInfoUnicode (int32 index, PClassInfoW* info) SMTG_OVERRIDE;
  76. tresult PLUGIN_API setHostContext (FUnknown* context) SMTG_OVERRIDE;
  77. //------------------------------------------------------------------------
  78. protected:
  79. /// @cond
  80. struct PClassEntry
  81. {
  82. //-----------------------------------
  83. PClassInfo2 info8;
  84. PClassInfoW info16;
  85. FUnknown* (*createFunc)(void*);
  86. void* context;
  87. bool isUnicode;
  88. //-----------------------------------
  89. };
  90. /// @endcond
  91. PFactoryInfo factoryInfo;
  92. PClassEntry* classes;
  93. int32 classCount;
  94. int32 maxClassCount;
  95. bool growClasses ();
  96. };
  97. extern CPluginFactory* gPluginFactory;
  98. //------------------------------------------------------------------------
  99. } // namespace Steinberg
  100. //------------------------------------------------------------------------
  101. #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
  102. #define EXPORT_FACTORY __attribute__ ((visibility ("default")))
  103. #else
  104. #define EXPORT_FACTORY
  105. #endif
  106. //------------------------------------------------------------------------
  107. /** \defgroup classFactoryMacros Macros for defining the class factory
  108. \ingroup sdkBase
  109. \b Example - How to use the class factory macros:
  110. \code
  111. BEGIN_FACTORY ("Steinberg Technologies",
  112. "http://www.steinberg.de",
  113. "mailto:info@steinberg.de",
  114. PFactoryInfo::kNoFlags)
  115. DEF_CLASS (INLINE_UID (0x00000000, 0x00000000, 0x00000000, 0x00000000),
  116. PClassInfo::kManyInstances,
  117. "Service",
  118. "Test Service",
  119. TestService::newInstance)
  120. END_FACTORY
  121. \endcode
  122. @{*/
  123. #define BEGIN_FACTORY(vendor,url,email,flags) using namespace Steinberg; \
  124. EXPORT_FACTORY IPluginFactory* PLUGIN_API GetPluginFactory () { \
  125. if (!gPluginFactory) \
  126. { static PFactoryInfo factoryInfo (vendor,url,email,flags); \
  127. gPluginFactory = new CPluginFactory (factoryInfo); \
  128. #define DEF_CLASS(cid,cardinality,category,name,createMethod) \
  129. { TUID lcid = cid; static PClassInfo componentClass (lcid,cardinality,category,name); \
  130. gPluginFactory->registerClass (&componentClass,createMethod); }
  131. #define DEF_CLASS1(cid,cardinality,category,name,createMethod) \
  132. { static PClassInfo componentClass (cid,cardinality,category,name); \
  133. gPluginFactory->registerClass (&componentClass,createMethod); }
  134. #define DEF_CLASS2(cid,cardinality,category,name,classFlags,subCategories,version,sdkVersion,createMethod) \
  135. { TUID lcid = cid; static PClassInfo2 componentClass (lcid,cardinality,category,name,classFlags,subCategories, 0 ,version,sdkVersion);\
  136. gPluginFactory->registerClass (&componentClass,createMethod); }
  137. #define DEF_CLASS_W(cid,cardinality,category,name,classFlags,subCategories,version,sdkVersion,createMethod) \
  138. { TUID lcid = cid; static PClassInfoUnicode componentClass (lcid,cardinality,category,name,classFlags,subCategories, 0,version,sdkVersion);\
  139. gPluginFactory->registerClass (&componentClass,createMethod); }
  140. #define END_FACTORY } else gPluginFactory->addRef (); \
  141. return gPluginFactory; }
  142. /** @} */