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.

135 lines
4.2KB

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