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#elif defined CLAP_API
276#ifndef CLAP_MANUAL_URL
277#define CLAP_MANUAL_URL ""
279#ifndef CLAP_SUPPORT_URL
280#define CLAP_SUPPORT_URL ""
282#ifndef CLAP_DESCRIPTION
283#define CLAP_DESCRIPTION ""
287 #define CLAP_FEATURES CLAP_PLUGIN_FEATURE_AUDIO_EFFECT
289 #define CLAP_FEATURES CLAP_PLUGIN_FEATURE_INSTRUMENT
291 #define CLAP_FEATURES CLAP_PLUGIN_FEATURE_NOTE_EFFECT
295std::string gPluginPath;
296std::unique_ptr<clap_plugin_descriptor> gPluginDesc;
298static bool clap_init(
const char* pluginPath)
302 gPluginPath = pluginPath;
303 gPluginDesc = std::unique_ptr<clap_plugin_descriptor>(
new clap_plugin_descriptor());
307 gPluginDesc->clap_version = CLAP_VERSION;
309 gPluginDesc->id = BUNDLE_DOMAIN
"." BUNDLE_MFR
"." BUNDLE_NAME;
310 gPluginDesc->name = PLUG_NAME;
311 gPluginDesc->vendor = PLUG_MFR;
312 gPluginDesc->url = PLUG_URL_STR;
314 gPluginDesc->manual_url = CLAP_MANUAL_URL;
315 gPluginDesc->version = PLUG_VERSION_STR;
316 gPluginDesc->support_url = CLAP_SUPPORT_URL;
317 gPluginDesc->description = CLAP_DESCRIPTION;
319 static const char *clap_features[] = { CLAP_FEATURES, NULL };
320 gPluginDesc->features = clap_features;
325static void clap_deinit(
void)
328 gPluginDesc =
nullptr;
331static uint32_t clap_get_plugin_count(
const clap_plugin_factory_t *factory)
336static const clap_plugin_descriptor* clap_get_plugin_descriptor(
const clap_plugin_factory_t *factory, uint32_t index)
339 return gPluginDesc.get();
344static const clap_plugin* clap_create_plugin(
const clap_plugin_factory_t *factory,
const clap_host* host,
const char* plugin_id)
346 if (!strcmp(gPluginDesc->id, plugin_id))
348 IPlugCLAP* pPlug = MakePlug(InstanceInfo{gPluginDesc.get(), host});
349 return pPlug->clapPlugin();
355CLAP_EXPORT
const clap_plugin_factory_t clap_factory = {
356 clap_get_plugin_count,
357 clap_get_plugin_descriptor,
361const void *clap_get_factory(
const char *factory_id)
363 if (!::strcmp(factory_id, CLAP_PLUGIN_FACTORY_ID))
364 return &clap_factory;
369CLAP_EXPORT
const clap_plugin_entry_t clap_entry = {
376#elif defined AUv3_API || defined AAX_API || defined APP_API
379 #error "No API defined!"
382#pragma mark - ** Instantiation **
387#pragma mark VST2, VST3, AAX, AUv3, APP, WAM, WEB, CLAP
389#if defined VST2_API || defined VST3_API || defined AAX_API || defined AUv3_API || defined APP_API || defined WAM_API || defined WEB_API || defined CLAP_API
391Plugin* MakePlug(
const iplug::InstanceInfo& info)
394 static WDL_Mutex sMutex;
395 WDL_MutexLock lock(&sMutex);
397 return new PLUG_CLASS_NAME(info);
403Plugin* MakePlug(
void* pMemory)
405 iplug::InstanceInfo info;
406 info.mCocoaViewFactoryClassName.Set(AUV2_VIEW_CLASS_STR);
409 return new(pMemory) PLUG_CLASS_NAME(info);
411 return new PLUG_CLASS_NAME(info);
414#pragma mark - VST3 Controller
415#elif defined VST3C_API
417Steinberg::FUnknown* MakeController()
419 static WDL_Mutex sMutex;
420 WDL_MutexLock lock(&sMutex);
421 iplug::IPlugVST3Controller::InstanceInfo info;
422 info.mOtherGUID = Steinberg::FUID(VST3_PROCESSOR_UID);
426 return static_cast<Steinberg::Vst::IEditController*
>(
new PLUG_CLASS_NAME(info));
429#pragma mark - VST3 Processor
430#elif defined VST3P_API
432Steinberg::FUnknown* MakeProcessor()
434 static WDL_Mutex sMutex;
435 WDL_MutexLock lock(&sMutex);
436 iplug::IPlugVST3Processor::InstanceInfo info;
437 info.mOtherGUID = Steinberg::FUID(VST3_CONTROLLER_UID);
438 return static_cast<Steinberg::Vst::IAudioProcessor*
>(
new PLUG_CLASS_NAME(info));
441#error "No API defined!"
444#pragma mark - ** Config Utility **
446static Config MakeConfig(
int nParams,
int nPresets)
448 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);
466#if !defined NO_IGRAPHICS && !defined VST3P_API
467#include "IGraphics_include_in_plug_src.h"
CLAP API base class for an IPlug plug-in.
VST2.4 API base class for an IPlug plug-in.
void EnsureDefaultPreset()
[VST2 only] Called to fill uninitialzed presets