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.

147 lines
4.5KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2022 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 "CarlaNativePlugin.h"
  18. #include "CarlaHostImpl.hpp"
  19. #include "CarlaEngine.hpp"
  20. #include "CarlaString.hpp"
  21. #include "water/files/File.h"
  22. // --------------------------------------------------------------------------------------------------------------------
  23. // Expose info functions as needed
  24. #ifndef CARLA_HOST_PLUGIN_BUILD
  25. # include "utils/Information.cpp"
  26. #endif
  27. // --------------------------------------------------------------------------------------------------------------------
  28. CARLA_BACKEND_USE_NAMESPACE
  29. // --------------------------------------------------------------------------------------------------------------------
  30. CarlaHostHandle carla_create_native_plugin_host_handle(const NativePluginDescriptor* desc, NativePluginHandle handle)
  31. {
  32. CarlaEngine* const engine = carla_get_native_plugin_engine(desc, handle);
  33. CARLA_SAFE_ASSERT_RETURN(engine, nullptr);
  34. CarlaHostHandleImpl* hosthandle;
  35. try {
  36. hosthandle = new CarlaHostHandleImpl();
  37. } CARLA_SAFE_EXCEPTION_RETURN("carla_create_native_plugin_host_handle()", nullptr);
  38. hosthandle->engine = engine;
  39. hosthandle->isPlugin = true;
  40. return hosthandle;
  41. }
  42. void carla_host_handle_free(CarlaHostHandle handle)
  43. {
  44. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  45. CARLA_SAFE_ASSERT_RETURN(handle->isPlugin,);
  46. delete (CarlaHostHandleImpl*)handle;
  47. }
  48. // --------------------------------------------------------------------------------------------------------------------
  49. CarlaEngine* carla_get_native_plugin_engine(const NativePluginDescriptor* desc, NativePluginHandle handle)
  50. {
  51. CARLA_SAFE_ASSERT_RETURN(desc != nullptr, nullptr);
  52. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, nullptr);
  53. return (CarlaEngine*)static_cast<uintptr_t>(desc->dispatcher(handle,
  54. NATIVE_PLUGIN_OPCODE_GET_INTERNAL_HANDLE,
  55. 0, 0, nullptr, 0.0f));
  56. }
  57. // --------------------------------------------------------------------------------------------------------------------
  58. // testing purposes only
  59. #if 0
  60. static uint32_t get_buffer_size(NativeHostHandle)
  61. {
  62. return 128;
  63. }
  64. static double get_sample_rate(NativeHostHandle)
  65. {
  66. return 44100.0;
  67. }
  68. static bool is_offline(NativeHostHandle)
  69. {
  70. return false;
  71. }
  72. int main()
  73. {
  74. const char* const filename = carla_get_library_filename();
  75. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', 1);
  76. const char* const folder = carla_get_library_folder();
  77. CARLA_SAFE_ASSERT_RETURN(folder != nullptr && folder[0] != '\0', 1);
  78. const NativePluginDescriptor* const rack = carla_get_native_rack_plugin();
  79. CARLA_SAFE_ASSERT_RETURN(rack != nullptr, 1);
  80. const NativePluginDescriptor* const patchbay = carla_get_native_patchbay_plugin();
  81. CARLA_SAFE_ASSERT_RETURN(patchbay != nullptr, 1);
  82. const NativeHostDescriptor host = {
  83. nullptr,
  84. "", // resourceDir
  85. "Carla Plugin UI",
  86. 0,
  87. get_buffer_size,
  88. get_sample_rate,
  89. is_offline,
  90. nullptr, // get_time_info
  91. nullptr, // write_midi_event
  92. nullptr, // ui_parameter_changed
  93. nullptr, // ui_midi_program_changed
  94. nullptr, // ui_custom_data_changed
  95. nullptr, // ui_closed
  96. nullptr, // ui_open_file
  97. nullptr, // ui_save_file
  98. nullptr, // dispatcher
  99. };
  100. const NativePluginHandle handle = rack->instantiate(&host);
  101. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, 1);
  102. CarlaEngine* const engine = carla_get_native_plugin_engine(rack, handle);
  103. CARLA_SAFE_ASSERT_RETURN(engine != nullptr, 1);
  104. carla_stdout("Got Engine %p, %s, %i, %f",
  105. engine, engine->getName(), engine->getBufferSize(), engine->getSampleRate());
  106. rack->cleanup(handle);
  107. return 0;
  108. }
  109. #endif
  110. // --------------------------------------------------------------------------------------------------------------------