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.

carla-vst-export.cpp 4.1KB

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