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.

132 lines
4.0KB

  1. // SPDX-FileCopyrightText: 2011-2025 Filipe Coelho <falktx@falktx.com>
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "CarlaNativePlugin.h"
  4. #include "CarlaHostImpl.hpp"
  5. #include "CarlaEngine.hpp"
  6. #include "water/files/File.h"
  7. // --------------------------------------------------------------------------------------------------------------------
  8. // Expose info functions as needed
  9. #ifndef CARLA_HOST_PLUGIN_BUILD
  10. # include "utils/Information.cpp"
  11. #endif
  12. // --------------------------------------------------------------------------------------------------------------------
  13. CARLA_BACKEND_USE_NAMESPACE
  14. // --------------------------------------------------------------------------------------------------------------------
  15. CarlaHostHandle carla_create_native_plugin_host_handle(const NativePluginDescriptor* desc, NativePluginHandle handle)
  16. {
  17. CarlaEngine* const engine = carla_get_native_plugin_engine(desc, handle);
  18. CARLA_SAFE_ASSERT_RETURN(engine, nullptr);
  19. CarlaHostHandleImpl* hosthandle;
  20. try {
  21. hosthandle = new CarlaHostHandleImpl();
  22. } CARLA_SAFE_EXCEPTION_RETURN("carla_create_native_plugin_host_handle()", nullptr);
  23. hosthandle->engine = engine;
  24. hosthandle->isPlugin = true;
  25. return hosthandle;
  26. }
  27. void carla_host_handle_free(CarlaHostHandle handle)
  28. {
  29. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  30. CARLA_SAFE_ASSERT_RETURN(handle->isPlugin,);
  31. delete (CarlaHostHandleImpl*)handle;
  32. }
  33. // --------------------------------------------------------------------------------------------------------------------
  34. CarlaEngine* carla_get_native_plugin_engine(const NativePluginDescriptor* desc, NativePluginHandle handle)
  35. {
  36. CARLA_SAFE_ASSERT_RETURN(desc != nullptr, nullptr);
  37. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, nullptr);
  38. return (CarlaEngine*)static_cast<uintptr_t>(desc->dispatcher(handle,
  39. NATIVE_PLUGIN_OPCODE_GET_INTERNAL_HANDLE,
  40. 0, 0, nullptr, 0.0f));
  41. }
  42. // --------------------------------------------------------------------------------------------------------------------
  43. // testing purposes only
  44. #if 0
  45. static uint32_t get_buffer_size(NativeHostHandle)
  46. {
  47. return 128;
  48. }
  49. static double get_sample_rate(NativeHostHandle)
  50. {
  51. return 44100.0;
  52. }
  53. static bool is_offline(NativeHostHandle)
  54. {
  55. return false;
  56. }
  57. int main()
  58. {
  59. const char* const filename = carla_get_library_filename();
  60. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', 1);
  61. const char* const folder = carla_get_library_folder();
  62. CARLA_SAFE_ASSERT_RETURN(folder != nullptr && folder[0] != '\0', 1);
  63. const NativePluginDescriptor* const rack = carla_get_native_rack_plugin();
  64. CARLA_SAFE_ASSERT_RETURN(rack != nullptr, 1);
  65. const NativePluginDescriptor* const patchbay = carla_get_native_patchbay_plugin();
  66. CARLA_SAFE_ASSERT_RETURN(patchbay != nullptr, 1);
  67. const NativeHostDescriptor host = {
  68. nullptr,
  69. "", // resourceDir
  70. "Carla Plugin UI",
  71. 0,
  72. get_buffer_size,
  73. get_sample_rate,
  74. is_offline,
  75. nullptr, // get_time_info
  76. nullptr, // write_midi_event
  77. nullptr, // ui_parameter_changed
  78. nullptr, // ui_midi_program_changed
  79. nullptr, // ui_custom_data_changed
  80. nullptr, // ui_closed
  81. nullptr, // ui_open_file
  82. nullptr, // ui_save_file
  83. nullptr, // dispatcher
  84. };
  85. const NativePluginHandle handle = rack->instantiate(&host);
  86. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, 1);
  87. CarlaEngine* const engine = carla_get_native_plugin_engine(rack, handle);
  88. CARLA_SAFE_ASSERT_RETURN(engine != nullptr, 1);
  89. carla_stdout("Got Engine %p, %s, %i, %f",
  90. engine, engine->getName(), engine->getBufferSize(), engine->getSampleRate());
  91. rack->cleanup(handle);
  92. return 0;
  93. }
  94. #endif
  95. // --------------------------------------------------------------------------------------------------------------------