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.

CarlaStateUtils.cpp 27KB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /*
  2. * Carla State utils
  3. * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "CarlaStateUtils.hpp"
  18. #include "CarlaBackendUtils.hpp"
  19. #include "CarlaMathUtils.hpp"
  20. #include "CarlaMIDI.h"
  21. #include "water/streams/MemoryOutputStream.h"
  22. #include "water/xml/XmlElement.h"
  23. #include <string>
  24. using water::MemoryOutputStream;
  25. using water::String;
  26. using water::XmlElement;
  27. CARLA_BACKEND_START_NAMESPACE
  28. // -----------------------------------------------------------------------
  29. // getNewLineSplittedString
  30. static void getNewLineSplittedString(MemoryOutputStream& stream, const String& string)
  31. {
  32. static const int kLineWidth = 120;
  33. int i = 0;
  34. const int length = string.length();
  35. const char* const raw = string.toUTF8();
  36. stream.preallocate(static_cast<std::size_t>(length + length/kLineWidth + 3));
  37. for (; i+kLineWidth < length; i += kLineWidth)
  38. {
  39. stream.write(raw+i, kLineWidth);
  40. stream.writeByte('\n');
  41. }
  42. stream << (raw+i);
  43. }
  44. // -----------------------------------------------------------------------
  45. // xmlSafeStringFast
  46. /* Based on some code by James Kanze from stackoverflow
  47. * https://stackoverflow.com/questions/7724011/in-c-whats-the-fastest-way-to-replace-all-occurrences-of-a-substring-within */
  48. static std::string replaceStdString(const std::string& original, const std::string& before, const std::string& after)
  49. {
  50. std::string::const_iterator current = original.begin(), end = original.end(), next;
  51. std::string retval;
  52. for (; (next = std::search(current, end, before.begin(), before.end())) != end;)
  53. {
  54. retval.append(current, next);
  55. retval.append(after);
  56. current = next + static_cast<ssize_t>(before.size());
  57. }
  58. retval.append(current, next);
  59. return retval;
  60. }
  61. static std::string xmlSafeStringFast(const char* const cstring, const bool toXml)
  62. {
  63. std::string string(cstring);
  64. if (toXml)
  65. {
  66. string = replaceStdString(string, "&","&amp;");
  67. string = replaceStdString(string, "<","&lt;");
  68. string = replaceStdString(string, ">","&gt;");
  69. string = replaceStdString(string, "'","&apos;");
  70. string = replaceStdString(string, "\"","&quot;");
  71. }
  72. else
  73. {
  74. string = replaceStdString(string, "&lt;","<");
  75. string = replaceStdString(string, "&gt;",">");
  76. string = replaceStdString(string, "&apos;","'");
  77. string = replaceStdString(string, "&quot;","\"");
  78. string = replaceStdString(string, "&amp;","&");
  79. }
  80. return string;
  81. }
  82. // -----------------------------------------------------------------------
  83. // xmlSafeStringCharDup
  84. /*
  85. static const char* xmlSafeStringCharDup(const char* const cstring, const bool toXml)
  86. {
  87. return carla_strdup(xmlSafeString(cstring, toXml).toRawUTF8());
  88. }
  89. */
  90. static const char* xmlSafeStringCharDup(const String& string, const bool toXml)
  91. {
  92. return carla_strdup(xmlSafeString(string, toXml).toRawUTF8());
  93. }
  94. // -----------------------------------------------------------------------
  95. // StateParameter
  96. CarlaStateSave::Parameter::Parameter() noexcept
  97. : dummy(true),
  98. index(-1),
  99. name(nullptr),
  100. symbol(nullptr),
  101. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  102. value(0.0f),
  103. mappedControlIndex(CONTROL_INDEX_NONE),
  104. midiChannel(0),
  105. mappedRangeValid(false),
  106. mappedMinimum(0.0f),
  107. mappedMaximum(1.0f) {}
  108. #else
  109. value(0.0f) {}
  110. #endif
  111. CarlaStateSave::Parameter::~Parameter() noexcept
  112. {
  113. if (name != nullptr)
  114. {
  115. delete[] name;
  116. name = nullptr;
  117. }
  118. if (symbol != nullptr)
  119. {
  120. delete[] symbol;
  121. symbol = nullptr;
  122. }
  123. }
  124. // -----------------------------------------------------------------------
  125. // StateCustomData
  126. CarlaStateSave::CustomData::CustomData() noexcept
  127. : type(nullptr),
  128. key(nullptr),
  129. value(nullptr) {}
  130. CarlaStateSave::CustomData::~CustomData() noexcept
  131. {
  132. if (type != nullptr)
  133. {
  134. delete[] type;
  135. type = nullptr;
  136. }
  137. if (key != nullptr)
  138. {
  139. delete[] key;
  140. key = nullptr;
  141. }
  142. if (value != nullptr)
  143. {
  144. delete[] value;
  145. value = nullptr;
  146. }
  147. }
  148. bool CarlaStateSave::CustomData::isValid() const noexcept
  149. {
  150. if (type == nullptr || type[0] == '\0') return false;
  151. if (key == nullptr || key [0] == '\0') return false;
  152. if (value == nullptr) return false;
  153. return true;
  154. }
  155. // -----------------------------------------------------------------------
  156. // StateSave
  157. CarlaStateSave::CarlaStateSave() noexcept
  158. : type(nullptr),
  159. name(nullptr),
  160. label(nullptr),
  161. binary(nullptr),
  162. uniqueId(0),
  163. options(0x0),
  164. temporary(false),
  165. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  166. active(false),
  167. dryWet(1.0f),
  168. volume(1.0f),
  169. balanceLeft(-1.0f),
  170. balanceRight(1.0f),
  171. panning(0.0f),
  172. ctrlChannel(-1),
  173. #endif
  174. currentProgramIndex(-1),
  175. currentProgramName(nullptr),
  176. currentMidiBank(-1),
  177. currentMidiProgram(-1),
  178. chunk(nullptr),
  179. parameters(),
  180. customData() {}
  181. CarlaStateSave::~CarlaStateSave() noexcept
  182. {
  183. clear();
  184. }
  185. void CarlaStateSave::clear() noexcept
  186. {
  187. if (type != nullptr)
  188. {
  189. delete[] type;
  190. type = nullptr;
  191. }
  192. if (name != nullptr)
  193. {
  194. delete[] name;
  195. name = nullptr;
  196. }
  197. if (label != nullptr)
  198. {
  199. delete[] label;
  200. label = nullptr;
  201. }
  202. if (binary != nullptr)
  203. {
  204. delete[] binary;
  205. binary = nullptr;
  206. }
  207. if (currentProgramName != nullptr)
  208. {
  209. delete[] currentProgramName;
  210. currentProgramName = nullptr;
  211. }
  212. if (chunk != nullptr)
  213. {
  214. delete[] chunk;
  215. chunk = nullptr;
  216. }
  217. uniqueId = 0;
  218. options = 0x0;
  219. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  220. active = false;
  221. dryWet = 1.0f;
  222. volume = 1.0f;
  223. balanceLeft = -1.0f;
  224. balanceRight = 1.0f;
  225. panning = 0.0f;
  226. ctrlChannel = -1;
  227. #endif
  228. currentProgramIndex = -1;
  229. currentMidiBank = -1;
  230. currentMidiProgram = -1;
  231. for (ParameterItenerator it = parameters.begin2(); it.valid(); it.next())
  232. {
  233. Parameter* const stateParameter(it.getValue(nullptr));
  234. delete stateParameter;
  235. }
  236. for (CustomDataItenerator it = customData.begin2(); it.valid(); it.next())
  237. {
  238. CustomData* const stateCustomData(it.getValue(nullptr));
  239. delete stateCustomData;
  240. }
  241. parameters.clear();
  242. customData.clear();
  243. }
  244. // -----------------------------------------------------------------------
  245. // fillFromXmlElement
  246. bool CarlaStateSave::fillFromXmlElement(const XmlElement* const xmlElement)
  247. {
  248. CARLA_SAFE_ASSERT_RETURN(xmlElement != nullptr, false);
  249. clear();
  250. for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
  251. {
  252. const String& tagName(elem->getTagName());
  253. // ---------------------------------------------------------------
  254. // Info
  255. if (tagName == "Info")
  256. {
  257. for (XmlElement* xmlInfo = elem->getFirstChildElement(); xmlInfo != nullptr; xmlInfo = xmlInfo->getNextElement())
  258. {
  259. const String& tag(xmlInfo->getTagName());
  260. const String text(xmlInfo->getAllSubText().trim());
  261. /**/ if (tag == "Type")
  262. type = xmlSafeStringCharDup(text, false);
  263. else if (tag == "Name")
  264. name = xmlSafeStringCharDup(text, false);
  265. else if (tag == "Label" || tag == "URI" || tag == "Identifier" || tag == "Setup")
  266. label = xmlSafeStringCharDup(text, false);
  267. else if (tag == "Binary" || tag == "Filename")
  268. binary = xmlSafeStringCharDup(text, false);
  269. else if (tag == "UniqueID")
  270. uniqueId = text.getLargeIntValue();
  271. }
  272. }
  273. // ---------------------------------------------------------------
  274. // Data
  275. else if (tagName == "Data")
  276. {
  277. for (XmlElement* xmlData = elem->getFirstChildElement(); xmlData != nullptr; xmlData = xmlData->getNextElement())
  278. {
  279. const String& tag(xmlData->getTagName());
  280. const String text(xmlData->getAllSubText().trim());
  281. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  282. // -------------------------------------------------------
  283. // Internal Data
  284. /**/ if (tag == "Active")
  285. {
  286. active = (text == "Yes");
  287. }
  288. else if (tag == "DryWet")
  289. {
  290. dryWet = carla_fixedValue(0.0f, 1.0f, text.getFloatValue());
  291. }
  292. else if (tag == "Volume")
  293. {
  294. volume = carla_fixedValue(0.0f, 1.27f, text.getFloatValue());
  295. }
  296. else if (tag == "Balance-Left")
  297. {
  298. balanceLeft = carla_fixedValue(-1.0f, 1.0f, text.getFloatValue());
  299. }
  300. else if (tag == "Balance-Right")
  301. {
  302. balanceRight = carla_fixedValue(-1.0f, 1.0f, text.getFloatValue());
  303. }
  304. else if (tag == "Panning")
  305. {
  306. panning = carla_fixedValue(-1.0f, 1.0f, text.getFloatValue());
  307. }
  308. else if (tag == "ControlChannel")
  309. {
  310. if (! text.startsWithIgnoreCase("n"))
  311. {
  312. const int value(text.getIntValue());
  313. if (value >= 1 && value <= MAX_MIDI_CHANNELS)
  314. ctrlChannel = static_cast<int8_t>(value-1);
  315. }
  316. }
  317. else if (tag == "Options")
  318. {
  319. const int value(text.getHexValue32());
  320. if (value > 0)
  321. options = static_cast<uint>(value);
  322. }
  323. #else
  324. if (false) {}
  325. #endif
  326. // -------------------------------------------------------
  327. // Program (current)
  328. else if (tag == "CurrentProgramIndex")
  329. {
  330. const int value(text.getIntValue());
  331. if (value >= 1)
  332. currentProgramIndex = value-1;
  333. }
  334. else if (tag == "CurrentProgramName")
  335. {
  336. currentProgramName = xmlSafeStringCharDup(text, false);
  337. }
  338. // -------------------------------------------------------
  339. // Midi Program (current)
  340. else if (tag == "CurrentMidiBank")
  341. {
  342. const int value(text.getIntValue());
  343. if (value >= 1)
  344. currentMidiBank = value-1;
  345. }
  346. else if (tag == "CurrentMidiProgram")
  347. {
  348. const int value(text.getIntValue());
  349. if (value >= 1)
  350. currentMidiProgram = value-1;
  351. }
  352. // -------------------------------------------------------
  353. // Parameters
  354. else if (tag == "Parameter")
  355. {
  356. Parameter* const stateParameter(new Parameter());
  357. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  358. bool hasMappedMinimum = false, hasMappedMaximum = false;
  359. #endif
  360. for (XmlElement* xmlSubData = xmlData->getFirstChildElement(); xmlSubData != nullptr; xmlSubData = xmlSubData->getNextElement())
  361. {
  362. const String& pTag(xmlSubData->getTagName());
  363. const String pText(xmlSubData->getAllSubText().trim());
  364. /**/ if (pTag == "Index")
  365. {
  366. const int index(pText.getIntValue());
  367. if (index >= 0)
  368. stateParameter->index = index;
  369. }
  370. else if (pTag == "Name")
  371. {
  372. stateParameter->name = xmlSafeStringCharDup(pText, false);
  373. }
  374. else if (pTag == "Symbol" || pTag == "Identifier")
  375. {
  376. stateParameter->symbol = xmlSafeStringCharDup(pText, false);
  377. }
  378. else if (pTag == "Value")
  379. {
  380. stateParameter->dummy = false;
  381. stateParameter->value = pText.getFloatValue();
  382. }
  383. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  384. else if (pTag == "MidiChannel")
  385. {
  386. const int channel(pText.getIntValue());
  387. if (channel >= 1 && channel <= MAX_MIDI_CHANNELS)
  388. stateParameter->midiChannel = static_cast<uint8_t>(channel-1);
  389. }
  390. else if (pTag == "MidiCC")
  391. {
  392. const int cc(pText.getIntValue());
  393. if (cc > 0 && cc < MAX_MIDI_CONTROL)
  394. stateParameter->mappedControlIndex = static_cast<int16_t>(cc);
  395. }
  396. else if (pTag == "MappedControlIndex")
  397. {
  398. const int ctrl(pText.getIntValue());
  399. if (ctrl > CONTROL_INDEX_NONE && ctrl <= CONTROL_INDEX_MAX_ALLOWED)
  400. if (ctrl != CONTROL_INDEX_MIDI_LEARN)
  401. stateParameter->mappedControlIndex = static_cast<int16_t>(ctrl);
  402. }
  403. else if (pTag == "MappedMinimum")
  404. {
  405. hasMappedMinimum = true;
  406. stateParameter->mappedMinimum = pText.getFloatValue();
  407. }
  408. else if (pTag == "MappedMaximum")
  409. {
  410. hasMappedMaximum = true;
  411. stateParameter->mappedMaximum = pText.getFloatValue();
  412. }
  413. #endif
  414. }
  415. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  416. if (hasMappedMinimum && hasMappedMaximum)
  417. stateParameter->mappedRangeValid = true;
  418. #endif
  419. parameters.append(stateParameter);
  420. }
  421. // -------------------------------------------------------
  422. // Custom Data
  423. else if (tag == "CustomData")
  424. {
  425. CustomData* const stateCustomData(new CustomData());
  426. // find type first
  427. for (XmlElement* xmlSubData = xmlData->getFirstChildElement(); xmlSubData != nullptr; xmlSubData = xmlSubData->getNextElement())
  428. {
  429. const String& cTag(xmlSubData->getTagName());
  430. if (cTag != "Type")
  431. continue;
  432. stateCustomData->type = xmlSafeStringCharDup(xmlSubData->getAllSubText().trim(), false);
  433. break;
  434. }
  435. if (stateCustomData->type == nullptr || stateCustomData->type[0] == '\0')
  436. {
  437. carla_stderr("Reading CustomData type failed");
  438. delete stateCustomData;
  439. continue;
  440. }
  441. // now fill in key and value, knowing what the type is
  442. for (XmlElement* xmlSubData = xmlData->getFirstChildElement(); xmlSubData != nullptr; xmlSubData = xmlSubData->getNextElement())
  443. {
  444. const String& cTag(xmlSubData->getTagName());
  445. String cText(xmlSubData->getAllSubText());
  446. /**/ if (cTag == "Key")
  447. {
  448. stateCustomData->key = xmlSafeStringCharDup(cText.trim(), false);
  449. }
  450. else if (cTag == "Value")
  451. {
  452. // save operation adds a newline and newline+space around the string in some cases
  453. const int len = cText.length();
  454. if (std::strcmp(stateCustomData->type, CUSTOM_DATA_TYPE_CHUNK) == 0 || len >= 128+6)
  455. {
  456. CARLA_SAFE_ASSERT_CONTINUE(len >= 6);
  457. cText = cText.substring(1, len - 5);
  458. }
  459. stateCustomData->value = xmlSafeStringCharDup(cText, false);
  460. }
  461. }
  462. if (stateCustomData->isValid())
  463. {
  464. customData.append(stateCustomData);
  465. }
  466. else
  467. {
  468. carla_stderr("Reading CustomData property failed, missing data");
  469. delete stateCustomData;
  470. }
  471. }
  472. // -------------------------------------------------------
  473. // Chunk
  474. else if (tag == "Chunk")
  475. {
  476. chunk = carla_strdup(text.toRawUTF8());
  477. }
  478. }
  479. }
  480. }
  481. return true;
  482. }
  483. // -----------------------------------------------------------------------
  484. // fillXmlStringFromStateSave
  485. void CarlaStateSave::dumpToMemoryStream(MemoryOutputStream& content) const
  486. {
  487. const PluginType pluginType = getPluginTypeFromString(type);
  488. {
  489. MemoryOutputStream infoXml;
  490. infoXml << " <Info>\n";
  491. infoXml << " <Type>" << String(type != nullptr ? type : "") << "</Type>\n";
  492. infoXml << " <Name>" << xmlSafeString(name, true) << "</Name>\n";
  493. switch (pluginType)
  494. {
  495. case PLUGIN_NONE:
  496. break;
  497. case PLUGIN_INTERNAL:
  498. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  499. break;
  500. case PLUGIN_LADSPA:
  501. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  502. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  503. infoXml << " <UniqueID>" << water::int64(uniqueId) << "</UniqueID>\n";
  504. break;
  505. case PLUGIN_DSSI:
  506. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  507. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  508. break;
  509. case PLUGIN_LV2:
  510. infoXml << " <URI>" << xmlSafeString(label, true) << "</URI>\n";
  511. break;
  512. case PLUGIN_VST2:
  513. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  514. infoXml << " <UniqueID>" << water::int64(uniqueId) << "</UniqueID>\n";
  515. break;
  516. case PLUGIN_VST3:
  517. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  518. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  519. break;
  520. case PLUGIN_AU:
  521. infoXml << " <Identifier>" << xmlSafeString(label, true) << "</Identifier>\n";
  522. break;
  523. case PLUGIN_CLAP:
  524. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  525. infoXml << " <Identifier>" << xmlSafeString(label, true) << "</Identifier>\n";
  526. break;
  527. case PLUGIN_DLS:
  528. case PLUGIN_GIG:
  529. case PLUGIN_SF2:
  530. case PLUGIN_JSFX:
  531. infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
  532. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  533. break;
  534. case PLUGIN_SFZ:
  535. infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
  536. break;
  537. case PLUGIN_JACK:
  538. infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
  539. infoXml << " <Setup>" << xmlSafeString(label, true) << "</Setup>\n";
  540. break;
  541. case PLUGIN_TYPE_COUNT:
  542. break;
  543. }
  544. infoXml << " </Info>\n\n";
  545. content << infoXml;
  546. }
  547. content << " <Data>\n";
  548. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  549. {
  550. MemoryOutputStream dataXml;
  551. dataXml << " <Active>" << (active ? "Yes" : "No") << "</Active>\n";
  552. if (carla_isNotEqual(dryWet, 1.0f))
  553. dataXml << " <DryWet>" << String(dryWet, 7) << "</DryWet>\n";
  554. if (carla_isNotEqual(volume, 1.0f))
  555. dataXml << " <Volume>" << String(volume, 7) << "</Volume>\n";
  556. if (carla_isNotEqual(balanceLeft, -1.0f))
  557. dataXml << " <Balance-Left>" << String(balanceLeft, 7) << "</Balance-Left>\n";
  558. if (carla_isNotEqual(balanceRight, 1.0f))
  559. dataXml << " <Balance-Right>" << String(balanceRight, 7) << "</Balance-Right>\n";
  560. if (carla_isNotEqual(panning, 0.0f))
  561. dataXml << " <Panning>" << String(panning, 7) << "</Panning>\n";
  562. if (ctrlChannel < 0)
  563. dataXml << " <ControlChannel>N</ControlChannel>\n";
  564. else
  565. dataXml << " <ControlChannel>" << int(ctrlChannel+1) << "</ControlChannel>\n";
  566. dataXml << " <Options>0x" << String::toHexString(static_cast<int>(options)) << "</Options>\n";
  567. content << dataXml;
  568. }
  569. #endif
  570. for (ParameterItenerator it = parameters.begin2(); it.valid(); it.next())
  571. {
  572. Parameter* const stateParameter(it.getValue(nullptr));
  573. CARLA_SAFE_ASSERT_CONTINUE(stateParameter != nullptr);
  574. MemoryOutputStream parameterXml;
  575. parameterXml << "\n";
  576. parameterXml << " <Parameter>\n";
  577. parameterXml << " <Index>" << String(stateParameter->index) << "</Index>\n";
  578. parameterXml << " <Name>" << xmlSafeString(stateParameter->name, true) << "</Name>\n";
  579. if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
  580. {
  581. if (pluginType == PLUGIN_CLAP)
  582. parameterXml << " <Identifier>" << xmlSafeString(stateParameter->symbol, true) << "</Identifier>\n";
  583. else
  584. parameterXml << " <Symbol>" << xmlSafeString(stateParameter->symbol, true) << "</Symbol>\n";
  585. }
  586. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  587. if (stateParameter->mappedControlIndex > CONTROL_INDEX_NONE && stateParameter->mappedControlIndex <= CONTROL_INDEX_MAX_ALLOWED)
  588. {
  589. parameterXml << " <MidiChannel>" << stateParameter->midiChannel+1 << "</MidiChannel>\n";
  590. parameterXml << " <MappedControlIndex>" << stateParameter->mappedControlIndex << "</MappedControlIndex>\n";
  591. if (stateParameter->mappedRangeValid)
  592. {
  593. parameterXml << " <MappedMinimum>" << String(stateParameter->mappedMinimum, 15) << "</MappedMinimum>\n";
  594. parameterXml << " <MappedMaximum>" << String(stateParameter->mappedMaximum, 15) << "</MappedMaximum>\n";
  595. }
  596. // backwards compatibility for older carla versions
  597. if (stateParameter->mappedControlIndex > 0 && stateParameter->mappedControlIndex < MAX_MIDI_CONTROL)
  598. parameterXml << " <MidiCC>" << stateParameter->mappedControlIndex << "</MidiCC>\n";
  599. }
  600. #endif
  601. if (! stateParameter->dummy)
  602. parameterXml << " <Value>" << String(stateParameter->value, 15) << "</Value>\n";
  603. parameterXml << " </Parameter>\n";
  604. content << parameterXml;
  605. }
  606. if (currentProgramIndex >= 0 && currentProgramName != nullptr && currentProgramName[0] != '\0')
  607. {
  608. // ignore 'default' program
  609. if (currentProgramIndex > 0 || ! String(currentProgramName).equalsIgnoreCase("default"))
  610. {
  611. MemoryOutputStream programXml;
  612. programXml << "\n";
  613. programXml << " <CurrentProgramIndex>" << currentProgramIndex+1 << "</CurrentProgramIndex>\n";
  614. programXml << " <CurrentProgramName>" << xmlSafeString(currentProgramName, true) << "</CurrentProgramName>\n";
  615. content << programXml;
  616. }
  617. }
  618. if (currentMidiBank >= 0 && currentMidiProgram >= 0)
  619. {
  620. MemoryOutputStream midiProgramXml;
  621. midiProgramXml << "\n";
  622. midiProgramXml << " <CurrentMidiBank>" << currentMidiBank+1 << "</CurrentMidiBank>\n";
  623. midiProgramXml << " <CurrentMidiProgram>" << currentMidiProgram+1 << "</CurrentMidiProgram>\n";
  624. content << midiProgramXml;
  625. }
  626. for (CustomDataItenerator it = customData.begin2(); it.valid(); it.next())
  627. {
  628. CustomData* const stateCustomData(it.getValue(nullptr));
  629. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData != nullptr);
  630. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData->isValid());
  631. MemoryOutputStream customDataXml;
  632. customDataXml << "\n";
  633. customDataXml << " <CustomData>\n";
  634. customDataXml << " <Type>" << xmlSafeString(stateCustomData->type, true) << "</Type>\n";
  635. customDataXml << " <Key>" << xmlSafeString(stateCustomData->key, true) << "</Key>\n";
  636. if (std::strcmp(stateCustomData->type, CUSTOM_DATA_TYPE_CHUNK) == 0 || std::strlen(stateCustomData->value) >= 128)
  637. {
  638. customDataXml << " <Value>\n";
  639. customDataXml << xmlSafeStringFast(stateCustomData->value, true);
  640. customDataXml << "\n </Value>\n";
  641. }
  642. else
  643. {
  644. customDataXml << " <Value>";
  645. customDataXml << xmlSafeStringFast(stateCustomData->value, true);
  646. customDataXml << "</Value>\n";
  647. }
  648. customDataXml << " </CustomData>\n";
  649. content << customDataXml;
  650. }
  651. if (chunk != nullptr && chunk[0] != '\0')
  652. {
  653. MemoryOutputStream chunkXml, chunkSplt;
  654. getNewLineSplittedString(chunkSplt, chunk);
  655. chunkXml << "\n <Chunk>\n";
  656. chunkXml << chunkSplt;
  657. chunkXml << "\n </Chunk>\n";
  658. content << chunkXml;
  659. }
  660. content << " </Data>\n";
  661. }
  662. // -----------------------------------------------------------------------
  663. CARLA_BACKEND_END_NAMESPACE