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.

72 lines
2.3KB

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