1 //-----------------------------------------------------------------------------
4 // Category : SDK Core Interfaces
5 // Filename : pluginterfaces/base/ipluginbase.h
6 // Created by : Steinberg, 01/2004
7 // Description : Basic Plug-in Interfaces
9 //-----------------------------------------------------------------------------
10 // This file is part of a Steinberg SDK. It is subject to the license terms
11 // in the LICENSE file found in the top-level directory of this distribution
12 // and at www.steinberg.net/sdklicenses.
13 // No part of the SDK, including this file, may be copied, modified, propagated,
14 // or distributed except according to the terms contained in the LICENSE file.
15 //-----------------------------------------------------------------------------
24 //------------------------------------------------------------------------
25 /** Basic interface to a plug-in component: IPluginBase
28 - initialize/terminate the plug-in component
30 The host uses this interface to initialize and to terminate the plug-in component.
31 The context that is passed to the initialize method contains any interface to the
32 host that the plug-in will need to work. These interfaces can vary from category to category.
33 A list of supported host context interfaces should be included in the documentation
34 of a specific category.
36 class IPluginBase
: public FUnknown
39 //------------------------------------------------------------------------
40 /** The host passes a number of interfaces as context to initialize the plug-in class.
41 @note Extensive memory allocations etc. should be performed in this method rather than in the class' constructor!
42 If the method does NOT return kResultOk, the object is released immediately. In this case terminate is not called! */
43 virtual tresult PLUGIN_API
initialize (FUnknown
* context
) = 0;
45 /** This function is called before the plug-in is unloaded and can be used for
46 cleanups. You have to release all references to any host application interfaces. */
47 virtual tresult PLUGIN_API
terminate () = 0;
49 //------------------------------------------------------------------------
50 static const FUID iid
;
53 DECLARE_CLASS_IID (IPluginBase
, 0x22888DDB, 0x156E45AE, 0x8358B348, 0x08190625)
56 //------------------------------------------------------------------------
57 /** Basic Information about the class factory of the plug-in.
62 //------------------------------------------------------------------------
65 kNoFlags
= 0, ///< Nothing
66 kClassesDiscardable
= 1 << 0, ///< The number of exported classes can change each time the Module is loaded. If this flag is set, the host does not cache class information. This leads to a longer startup time because the host always has to load the Module to get the current class information.
67 kLicenseCheck
= 1 << 1, ///< Class IDs of components are interpreted as Syncrosoft-License (LICENCE_UID). Loaded in a Steinberg host, the module will not be loaded when the license is not valid
68 kComponentNonDiscardable
= 1 << 3, ///< Component will not be unloaded until process exit
69 kUnicode
= 1 << 4 ///< Components have entirely unicode encoded strings. (True for VST 3 plug-ins so far)
79 //------------------------------------------------------------------------
80 char8 vendor
[kNameSize
]; ///< e.g. "Steinberg Media Technologies"
81 char8 url
[kURLSize
]; ///< e.g. "http://www.steinberg.de"
82 char8 email
[kEmailSize
]; ///< e.g. "info@steinberg.de"
83 int32 flags
; ///< (see above)
84 //------------------------------------------------------------------------
85 PFactoryInfo (const char8
* _vendor
, const char8
* _url
, const char8
* _email
, int32 _flags
)
87 strncpy8 (vendor
, _vendor
, kNameSize
);
88 strncpy8 (url
, _url
, kURLSize
);
89 strncpy8 (email
, _email
, kEmailSize
);
96 constexpr PFactoryInfo () : vendor (), url (), email (), flags () {}
98 PFactoryInfo () { memset (this, 0, sizeof (PFactoryInfo
)); }
102 //------------------------------------------------------------------------
103 /** Basic Information about a class provided by the plug-in.
108 //------------------------------------------------------------------------
109 enum ClassCardinality
111 kManyInstances
= 0x7FFFFFFF
119 //------------------------------------------------------------------------
120 TUID cid
; ///< Class ID 16 Byte class GUID
121 int32 cardinality
; ///< cardinality of the class, set to kManyInstances (see \ref ClassCardinality)
122 char8 category
[kCategorySize
]; ///< class category, host uses this to categorize interfaces
123 char8 name
[kNameSize
]; ///< class name, visible to the user
124 //------------------------------------------------------------------------
126 PClassInfo (const TUID _cid
, int32 _cardinality
, const char8
* _category
, const char8
* _name
)
128 memset (this, 0, sizeof (PClassInfo
));
129 memcpy (cid
, _cid
, sizeof (TUID
));
131 strncpy8 (category
, _category
, kCategorySize
);
133 strncpy8 (name
, _name
, kNameSize
);
134 cardinality
= _cardinality
;
137 constexpr PClassInfo () : cid (), cardinality (), category (), name () {}
139 PClassInfo () { memset (this, 0, sizeof (PClassInfo
)); }
143 //------------------------------------------------------------------------
144 // IPluginFactory interface declaration
145 //------------------------------------------------------------------------
146 /** Class factory that any plug-in defines for creating class instances: IPluginFactory
150 From the host's point of view a plug-in module is a factory which can create
151 a certain kind of object(s). The interface IPluginFactory provides methods
152 to get information about the classes exported by the plug-in and a
153 mechanism to create instances of these classes (that usually define the IPluginBase interface).
155 <b> An implementation is provided in public.sdk/source/common/pluginfactory.cpp </b>
156 \see GetPluginFactory
158 class IPluginFactory
: public FUnknown
161 //------------------------------------------------------------------------
162 /** Fill a PFactoryInfo structure with information about the plug-in vendor. */
163 virtual tresult PLUGIN_API
getFactoryInfo (PFactoryInfo
* info
) = 0;
165 /** Returns the number of exported classes by this factory.
166 If you are using the CPluginFactory implementation provided by the SDK, it returns the number of classes you registered with CPluginFactory::registerClass. */
167 virtual int32 PLUGIN_API
countClasses () = 0;
169 /** Fill a PClassInfo structure with information about the class at the specified index. */
170 virtual tresult PLUGIN_API
getClassInfo (int32 index
, PClassInfo
* info
) = 0;
172 /** Create a new class instance. */
173 virtual tresult PLUGIN_API
createInstance (FIDString cid
, FIDString _iid
, void** obj
) = 0;
175 //------------------------------------------------------------------------
176 static const FUID iid
;
179 DECLARE_CLASS_IID (IPluginFactory
, 0x7A4D811C, 0x52114A1F, 0xAED9D2EE, 0x0B43BF9F)
182 //------------------------------------------------------------------------
183 /** Version 2 of Basic Information about a class provided by the plug-in.
188 //------------------------------------------------------------------------
189 TUID cid
; ///< Class ID 16 Byte class GUID
190 int32 cardinality
; ///< cardinality of the class, set to kManyInstances (see \ref PClassInfo::ClassCardinality)
191 char8 category
[PClassInfo::kCategorySize
]; ///< class category, host uses this to categorize interfaces
192 char8 name
[PClassInfo::kNameSize
]; ///< class name, visible to the user
197 kSubCategoriesSize
= 128
200 uint32 classFlags
; ///< flags used for a specific category, must be defined where category is defined
201 char8 subCategories
[kSubCategoriesSize
]; ///< module specific subcategories, can be more than one, logically added by the \c OR operator
202 char8 vendor
[kVendorSize
]; ///< overwrite vendor information from factory info
203 char8 version
[kVersionSize
]; ///< Version string (e.g. "1.0.0.512" with Major.Minor.Subversion.Build)
204 char8 sdkVersion
[kVersionSize
]; ///< SDK version used to build this class (e.g. "VST 3.0")
206 //------------------------------------------------------------------------
208 PClassInfo2 (const TUID _cid
, int32 _cardinality
, const char8
* _category
, const char8
* _name
,
209 int32 _classFlags
, const char8
* _subCategories
, const char8
* _vendor
, const char8
* _version
,
210 const char8
* _sdkVersion
)
212 memset (this, 0, sizeof (PClassInfo2
));
213 memcpy (cid
, _cid
, sizeof (TUID
));
214 cardinality
= _cardinality
;
216 strncpy8 (category
, _category
, PClassInfo::kCategorySize
);
218 strncpy8 (name
, _name
, PClassInfo::kNameSize
);
219 classFlags
= static_cast<uint32
> (_classFlags
);
221 strncpy8 (subCategories
, _subCategories
, kSubCategoriesSize
);
223 strncpy8 (vendor
, _vendor
, kVendorSize
);
225 strncpy8 (version
, _version
, kVersionSize
);
227 strncpy8 (sdkVersion
, _sdkVersion
, kVersionSize
);
230 constexpr PClassInfo2 ()
243 PClassInfo2 () { memset (this, 0, sizeof (PClassInfo2
)); }
247 //------------------------------------------------------------------------
248 // IPluginFactory2 interface declaration
249 //------------------------------------------------------------------------
250 /** Version 2 of class factory supporting PClassInfo2: IPluginFactory2
252 \copydoc IPluginFactory
254 class IPluginFactory2
: public IPluginFactory
257 //------------------------------------------------------------------------
258 /** Returns the class info (version 2) for a given index. */
259 virtual tresult PLUGIN_API
getClassInfo2 (int32 index
, PClassInfo2
* info
) = 0;
261 //------------------------------------------------------------------------
262 static const FUID iid
;
264 DECLARE_CLASS_IID (IPluginFactory2
, 0x0007B650, 0xF24B4C0B, 0xA464EDB9, 0xF00B2ABB)
267 //------------------------------------------------------------------------
268 /** Unicode Version of Basic Information about a class provided by the plug-in
272 //------------------------------------------------------------------------
273 TUID cid
; ///< see \ref PClassInfo
274 int32 cardinality
; ///< see \ref PClassInfo
275 char8 category
[PClassInfo::kCategorySize
]; ///< see \ref PClassInfo
276 char16 name
[PClassInfo::kNameSize
]; ///< see \ref PClassInfo
281 kSubCategoriesSize
= 128
284 uint32 classFlags
; ///< flags used for a specific category, must be defined where category is defined
285 char8 subCategories
[kSubCategoriesSize
];///< module specific subcategories, can be more than one, logically added by the \c OR operator
286 char16 vendor
[kVendorSize
]; ///< overwrite vendor information from factory info
287 char16 version
[kVersionSize
]; ///< Version string (e.g. "1.0.0.512" with Major.Minor.Subversion.Build)
288 char16 sdkVersion
[kVersionSize
]; ///< SDK version used to build this class (e.g. "VST 3.0")
290 //------------------------------------------------------------------------
291 PClassInfoW (const TUID _cid
, int32 _cardinality
, const char8
* _category
, const char16
* _name
,
292 int32 _classFlags
, const char8
* _subCategories
, const char16
* _vendor
, const char16
* _version
,
293 const char16
* _sdkVersion
)
295 memset (this, 0, sizeof (PClassInfoW
));
296 memcpy (cid
, _cid
, sizeof (TUID
));
297 cardinality
= _cardinality
;
299 strncpy8 (category
, _category
, PClassInfo::kCategorySize
);
301 strncpy16 (name
, _name
, PClassInfo::kNameSize
);
302 classFlags
= static_cast<uint32
> (_classFlags
);
304 strncpy8 (subCategories
, _subCategories
, kSubCategoriesSize
);
306 strncpy16 (vendor
, _vendor
, kVendorSize
);
308 strncpy16 (version
, _version
, kVersionSize
);
310 strncpy16 (sdkVersion
, _sdkVersion
, kVersionSize
);
313 constexpr PClassInfoW ()
326 PClassInfoW () { memset (this, 0, sizeof (PClassInfoW
)); }
329 void fromAscii (const PClassInfo2
& ci2
)
331 memcpy (cid
, ci2
.cid
, sizeof (TUID
));
332 cardinality
= ci2
.cardinality
;
333 strncpy8 (category
, ci2
.category
, PClassInfo::kCategorySize
);
334 str8ToStr16 (name
, ci2
.name
, PClassInfo::kNameSize
);
335 classFlags
= ci2
.classFlags
;
336 strncpy8 (subCategories
, ci2
.subCategories
, kSubCategoriesSize
);
338 str8ToStr16 (vendor
, ci2
.vendor
, kVendorSize
);
339 str8ToStr16 (version
, ci2
.version
, kVersionSize
);
340 str8ToStr16 (sdkVersion
, ci2
.sdkVersion
, kVersionSize
);
344 //------------------------------------------------------------------------
345 // IPluginFactory3 interface declaration
346 //------------------------------------------------------------------------
347 /** Version 3 of class factory supporting PClassInfoW: IPluginFactory3
349 \copydoc IPluginFactory
351 class IPluginFactory3
: public IPluginFactory2
354 //------------------------------------------------------------------------
355 /** Returns the unicode class info for a given index. */
356 virtual tresult PLUGIN_API
getClassInfoUnicode (int32 index
, PClassInfoW
* info
) = 0;
358 /** Receives information about host*/
359 virtual tresult PLUGIN_API
setHostContext (FUnknown
* context
) = 0;
361 //------------------------------------------------------------------------
362 static const FUID iid
;
364 DECLARE_CLASS_IID (IPluginFactory3
, 0x4555A2AB, 0xC1234E57, 0x9B122910, 0x36878931)
365 //------------------------------------------------------------------------
366 } // namespace Steinberg
368 //------------------------------------------------------------------------
369 #define LICENCE_UID(l1, l2, l3, l4) \
371 (int8)((l1 & 0xFF000000) >> 24), (int8)((l1 & 0x00FF0000) >> 16), \
372 (int8)((l1 & 0x0000FF00) >> 8), (int8)((l1 & 0x000000FF) ), \
373 (int8)((l2 & 0xFF000000) >> 24), (int8)((l2 & 0x00FF0000) >> 16), \
374 (int8)((l2 & 0x0000FF00) >> 8), (int8)((l2 & 0x000000FF) ), \
375 (int8)((l3 & 0xFF000000) >> 24), (int8)((l3 & 0x00FF0000) >> 16), \
376 (int8)((l3 & 0x0000FF00) >> 8), (int8)((l3 & 0x000000FF) ), \
377 (int8)((l4 & 0xFF000000) >> 24), (int8)((l4 & 0x00FF0000) >> 16), \
378 (int8)((l4 & 0x0000FF00) >> 8), (int8)((l4 & 0x000000FF) ) \
381 //------------------------------------------------------------------------
383 //------------------------------------------------------------------------
384 /** Plug-in entry point.
386 Any plug-in must define and export this function. \n
387 A typical implementation of GetPluginFactory looks like this
389 SMTG_EXPORT_SYMBOL IPluginFactory* PLUGIN_API GetPluginFactory ()
393 static PFactoryInfo factoryInfo =
396 "http://www.mywebpage.com",
397 "mailto:myemail@address.com",
398 PFactoryInfo::kNoFlags
401 gPluginFactory = new CPluginFactory (factoryInfo);
403 static PClassInfo componentClass =
405 INLINE_UID (0x00000000, 0x00000000, 0x00000000, 0x00000000), // replace by a valid uid
407 "Service", // category
411 gPluginFactory->registerClass (&componentClass, MyComponentClass::newInstance);
414 gPluginFactory->addRef ();
416 return gPluginFactory;
423 SMTG_EXPORT_SYMBOL
Steinberg::IPluginFactory
* PLUGIN_API
GetPluginFactory ();
424 typedef Steinberg::IPluginFactory
* (PLUGIN_API
*GetFactoryProc
) ();