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.

carla-utils.cpp 4.0KB

6 years ago
6 years ago
6 years ago
6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Carla REST API Server
  3. * Copyright (C) 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 "common.hpp"
  18. #include "CarlaUtils.h"
  19. // -------------------------------------------------------------------------------------------------------------------
  20. void handle_carla_get_complete_license_text(const std::shared_ptr<Session> session)
  21. {
  22. const char* const buf = str_buf_string(carla_get_complete_license_text());
  23. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  24. }
  25. void handle_carla_get_supported_file_extensions(const std::shared_ptr<Session> session)
  26. {
  27. const char* const buf = str_buf_string_array(carla_get_supported_file_extensions());
  28. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  29. }
  30. void handle_carla_get_supported_features(const std::shared_ptr<Session> session)
  31. {
  32. const char* const buf = str_buf_string_array(carla_get_supported_features());
  33. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  34. }
  35. void handle_carla_get_cached_plugin_count(const std::shared_ptr<Session> session)
  36. {
  37. const std::shared_ptr<const Request> request = session->get_request();
  38. const int ptype = std::atoi(request->get_query_parameter("ptype").c_str());
  39. CARLA_SAFE_ASSERT_RETURN(ptype >= PLUGIN_NONE && ptype <= PLUGIN_JACK,)
  40. const std::string pluginPath = request->get_query_parameter("pluginPath");
  41. const char* const buf = str_buf_uint(carla_get_cached_plugin_count(static_cast<PluginType>(ptype),
  42. pluginPath.c_str()));
  43. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  44. }
  45. void handle_carla_get_cached_plugin_info(const std::shared_ptr<Session> session)
  46. {
  47. const std::shared_ptr<const Request> request = session->get_request();
  48. const int ptype = std::atoi(request->get_query_parameter("ptype").c_str());
  49. CARLA_SAFE_ASSERT_RETURN(ptype >= PLUGIN_NONE && ptype <= PLUGIN_JACK,)
  50. const int index = std::atoi(request->get_query_parameter("index").c_str());
  51. CARLA_SAFE_ASSERT_RETURN(index >= 0 /*&& index < INT_MAX*/,)
  52. const CarlaCachedPluginInfo* const info = carla_get_cached_plugin_info(static_cast<PluginType>(ptype),
  53. static_cast<uint>(index));
  54. char* jsonBuf;
  55. jsonBuf = json_buf_start();
  56. jsonBuf = json_buf_add_bool(jsonBuf, "valid", info->valid);
  57. jsonBuf = json_buf_add_uint(jsonBuf, "category", info->category);
  58. jsonBuf = json_buf_add_uint(jsonBuf, "hints", info->hints);
  59. jsonBuf = json_buf_add_uint(jsonBuf, "audioIns", info->audioIns);
  60. jsonBuf = json_buf_add_uint(jsonBuf, "audioOuts", info->audioOuts);
  61. jsonBuf = json_buf_add_uint(jsonBuf, "midiIns", info->midiIns);
  62. jsonBuf = json_buf_add_uint(jsonBuf, "midiOuts", info->midiOuts);
  63. jsonBuf = json_buf_add_uint(jsonBuf, "parameterIns", info->parameterIns);
  64. jsonBuf = json_buf_add_uint(jsonBuf, "parameterOuts", info->parameterOuts);
  65. jsonBuf = json_buf_add_string(jsonBuf, "name", info->name);
  66. jsonBuf = json_buf_add_string(jsonBuf, "label", info->label);
  67. jsonBuf = json_buf_add_string(jsonBuf, "maker", info->maker);
  68. jsonBuf = json_buf_add_string(jsonBuf, "copyright", info->copyright);
  69. const char* const buf = json_buf_end(jsonBuf);
  70. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  71. }
  72. // -------------------------------------------------------------------------------------------------------------------