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.

108 lines
3.3KB

  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 "CarlaEngine.hpp"
  19. #include "CarlaString.hpp"
  20. #include "water/files/File.h"
  21. CARLA_BACKEND_USE_NAMESPACE
  22. // --------------------------------------------------------------------------------------------------------------------
  23. CarlaEngine* carla_get_native_plugin_engine(const NativePluginDescriptor* desc, NativePluginHandle handle)
  24. {
  25. CARLA_SAFE_ASSERT_RETURN(desc != nullptr, nullptr);
  26. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, nullptr);
  27. return (CarlaEngine*)static_cast<uintptr_t>(desc->dispatcher(handle,
  28. NATIVE_PLUGIN_OPCODE_GET_INTERNAL_HANDLE,
  29. 0, 0, nullptr, 0.0f));
  30. }
  31. // --------------------------------------------------------------------------------------------------------------------
  32. static uint32_t get_buffer_size(NativeHostHandle)
  33. {
  34. return 128;
  35. }
  36. static double get_sample_rate(NativeHostHandle)
  37. {
  38. return 44100.0;
  39. }
  40. static bool is_offline(NativeHostHandle)
  41. {
  42. return false;
  43. }
  44. int main()
  45. {
  46. const char* const filename = carla_get_library_filename();
  47. CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', 1);
  48. const char* const folder = carla_get_library_folder();
  49. CARLA_SAFE_ASSERT_RETURN(folder != nullptr && folder[0] != '\0', 1);
  50. const NativePluginDescriptor* const rack = carla_get_native_rack_plugin();
  51. CARLA_SAFE_ASSERT_RETURN(rack != nullptr, 1);
  52. const NativePluginDescriptor* const patchbay = carla_get_native_patchbay_plugin();
  53. CARLA_SAFE_ASSERT_RETURN(patchbay != nullptr, 1);
  54. const NativeHostDescriptor host = {
  55. nullptr,
  56. "", // resourceDir
  57. "Carla Plugin UI",
  58. 0,
  59. get_buffer_size,
  60. get_sample_rate,
  61. is_offline,
  62. nullptr, // get_time_info
  63. nullptr, // write_midi_event
  64. nullptr, // ui_parameter_changed
  65. nullptr, // ui_midi_program_changed
  66. nullptr, // ui_custom_data_changed
  67. nullptr, // ui_closed
  68. nullptr, // ui_open_file
  69. nullptr, // ui_save_file
  70. nullptr, // dispatcher
  71. };
  72. const NativePluginHandle handle = rack->instantiate(&host);
  73. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, 1);
  74. CarlaEngine* const engine = carla_get_native_plugin_engine(rack, handle);
  75. CARLA_SAFE_ASSERT_RETURN(engine != nullptr, 1);
  76. carla_stdout("Got Engine %p, %s, %i, %f",
  77. engine, engine->getName(), engine->getBufferSize(), engine->getSampleRate());
  78. rack->cleanup(handle);
  79. return 0;
  80. }
  81. // --------------------------------------------------------------------------------------------------------------------