Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.2KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2013-2022 Filipe Coelho <falktx@falktx.com>
  4. *
  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.
  9. *
  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.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "carla-vst.hpp"
  18. #include "ui_launcher.cpp"
  19. #include "ui_launcher_res.cpp"
  20. #include <cstring>
  21. #include <vector>
  22. #ifdef __WINE__
  23. __cdecl static intptr_t cvst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t index, intptr_t value, void* ptr, float opt)
  24. {
  25. return vst_dispatcherCallback(effect, opcode, index, value, ptr, opt);
  26. }
  27. __cdecl static float cvst_getParameterCallback(AEffect* effect, int32_t index)
  28. {
  29. return vst_getParameterCallback(effect, index);
  30. }
  31. __cdecl static void cvst_setParameterCallback(AEffect* effect, int32_t index, float value)
  32. {
  33. return vst_setParameterCallback(effect, index, value);
  34. }
  35. __cdecl static void cvst_processCallback(AEffect* effect, float** inputs, float** outputs, int32_t sampleFrames)
  36. {
  37. return vst_processCallback(effect, inputs, outputs, sampleFrames);
  38. }
  39. __cdecl static void cvst_processReplacingCallback(AEffect* effect, float** inputs, float** outputs, int32_t sampleFrames)
  40. {
  41. return vst_processReplacingCallback(effect, inputs, outputs, sampleFrames);
  42. }
  43. #endif
  44. static struct CarlaVSTCleanup {
  45. std::vector<AEffect*> effects;
  46. std::vector<VstObject*> objects;
  47. CarlaVSTCleanup()
  48. : effects(),
  49. objects() {}
  50. ~CarlaVSTCleanup()
  51. {
  52. for (std::vector<VstObject*>::iterator it=objects.begin(), end=objects.end(); it != end; ++it)
  53. delete (*it);
  54. for (std::vector<AEffect*>::iterator it=effects.begin(), end=effects.end(); it != end; ++it)
  55. delete (*it);
  56. }
  57. } gCarlaVSTCleanup;
  58. CARLA_PLUGIN_EXPORT __cdecl
  59. const AEffect* VSTPluginMain(audioMasterCallback audioMaster);
  60. CARLA_PLUGIN_EXPORT __cdecl
  61. const AEffect* VSTPluginMain(audioMasterCallback audioMaster)
  62. {
  63. // old version
  64. if (audioMaster(nullptr, audioMasterVersion, 0, 0, nullptr, 0.0f) == 0)
  65. return nullptr;
  66. AEffect* const effect(new AEffect);
  67. std::memset(effect, 0, sizeof(AEffect));
  68. // vst fields
  69. effect->magic = kEffectMagic;
  70. effect->version = CARLA_VERSION_HEX;
  71. // pointers
  72. VstObject* const obj(new VstObject());
  73. obj->audioMaster = (void*)audioMaster;
  74. obj->plugin = nullptr;
  75. effect->object = obj;
  76. gCarlaVSTCleanup.effects.push_back(effect);
  77. gCarlaVSTCleanup.objects.push_back(obj);
  78. // static calls
  79. #ifdef __WINE__
  80. effect->dispatcher = cvst_dispatcherCallback;
  81. effect->getParameter = cvst_getParameterCallback;
  82. effect->setParameter = cvst_setParameterCallback;
  83. effect->process = cvst_processCallback;
  84. effect->processReplacing = cvst_processReplacingCallback;
  85. #else
  86. effect->dispatcher = vst_dispatcherCallback;
  87. effect->process = vst_processCallback;
  88. effect->getParameter = vst_getParameterCallback;
  89. effect->setParameter = vst_setParameterCallback;
  90. effect->processReplacing = vst_processReplacingCallback;
  91. #endif
  92. return VSTPluginMainInit(effect);
  93. }
  94. #if ! (defined(CARLA_OS_MAC) || defined(CARLA_OS_WASM) || defined(CARLA_OS_WIN))
  95. CARLA_PLUGIN_EXPORT __cdecl
  96. const AEffect* VSTPluginMain_asm(audioMasterCallback audioMaster) asm ("main");
  97. CARLA_PLUGIN_EXPORT __cdecl
  98. const AEffect* VSTPluginMain_asm(audioMasterCallback audioMaster)
  99. {
  100. return VSTPluginMain(audioMaster);
  101. }
  102. #endif
  103. intptr_t VSTAudioMaster(AEffect* effect, int32_t opcode, int32_t index, intptr_t value, void* ptr, float opt)
  104. {
  105. const audioMasterCallback audioMaster = (audioMasterCallback)((VstObject*)effect->object)->audioMaster;
  106. return audioMaster(effect, opcode, index, value, ptr, opt);
  107. }
  108. bool isUsingUILauncher()
  109. {
  110. #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
  111. return true;
  112. #else
  113. return false;
  114. #endif
  115. }