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.

728 lines
25KB

  1. /*
  2. * Carla State utils
  3. * Copyright (C) 2012-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 "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. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  165. active(false),
  166. dryWet(1.0f),
  167. volume(1.0f),
  168. balanceLeft(-1.0f),
  169. balanceRight(1.0f),
  170. panning(0.0f),
  171. ctrlChannel(-1),
  172. #endif
  173. currentProgramIndex(-1),
  174. currentProgramName(nullptr),
  175. currentMidiBank(-1),
  176. currentMidiProgram(-1),
  177. chunk(nullptr),
  178. parameters(),
  179. customData() {}
  180. CarlaStateSave::~CarlaStateSave() noexcept
  181. {
  182. clear();
  183. }
  184. void CarlaStateSave::clear() noexcept
  185. {
  186. if (type != nullptr)
  187. {
  188. delete[] type;
  189. type = nullptr;
  190. }
  191. if (name != nullptr)
  192. {
  193. delete[] name;
  194. name = nullptr;
  195. }
  196. if (label != nullptr)
  197. {
  198. delete[] label;
  199. label = nullptr;
  200. }
  201. if (binary != nullptr)
  202. {
  203. delete[] binary;
  204. binary = nullptr;
  205. }
  206. if (currentProgramName != nullptr)
  207. {
  208. delete[] currentProgramName;
  209. currentProgramName = nullptr;
  210. }
  211. if (chunk != nullptr)
  212. {
  213. delete[] chunk;
  214. chunk = nullptr;
  215. }
  216. uniqueId = 0;
  217. options = 0x0;
  218. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  219. active = false;
  220. dryWet = 1.0f;
  221. volume = 1.0f;
  222. balanceLeft = -1.0f;
  223. balanceRight = 1.0f;
  224. panning = 0.0f;
  225. ctrlChannel = -1;
  226. #endif
  227. currentProgramIndex = -1;
  228. currentMidiBank = -1;
  229. currentMidiProgram = -1;
  230. for (ParameterItenerator it = parameters.begin2(); it.valid(); it.next())
  231. {
  232. Parameter* const stateParameter(it.getValue(nullptr));
  233. delete stateParameter;
  234. }
  235. for (CustomDataItenerator it = customData.begin2(); it.valid(); it.next())
  236. {
  237. CustomData* const stateCustomData(it.getValue(nullptr));
  238. delete stateCustomData;
  239. }
  240. parameters.clear();
  241. customData.clear();
  242. }
  243. // -----------------------------------------------------------------------
  244. // fillFromXmlElement
  245. bool CarlaStateSave::fillFromXmlElement(const XmlElement* const xmlElement)
  246. {
  247. CARLA_SAFE_ASSERT_RETURN(xmlElement != nullptr, false);
  248. clear();
  249. for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
  250. {
  251. const String& tagName(elem->getTagName());
  252. // ---------------------------------------------------------------
  253. // Info
  254. if (tagName == "Info")
  255. {
  256. for (XmlElement* xmlInfo = elem->getFirstChildElement(); xmlInfo != nullptr; xmlInfo = xmlInfo->getNextElement())
  257. {
  258. const String& tag(xmlInfo->getTagName());
  259. const String text(xmlInfo->getAllSubText().trim());
  260. /**/ if (tag == "Type")
  261. type = xmlSafeStringCharDup(text, false);
  262. else if (tag == "Name")
  263. name = xmlSafeStringCharDup(text, false);
  264. else if (tag == "Label" || tag == "URI" || tag == "Identifier" || tag == "Setup")
  265. label = xmlSafeStringCharDup(text, false);
  266. else if (tag == "Binary" || tag == "Filename")
  267. binary = xmlSafeStringCharDup(text, false);
  268. else if (tag == "UniqueID")
  269. uniqueId = text.getLargeIntValue();
  270. }
  271. }
  272. // ---------------------------------------------------------------
  273. // Data
  274. else if (tagName == "Data")
  275. {
  276. for (XmlElement* xmlData = elem->getFirstChildElement(); xmlData != nullptr; xmlData = xmlData->getNextElement())
  277. {
  278. const String& tag(xmlData->getTagName());
  279. const String text(xmlData->getAllSubText().trim());
  280. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  281. // -------------------------------------------------------
  282. // Internal Data
  283. /**/ if (tag == "Active")
  284. {
  285. active = (text == "Yes");
  286. }
  287. else if (tag == "DryWet")
  288. {
  289. dryWet = carla_fixedValue(0.0f, 1.0f, text.getFloatValue());
  290. }
  291. else if (tag == "Volume")
  292. {
  293. volume = carla_fixedValue(0.0f, 1.27f, text.getFloatValue());
  294. }
  295. else if (tag == "Balance-Left")
  296. {
  297. balanceLeft = carla_fixedValue(-1.0f, 1.0f, text.getFloatValue());
  298. }
  299. else if (tag == "Balance-Right")
  300. {
  301. balanceRight = carla_fixedValue(-1.0f, 1.0f, text.getFloatValue());
  302. }
  303. else if (tag == "Panning")
  304. {
  305. panning = carla_fixedValue(-1.0f, 1.0f, text.getFloatValue());
  306. }
  307. else if (tag == "ControlChannel")
  308. {
  309. if (! text.startsWithIgnoreCase("n"))
  310. {
  311. const int value(text.getIntValue());
  312. if (value >= 1 && value <= MAX_MIDI_CHANNELS)
  313. ctrlChannel = static_cast<int8_t>(value-1);
  314. }
  315. }
  316. else if (tag == "Options")
  317. {
  318. const int value(text.getHexValue32());
  319. if (value > 0)
  320. options = static_cast<uint>(value);
  321. }
  322. #else
  323. if (false) {}
  324. #endif
  325. // -------------------------------------------------------
  326. // Program (current)
  327. else if (tag == "CurrentProgramIndex")
  328. {
  329. const int value(text.getIntValue());
  330. if (value >= 1)
  331. currentProgramIndex = value-1;
  332. }
  333. else if (tag == "CurrentProgramName")
  334. {
  335. currentProgramName = xmlSafeStringCharDup(text, false);
  336. }
  337. // -------------------------------------------------------
  338. // Midi Program (current)
  339. else if (tag == "CurrentMidiBank")
  340. {
  341. const int value(text.getIntValue());
  342. if (value >= 1)
  343. currentMidiBank = value-1;
  344. }
  345. else if (tag == "CurrentMidiProgram")
  346. {
  347. const int value(text.getIntValue());
  348. if (value >= 1)
  349. currentMidiProgram = value-1;
  350. }
  351. // -------------------------------------------------------
  352. // Parameters
  353. else if (tag == "Parameter")
  354. {
  355. Parameter* const stateParameter(new Parameter());
  356. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  357. bool hasMappedMinimum = false, hasMappedMaximum = false;
  358. #endif
  359. for (XmlElement* xmlSubData = xmlData->getFirstChildElement(); xmlSubData != nullptr; xmlSubData = xmlSubData->getNextElement())
  360. {
  361. const String& pTag(xmlSubData->getTagName());
  362. const String pText(xmlSubData->getAllSubText().trim());
  363. /**/ if (pTag == "Index")
  364. {
  365. const int index(pText.getIntValue());
  366. if (index >= 0)
  367. stateParameter->index = index;
  368. }
  369. else if (pTag == "Name")
  370. {
  371. stateParameter->name = xmlSafeStringCharDup(pText, false);
  372. }
  373. else if (pTag == "Symbol")
  374. {
  375. stateParameter->symbol = xmlSafeStringCharDup(pText, false);
  376. }
  377. else if (pTag == "Value")
  378. {
  379. stateParameter->dummy = false;
  380. stateParameter->value = pText.getFloatValue();
  381. }
  382. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  383. else if (pTag == "MidiChannel")
  384. {
  385. const int channel(pText.getIntValue());
  386. if (channel >= 1 && channel <= MAX_MIDI_CHANNELS)
  387. stateParameter->midiChannel = static_cast<uint8_t>(channel-1);
  388. }
  389. else if (pTag == "MidiCC")
  390. {
  391. const int cc(pText.getIntValue());
  392. if (cc > 0 && cc < MAX_MIDI_CONTROL)
  393. stateParameter->mappedControlIndex = static_cast<int16_t>(cc);
  394. }
  395. else if (pTag == "MappedControlIndex")
  396. {
  397. const int ctrl(pText.getIntValue());
  398. if (ctrl > CONTROL_INDEX_NONE && ctrl <= CONTROL_INDEX_MAX_ALLOWED)
  399. stateParameter->mappedControlIndex = static_cast<int16_t>(ctrl);
  400. }
  401. else if (pTag == "MappedMinimum")
  402. {
  403. hasMappedMinimum = true;
  404. stateParameter->mappedMinimum = pText.getFloatValue();
  405. }
  406. else if (pTag == "MappedMaximum")
  407. {
  408. hasMappedMaximum = true;
  409. stateParameter->mappedMaximum = pText.getFloatValue();
  410. }
  411. #endif
  412. }
  413. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  414. if (hasMappedMinimum && hasMappedMaximum)
  415. stateParameter->mappedRangeValid = true;
  416. #endif
  417. parameters.append(stateParameter);
  418. }
  419. // -------------------------------------------------------
  420. // Custom Data
  421. else if (tag == "CustomData")
  422. {
  423. CustomData* const stateCustomData(new CustomData());
  424. for (XmlElement* xmlSubData = xmlData->getFirstChildElement(); xmlSubData != nullptr; xmlSubData = xmlSubData->getNextElement())
  425. {
  426. const String& cTag(xmlSubData->getTagName());
  427. const String cText(xmlSubData->getAllSubText().trim());
  428. /**/ if (cTag == "Type")
  429. stateCustomData->type = xmlSafeStringCharDup(cText, false);
  430. else if (cTag == "Key")
  431. stateCustomData->key = xmlSafeStringCharDup(cText, false);
  432. else if (cTag == "Value")
  433. stateCustomData->value = carla_strdup(cText.toRawUTF8()); //xmlSafeStringCharDup(cText, false);
  434. }
  435. if (stateCustomData->isValid())
  436. customData.append(stateCustomData);
  437. else
  438. carla_stderr("Reading CustomData property failed, missing data");
  439. }
  440. // -------------------------------------------------------
  441. // Chunk
  442. else if (tag == "Chunk")
  443. {
  444. chunk = carla_strdup(text.toRawUTF8());
  445. }
  446. }
  447. }
  448. }
  449. return true;
  450. }
  451. // -----------------------------------------------------------------------
  452. // fillXmlStringFromStateSave
  453. void CarlaStateSave::dumpToMemoryStream(MemoryOutputStream& content) const
  454. {
  455. {
  456. MemoryOutputStream infoXml;
  457. infoXml << " <Info>\n";
  458. infoXml << " <Type>" << String(type != nullptr ? type : "") << "</Type>\n";
  459. infoXml << " <Name>" << xmlSafeString(name, true) << "</Name>\n";
  460. switch (getPluginTypeFromString(type))
  461. {
  462. case PLUGIN_NONE:
  463. break;
  464. case PLUGIN_INTERNAL:
  465. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  466. break;
  467. case PLUGIN_LADSPA:
  468. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  469. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  470. infoXml << " <UniqueID>" << water::int64(uniqueId) << "</UniqueID>\n";
  471. break;
  472. case PLUGIN_DSSI:
  473. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  474. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  475. break;
  476. case PLUGIN_LV2:
  477. infoXml << " <URI>" << xmlSafeString(label, true) << "</URI>\n";
  478. break;
  479. case PLUGIN_VST2:
  480. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  481. infoXml << " <UniqueID>" << water::int64(uniqueId) << "</UniqueID>\n";
  482. break;
  483. case PLUGIN_VST3:
  484. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  485. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  486. break;
  487. case PLUGIN_AU:
  488. infoXml << " <Identifier>" << xmlSafeString(label, true) << "</Identifier>\n";
  489. break;
  490. case PLUGIN_DLS:
  491. case PLUGIN_GIG:
  492. case PLUGIN_SF2:
  493. infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
  494. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  495. break;
  496. case PLUGIN_SFZ:
  497. infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
  498. break;
  499. case PLUGIN_JACK:
  500. infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
  501. infoXml << " <Setup>" << xmlSafeString(label, true) << "</Setup>\n";
  502. break;
  503. }
  504. infoXml << " </Info>\n\n";
  505. content << infoXml;
  506. }
  507. content << " <Data>\n";
  508. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  509. {
  510. MemoryOutputStream dataXml;
  511. dataXml << " <Active>" << (active ? "Yes" : "No") << "</Active>\n";
  512. if (carla_isNotEqual(dryWet, 1.0f))
  513. dataXml << " <DryWet>" << String(dryWet, 7) << "</DryWet>\n";
  514. if (carla_isNotEqual(volume, 1.0f))
  515. dataXml << " <Volume>" << String(volume, 7) << "</Volume>\n";
  516. if (carla_isNotEqual(balanceLeft, -1.0f))
  517. dataXml << " <Balance-Left>" << String(balanceLeft, 7) << "</Balance-Left>\n";
  518. if (carla_isNotEqual(balanceRight, 1.0f))
  519. dataXml << " <Balance-Right>" << String(balanceRight, 7) << "</Balance-Right>\n";
  520. if (carla_isNotEqual(panning, 0.0f))
  521. dataXml << " <Panning>" << String(panning, 7) << "</Panning>\n";
  522. if (ctrlChannel < 0)
  523. dataXml << " <ControlChannel>N</ControlChannel>\n";
  524. else
  525. dataXml << " <ControlChannel>" << int(ctrlChannel+1) << "</ControlChannel>\n";
  526. dataXml << " <Options>0x" << String::toHexString(static_cast<int>(options)) << "</Options>\n";
  527. content << dataXml;
  528. }
  529. #endif
  530. for (ParameterItenerator it = parameters.begin2(); it.valid(); it.next())
  531. {
  532. Parameter* const stateParameter(it.getValue(nullptr));
  533. CARLA_SAFE_ASSERT_CONTINUE(stateParameter != nullptr);
  534. MemoryOutputStream parameterXml;
  535. parameterXml << "\n";
  536. parameterXml << " <Parameter>\n";
  537. parameterXml << " <Index>" << String(stateParameter->index) << "</Index>\n";
  538. parameterXml << " <Name>" << xmlSafeString(stateParameter->name, true) << "</Name>\n";
  539. if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
  540. parameterXml << " <Symbol>" << xmlSafeString(stateParameter->symbol, true) << "</Symbol>\n";
  541. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  542. if (stateParameter->mappedControlIndex > CONTROL_INDEX_NONE && stateParameter->mappedControlIndex <= CONTROL_INDEX_MAX_ALLOWED)
  543. {
  544. parameterXml << " <MidiChannel>" << stateParameter->midiChannel+1 << "</MidiChannel>\n";
  545. parameterXml << " <MappedControlIndex>" << stateParameter->mappedControlIndex << "</MappedControlIndex>\n";
  546. if (stateParameter->mappedRangeValid)
  547. {
  548. parameterXml << " <MappedMinimum>" << String(stateParameter->mappedMinimum, 15) << "</MappedMinimum>\n";
  549. parameterXml << " <MappedMaximum>" << String(stateParameter->mappedMaximum, 15) << "</MappedMaximum>\n";
  550. }
  551. // backwards compatibility for older carla versions
  552. if (stateParameter->mappedControlIndex > 0 && stateParameter->mappedControlIndex < MAX_MIDI_CONTROL)
  553. parameterXml << " <MidiCC>" << stateParameter->mappedControlIndex << "</MidiCC>\n";
  554. }
  555. #endif
  556. if (! stateParameter->dummy)
  557. parameterXml << " <Value>" << String(stateParameter->value, 15) << "</Value>\n";
  558. parameterXml << " </Parameter>\n";
  559. content << parameterXml;
  560. }
  561. if (currentProgramIndex >= 0 && currentProgramName != nullptr && currentProgramName[0] != '\0')
  562. {
  563. // ignore 'default' program
  564. if (currentProgramIndex > 0 || ! String(currentProgramName).equalsIgnoreCase("default"))
  565. {
  566. MemoryOutputStream programXml;
  567. programXml << "\n";
  568. programXml << " <CurrentProgramIndex>" << currentProgramIndex+1 << "</CurrentProgramIndex>\n";
  569. programXml << " <CurrentProgramName>" << xmlSafeString(currentProgramName, true) << "</CurrentProgramName>\n";
  570. content << programXml;
  571. }
  572. }
  573. if (currentMidiBank >= 0 && currentMidiProgram >= 0)
  574. {
  575. MemoryOutputStream midiProgramXml;
  576. midiProgramXml << "\n";
  577. midiProgramXml << " <CurrentMidiBank>" << currentMidiBank+1 << "</CurrentMidiBank>\n";
  578. midiProgramXml << " <CurrentMidiProgram>" << currentMidiProgram+1 << "</CurrentMidiProgram>\n";
  579. content << midiProgramXml;
  580. }
  581. for (CustomDataItenerator it = customData.begin2(); it.valid(); it.next())
  582. {
  583. CustomData* const stateCustomData(it.getValue(nullptr));
  584. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData != nullptr);
  585. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData->isValid());
  586. MemoryOutputStream customDataXml;
  587. customDataXml << "\n";
  588. customDataXml << " <CustomData>\n";
  589. customDataXml << " <Type>" << xmlSafeString(stateCustomData->type, true) << "</Type>\n";
  590. customDataXml << " <Key>" << xmlSafeString(stateCustomData->key, true) << "</Key>\n";
  591. if (std::strcmp(stateCustomData->type, CUSTOM_DATA_TYPE_CHUNK) == 0 || std::strlen(stateCustomData->value) >= 128)
  592. {
  593. customDataXml << " <Value>\n";
  594. customDataXml << xmlSafeStringFast(stateCustomData->value, true);
  595. customDataXml << "\n </Value>\n";
  596. }
  597. else
  598. {
  599. customDataXml << " <Value>";
  600. customDataXml << xmlSafeStringFast(stateCustomData->value, true);
  601. customDataXml << "</Value>\n";
  602. }
  603. customDataXml << " </CustomData>\n";
  604. content << customDataXml;
  605. }
  606. if (chunk != nullptr && chunk[0] != '\0')
  607. {
  608. MemoryOutputStream chunkXml, chunkSplt;
  609. getNewLineSplittedString(chunkSplt, chunk);
  610. chunkXml << "\n <Chunk>\n";
  611. chunkXml << chunkSplt;
  612. chunkXml << "\n </Chunk>\n";
  613. content << chunkXml;
  614. }
  615. content << " </Data>\n";
  616. }
  617. // -----------------------------------------------------------------------
  618. CARLA_BACKEND_END_NAMESPACE