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.

76 lines
2.1KB

  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 "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_EXPORT
  37. BOOL WINAPI DllMain(HINSTANCE hInst, DWORD, LPVOID)
  38. {
  39. currentModuleHandle = hInst;
  40. return 1;
  41. }
  42. CARLA_EXPORT __cdecl
  43. const AEffect* VSTPluginMain(audioMasterCallback audioMaster)
  44. {
  45. static MainCallback sCallback = nullptr;
  46. if (sCallback == nullptr)
  47. {
  48. CHAR filename[MAX_PATH + 256];
  49. filename[0] = 0;
  50. GetModuleFileName(getCurrentModuleInstanceHandle(), filename, MAX_PATH + 256);
  51. strcat(filename, ".so");
  52. carla_stdout("FILENAME: '%s'", filename);
  53. static const lib_t lib = lib_open(filename);
  54. if (lib == nullptr)
  55. {
  56. carla_stderr2("lib_open failed: %s", lib_error(filename));
  57. return nullptr;
  58. }
  59. sCallback = lib_symbol<MainCallback>(lib, "VSTPluginMain");
  60. }
  61. CARLA_SAFE_ASSERT_RETURN(sCallback != nullptr, nullptr);
  62. return sCallback(audioMaster);
  63. }