The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

79 lines
2.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #ifdef _WIN32
  19. #include <windows.h>
  20. HMODULE dlopen (const char* filename, int) { return LoadLibrary (filename); }
  21. FARPROC dlsym (HMODULE handle, const char* name) { return GetProcAddress (handle, name); }
  22. enum { RTLD_LAZY = 0 };
  23. #else
  24. #include <dlfcn.h>
  25. #endif
  26. #include <cstdint>
  27. // Replicating some of the LV2 header here so that we don't have to set up any
  28. // custom include paths for this file.
  29. // Normally this would be a bad idea, but the LV2 API has to keep these definitions
  30. // in order to remain backwards-compatible.
  31. extern "C"
  32. {
  33. typedef struct LV2_Descriptor
  34. {
  35. const void* a;
  36. const void* b;
  37. const void* c;
  38. const void* d;
  39. const void* e;
  40. const void* f;
  41. const void* g;
  42. const void* (*extension_data)(const char* uri);
  43. } LV2_Descriptor;
  44. }
  45. int main (int argc, const char** argv)
  46. {
  47. if (argc != 2)
  48. return 1;
  49. const auto* libraryPath = argv[1];
  50. struct RecallFeature
  51. {
  52. int (*doRecall) (const char*);
  53. };
  54. if (auto* handle = dlopen (libraryPath, RTLD_LAZY))
  55. if (auto* getDescriptor = reinterpret_cast<const LV2_Descriptor* (*) (uint32_t)> (dlsym (handle, "lv2_descriptor")))
  56. if (auto* descriptor = getDescriptor (0))
  57. if (auto* extensionData = descriptor->extension_data)
  58. if (auto* recallFeature = reinterpret_cast<const RecallFeature*> (extensionData ("https://lv2-extensions.juce.com/turtle_recall")))
  59. if (auto* doRecall = recallFeature->doRecall)
  60. return doRecall (libraryPath);
  61. return 1;
  62. }