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-bridged.cpp 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 "CarlaLibUtils.hpp"
  18. #include "vestige/vestige.h"
  19. #ifdef __WINE__
  20. #error This file is not meant to be used by wine!
  21. #endif
  22. #ifndef CARLA_OS_WIN
  23. #error This file is only meant to be used by mingw compilers!
  24. #endif
  25. #ifndef CARLA_PLUGIN_SYNTH
  26. #error CARLA_PLUGIN_SYNTH undefined
  27. #endif
  28. typedef const AEffect* (__cdecl *MainCallback)(audioMasterCallback);
  29. static HINSTANCE currentModuleHandle = nullptr;
  30. static HINSTANCE getCurrentModuleInstanceHandle() noexcept
  31. {
  32. if (currentModuleHandle == nullptr)
  33. currentModuleHandle = GetModuleHandleA(nullptr);
  34. return currentModuleHandle;
  35. }
  36. CARLA_PLUGIN_EXPORT
  37. BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID)
  38. {
  39. if (reason == DLL_PROCESS_ATTACH)
  40. currentModuleHandle = hInst;
  41. return 1;
  42. }
  43. CARLA_PLUGIN_EXPORT __cdecl
  44. const AEffect* VSTPluginMain(audioMasterCallback audioMaster)
  45. {
  46. static MainCallback sCallback = nullptr;
  47. if (sCallback == nullptr)
  48. {
  49. CHAR filename[MAX_PATH + 256];
  50. filename[0] = 0;
  51. GetModuleFileName(getCurrentModuleInstanceHandle(), filename, MAX_PATH + 256);
  52. strcat(filename, ".so");
  53. carla_stdout("FILENAME: '%s'", filename);
  54. static const lib_t lib = lib_open(filename);
  55. if (lib == nullptr)
  56. {
  57. carla_stderr2("lib_open failed: %s", lib_error(filename));
  58. return nullptr;
  59. }
  60. sCallback = lib_symbol<MainCallback>(lib, "VSTPluginMain");
  61. }
  62. CARLA_SAFE_ASSERT_RETURN(sCallback != nullptr, nullptr);
  63. return sCallback(audioMaster);
  64. }