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 23KB

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