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.

1215 lines
47KB

  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 "CarlaHost.h"
  19. #include "CarlaBackendUtils.hpp"
  20. // -------------------------------------------------------------------------------------------------------------------
  21. static bool gEngineRunning = false;
  22. void engine_idle_handler()
  23. {
  24. if (gEngineRunning)
  25. carla_engine_idle();
  26. }
  27. // -------------------------------------------------------------------------------------------------------------------
  28. static void EngineCallback(void* ptr, EngineCallbackOpcode action, uint pluginId, int value1, int value2, float value3, const char* valueStr)
  29. {
  30. #if 0
  31. carla_stdout("EngineCallback(%p, %u:%s, %u, %i, %i, %f, %s)",
  32. ptr, (uint)action, EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  33. #endif
  34. char msgBuf[1024];
  35. std::snprintf(msgBuf, 1023, "Carla: %u %u %i %i %f %s\n", action, pluginId, value1, value2, value3, valueStr);
  36. msgBuf[1023] = '\0';
  37. switch (action)
  38. {
  39. case ENGINE_CALLBACK_ENGINE_STARTED:
  40. gEngineRunning = true;
  41. break;
  42. case ENGINE_CALLBACK_ENGINE_STOPPED:
  43. case ENGINE_CALLBACK_QUIT:
  44. gEngineRunning = false;
  45. break;
  46. default:
  47. break;
  48. }
  49. send_server_side_message(msgBuf);
  50. }
  51. static const char* FileCallback(void* ptr, FileCallbackOpcode action, bool isDir, const char* title, const char* filter)
  52. {
  53. carla_stdout("FileCallback(%p, %u:%s, %s, %s, %s)",
  54. ptr, (uint)action, FileCallbackOpcode(action), bool2str(isDir), title, filter);
  55. char msgBuf[1024];
  56. std::snprintf(msgBuf, 1023, "fc %u %i \"%s\" \"%s\"", action, isDir, title, filter);
  57. msgBuf[1023] = '\0';
  58. send_server_side_message(msgBuf);
  59. // FIXME, need to wait for response!
  60. return nullptr;
  61. }
  62. // -------------------------------------------------------------------------------------------------------------------
  63. void handle_carla_get_engine_driver_count(const std::shared_ptr<Session> session)
  64. {
  65. const char* const buf = str_buf_uint(carla_get_engine_driver_count());
  66. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  67. }
  68. void handle_carla_get_engine_driver_name(const std::shared_ptr<Session> session)
  69. {
  70. const std::shared_ptr<const Request> request = session->get_request();
  71. const int index = std::atoi(request->get_query_parameter("index").c_str());
  72. CARLA_SAFE_ASSERT_RETURN(index >= 0 /*&& index < INT_MAX*/,)
  73. const char* const buf = str_buf_string(carla_get_engine_driver_name(index));
  74. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  75. }
  76. void handle_carla_get_engine_driver_device_names(const std::shared_ptr<Session> session)
  77. {
  78. const std::shared_ptr<const Request> request = session->get_request();
  79. const int index = std::atoi(request->get_query_parameter("index").c_str());
  80. CARLA_SAFE_ASSERT_RETURN(index >= 0 /*&& index < INT_MAX*/,)
  81. const char* const buf = str_buf_string_array(carla_get_engine_driver_device_names(index));
  82. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  83. }
  84. void handle_carla_get_engine_driver_device_info(const std::shared_ptr<Session> session)
  85. {
  86. const std::shared_ptr<const Request> request = session->get_request();
  87. const int index = std::atoi(request->get_query_parameter("index").c_str());
  88. CARLA_SAFE_ASSERT_RETURN(index >= 0 /*&& index < INT_MAX*/,)
  89. const std::string name = request->get_query_parameter("name");
  90. const EngineDriverDeviceInfo* const info = carla_get_engine_driver_device_info(index, name.c_str());
  91. char* jsonBuf;
  92. jsonBuf = json_buf_start();
  93. jsonBuf = json_buf_add_uint(jsonBuf, "hints", info->hints);
  94. jsonBuf = json_buf_add_uint_array(jsonBuf, "bufferSizes", info->bufferSizes);
  95. jsonBuf = json_buf_add_float_array(jsonBuf, "sampleRates", info->sampleRates);
  96. const char* const buf = json_buf_end(jsonBuf);
  97. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  98. }
  99. // -------------------------------------------------------------------------------------------------------------------
  100. void handle_carla_engine_init(const std::shared_ptr<Session> session)
  101. {
  102. // setup callbacks
  103. carla_set_engine_callback(EngineCallback, nullptr);
  104. carla_set_file_callback(FileCallback, nullptr);
  105. // handle request now
  106. const std::shared_ptr<const Request> request = session->get_request();
  107. const std::string driverName = request->get_query_parameter("driverName");
  108. const std::string clientName = request->get_query_parameter("clientName");
  109. const char* const buf = str_buf_bool(carla_engine_init(driverName.c_str(), clientName.c_str()));
  110. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  111. }
  112. void handle_carla_engine_close(const std::shared_ptr<Session> session)
  113. {
  114. const char* const buf = str_buf_bool(carla_engine_close());
  115. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  116. }
  117. void handle_carla_is_engine_running(const std::shared_ptr<Session> session)
  118. {
  119. const char* const buf = str_buf_bool(carla_is_engine_running());
  120. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  121. }
  122. void handle_carla_set_engine_about_to_close(const std::shared_ptr<Session> session)
  123. {
  124. const char* const buf = str_buf_bool(carla_set_engine_about_to_close());
  125. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  126. }
  127. // -------------------------------------------------------------------------------------------------------------------
  128. void handle_carla_set_engine_option(const std::shared_ptr<Session> session)
  129. {
  130. const std::shared_ptr<const Request> request = session->get_request();
  131. const int option = std::atol(request->get_query_parameter("option").c_str());
  132. CARLA_SAFE_ASSERT_RETURN(option >= ENGINE_OPTION_DEBUG && option < ENGINE_OPTION_DEBUG_CONSOLE_OUTPUT,)
  133. const int value = std::atol(request->get_query_parameter("value").c_str());
  134. CARLA_SAFE_ASSERT_RETURN(value >= 0,)
  135. const std::string valueStr = request->get_query_parameter("valueStr");
  136. carla_set_engine_option(static_cast<EngineOption>(option), value, valueStr.c_str());
  137. session->close(OK);
  138. }
  139. // -------------------------------------------------------------------------------------------------------------------
  140. void handle_carla_load_file(const std::shared_ptr<Session> session)
  141. {
  142. const std::shared_ptr<const Request> request = session->get_request();
  143. const std::string filename = request->get_query_parameter("filename");
  144. const char* const buf = str_buf_bool(carla_load_file(filename.c_str()));
  145. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  146. }
  147. void handle_carla_load_project(const std::shared_ptr<Session> session)
  148. {
  149. const std::shared_ptr<const Request> request = session->get_request();
  150. const std::string filename = request->get_query_parameter("filename");
  151. const char* const buf = str_buf_bool(carla_load_project(filename.c_str()));
  152. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  153. }
  154. void handle_carla_save_project(const std::shared_ptr<Session> session)
  155. {
  156. const std::shared_ptr<const Request> request = session->get_request();
  157. const std::string filename = request->get_query_parameter("filename");
  158. const char* const buf = str_buf_bool(carla_save_project(filename.c_str()));
  159. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  160. }
  161. // -------------------------------------------------------------------------------------------------------------------
  162. void handle_carla_patchbay_connect(const std::shared_ptr<Session> session)
  163. {
  164. const std::shared_ptr<const Request> request = session->get_request();
  165. const int groupIdA = std::atoi(request->get_query_parameter("groupIdA").c_str());
  166. CARLA_SAFE_ASSERT_RETURN(groupIdA >= 0,)
  167. const int portIdA = std::atoi(request->get_query_parameter("portIdA").c_str());
  168. CARLA_SAFE_ASSERT_RETURN(portIdA >= 0,)
  169. const int groupIdB = std::atoi(request->get_query_parameter("groupIdB").c_str());
  170. CARLA_SAFE_ASSERT_RETURN(groupIdB >= 0,)
  171. const int portIdB = std::atoi(request->get_query_parameter("portIdB").c_str());
  172. CARLA_SAFE_ASSERT_RETURN(portIdB >= 0,)
  173. const char* const buf = str_buf_bool(carla_patchbay_connect(groupIdA, portIdA, groupIdB, portIdB));
  174. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  175. }
  176. void handle_carla_patchbay_disconnect(const std::shared_ptr<Session> session)
  177. {
  178. const std::shared_ptr<const Request> request = session->get_request();
  179. const int connectionId = std::atoi(request->get_query_parameter("connectionId").c_str());
  180. CARLA_SAFE_ASSERT_RETURN(connectionId >= 0,)
  181. const char* const buf = str_buf_bool(carla_patchbay_disconnect(connectionId));
  182. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  183. }
  184. void handle_carla_patchbay_refresh(const std::shared_ptr<Session> session)
  185. {
  186. const std::shared_ptr<const Request> request = session->get_request();
  187. const int external = std::atoi(request->get_query_parameter("external").c_str());
  188. CARLA_SAFE_ASSERT_RETURN(external == 0 || external == 1,)
  189. const char* const buf = str_buf_bool(carla_patchbay_refresh(external));
  190. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  191. }
  192. // -------------------------------------------------------------------------------------------------------------------
  193. void handle_carla_transport_play(const std::shared_ptr<Session> session)
  194. {
  195. carla_transport_play();
  196. session->close(OK);
  197. }
  198. void handle_carla_transport_pause(const std::shared_ptr<Session> session)
  199. {
  200. carla_transport_pause();
  201. session->close(OK);
  202. }
  203. void handle_carla_transport_bpm(const std::shared_ptr<Session> session)
  204. {
  205. const std::shared_ptr<const Request> request = session->get_request();
  206. const double bpm = std::atof(request->get_query_parameter("bpm").c_str());
  207. CARLA_SAFE_ASSERT_RETURN(bpm > 0.0,) // FIXME
  208. carla_transport_bpm(bpm);
  209. session->close(OK);
  210. }
  211. void handle_carla_transport_relocate(const std::shared_ptr<Session> session)
  212. {
  213. const std::shared_ptr<const Request> request = session->get_request();
  214. const long int frame = std::atol(request->get_query_parameter("frame").c_str());
  215. CARLA_SAFE_ASSERT_RETURN(frame >= 0,)
  216. carla_transport_relocate(frame);
  217. session->close(OK);
  218. }
  219. void handle_carla_get_current_transport_frame(const std::shared_ptr<Session> session)
  220. {
  221. const char* const buf = str_buf_uint64(carla_get_current_transport_frame());
  222. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  223. }
  224. void handle_carla_get_transport_info(const std::shared_ptr<Session> session)
  225. {
  226. const CarlaTransportInfo* const info = carla_get_transport_info();
  227. char* jsonBuf;
  228. jsonBuf = json_buf_start();
  229. jsonBuf = json_buf_add_bool(jsonBuf, "playing", info->playing);
  230. jsonBuf = json_buf_add_uint64(jsonBuf, "frame", info->frame);
  231. jsonBuf = json_buf_add_int(jsonBuf, "bar", info->bar);
  232. jsonBuf = json_buf_add_int(jsonBuf, "beat", info->beat);
  233. jsonBuf = json_buf_add_int(jsonBuf, "tick", info->tick);
  234. jsonBuf = json_buf_add_float(jsonBuf, "bpm", info->bpm);
  235. const char* const buf = json_buf_end(jsonBuf);
  236. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  237. }
  238. // -------------------------------------------------------------------------------------------------------------------
  239. void handle_carla_get_current_plugin_count(const std::shared_ptr<Session> session)
  240. {
  241. const char* const buf = str_buf_uint(carla_get_current_plugin_count());
  242. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  243. }
  244. void handle_carla_get_max_plugin_number(const std::shared_ptr<Session> session)
  245. {
  246. const char* const buf = str_buf_uint(carla_get_max_plugin_number());
  247. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  248. }
  249. void handle_carla_add_plugin(const std::shared_ptr<Session> session)
  250. {
  251. const std::shared_ptr<const Request> request = session->get_request();
  252. const long int btype = std::atoi(request->get_query_parameter("btype").c_str());
  253. CARLA_SAFE_ASSERT_RETURN(btype >= BINARY_NONE && btype <= BINARY_OTHER,)
  254. const long int ptype = std::atoi(request->get_query_parameter("ptype").c_str());
  255. CARLA_SAFE_ASSERT_RETURN(ptype >= PLUGIN_NONE && ptype <= PLUGIN_JACK,)
  256. const std::string filename = request->get_query_parameter("filename");
  257. const std::string name = request->get_query_parameter("name");
  258. const std::string label = request->get_query_parameter("label");
  259. const long int uniqueId = std::atol(request->get_query_parameter("uniqueId").c_str());
  260. CARLA_SAFE_ASSERT_RETURN(uniqueId >= 0,)
  261. const int options = std::atoi(request->get_query_parameter("options").c_str());
  262. CARLA_SAFE_ASSERT_RETURN(options >= 0,)
  263. const char* const buf = str_buf_bool(carla_add_plugin(static_cast<BinaryType>(btype),
  264. static_cast<PluginType>(ptype),
  265. filename.c_str(),
  266. name.c_str(),
  267. label.c_str(),
  268. uniqueId,
  269. nullptr,
  270. options));
  271. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  272. }
  273. void handle_carla_remove_plugin(const std::shared_ptr<Session> session)
  274. {
  275. const std::shared_ptr<const Request> request = session->get_request();
  276. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  277. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  278. const char* const buf = str_buf_bool(carla_remove_plugin(pluginId));
  279. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  280. }
  281. void handle_carla_remove_all_plugins(const std::shared_ptr<Session> session)
  282. {
  283. const char* const buf = str_buf_bool(carla_remove_all_plugins());
  284. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  285. }
  286. // -------------------------------------------------------------------------------------------------------------------
  287. void handle_carla_rename_plugin(const std::shared_ptr<Session> session)
  288. {
  289. const std::shared_ptr<const Request> request = session->get_request();
  290. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  291. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  292. const std::string newName = request->get_query_parameter("newName");
  293. const char* const buf = carla_rename_plugin(pluginId, newName.c_str());
  294. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  295. }
  296. void handle_carla_clone_plugin(const std::shared_ptr<Session> session)
  297. {
  298. const std::shared_ptr<const Request> request = session->get_request();
  299. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  300. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  301. const char* const buf = str_buf_bool(carla_clone_plugin(pluginId));
  302. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  303. }
  304. void handle_carla_replace_plugin(const std::shared_ptr<Session> session)
  305. {
  306. const std::shared_ptr<const Request> request = session->get_request();
  307. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  308. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  309. const char* const buf = str_buf_bool(carla_replace_plugin(pluginId));
  310. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  311. }
  312. void handle_carla_switch_plugins(const std::shared_ptr<Session> session)
  313. {
  314. const std::shared_ptr<const Request> request = session->get_request();
  315. const int pluginIdA = std::atol(request->get_query_parameter("pluginIdA").c_str());
  316. CARLA_SAFE_ASSERT_RETURN(pluginIdA >= 0,)
  317. const int pluginIdB = std::atol(request->get_query_parameter("pluginIdB").c_str());
  318. CARLA_SAFE_ASSERT_RETURN(pluginIdB >= 0,)
  319. const char* const buf = str_buf_bool(carla_switch_plugins(pluginIdA, pluginIdB));
  320. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  321. }
  322. // -------------------------------------------------------------------------------------------------------------------
  323. void handle_carla_load_plugin_state(const std::shared_ptr<Session> session)
  324. {
  325. const std::shared_ptr<const Request> request = session->get_request();
  326. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  327. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  328. const std::string filename = request->get_query_parameter("filename");
  329. const char* const buf = str_buf_bool(carla_load_plugin_state(pluginId, filename.c_str()));
  330. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  331. }
  332. void handle_carla_save_plugin_state(const std::shared_ptr<Session> session)
  333. {
  334. const std::shared_ptr<const Request> request = session->get_request();
  335. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  336. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  337. const std::string filename = request->get_query_parameter("filename");
  338. const char* const buf = str_buf_bool(carla_save_plugin_state(pluginId, filename.c_str()));
  339. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  340. }
  341. void handle_carla_export_plugin_lv2(const std::shared_ptr<Session> session)
  342. {
  343. const std::shared_ptr<const Request> request = session->get_request();
  344. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  345. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  346. const std::string lv2path = request->get_query_parameter("lv2path");
  347. const char* const buf = str_buf_bool(carla_export_plugin_lv2(pluginId, lv2path.c_str()));
  348. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  349. }
  350. // -------------------------------------------------------------------------------------------------------------------
  351. void handle_carla_get_plugin_info(const std::shared_ptr<Session> session)
  352. {
  353. const std::shared_ptr<const Request> request = session->get_request();
  354. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  355. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  356. const CarlaPluginInfo* const info = carla_get_plugin_info(pluginId);
  357. // running remotely, so we cannot show custom UI or inline display
  358. const uint hints = info->hints & ~(PLUGIN_HAS_CUSTOM_UI|PLUGIN_HAS_INLINE_DISPLAY);
  359. char* jsonBuf;
  360. jsonBuf = json_buf_start();
  361. jsonBuf = json_buf_add_uint(jsonBuf, "type", info->type);
  362. jsonBuf = json_buf_add_uint(jsonBuf, "category", info->category);
  363. jsonBuf = json_buf_add_uint(jsonBuf, "hints", hints);
  364. jsonBuf = json_buf_add_uint(jsonBuf, "optionsAvailable", info->optionsAvailable);
  365. jsonBuf = json_buf_add_uint(jsonBuf, "optionsEnabled", info->optionsEnabled);
  366. jsonBuf = json_buf_add_string(jsonBuf, "filename", info->filename);
  367. jsonBuf = json_buf_add_string(jsonBuf, "name", info->name);
  368. jsonBuf = json_buf_add_string(jsonBuf, "label", info->label);
  369. jsonBuf = json_buf_add_string(jsonBuf, "maker", info->maker);
  370. jsonBuf = json_buf_add_string(jsonBuf, "copyright", info->copyright);
  371. jsonBuf = json_buf_add_string(jsonBuf, "iconName", info->iconName);
  372. jsonBuf = json_buf_add_int64(jsonBuf, "uniqueId", info->uniqueId);
  373. const char* const buf = json_buf_end(jsonBuf);
  374. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  375. }
  376. void handle_carla_get_audio_port_count_info(const std::shared_ptr<Session> session)
  377. {
  378. const std::shared_ptr<const Request> request = session->get_request();
  379. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  380. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  381. const CarlaPortCountInfo* const info = carla_get_audio_port_count_info(pluginId);
  382. char* jsonBuf;
  383. jsonBuf = json_buf_start();
  384. jsonBuf = json_buf_add_uint(jsonBuf, "ins", info->ins);
  385. jsonBuf = json_buf_add_uint(jsonBuf, "outs", info->outs);
  386. const char* const buf = json_buf_end(jsonBuf);
  387. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  388. }
  389. void handle_carla_get_midi_port_count_info(const std::shared_ptr<Session> session)
  390. {
  391. const std::shared_ptr<const Request> request = session->get_request();
  392. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  393. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  394. const CarlaPortCountInfo* const info = carla_get_midi_port_count_info(pluginId);
  395. char* jsonBuf;
  396. jsonBuf = json_buf_start();
  397. jsonBuf = json_buf_add_uint(jsonBuf, "ins", info->ins);
  398. jsonBuf = json_buf_add_uint(jsonBuf, "outs", info->outs);
  399. const char* const buf = json_buf_end(jsonBuf);
  400. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  401. }
  402. void handle_carla_get_parameter_count_info(const std::shared_ptr<Session> session)
  403. {
  404. const std::shared_ptr<const Request> request = session->get_request();
  405. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  406. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  407. const CarlaPortCountInfo* const info = carla_get_parameter_count_info(pluginId);
  408. char* jsonBuf;
  409. jsonBuf = json_buf_start();
  410. jsonBuf = json_buf_add_uint(jsonBuf, "ins", info->ins);
  411. jsonBuf = json_buf_add_uint(jsonBuf, "outs", info->outs);
  412. const char* const buf = json_buf_end(jsonBuf);
  413. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  414. }
  415. void handle_carla_get_parameter_info(const std::shared_ptr<Session> session)
  416. {
  417. const std::shared_ptr<const Request> request = session->get_request();
  418. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  419. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  420. const int parameterId = std::atoi(request->get_query_parameter("parameterId").c_str());
  421. CARLA_SAFE_ASSERT_RETURN(parameterId >= 0,)
  422. const CarlaParameterInfo* const info = carla_get_parameter_info(pluginId, parameterId);
  423. char* jsonBuf;
  424. jsonBuf = json_buf_start();
  425. jsonBuf = json_buf_add_string(jsonBuf, "name", info->name);
  426. jsonBuf = json_buf_add_string(jsonBuf, "symbol", info->symbol);
  427. jsonBuf = json_buf_add_string(jsonBuf, "unit", info->unit);
  428. jsonBuf = json_buf_add_uint(jsonBuf, "scalePointCount", info->scalePointCount);
  429. const char* const buf = json_buf_end(jsonBuf);
  430. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  431. }
  432. void handle_carla_get_parameter_scalepoint_info(const std::shared_ptr<Session> session)
  433. {
  434. const std::shared_ptr<const Request> request = session->get_request();
  435. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  436. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  437. const int parameterId = std::atoi(request->get_query_parameter("parameterId").c_str());
  438. CARLA_SAFE_ASSERT_RETURN(parameterId >= 0,)
  439. const int scalePointId = std::atoi(request->get_query_parameter("scalePointId").c_str());
  440. CARLA_SAFE_ASSERT_RETURN(scalePointId >= 0,)
  441. const CarlaScalePointInfo* const info = carla_get_parameter_scalepoint_info(pluginId, parameterId, scalePointId);
  442. char* jsonBuf;
  443. jsonBuf = json_buf_start();
  444. jsonBuf = json_buf_add_float(jsonBuf, "value", info->value);
  445. jsonBuf = json_buf_add_string(jsonBuf, "label", info->label);
  446. const char* const buf = json_buf_end(jsonBuf);
  447. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  448. }
  449. void handle_carla_get_parameter_data(const std::shared_ptr<Session> session)
  450. {
  451. const std::shared_ptr<const Request> request = session->get_request();
  452. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  453. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  454. const int parameterId = std::atoi(request->get_query_parameter("parameterId").c_str());
  455. CARLA_SAFE_ASSERT_RETURN(parameterId >= 0,)
  456. const ParameterData* const info = carla_get_parameter_data(pluginId, parameterId);
  457. char* jsonBuf;
  458. jsonBuf = json_buf_start();
  459. jsonBuf = json_buf_add_uint(jsonBuf, "type", info->type);
  460. jsonBuf = json_buf_add_uint(jsonBuf, "hints", info->hints);
  461. jsonBuf = json_buf_add_int(jsonBuf, "index", info->index);
  462. jsonBuf = json_buf_add_int(jsonBuf, "rindex", info->rindex);
  463. jsonBuf = json_buf_add_int(jsonBuf, "midiCC", info->midiCC);
  464. jsonBuf = json_buf_add_uint(jsonBuf, "midiChannel", info->midiChannel);
  465. const char* const buf = json_buf_end(jsonBuf);
  466. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  467. }
  468. void handle_carla_get_parameter_ranges(const std::shared_ptr<Session> session)
  469. {
  470. const std::shared_ptr<const Request> request = session->get_request();
  471. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  472. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  473. const int parameterId = std::atoi(request->get_query_parameter("parameterId").c_str());
  474. CARLA_SAFE_ASSERT_RETURN(parameterId >= 0,)
  475. const ParameterRanges* const info = carla_get_parameter_ranges(pluginId, parameterId);
  476. char* jsonBuf;
  477. jsonBuf = json_buf_start();
  478. jsonBuf = json_buf_add_float(jsonBuf, "def", info->def);
  479. jsonBuf = json_buf_add_float(jsonBuf, "min", info->min);
  480. jsonBuf = json_buf_add_float(jsonBuf, "max", info->max);
  481. jsonBuf = json_buf_add_float(jsonBuf, "step", info->step);
  482. jsonBuf = json_buf_add_float(jsonBuf, "stepSmall", info->stepSmall);
  483. jsonBuf = json_buf_add_float(jsonBuf, "stepLarge", info->stepLarge);
  484. const char* const buf = json_buf_end(jsonBuf);
  485. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  486. }
  487. void handle_carla_get_midi_program_data(const std::shared_ptr<Session> session)
  488. {
  489. const std::shared_ptr<const Request> request = session->get_request();
  490. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  491. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  492. const int midiProgramId = std::atoi(request->get_query_parameter("midiProgramId").c_str());
  493. CARLA_SAFE_ASSERT_RETURN(midiProgramId >= 0,)
  494. const MidiProgramData* const info = carla_get_midi_program_data(pluginId, midiProgramId);
  495. char* jsonBuf;
  496. jsonBuf = json_buf_start();
  497. jsonBuf = json_buf_add_uint(jsonBuf, "bank", info->bank);
  498. jsonBuf = json_buf_add_uint(jsonBuf, "program", info->program);
  499. jsonBuf = json_buf_add_string(jsonBuf, "name", info->name);
  500. const char* const buf = json_buf_end(jsonBuf);
  501. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  502. }
  503. void handle_carla_get_custom_data(const std::shared_ptr<Session> session)
  504. {
  505. const std::shared_ptr<const Request> request = session->get_request();
  506. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  507. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  508. const int customDataId = std::atoi(request->get_query_parameter("customDataId").c_str());
  509. CARLA_SAFE_ASSERT_RETURN(customDataId >= 0,)
  510. const CustomData* const info = carla_get_custom_data(pluginId, customDataId);
  511. char* jsonBuf;
  512. jsonBuf = json_buf_start();
  513. jsonBuf = json_buf_add_string(jsonBuf, "type", info->type);
  514. jsonBuf = json_buf_add_string(jsonBuf, "key", info->key);
  515. jsonBuf = json_buf_add_string(jsonBuf, "value", info->value);
  516. const char* const buf = json_buf_end(jsonBuf);
  517. puts(buf);
  518. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  519. }
  520. void handle_carla_get_chunk_data(const std::shared_ptr<Session> session)
  521. {
  522. const std::shared_ptr<const Request> request = session->get_request();
  523. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  524. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  525. const char* const buf = carla_get_chunk_data(pluginId);
  526. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  527. }
  528. // -------------------------------------------------------------------------------------------------------------------
  529. void handle_carla_get_parameter_count(const std::shared_ptr<Session> session)
  530. {
  531. const std::shared_ptr<const Request> request = session->get_request();
  532. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  533. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  534. const char* const buf = str_buf_uint(carla_get_parameter_count(pluginId));
  535. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  536. }
  537. void handle_carla_get_program_count(const std::shared_ptr<Session> session)
  538. {
  539. const std::shared_ptr<const Request> request = session->get_request();
  540. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  541. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  542. const char* const buf = str_buf_uint(carla_get_program_count(pluginId));
  543. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  544. }
  545. void handle_carla_get_midi_program_count(const std::shared_ptr<Session> session)
  546. {
  547. const std::shared_ptr<const Request> request = session->get_request();
  548. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  549. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  550. const char* const buf = str_buf_uint(carla_get_midi_program_count(pluginId));
  551. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  552. }
  553. void handle_carla_get_custom_data_count(const std::shared_ptr<Session> session)
  554. {
  555. const std::shared_ptr<const Request> request = session->get_request();
  556. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  557. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  558. const char* const buf = str_buf_uint(carla_get_custom_data_count(pluginId));
  559. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  560. }
  561. void handle_carla_get_parameter_text(const std::shared_ptr<Session> session)
  562. {
  563. const std::shared_ptr<const Request> request = session->get_request();
  564. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  565. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  566. const int parameterId = std::atoi(request->get_query_parameter("parameterId").c_str());
  567. CARLA_SAFE_ASSERT_RETURN(parameterId >= 0,)
  568. const char* const buf = carla_get_parameter_text(pluginId, parameterId);
  569. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  570. }
  571. void handle_carla_get_program_name(const std::shared_ptr<Session> session)
  572. {
  573. const std::shared_ptr<const Request> request = session->get_request();
  574. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  575. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  576. const int programId = std::atoi(request->get_query_parameter("programId").c_str());
  577. CARLA_SAFE_ASSERT_RETURN(programId >= 0,)
  578. const char* const buf = carla_get_program_name(pluginId, programId);
  579. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  580. }
  581. void handle_carla_get_midi_program_name(const std::shared_ptr<Session> session)
  582. {
  583. const std::shared_ptr<const Request> request = session->get_request();
  584. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  585. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  586. const int midiProgramId = std::atoi(request->get_query_parameter("midiProgramId").c_str());
  587. CARLA_SAFE_ASSERT_RETURN(midiProgramId >= 0,)
  588. const char* const buf = carla_get_midi_program_name(pluginId, midiProgramId);
  589. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  590. }
  591. void handle_carla_get_real_plugin_name(const std::shared_ptr<Session> session)
  592. {
  593. const std::shared_ptr<const Request> request = session->get_request();
  594. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  595. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  596. const char* const buf = carla_get_real_plugin_name(pluginId);
  597. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  598. }
  599. void handle_carla_get_current_program_index(const std::shared_ptr<Session> session)
  600. {
  601. const std::shared_ptr<const Request> request = session->get_request();
  602. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  603. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  604. const char* const buf = str_buf_uint(carla_get_current_program_index(pluginId));
  605. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  606. }
  607. void handle_carla_get_current_midi_program_index(const std::shared_ptr<Session> session)
  608. {
  609. const std::shared_ptr<const Request> request = session->get_request();
  610. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  611. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  612. const char* const buf = str_buf_uint(carla_get_current_midi_program_index(pluginId));
  613. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  614. }
  615. void handle_carla_get_default_parameter_value(const std::shared_ptr<Session> session)
  616. {
  617. const std::shared_ptr<const Request> request = session->get_request();
  618. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  619. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  620. const int parameterId = std::atoi(request->get_query_parameter("parameterId").c_str());
  621. CARLA_SAFE_ASSERT_RETURN(parameterId >= 0,)
  622. const char* const buf = str_buf_float(carla_get_default_parameter_value(pluginId, parameterId));
  623. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  624. }
  625. void handle_carla_get_current_parameter_value(const std::shared_ptr<Session> session)
  626. {
  627. const std::shared_ptr<const Request> request = session->get_request();
  628. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  629. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  630. const int parameterId = std::atoi(request->get_query_parameter("parameterId").c_str());
  631. CARLA_SAFE_ASSERT_RETURN(parameterId >= 0,)
  632. const char* const buf = str_buf_float(carla_get_current_parameter_value(pluginId, parameterId));
  633. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  634. }
  635. void handle_carla_get_internal_parameter_value(const std::shared_ptr<Session> session)
  636. {
  637. const std::shared_ptr<const Request> request = session->get_request();
  638. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  639. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  640. const int parameterId = std::atoi(request->get_query_parameter("parameterId").c_str());
  641. CARLA_SAFE_ASSERT_RETURN(parameterId > PARAMETER_MAX,);
  642. const char* const buf = str_buf_float(carla_get_internal_parameter_value(pluginId, parameterId));
  643. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  644. }
  645. void handle_carla_get_input_peak_value(const std::shared_ptr<Session> session)
  646. {
  647. const std::shared_ptr<const Request> request = session->get_request();
  648. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  649. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  650. const int isLeft = std::atoi(request->get_query_parameter("isLeft").c_str());
  651. CARLA_SAFE_ASSERT_RETURN(isLeft == 0 || isLeft == 1,)
  652. const char* const buf = str_buf_float(carla_get_input_peak_value(pluginId, isLeft));
  653. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  654. }
  655. void handle_carla_get_output_peak_value(const std::shared_ptr<Session> session)
  656. {
  657. const std::shared_ptr<const Request> request = session->get_request();
  658. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  659. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  660. const int isLeft = std::atoi(request->get_query_parameter("isLeft").c_str());
  661. CARLA_SAFE_ASSERT_RETURN(isLeft == 0 || isLeft == 1,)
  662. const char* const buf = str_buf_float(carla_get_output_peak_value(pluginId, isLeft));
  663. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  664. }
  665. // -------------------------------------------------------------------------------------------------------------------
  666. void handle_carla_set_active(const std::shared_ptr<Session> session)
  667. {
  668. const std::shared_ptr<const Request> request = session->get_request();
  669. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  670. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  671. const int onOff = std::atoi(request->get_query_parameter("onOff").c_str());
  672. CARLA_SAFE_ASSERT_RETURN(onOff == 0 || onOff == 1,)
  673. carla_set_active(pluginId, onOff);
  674. session->close(OK);
  675. }
  676. void handle_carla_set_drywet(const std::shared_ptr<Session> session)
  677. {
  678. const std::shared_ptr<const Request> request = session->get_request();
  679. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  680. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  681. const double value = std::atof(request->get_query_parameter("value").c_str());
  682. CARLA_SAFE_ASSERT_RETURN(value >= 0.0 && value >= 1.0,)
  683. carla_set_drywet(pluginId, value);
  684. session->close(OK);
  685. }
  686. void handle_carla_set_volume(const std::shared_ptr<Session> session)
  687. {
  688. const std::shared_ptr<const Request> request = session->get_request();
  689. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  690. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  691. const double value = std::atof(request->get_query_parameter("value").c_str());
  692. CARLA_SAFE_ASSERT_RETURN(value >= 0.0 && value >= 1.0,)
  693. carla_set_volume(pluginId, value);
  694. session->close(OK);
  695. }
  696. void handle_carla_set_balance_left(const std::shared_ptr<Session> session)
  697. {
  698. const std::shared_ptr<const Request> request = session->get_request();
  699. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  700. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  701. const double value = std::atof(request->get_query_parameter("value").c_str());
  702. CARLA_SAFE_ASSERT_RETURN(value >= 0.0 && value >= 1.0,)
  703. carla_set_balance_left(pluginId, value);
  704. session->close(OK);
  705. }
  706. void handle_carla_set_balance_right(const std::shared_ptr<Session> session)
  707. {
  708. const std::shared_ptr<const Request> request = session->get_request();
  709. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  710. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  711. const double value = std::atof(request->get_query_parameter("value").c_str());
  712. CARLA_SAFE_ASSERT_RETURN(value >= 0.0 && value >= 1.0,)
  713. carla_set_balance_right(pluginId, value);
  714. session->close(OK);
  715. }
  716. void handle_carla_set_panning(const std::shared_ptr<Session> session)
  717. {
  718. const std::shared_ptr<const Request> request = session->get_request();
  719. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  720. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  721. const double value = std::atof(request->get_query_parameter("value").c_str());
  722. CARLA_SAFE_ASSERT_RETURN(value >= 0.0 && value >= 1.0,)
  723. carla_set_panning(pluginId, value);
  724. session->close(OK);
  725. }
  726. void handle_carla_set_ctrl_channel(const std::shared_ptr<Session> session)
  727. {
  728. const std::shared_ptr<const Request> request = session->get_request();
  729. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  730. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  731. const int channel = std::atoi(request->get_query_parameter("channel").c_str());
  732. CARLA_SAFE_ASSERT_RETURN(channel < 16,)
  733. carla_set_ctrl_channel(pluginId, channel);
  734. session->close(OK);
  735. }
  736. void handle_carla_set_option(const std::shared_ptr<Session> session)
  737. {
  738. const std::shared_ptr<const Request> request = session->get_request();
  739. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  740. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  741. const int option = std::atoi(request->get_query_parameter("option").c_str());
  742. CARLA_SAFE_ASSERT_RETURN(option >= 0,)
  743. const int yesNo = std::atoi(request->get_query_parameter("yesNo").c_str());
  744. CARLA_SAFE_ASSERT_RETURN(yesNo == 0 || yesNo == 1,)
  745. carla_set_option(pluginId, option, yesNo);
  746. session->close(OK);
  747. }
  748. // -------------------------------------------------------------------------------------------------------------------
  749. void handle_carla_set_parameter_value(const std::shared_ptr<Session> session)
  750. {
  751. const std::shared_ptr<const Request> request = session->get_request();
  752. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  753. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  754. const int parameterId = std::atoi(request->get_query_parameter("parameterId").c_str());
  755. CARLA_SAFE_ASSERT_RETURN(parameterId >= 0,)
  756. const double value = std::atof(request->get_query_parameter("value").c_str());
  757. carla_set_parameter_value(pluginId, parameterId, value);
  758. session->close(OK);
  759. }
  760. void handle_carla_set_parameter_midi_channel(const std::shared_ptr<Session> session)
  761. {
  762. const std::shared_ptr<const Request> request = session->get_request();
  763. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  764. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  765. const int parameterId = std::atoi(request->get_query_parameter("parameterId").c_str());
  766. CARLA_SAFE_ASSERT_RETURN(parameterId >= 0,)
  767. const int channel = std::atoi(request->get_query_parameter("channel").c_str());
  768. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < 16,)
  769. carla_set_parameter_midi_channel(pluginId, parameterId, channel);
  770. session->close(OK);
  771. }
  772. void handle_carla_set_parameter_midi_cc(const std::shared_ptr<Session> session)
  773. {
  774. const std::shared_ptr<const Request> request = session->get_request();
  775. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  776. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  777. const int parameterId = std::atoi(request->get_query_parameter("parameterId").c_str());
  778. CARLA_SAFE_ASSERT_RETURN(parameterId >= 0,)
  779. const int cc = std::atoi(request->get_query_parameter("channel").c_str());
  780. CARLA_SAFE_ASSERT_RETURN(cc >= -1 && cc < INT16_MAX,);
  781. carla_set_parameter_midi_cc(pluginId, parameterId, cc);
  782. session->close(OK);
  783. }
  784. void handle_carla_set_program(const std::shared_ptr<Session> session)
  785. {
  786. const std::shared_ptr<const Request> request = session->get_request();
  787. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  788. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  789. const int programId = std::atoi(request->get_query_parameter("programId").c_str());
  790. CARLA_SAFE_ASSERT_RETURN(programId >= 0,)
  791. carla_set_program(pluginId, programId);
  792. session->close(OK);
  793. }
  794. void handle_carla_set_midi_program(const std::shared_ptr<Session> session)
  795. {
  796. const std::shared_ptr<const Request> request = session->get_request();
  797. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  798. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  799. const int midiProgramId = std::atoi(request->get_query_parameter("midiProgramId").c_str());
  800. CARLA_SAFE_ASSERT_RETURN(midiProgramId >= 0,)
  801. carla_set_midi_program(pluginId, midiProgramId);
  802. session->close(OK);
  803. }
  804. void handle_carla_set_custom_data(const std::shared_ptr<Session> session)
  805. {
  806. const std::shared_ptr<const Request> request = session->get_request();
  807. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  808. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  809. const std::string type = request->get_query_parameter("type");
  810. const std::string key = request->get_query_parameter("key");
  811. const std::string value = request->get_query_parameter("value");
  812. carla_set_custom_data(pluginId, type.c_str(), key.c_str(), value.c_str());
  813. session->close(OK);
  814. }
  815. void handle_carla_set_chunk_data(const std::shared_ptr<Session> session)
  816. {
  817. const std::shared_ptr<const Request> request = session->get_request();
  818. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  819. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  820. const std::string chunkData = request->get_query_parameter("chunkData");
  821. carla_set_chunk_data(pluginId, chunkData.c_str());
  822. session->close(OK);
  823. }
  824. // -------------------------------------------------------------------------------------------------------------------
  825. void handle_carla_prepare_for_save(const std::shared_ptr<Session> session)
  826. {
  827. const std::shared_ptr<const Request> request = session->get_request();
  828. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  829. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  830. carla_prepare_for_save(pluginId);
  831. session->close(OK);
  832. }
  833. void handle_carla_reset_parameters(const std::shared_ptr<Session> session)
  834. {
  835. const std::shared_ptr<const Request> request = session->get_request();
  836. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  837. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  838. carla_reset_parameters(pluginId);
  839. session->close(OK);
  840. }
  841. void handle_carla_randomize_parameters(const std::shared_ptr<Session> session)
  842. {
  843. const std::shared_ptr<const Request> request = session->get_request();
  844. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  845. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  846. carla_randomize_parameters(pluginId);
  847. session->close(OK);
  848. }
  849. void handle_carla_send_midi_note(const std::shared_ptr<Session> session)
  850. {
  851. const std::shared_ptr<const Request> request = session->get_request();
  852. const int pluginId = std::atoi(request->get_query_parameter("pluginId").c_str());
  853. CARLA_SAFE_ASSERT_RETURN(pluginId >= 0,)
  854. const int channel = std::atoi(request->get_query_parameter("channel").c_str());
  855. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < 16,)
  856. const int note = std::atoi(request->get_query_parameter("note").c_str());
  857. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < 128,)
  858. const int velocity = std::atoi(request->get_query_parameter("velocity").c_str());
  859. CARLA_SAFE_ASSERT_RETURN(velocity >= 0 && velocity < 128,)
  860. carla_send_midi_note(pluginId, channel, note, velocity);
  861. session->close(OK);
  862. }
  863. // -------------------------------------------------------------------------------------------------------------------
  864. void handle_carla_get_buffer_size(const std::shared_ptr<Session> session)
  865. {
  866. const char* const buf = str_buf_uint(carla_get_buffer_size());
  867. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  868. }
  869. void handle_carla_get_sample_rate(const std::shared_ptr<Session> session)
  870. {
  871. const char* const buf = str_buf_float(carla_get_sample_rate());
  872. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  873. }
  874. void handle_carla_get_last_error(const std::shared_ptr<Session> session)
  875. {
  876. const char* const buf = carla_get_last_error();
  877. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  878. }
  879. void handle_carla_get_host_osc_url_tcp(const std::shared_ptr<Session> session)
  880. {
  881. const char* const buf = carla_get_host_osc_url_tcp();
  882. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  883. }
  884. void handle_carla_get_host_osc_url_udp(const std::shared_ptr<Session> session)
  885. {
  886. const char* const buf = carla_get_host_osc_url_udp();
  887. session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
  888. }
  889. // -------------------------------------------------------------------------------------------------------------------