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.

109 lines
3.6KB

  1. /*
  2. * Carla Host Plugin SDL test
  3. * Copyright (C) 2022-2024 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 "CarlaHost.h"
  18. #include "CarlaUtils.h"
  19. #include <emscripten.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. static void engine_idle_loop(void* const arg)
  23. {
  24. const CarlaHostHandle handle = arg;
  25. carla_engine_idle(handle);
  26. /*
  27. static int counter = 0;
  28. if (++counter == 100)
  29. {
  30. counter = 0;
  31. const uint64_t frame = carla_get_current_transport_frame(handle);
  32. printf("engine_idle_loop | play frame %llu | audio peaks %f %f\n",
  33. frame,
  34. carla_get_output_peak_value(handle, 0, true),
  35. carla_get_output_peak_value(handle, 0, false));
  36. }
  37. */
  38. }
  39. int main(void)
  40. {
  41. printf("carla_get_complete_license_text: %s\n", carla_get_complete_license_text());
  42. // printf("carla_get_supported_file_extensions: %s\n", carla_get_supported_file_extensions());
  43. // printf("carla_get_supported_features: %s\n", carla_get_supported_features());
  44. printf("carla_get_library_filename: %s\n", carla_get_library_filename());
  45. printf("carla_get_library_folder: %s\n", carla_get_library_folder());
  46. /*
  47. const uint32_t plugins_count = carla_get_cached_plugin_count(PLUGIN_INTERNAL, NULL);
  48. printf("carla_get_cached_plugin_count: %u\n", plugins_count);
  49. for (uint32_t i=0; i<plugins_count; ++i)
  50. {
  51. const CarlaCachedPluginInfo* const plugin_info = carla_get_cached_plugin_info(PLUGIN_INTERNAL, i);
  52. printf("Loading carla_get_cached_plugin_info #%u '%s'\n", i+1, plugin_info->label);
  53. }
  54. */
  55. const CarlaHostHandle handle = carla_standalone_host_init();
  56. printf("carla_standalone_host_init: %p\n", handle);
  57. carla_set_engine_option(handle, ENGINE_OPTION_PROCESS_MODE, ENGINE_PROCESS_MODE_CONTINUOUS_RACK, NULL);
  58. const bool engine_init = carla_engine_init(handle, "SDL", "Engine Test");
  59. printf("carla_engine_init: %d\n", engine_init);
  60. if (!engine_init)
  61. return 1;
  62. const bool plugin_added = carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, NULL, "Music", "audiofile", 0, NULL, 0x0);
  63. printf("carla_add_plugin: %d\n", plugin_added);
  64. if (!plugin_added)
  65. goto close;
  66. const bool plugin_added2 = carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, NULL, "Gain", "audiogain_s", 0, NULL, 0x0);
  67. printf("carla_add_plugin2: %d\n", plugin_added2);
  68. if (!plugin_added2)
  69. goto close;
  70. const uint32_t current_plugins_count = carla_get_current_plugin_count(handle);
  71. printf("carla_get_current_plugin_count: %u\n", current_plugins_count);
  72. if (current_plugins_count != 2)
  73. goto close;
  74. carla_set_parameter_value(handle, 1, 0, 1.0f); // gain
  75. carla_patchbay_connect(handle, false, 1, 3, 3, 1);
  76. carla_patchbay_connect(handle, false, 1, 4, 3, 2);
  77. carla_set_custom_data(handle, 0, CUSTOM_DATA_TYPE_PATH, "file", "/foolme.mp3");
  78. carla_transport_play(handle);
  79. emscripten_set_main_loop_arg(engine_idle_loop, handle, 0, false);
  80. return 0;
  81. close:
  82. printf("carla_engine_close: %d\n", carla_engine_close(handle));
  83. return 1;
  84. }