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 extern "C" void IPlugWasmUI_ApplyPendingParentWindowResize();
286 EMSCRIPTEN_KEEPALIVE
void iplug_syncfs()
289 if(Module.syncdone == 1) {
291 FS.syncfs(false, function (err) {
293 console.log(
"Synced to IDBFS...");
300 EMSCRIPTEN_KEEPALIVE
void iplug_fsready()
302 gPlug = std::unique_ptr<iplug::IPlugWasmUI>(iplug::MakePlug(iplug::InstanceInfo()));
303 gPlug->SetHost(
"www", 0);
304 gPlug->OpenWindow(
nullptr);
308 IPlugWasmUI_ApplyPendingParentWindowResize();
317 var name =
'/' + UTF8ToString($0) +
'_data';
319 FS.mount(IDBFS, {}, name);
322 FS.syncfs(
true, function (err) {
324 console.log(
"Synced from IDBFS...");
326 ccall(
'iplug_fsready',
'v');
330 StartMainLoopTimer();
338#elif defined CLAP_API
342#ifndef CLAP_MANUAL_URL
343#define CLAP_MANUAL_URL ""
345#ifndef CLAP_SUPPORT_URL
346#define CLAP_SUPPORT_URL ""
348#ifndef CLAP_DESCRIPTION
349#define CLAP_DESCRIPTION ""
353 #define CLAP_FEATURES CLAP_PLUGIN_FEATURE_AUDIO_EFFECT
355 #define CLAP_FEATURES CLAP_PLUGIN_FEATURE_INSTRUMENT
357 #define CLAP_FEATURES CLAP_PLUGIN_FEATURE_NOTE_EFFECT
361std::string gPluginPath;
362std::unique_ptr<clap_plugin_descriptor> gPluginDesc;
364static bool clap_init(
const char* pluginPath)
368 gPluginPath = pluginPath;
369 gPluginDesc = std::unique_ptr<clap_plugin_descriptor>(
new clap_plugin_descriptor());
373 gPluginDesc->clap_version = CLAP_VERSION;
375 gPluginDesc->id = BUNDLE_DOMAIN
"." BUNDLE_MFR
"." BUNDLE_NAME;
376 gPluginDesc->name = PLUG_NAME;
377 gPluginDesc->vendor = PLUG_MFR;
378 gPluginDesc->url = PLUG_URL_STR;
380 gPluginDesc->manual_url = CLAP_MANUAL_URL;
381 gPluginDesc->version = PLUG_VERSION_STR;
382 gPluginDesc->support_url = CLAP_SUPPORT_URL;
383 gPluginDesc->description = CLAP_DESCRIPTION;
385 static const char *clap_features[] = { CLAP_FEATURES, NULL };
386 gPluginDesc->features = clap_features;
391static void clap_deinit(
void)
394 gPluginDesc =
nullptr;
397static uint32_t clap_get_plugin_count(
const clap_plugin_factory_t *factory)
402static const clap_plugin_descriptor* clap_get_plugin_descriptor(
const clap_plugin_factory_t *factory, uint32_t index)
405 return gPluginDesc.get();
410static const clap_plugin* clap_create_plugin(
const clap_plugin_factory_t *factory,
const clap_host* host,
const char* plugin_id)
412 if (!strcmp(gPluginDesc->id, plugin_id))
414 iplug::IPlugCLAP* pPlug = iplug::MakePlug(iplug::InstanceInfo{gPluginDesc.get(), host});
415 return pPlug->clapPlugin();
421CLAP_EXPORT
const clap_plugin_factory_t clap_factory = {
422 clap_get_plugin_count,
423 clap_get_plugin_descriptor,
427const void *clap_get_factory(
const char *factory_id)
429 if (!::strcmp(factory_id, CLAP_PLUGIN_FACTORY_ID))
430 return &clap_factory;
435CLAP_EXPORT
const clap_plugin_entry_t clap_entry = {
442#elif defined AUv3_API || defined AAX_API || defined APP_API || defined WAM_API || defined WEB_API || defined WASM_DSP_API || defined WASM_UI_API
445 #error "No API defined!"
448#pragma mark - ** Instantiation **
453#pragma mark VST2, VST3, AAX, AUv3, APP, WAM, WEB, CLAP
455#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
457Plugin* MakePlug(
const iplug::InstanceInfo& info)
460 static WDL_Mutex sMutex;
461 WDL_MutexLock lock(&sMutex);
463 return new PLUG_CLASS_NAME(info);
469Plugin* MakePlug(
void* pMemory)
471 iplug::InstanceInfo info;
472 info.mCocoaViewFactoryClassName.Set(AUV2_VIEW_CLASS_STR);
475 return new(pMemory) PLUG_CLASS_NAME(info);
477 return new PLUG_CLASS_NAME(info);
480#pragma mark - VST3 Controller
481#elif defined VST3C_API
483Steinberg::FUnknown* MakeController()
485 static WDL_Mutex sMutex;
486 WDL_MutexLock lock(&sMutex);
487 iplug::IPlugVST3Controller::InstanceInfo info;
488 info.mOtherGUID = Steinberg::FUID(VST3_PROCESSOR_UID);
492 return static_cast<Steinberg::Vst::IEditController*
>(
new PLUG_CLASS_NAME(info));
495#pragma mark - VST3 Processor
496#elif defined VST3P_API
498Steinberg::FUnknown* MakeProcessor()
500 static WDL_Mutex sMutex;
501 WDL_MutexLock lock(&sMutex);
502 iplug::IPlugVST3Processor::InstanceInfo info;
503 info.mOtherGUID = Steinberg::FUID(VST3_CONTROLLER_UID);
504 return static_cast<Steinberg::Vst::IAudioProcessor*
>(
new PLUG_CLASS_NAME(info));
507#error "No API defined!"
510#pragma mark - ** Config Utility **
512static Config MakeConfig(
int nParams,
int nPresets)
514 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);
532#if !defined NO_IGRAPHICS && !defined VST3P_API
533#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