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.

110 lines
3.7KB

  1. /*
  2. * Carla Host Plugin SDL test
  3. * Copyright (C) 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 "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_juce_version: %s\n", carla_get_juce_version());
  43. // printf("carla_get_supported_file_extensions: %s\n", carla_get_supported_file_extensions());
  44. // printf("carla_get_supported_features: %s\n", carla_get_supported_features());
  45. printf("carla_get_library_filename: %s\n", carla_get_library_filename());
  46. printf("carla_get_library_folder: %s\n", carla_get_library_folder());
  47. /*
  48. const uint32_t plugins_count = carla_get_cached_plugin_count(PLUGIN_INTERNAL, NULL);
  49. printf("carla_get_cached_plugin_count: %u\n", plugins_count);
  50. for (uint32_t i=0; i<plugins_count; ++i)
  51. {
  52. const CarlaCachedPluginInfo* const plugin_info = carla_get_cached_plugin_info(PLUGIN_INTERNAL, i);
  53. printf("Loading carla_get_cached_plugin_info #%u '%s'\n", i+1, plugin_info->label);
  54. }
  55. */
  56. const CarlaHostHandle handle = carla_standalone_host_init();
  57. printf("carla_standalone_host_init: %p\n", handle);
  58. carla_set_engine_option(handle, ENGINE_OPTION_PROCESS_MODE, ENGINE_PROCESS_MODE_CONTINUOUS_RACK, NULL);
  59. const bool engine_init = carla_engine_init(handle, "SDL", "Engine Test");
  60. printf("carla_engine_init: %d\n", engine_init);
  61. if (!engine_init)
  62. return 1;
  63. const bool plugin_added = carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, NULL, "Music", "audiofile", 0, NULL, 0x0);
  64. printf("carla_add_plugin: %d\n", plugin_added);
  65. if (!plugin_added)
  66. goto close;
  67. const bool plugin_added2 = carla_add_plugin(handle, BINARY_NATIVE, PLUGIN_INTERNAL, NULL, "Gain", "audiogain_s", 0, NULL, 0x0);
  68. printf("carla_add_plugin2: %d\n", plugin_added2);
  69. if (!plugin_added2)
  70. goto close;
  71. const uint32_t current_plugins_count = carla_get_current_plugin_count(handle);
  72. printf("carla_get_current_plugin_count: %u\n", current_plugins_count);
  73. if (current_plugins_count != 2)
  74. goto close;
  75. carla_set_parameter_value(handle, 1, 0, 1.0f); // gain
  76. carla_patchbay_connect(handle, false, 1, 3, 3, 1);
  77. carla_patchbay_connect(handle, false, 1, 4, 3, 2);
  78. carla_set_custom_data(handle, 0, CUSTOM_DATA_TYPE_PATH, "file", "/foolme.mp3");
  79. carla_transport_play(handle);
  80. emscripten_set_main_loop_arg(engine_idle_loop, handle, 0, false);
  81. return 0;
  82. close:
  83. printf("carla_engine_close: %d\n", carla_engine_close(handle));
  84. return 1;
  85. }