25#if defined OS_WIN && !defined VST3C_API
26 HINSTANCE gHINSTANCE = 0;
27 #if defined(VST2_API) || defined(AAX_API) || defined(CLAP_API)
31 BOOL WINAPI DllMain(HINSTANCE hDllInst, DWORD fdwReason, LPVOID res)
33 gHINSTANCE = hDllInst;
38 UINT(WINAPI *__GetDpiForWindow)(HWND);
40 float GetScaleForHWND(HWND hWnd)
42 if (!__GetDpiForWindow)
44 HINSTANCE h = LoadLibraryW(L
"user32.dll");
45 if (h) *(
void **)&__GetDpiForWindow = GetProcAddress(h,
"GetDpiForWindow");
47 if (!__GetDpiForWindow)
51 int dpi = __GetDpiForWindow(hWnd);
53 if (dpi != USER_DEFAULT_SCREEN_DPI)
55#if defined IGRAPHICS_QUANTISE_SCREENSCALE
56 return std::round(
static_cast<float>(dpi) / USER_DEFAULT_SCREEN_DPI);
58 return static_cast<float>(dpi) / USER_DEFAULT_SCREEN_DPI;
67#pragma mark - ** Global Functions and Defines **
73 EXPORT
void* VSTPluginMain(audioMasterCallback hostCallback)
75 using namespace iplug;
77 IPlugVST2* pPlug = iplug::MakePlug(iplug::InstanceInfo{hostCallback});
81 AEffect& aEffect = pPlug->GetAEffect();
83 aEffect.numPrograms = std::max(aEffect.numPrograms, 1);
89 EXPORT
int main(
int hostCallback)
91 audioMasterCallback callback =
reinterpret_cast<audioMasterCallback
>(
static_cast<VstIntPtr
>(hostCallback));
92 return static_cast<int>(
reinterpret_cast<std::uintptr_t
>(VSTPluginMain(callback)));
95#pragma mark - VST3 (All)
96#elif defined VST3_API || VST3C_API || defined VST3P_API
97 #include "public.sdk/source/main/pluginfactory.h"
98 #include "pluginterfaces/vst/ivstcomponent.h"
99 #include "pluginterfaces/vst/ivsteditcontroller.h"
101#if !defined VST3_PROCESSOR_UID && !defined VST3_CONTROLLER_UID
102#define VST3_PROCESSOR_UID 0xF2AEE70D, 0x00DE4F4E, PLUG_MFR_ID, PLUG_UNIQUE_ID
103#define VST3_CONTROLLER_UID 0xF2AEE70E, 0x00DE4F4F, PLUG_MFR_ID, PLUG_UNIQUE_ID
106 #ifndef EFFECT_TYPE_VST3
108 #define EFFECT_TYPE_VST3 kInstrumentSynth
110 #define EFFECT_TYPE_VST3 kFx
114 #if defined VST3P_API || defined VST3_API
118 extern void* moduleHandle;
119 gHINSTANCE = (HINSTANCE) moduleHandle;
132 static Steinberg::FUnknown* createInstance(
void*)
134 return (Steinberg::Vst::IAudioProcessor*) iplug::MakePlug(iplug::InstanceInfo());
137 BEGIN_FACTORY_DEF(PLUG_MFR, PLUG_URL_STR, PLUG_EMAIL_STR)
139 DEF_CLASS2(INLINE_UID_FROM_FUID(FUID(VST3_PROCESSOR_UID)),
140 Steinberg::PClassInfo::kManyInstances,
141 kVstAudioEffectClass,
143 Steinberg::Vst::kSimpleModeSupported,
150 #pragma mark - VST3 Processor
151 #elif defined VST3P_API
152 static Steinberg::FUnknown* createProcessorInstance(
void*)
154 return MakeProcessor();
157 static Steinberg::FUnknown* createControllerInstance(
void*)
159 return MakeController();
162 BEGIN_FACTORY_DEF(PLUG_MFR, PLUG_URL_STR, PLUG_EMAIL_STR)
164 DEF_CLASS2 (INLINE_UID_FROM_FUID(FUID(VST3_PROCESSOR_UID)),
165 PClassInfo::kManyInstances,
166 kVstAudioEffectClass,
172 createProcessorInstance)
174 DEF_CLASS2(INLINE_UID_FROM_FUID(FUID(VST3_CONTROLLER_UID)),
175 PClassInfo::kManyInstances,
176 kVstComponentControllerClass,
177 PLUG_NAME
" Controller",
182 createControllerInstance)
190 #ifndef AU_NO_COMPONENT_ENTRY
192 EXPORT ComponentResult AUV2_ENTRY(ComponentParameters* pParams,
void* pPlug)
194 return iplug::IPlugAU::IPlugAUEntry(pParams, pPlug);
199 EXPORT
void* AUV2_FACTORY(
const AudioComponentDescription* pInDesc)
201 return iplug::IPlugAUFactory<PLUG_CLASS_NAME, PLUG_DOES_MIDI_IN>::Factory(pInDesc);
208 EMSCRIPTEN_KEEPALIVE
void* createModule()
210 Processor* pWAM =
dynamic_cast<Processor*
>(iplug::MakePlug(iplug::InstanceInfo()));
218 std::unique_ptr<iplug::IPlugWeb> gPlug;
219 extern void StartMainLoopTimer();
223 EMSCRIPTEN_KEEPALIVE
void iplug_syncfs()
226 if(Module.syncdone == 1) {
228 FS.syncfs(false, function (err) {
230 console.log(
"Synced to IDBFS...");
237 EMSCRIPTEN_KEEPALIVE
void iplug_fsready()
239 gPlug = std::unique_ptr<iplug::IPlugWeb>(iplug::MakePlug(iplug::InstanceInfo()));
240 gPlug->SetHost(
"www", 0);
241 gPlug->OpenWindow(
nullptr);
250 var name =
'/' + UTF8ToString($0) +
'_data';
252 FS.mount(IDBFS, {}, name);
255 FS.syncfs(
true, function (err) {
257 console.log(
"Synced from IDBFS...");
259 ccall(
'iplug_fsready',
'v');
263 StartMainLoopTimer();
272#pragma mark - Wasm UI
273#elif defined WASM_UI_API
277 std::unique_ptr<iplug::IPlugWasmUI> gPlug;
278 extern void StartMainLoopTimer();
282 EMSCRIPTEN_KEEPALIVE
void iplug_syncfs()
285 if(Module.syncdone == 1) {
287 FS.syncfs(false, function (err) {
289 console.log(
"Synced to IDBFS...");
296 EMSCRIPTEN_KEEPALIVE
void iplug_fsready()
298 gPlug = std::unique_ptr<iplug::IPlugWasmUI>(iplug::MakePlug(iplug::InstanceInfo()));
299 gPlug->SetHost(
"www", 0);
300 gPlug->OpenWindow(
nullptr);
309 var name =
'/' + UTF8ToString($0) +
'_data';
311 FS.mount(IDBFS, {}, name);
314 FS.syncfs(
true, function (err) {
316 console.log(
"Synced from IDBFS...");
318 ccall(
'iplug_fsready',
'v');
322 StartMainLoopTimer();
330#elif defined CLAP_API
334#ifndef CLAP_MANUAL_URL
335#define CLAP_MANUAL_URL ""
337#ifndef CLAP_SUPPORT_URL
338#define CLAP_SUPPORT_URL ""
340#ifndef CLAP_DESCRIPTION
341#define CLAP_DESCRIPTION ""
345 #define CLAP_FEATURES CLAP_PLUGIN_FEATURE_AUDIO_EFFECT
347 #define CLAP_FEATURES CLAP_PLUGIN_FEATURE_INSTRUMENT
349 #define CLAP_FEATURES CLAP_PLUGIN_FEATURE_NOTE_EFFECT
353std::string gPluginPath;
354std::unique_ptr<clap_plugin_descriptor> gPluginDesc;
356static bool clap_init(
const char* pluginPath)
360 gPluginPath = pluginPath;
361 gPluginDesc = std::unique_ptr<clap_plugin_descriptor>(
new clap_plugin_descriptor());
365 gPluginDesc->clap_version = CLAP_VERSION;
367 gPluginDesc->id = BUNDLE_DOMAIN
"." BUNDLE_MFR
"." BUNDLE_NAME;
368 gPluginDesc->name = PLUG_NAME;
369 gPluginDesc->vendor = PLUG_MFR;
370 gPluginDesc->url = PLUG_URL_STR;
372 gPluginDesc->manual_url = CLAP_MANUAL_URL;
373 gPluginDesc->version = PLUG_VERSION_STR;
374 gPluginDesc->support_url = CLAP_SUPPORT_URL;
375 gPluginDesc->description = CLAP_DESCRIPTION;
377 static const char *clap_features[] = { CLAP_FEATURES, NULL };
378 gPluginDesc->features = clap_features;
383static void clap_deinit(
void)
386 gPluginDesc =
nullptr;
389static uint32_t clap_get_plugin_count(
const clap_plugin_factory_t *factory)
394static const clap_plugin_descriptor* clap_get_plugin_descriptor(
const clap_plugin_factory_t *factory, uint32_t index)
397 return gPluginDesc.get();
402static const clap_plugin* clap_create_plugin(
const clap_plugin_factory_t *factory,
const clap_host* host,
const char* plugin_id)
404 if (!strcmp(gPluginDesc->id, plugin_id))
406 iplug::IPlugCLAP* pPlug = iplug::MakePlug(iplug::InstanceInfo{gPluginDesc.get(), host});
407 return pPlug->clapPlugin();
413CLAP_EXPORT
const clap_plugin_factory_t clap_factory = {
414 clap_get_plugin_count,
415 clap_get_plugin_descriptor,
419const void *clap_get_factory(
const char *factory_id)
421 if (!::strcmp(factory_id, CLAP_PLUGIN_FACTORY_ID))
422 return &clap_factory;
427CLAP_EXPORT
const clap_plugin_entry_t clap_entry = {
434#elif defined AUv3_API || defined AAX_API || defined APP_API || defined WAM_API || defined WEB_API || defined WASM_DSP_API || defined WASM_UI_API
437 #error "No API defined!"
440#pragma mark - ** Instantiation **
445#pragma mark VST2, VST3, AAX, AUv3, APP, WAM, WEB, CLAP
447#if defined VST2_API || defined VST3_API || defined AAX_API || defined AUv3_API || defined APP_API || defined WAM_API || defined WEB_API || defined WASM_DSP_API || defined WASM_UI_API || defined CLAP_API
449Plugin* MakePlug(
const iplug::InstanceInfo& info)
452 static WDL_Mutex sMutex;
453 WDL_MutexLock lock(&sMutex);
455 return new PLUG_CLASS_NAME(info);
461Plugin* MakePlug(
void* pMemory)
463 iplug::InstanceInfo info;
464 info.mCocoaViewFactoryClassName.Set(AUV2_VIEW_CLASS_STR);
467 return new(pMemory) PLUG_CLASS_NAME(info);
469 return new PLUG_CLASS_NAME(info);
472#pragma mark - VST3 Controller
473#elif defined VST3C_API
475Steinberg::FUnknown* MakeController()
477 static WDL_Mutex sMutex;
478 WDL_MutexLock lock(&sMutex);
479 iplug::IPlugVST3Controller::InstanceInfo info;
480 info.mOtherGUID = Steinberg::FUID(VST3_PROCESSOR_UID);
484 return static_cast<Steinberg::Vst::IEditController*
>(
new PLUG_CLASS_NAME(info));
487#pragma mark - VST3 Processor
488#elif defined VST3P_API
490Steinberg::FUnknown* MakeProcessor()
492 static WDL_Mutex sMutex;
493 WDL_MutexLock lock(&sMutex);
494 iplug::IPlugVST3Processor::InstanceInfo info;
495 info.mOtherGUID = Steinberg::FUID(VST3_CONTROLLER_UID);
496 return static_cast<Steinberg::Vst::IAudioProcessor*
>(
new PLUG_CLASS_NAME(info));
499#error "No API defined!"
502#pragma mark - ** Config Utility **
504static Config MakeConfig(
int nParams,
int nPresets)
506 return Config(nParams, nPresets, PLUG_CHANNEL_IO, PLUG_NAME, PLUG_NAME, PLUG_MFR, PLUG_VERSION_HEX, PLUG_UNIQUE_ID, PLUG_MFR_ID, PLUG_LATENCY, PLUG_DOES_MIDI_IN, PLUG_DOES_MIDI_OUT, PLUG_DOES_MPE, PLUG_DOES_STATE_CHUNKS, PLUG_TYPE, PLUG_HAS_UI, PLUG_WIDTH, PLUG_HEIGHT, PLUG_HOST_RESIZE, PLUG_MIN_WIDTH, PLUG_MAX_WIDTH, PLUG_MIN_HEIGHT, PLUG_MAX_HEIGHT, BUNDLE_ID, APP_GROUP_ID);
524#if !defined NO_IGRAPHICS && !defined VST3P_API
525#include "IGraphics_include_in_plug_src.h"
VST2.4 API base class for an IPlug plug-in.
void EnsureDefaultPreset()
[VST2 only] Called to fill uninitialzed presets