Fix potential wrong-over-optimization in math utilities
[carla.git] / source / plugin / carla-vst-export.cpp
bloba5ba792117d5db6b68fa8f54bd56cce21766b43f
1 /*
2 * Carla Native Plugins
3 * Copyright (C) 2013-2022 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "carla-vst.hpp"
20 #include "ui_launcher.cpp"
21 #include "ui_launcher_res.cpp"
23 #include <cstring>
24 #include <vector>
26 #ifdef __WINE__
27 __cdecl static intptr_t cvst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t index, intptr_t value, void* ptr, float opt)
29 return vst_dispatcherCallback(effect, opcode, index, value, ptr, opt);
32 __cdecl static float cvst_getParameterCallback(AEffect* effect, int32_t index)
34 return vst_getParameterCallback(effect, index);
37 __cdecl static void cvst_setParameterCallback(AEffect* effect, int32_t index, float value)
39 return vst_setParameterCallback(effect, index, value);
42 __cdecl static void cvst_processCallback(AEffect* effect, float** inputs, float** outputs, int32_t sampleFrames)
44 return vst_processCallback(effect, inputs, outputs, sampleFrames);
47 __cdecl static void cvst_processReplacingCallback(AEffect* effect, float** inputs, float** outputs, int32_t sampleFrames)
49 return vst_processReplacingCallback(effect, inputs, outputs, sampleFrames);
51 #endif
53 static struct CarlaVSTCleanup {
54 std::vector<AEffect*> effects;
55 std::vector<VstObject*> objects;
57 CarlaVSTCleanup()
58 : effects(),
59 objects() {}
61 ~CarlaVSTCleanup()
63 for (std::vector<VstObject*>::iterator it=objects.begin(), end=objects.end(); it != end; ++it)
64 delete (*it);
66 for (std::vector<AEffect*>::iterator it=effects.begin(), end=effects.end(); it != end; ++it)
67 delete (*it);
69 } gCarlaVSTCleanup;
71 CARLA_PLUGIN_EXPORT __cdecl
72 const AEffect* VSTPluginMain(audioMasterCallback audioMaster);
74 CARLA_PLUGIN_EXPORT __cdecl
75 const AEffect* VSTPluginMain(audioMasterCallback audioMaster)
77 // old version
78 if (audioMaster(nullptr, audioMasterVersion, 0, 0, nullptr, 0.0f) == 0)
79 return nullptr;
81 AEffect* const effect(new AEffect);
82 std::memset(effect, 0, sizeof(AEffect));
84 // vst fields
85 effect->magic = kEffectMagic;
86 effect->version = CARLA_VERSION_HEX;
88 // pointers
89 VstObject* const obj(new VstObject());
90 obj->audioMaster = (void*)audioMaster;
91 obj->plugin = nullptr;
92 effect->object = obj;
94 gCarlaVSTCleanup.effects.push_back(effect);
95 gCarlaVSTCleanup.objects.push_back(obj);
97 // static calls
98 #ifdef __WINE__
99 effect->dispatcher = cvst_dispatcherCallback;
100 effect->getParameter = cvst_getParameterCallback;
101 effect->setParameter = cvst_setParameterCallback;
102 effect->process = cvst_processCallback;
103 effect->processReplacing = cvst_processReplacingCallback;
104 #else
105 effect->dispatcher = vst_dispatcherCallback;
106 effect->process = vst_processCallback;
107 effect->getParameter = vst_getParameterCallback;
108 effect->setParameter = vst_setParameterCallback;
109 effect->processReplacing = vst_processReplacingCallback;
110 #endif
112 return VSTPluginMainInit(effect);
115 #if ! (defined(CARLA_OS_MAC) || defined(CARLA_OS_WASM) || defined(CARLA_OS_WIN))
116 CARLA_PLUGIN_EXPORT __cdecl
117 const AEffect* VSTPluginMain_asm(audioMasterCallback audioMaster) asm ("main");
119 CARLA_PLUGIN_EXPORT __cdecl
120 const AEffect* VSTPluginMain_asm(audioMasterCallback audioMaster)
122 return VSTPluginMain(audioMaster);
124 #endif
126 intptr_t VSTAudioMaster(AEffect* effect, int32_t opcode, int32_t index, intptr_t value, void* ptr, float opt)
128 const audioMasterCallback audioMaster = (audioMasterCallback)((VstObject*)effect->object)->audioMaster;
129 return audioMaster(effect, opcode, index, value, ptr, opt);
132 bool isUsingUILauncher()
134 #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
135 return true;
136 #else
137 return false;
138 #endif