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.

734 lines
25KB

  1. /*
  2. * Carla State utils
  3. * Copyright (C) 2012-2020 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")
  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. for (XmlElement* xmlSubData = xmlData->getFirstChildElement(); xmlSubData != nullptr; xmlSubData = xmlSubData->getNextElement())
  427. {
  428. const String& cTag(xmlSubData->getTagName());
  429. const String cText(xmlSubData->getAllSubText().trim());
  430. /**/ if (cTag == "Type")
  431. stateCustomData->type = xmlSafeStringCharDup(cText, false);
  432. else if (cTag == "Key")
  433. stateCustomData->key = xmlSafeStringCharDup(cText, false);
  434. else if (cTag == "Value")
  435. stateCustomData->value = carla_strdup(cText.toRawUTF8()); //xmlSafeStringCharDup(cText, false);
  436. }
  437. if (stateCustomData->isValid())
  438. customData.append(stateCustomData);
  439. else
  440. carla_stderr("Reading CustomData property failed, missing data");
  441. }
  442. // -------------------------------------------------------
  443. // Chunk
  444. else if (tag == "Chunk")
  445. {
  446. chunk = carla_strdup(text.toRawUTF8());
  447. }
  448. }
  449. }
  450. }
  451. return true;
  452. }
  453. // -----------------------------------------------------------------------
  454. // fillXmlStringFromStateSave
  455. void CarlaStateSave::dumpToMemoryStream(MemoryOutputStream& content) const
  456. {
  457. {
  458. MemoryOutputStream infoXml;
  459. infoXml << " <Info>\n";
  460. infoXml << " <Type>" << String(type != nullptr ? type : "") << "</Type>\n";
  461. infoXml << " <Name>" << xmlSafeString(name, true) << "</Name>\n";
  462. switch (getPluginTypeFromString(type))
  463. {
  464. case PLUGIN_NONE:
  465. break;
  466. case PLUGIN_INTERNAL:
  467. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  468. break;
  469. case PLUGIN_LADSPA:
  470. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  471. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  472. infoXml << " <UniqueID>" << water::int64(uniqueId) << "</UniqueID>\n";
  473. break;
  474. case PLUGIN_DSSI:
  475. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  476. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  477. break;
  478. case PLUGIN_LV2:
  479. infoXml << " <URI>" << xmlSafeString(label, true) << "</URI>\n";
  480. break;
  481. case PLUGIN_VST2:
  482. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  483. infoXml << " <UniqueID>" << water::int64(uniqueId) << "</UniqueID>\n";
  484. break;
  485. case PLUGIN_VST3:
  486. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  487. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  488. break;
  489. case PLUGIN_AU:
  490. infoXml << " <Identifier>" << xmlSafeString(label, true) << "</Identifier>\n";
  491. break;
  492. case PLUGIN_JSFX:
  493. // TODO(jsfx) this might be incorrect
  494. infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
  495. break;
  496. case PLUGIN_DLS:
  497. case PLUGIN_GIG:
  498. case PLUGIN_SF2:
  499. infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
  500. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  501. break;
  502. case PLUGIN_SFZ:
  503. infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
  504. break;
  505. case PLUGIN_JACK:
  506. infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
  507. infoXml << " <Setup>" << xmlSafeString(label, true) << "</Setup>\n";
  508. break;
  509. }
  510. infoXml << " </Info>\n\n";
  511. content << infoXml;
  512. }
  513. content << " <Data>\n";
  514. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  515. {
  516. MemoryOutputStream dataXml;
  517. dataXml << " <Active>" << (active ? "Yes" : "No") << "</Active>\n";
  518. if (carla_isNotEqual(dryWet, 1.0f))
  519. dataXml << " <DryWet>" << String(dryWet, 7) << "</DryWet>\n";
  520. if (carla_isNotEqual(volume, 1.0f))
  521. dataXml << " <Volume>" << String(volume, 7) << "</Volume>\n";
  522. if (carla_isNotEqual(balanceLeft, -1.0f))
  523. dataXml << " <Balance-Left>" << String(balanceLeft, 7) << "</Balance-Left>\n";
  524. if (carla_isNotEqual(balanceRight, 1.0f))
  525. dataXml << " <Balance-Right>" << String(balanceRight, 7) << "</Balance-Right>\n";
  526. if (carla_isNotEqual(panning, 0.0f))
  527. dataXml << " <Panning>" << String(panning, 7) << "</Panning>\n";
  528. if (ctrlChannel < 0)
  529. dataXml << " <ControlChannel>N</ControlChannel>\n";
  530. else
  531. dataXml << " <ControlChannel>" << int(ctrlChannel+1) << "</ControlChannel>\n";
  532. dataXml << " <Options>0x" << String::toHexString(static_cast<int>(options)) << "</Options>\n";
  533. content << dataXml;
  534. }
  535. #endif
  536. for (ParameterItenerator it = parameters.begin2(); it.valid(); it.next())
  537. {
  538. Parameter* const stateParameter(it.getValue(nullptr));
  539. CARLA_SAFE_ASSERT_CONTINUE(stateParameter != nullptr);
  540. MemoryOutputStream parameterXml;
  541. parameterXml << "\n";
  542. parameterXml << " <Parameter>\n";
  543. parameterXml << " <Index>" << String(stateParameter->index) << "</Index>\n";
  544. parameterXml << " <Name>" << xmlSafeString(stateParameter->name, true) << "</Name>\n";
  545. if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
  546. parameterXml << " <Symbol>" << xmlSafeString(stateParameter->symbol, true) << "</Symbol>\n";
  547. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  548. if (stateParameter->mappedControlIndex > CONTROL_INDEX_NONE && stateParameter->mappedControlIndex <= CONTROL_INDEX_MAX_ALLOWED)
  549. {
  550. parameterXml << " <MidiChannel>" << stateParameter->midiChannel+1 << "</MidiChannel>\n";
  551. parameterXml << " <MappedControlIndex>" << stateParameter->mappedControlIndex << "</MappedControlIndex>\n";
  552. if (stateParameter->mappedRangeValid)
  553. {
  554. parameterXml << " <MappedMinimum>" << String(stateParameter->mappedMinimum, 15) << "</MappedMinimum>\n";
  555. parameterXml << " <MappedMaximum>" << String(stateParameter->mappedMaximum, 15) << "</MappedMaximum>\n";
  556. }
  557. // backwards compatibility for older carla versions
  558. if (stateParameter->mappedControlIndex > 0 && stateParameter->mappedControlIndex < MAX_MIDI_CONTROL)
  559. parameterXml << " <MidiCC>" << stateParameter->mappedControlIndex << "</MidiCC>\n";
  560. }
  561. #endif
  562. if (! stateParameter->dummy)
  563. parameterXml << " <Value>" << String(stateParameter->value, 15) << "</Value>\n";
  564. parameterXml << " </Parameter>\n";
  565. content << parameterXml;
  566. }
  567. if (currentProgramIndex >= 0 && currentProgramName != nullptr && currentProgramName[0] != '\0')
  568. {
  569. // ignore 'default' program
  570. if (currentProgramIndex > 0 || ! String(currentProgramName).equalsIgnoreCase("default"))
  571. {
  572. MemoryOutputStream programXml;
  573. programXml << "\n";
  574. programXml << " <CurrentProgramIndex>" << currentProgramIndex+1 << "</CurrentProgramIndex>\n";
  575. programXml << " <CurrentProgramName>" << xmlSafeString(currentProgramName, true) << "</CurrentProgramName>\n";
  576. content << programXml;
  577. }
  578. }
  579. if (currentMidiBank >= 0 && currentMidiProgram >= 0)
  580. {
  581. MemoryOutputStream midiProgramXml;
  582. midiProgramXml << "\n";
  583. midiProgramXml << " <CurrentMidiBank>" << currentMidiBank+1 << "</CurrentMidiBank>\n";
  584. midiProgramXml << " <CurrentMidiProgram>" << currentMidiProgram+1 << "</CurrentMidiProgram>\n";
  585. content << midiProgramXml;
  586. }
  587. for (CustomDataItenerator it = customData.begin2(); it.valid(); it.next())
  588. {
  589. CustomData* const stateCustomData(it.getValue(nullptr));
  590. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData != nullptr);
  591. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData->isValid());
  592. MemoryOutputStream customDataXml;
  593. customDataXml << "\n";
  594. customDataXml << " <CustomData>\n";
  595. customDataXml << " <Type>" << xmlSafeString(stateCustomData->type, true) << "</Type>\n";
  596. customDataXml << " <Key>" << xmlSafeString(stateCustomData->key, true) << "</Key>\n";
  597. if (std::strcmp(stateCustomData->type, CUSTOM_DATA_TYPE_CHUNK) == 0 || std::strlen(stateCustomData->value) >= 128)
  598. {
  599. customDataXml << " <Value>\n";
  600. customDataXml << xmlSafeStringFast(stateCustomData->value, true);
  601. customDataXml << "\n </Value>\n";
  602. }
  603. else
  604. {
  605. customDataXml << " <Value>";
  606. customDataXml << xmlSafeStringFast(stateCustomData->value, true);
  607. customDataXml << "</Value>\n";
  608. }
  609. customDataXml << " </CustomData>\n";
  610. content << customDataXml;
  611. }
  612. if (chunk != nullptr && chunk[0] != '\0')
  613. {
  614. MemoryOutputStream chunkXml, chunkSplt;
  615. getNewLineSplittedString(chunkSplt, chunk);
  616. chunkXml << "\n <Chunk>\n";
  617. chunkXml << chunkSplt;
  618. chunkXml << "\n </Chunk>\n";
  619. content << chunkXml;
  620. }
  621. content << " </Data>\n";
  622. }
  623. // -----------------------------------------------------------------------
  624. CARLA_BACKEND_END_NAMESPACE