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-host.cpp 48KB

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