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.

103 lines
3.1KB

  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. #include <cstdint>
  19. #include <cstdio>
  20. #ifdef _WIN32
  21. #include <windows.h>
  22. #include <tchar.h>
  23. HMODULE dlopen (const char* filename, int) { return LoadLibrary (filename); }
  24. FARPROC dlsym (HMODULE handle, const char* name) { return GetProcAddress (handle, name); }
  25. void printError()
  26. {
  27. constexpr DWORD numElements = 256;
  28. TCHAR messageBuffer[numElements]{};
  29. FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
  30. nullptr,
  31. GetLastError(),
  32. MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
  33. messageBuffer,
  34. numElements - 1,
  35. nullptr);
  36. _tprintf ("%s", messageBuffer);
  37. }
  38. enum { RTLD_LAZY = 0 };
  39. #else
  40. #include <dlfcn.h>
  41. void printError() { printf ("%s\n", dlerror()); }
  42. #endif
  43. // Replicating part of the LV2 header here so that we don't have to set up any
  44. // custom include paths for this file.
  45. // Normally this would be a bad idea, but the LV2 API has to keep these definitions
  46. // in order to remain backwards-compatible.
  47. extern "C"
  48. {
  49. typedef struct LV2_Descriptor
  50. {
  51. const void* a;
  52. const void* b;
  53. const void* c;
  54. const void* d;
  55. const void* e;
  56. const void* f;
  57. const void* g;
  58. const void* (*extension_data)(const char* uri);
  59. } LV2_Descriptor;
  60. }
  61. int main (int argc, const char** argv)
  62. {
  63. if (argc != 2)
  64. return 1;
  65. const auto* libraryPath = argv[1];
  66. struct RecallFeature
  67. {
  68. int (*doRecall) (const char*);
  69. };
  70. if (auto* handle = dlopen (libraryPath, RTLD_LAZY))
  71. {
  72. if (auto* getDescriptor = reinterpret_cast<const LV2_Descriptor* (*) (uint32_t)> (dlsym (handle, "lv2_descriptor")))
  73. if (auto* descriptor = getDescriptor (0))
  74. if (auto* extensionData = descriptor->extension_data)
  75. if (auto* recallFeature = reinterpret_cast<const RecallFeature*> (extensionData ("https://lv2-extensions.juce.com/turtle_recall")))
  76. if (auto* doRecall = recallFeature->doRecall)
  77. return doRecall (libraryPath);
  78. }
  79. else
  80. {
  81. printError();
  82. }
  83. return 1;
  84. }