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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /*
  2. * Carla State utils
  3. * Copyright (C) 2012-2014 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 <string>
  22. using juce::MemoryOutputStream;
  23. using juce::String;
  24. using juce::XmlElement;
  25. CARLA_BACKEND_START_NAMESPACE
  26. // -----------------------------------------------------------------------
  27. // getNewLineSplittedString
  28. static void getNewLineSplittedString(MemoryOutputStream& stream, const String& string)
  29. {
  30. static const int kLineWidth = 120;
  31. int i = 0;
  32. const int length = string.length();
  33. const char* const raw = string.toUTF8();
  34. stream.preallocate(static_cast<std::size_t>(length + length/kLineWidth + 3));
  35. for (; i+kLineWidth < length; i += kLineWidth)
  36. {
  37. stream.write(raw+i, kLineWidth);
  38. stream.writeByte('\n');
  39. }
  40. stream << (raw+i);
  41. }
  42. // -----------------------------------------------------------------------
  43. // xmlSafeStringFast
  44. /* Based on some code by James Kanze from stackoverflow
  45. * https://stackoverflow.com/questions/7724011/in-c-whats-the-fastest-way-to-replace-all-occurrences-of-a-substring-within */
  46. static std::string replaceStdString(const std::string& original, const std::string& before, const std::string& after)
  47. {
  48. std::string::const_iterator current = original.begin(), end = original.end(), next;
  49. std::string retval;
  50. for (; (next = std::search(current, end, before.begin(), before.end())) != end;)
  51. {
  52. retval.append(current, next);
  53. retval.append(after);
  54. current = next + static_cast<std::ssize_t>(before.size());
  55. }
  56. retval.append(current, next);
  57. return retval;
  58. }
  59. static std::string xmlSafeStringFast(const char* const cstring, const bool toXml)
  60. {
  61. std::string string(cstring);
  62. if (toXml)
  63. {
  64. string = replaceStdString(string, "&","&amp;");
  65. string = replaceStdString(string, "<","&lt;");
  66. string = replaceStdString(string, ">","&gt;");
  67. string = replaceStdString(string, "'","&apos;");
  68. string = replaceStdString(string, "\"","&quot;");
  69. }
  70. else
  71. {
  72. string = replaceStdString(string, "&lt;","<");
  73. string = replaceStdString(string, "&gt;",">");
  74. string = replaceStdString(string, "&apos;","'");
  75. string = replaceStdString(string, "&quot;","\"");
  76. string = replaceStdString(string, "&amp;","&");
  77. }
  78. return string;
  79. }
  80. // -----------------------------------------------------------------------
  81. // xmlSafeStringCharDup
  82. /*
  83. static const char* xmlSafeStringCharDup(const char* const cstring, const bool toXml)
  84. {
  85. return carla_strdup(xmlSafeString(cstring, toXml).toRawUTF8());
  86. }
  87. */
  88. static const char* xmlSafeStringCharDup(const String& string, const bool toXml)
  89. {
  90. return carla_strdup(xmlSafeString(string, toXml).toRawUTF8());
  91. }
  92. // -----------------------------------------------------------------------
  93. // StateParameter
  94. CarlaStateSave::Parameter::Parameter() noexcept
  95. : dummy(true),
  96. index(-1),
  97. name(nullptr),
  98. symbol(nullptr),
  99. #ifndef BUILD_BRIDGE
  100. value(0.0f),
  101. midiChannel(0),
  102. midiCC(-1) {}
  103. #else
  104. value(0.0f) {}
  105. #endif
  106. CarlaStateSave::Parameter::~Parameter() noexcept
  107. {
  108. if (name != nullptr)
  109. {
  110. delete[] name;
  111. name = nullptr;
  112. }
  113. if (symbol != nullptr)
  114. {
  115. delete[] symbol;
  116. symbol = nullptr;
  117. }
  118. }
  119. // -----------------------------------------------------------------------
  120. // StateCustomData
  121. CarlaStateSave::CustomData::CustomData() noexcept
  122. : type(nullptr),
  123. key(nullptr),
  124. value(nullptr) {}
  125. CarlaStateSave::CustomData::~CustomData() noexcept
  126. {
  127. if (type != nullptr)
  128. {
  129. delete[] type;
  130. type = nullptr;
  131. }
  132. if (key != nullptr)
  133. {
  134. delete[] key;
  135. key = nullptr;
  136. }
  137. if (value != nullptr)
  138. {
  139. delete[] value;
  140. value = nullptr;
  141. }
  142. }
  143. bool CarlaStateSave::CustomData::isValid() const noexcept
  144. {
  145. if (type == nullptr || type[0] == '\0') return false;
  146. if (key == nullptr || key [0] == '\0') return false;
  147. if (value == nullptr) return false;
  148. return true;
  149. }
  150. // -----------------------------------------------------------------------
  151. // StateSave
  152. CarlaStateSave::CarlaStateSave() noexcept
  153. : type(nullptr),
  154. name(nullptr),
  155. label(nullptr),
  156. binary(nullptr),
  157. uniqueId(0),
  158. options(0x0),
  159. #ifndef BUILD_BRIDGE
  160. active(false),
  161. dryWet(1.0f),
  162. volume(1.0f),
  163. balanceLeft(-1.0f),
  164. balanceRight(1.0f),
  165. panning(0.0f),
  166. ctrlChannel(-1),
  167. #endif
  168. currentProgramIndex(-1),
  169. currentProgramName(nullptr),
  170. currentMidiBank(-1),
  171. currentMidiProgram(-1),
  172. chunk(nullptr),
  173. parameters(),
  174. customData() {}
  175. CarlaStateSave::~CarlaStateSave() noexcept
  176. {
  177. clear();
  178. }
  179. void CarlaStateSave::clear() noexcept
  180. {
  181. if (type != nullptr)
  182. {
  183. delete[] type;
  184. type = nullptr;
  185. }
  186. if (name != nullptr)
  187. {
  188. delete[] name;
  189. name = nullptr;
  190. }
  191. if (label != nullptr)
  192. {
  193. delete[] label;
  194. label = nullptr;
  195. }
  196. if (binary != nullptr)
  197. {
  198. delete[] binary;
  199. binary = nullptr;
  200. }
  201. if (currentProgramName != nullptr)
  202. {
  203. delete[] currentProgramName;
  204. currentProgramName = nullptr;
  205. }
  206. if (chunk != nullptr)
  207. {
  208. delete[] chunk;
  209. chunk = nullptr;
  210. }
  211. uniqueId = 0;
  212. options = 0x0;
  213. #ifndef BUILD_BRIDGE
  214. active = false;
  215. dryWet = 1.0f;
  216. volume = 1.0f;
  217. balanceLeft = -1.0f;
  218. balanceRight = 1.0f;
  219. panning = 0.0f;
  220. ctrlChannel = -1;
  221. #endif
  222. currentProgramIndex = -1;
  223. currentMidiBank = -1;
  224. currentMidiProgram = -1;
  225. for (ParameterItenerator it = parameters.begin(); it.valid(); it.next())
  226. {
  227. Parameter* const stateParameter(it.getValue(nullptr));
  228. delete stateParameter;
  229. }
  230. for (CustomDataItenerator it = customData.begin(); it.valid(); it.next())
  231. {
  232. CustomData* const stateCustomData(it.getValue(nullptr));
  233. delete stateCustomData;
  234. }
  235. parameters.clear();
  236. customData.clear();
  237. }
  238. // -----------------------------------------------------------------------
  239. // fillFromXmlElement
  240. bool CarlaStateSave::fillFromXmlElement(const XmlElement* const xmlElement)
  241. {
  242. CARLA_SAFE_ASSERT_RETURN(xmlElement != nullptr, false);
  243. clear();
  244. for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
  245. {
  246. const String& tagName(elem->getTagName());
  247. // ---------------------------------------------------------------
  248. // Info
  249. if (tagName.equalsIgnoreCase("info"))
  250. {
  251. for (XmlElement* xmlInfo = elem->getFirstChildElement(); xmlInfo != nullptr; xmlInfo = xmlInfo->getNextElement())
  252. {
  253. const String& tag(xmlInfo->getTagName());
  254. const String text(xmlInfo->getAllSubText().trim());
  255. if (tag.equalsIgnoreCase("type"))
  256. type = xmlSafeStringCharDup(text, false);
  257. else if (tag.equalsIgnoreCase("name"))
  258. name = xmlSafeStringCharDup(text, false);
  259. else if (tag.equalsIgnoreCase("label") || tag.equalsIgnoreCase("identifier") || tag.equalsIgnoreCase("uri"))
  260. label = xmlSafeStringCharDup(text, false);
  261. else if (tag.equalsIgnoreCase("binary") || tag.equalsIgnoreCase("bundle") || tag.equalsIgnoreCase("filename"))
  262. binary = xmlSafeStringCharDup(text, false);
  263. else if (tag.equalsIgnoreCase("uniqueid"))
  264. uniqueId = text.getLargeIntValue();
  265. }
  266. }
  267. // ---------------------------------------------------------------
  268. // Data
  269. else if (tagName.equalsIgnoreCase("data"))
  270. {
  271. for (XmlElement* xmlData = elem->getFirstChildElement(); xmlData != nullptr; xmlData = xmlData->getNextElement())
  272. {
  273. const String& tag(xmlData->getTagName());
  274. const String text(xmlData->getAllSubText().trim());
  275. #ifndef BUILD_BRIDGE
  276. // -------------------------------------------------------
  277. // Internal Data
  278. if (tag.equalsIgnoreCase("active"))
  279. {
  280. active = (text.equalsIgnoreCase("yes") || text.equalsIgnoreCase("true"));
  281. }
  282. else if (tag.equalsIgnoreCase("drywet"))
  283. {
  284. dryWet = carla_fixValue(0.0f, 1.0f, text.getFloatValue());
  285. }
  286. else if (tag.equalsIgnoreCase("volume"))
  287. {
  288. volume = carla_fixValue(0.0f, 1.27f, text.getFloatValue());
  289. }
  290. else if (tag.equalsIgnoreCase("balanceleft") || tag.equalsIgnoreCase("balance-left"))
  291. {
  292. balanceLeft = carla_fixValue(-1.0f, 1.0f, text.getFloatValue());
  293. }
  294. else if (tag.equalsIgnoreCase("balanceright") || tag.equalsIgnoreCase("balance-right"))
  295. {
  296. balanceRight = carla_fixValue(-1.0f, 1.0f, text.getFloatValue());
  297. }
  298. else if (tag.equalsIgnoreCase("panning"))
  299. {
  300. panning = carla_fixValue(-1.0f, 1.0f, text.getFloatValue());
  301. }
  302. else if (tag.equalsIgnoreCase("controlchannel") || tag.equalsIgnoreCase("control-channel"))
  303. {
  304. if (! text.startsWithIgnoreCase("n"))
  305. {
  306. const int value(text.getIntValue());
  307. if (value >= 1 && value <= MAX_MIDI_CHANNELS)
  308. ctrlChannel = static_cast<int8_t>(value-1);
  309. }
  310. }
  311. else if (tag.equalsIgnoreCase("options"))
  312. {
  313. const int value(text.getHexValue32());
  314. if (value > 0)
  315. options = static_cast<uint>(value);
  316. }
  317. #else
  318. if (false) {}
  319. #endif
  320. // -------------------------------------------------------
  321. // Program (current)
  322. else if (tag.equalsIgnoreCase("currentprogramindex") || tag.equalsIgnoreCase("current-program-index"))
  323. {
  324. const int value(text.getIntValue());
  325. if (value >= 1)
  326. currentProgramIndex = value-1;
  327. }
  328. else if (tag.equalsIgnoreCase("currentprogramname") || tag.equalsIgnoreCase("current-program-name"))
  329. {
  330. currentProgramName = xmlSafeStringCharDup(text, false);
  331. }
  332. // -------------------------------------------------------
  333. // Midi Program (current)
  334. else if (tag.equalsIgnoreCase("currentmidibank") || tag.equalsIgnoreCase("current-midi-bank"))
  335. {
  336. const int value(text.getIntValue());
  337. if (value >= 1)
  338. currentMidiBank = value-1;
  339. }
  340. else if (tag.equalsIgnoreCase("currentmidiprogram") || tag.equalsIgnoreCase("current-midi-program"))
  341. {
  342. const int value(text.getIntValue());
  343. if (value >= 1)
  344. currentMidiProgram = value-1;
  345. }
  346. // -------------------------------------------------------
  347. // Parameters
  348. else if (tag.equalsIgnoreCase("parameter"))
  349. {
  350. Parameter* const stateParameter(new Parameter());
  351. for (XmlElement* xmlSubData = xmlData->getFirstChildElement(); xmlSubData != nullptr; xmlSubData = xmlSubData->getNextElement())
  352. {
  353. const String& pTag(xmlSubData->getTagName());
  354. const String pText(xmlSubData->getAllSubText().trim());
  355. if (pTag.equalsIgnoreCase("index"))
  356. {
  357. const int index(pText.getIntValue());
  358. if (index >= 0)
  359. stateParameter->index = index;
  360. }
  361. else if (pTag.equalsIgnoreCase("name"))
  362. {
  363. stateParameter->name = xmlSafeStringCharDup(pText, false);
  364. }
  365. else if (pTag.equalsIgnoreCase("symbol"))
  366. {
  367. stateParameter->symbol = xmlSafeStringCharDup(pText, false);
  368. }
  369. else if (pTag.equalsIgnoreCase("value"))
  370. {
  371. stateParameter->dummy = false;
  372. stateParameter->value = pText.getFloatValue();
  373. }
  374. #ifndef BUILD_BRIDGE
  375. else if (pTag.equalsIgnoreCase("midichannel") || pTag.equalsIgnoreCase("midi-channel"))
  376. {
  377. const int channel(pText.getIntValue());
  378. if (channel >= 1 && channel <= MAX_MIDI_CHANNELS)
  379. stateParameter->midiChannel = static_cast<uint8_t>(channel-1);
  380. }
  381. else if (pTag.equalsIgnoreCase("midicc") || pTag.equalsIgnoreCase("midi-cc"))
  382. {
  383. const int cc(pText.getIntValue());
  384. if (cc >= -1 && cc < MAX_MIDI_CONTROL)
  385. stateParameter->midiCC = static_cast<int16_t>(cc);
  386. }
  387. #endif
  388. }
  389. parameters.append(stateParameter);
  390. }
  391. // -------------------------------------------------------
  392. // Custom Data
  393. else if (tag.equalsIgnoreCase("customdata") || tag.equalsIgnoreCase("custom-data"))
  394. {
  395. CustomData* const stateCustomData(new CustomData());
  396. for (XmlElement* xmlSubData = xmlData->getFirstChildElement(); xmlSubData != nullptr; xmlSubData = xmlSubData->getNextElement())
  397. {
  398. const String& cTag(xmlSubData->getTagName());
  399. const String cText(xmlSubData->getAllSubText().trim());
  400. if (cTag.equalsIgnoreCase("type"))
  401. stateCustomData->type = xmlSafeStringCharDup(cText, false);
  402. else if (cTag.equalsIgnoreCase("key"))
  403. stateCustomData->key = xmlSafeStringCharDup(cText, false);
  404. else if (cTag.equalsIgnoreCase("value"))
  405. stateCustomData->value = carla_strdup(cText.toRawUTF8()); //xmlSafeStringCharDup(cText, false);
  406. }
  407. if (stateCustomData->isValid())
  408. customData.append(stateCustomData);
  409. else
  410. carla_stderr("Reading CustomData property failed, missing data");
  411. }
  412. // -------------------------------------------------------
  413. // Chunk
  414. else if (tag.equalsIgnoreCase("chunk"))
  415. {
  416. chunk = carla_strdup(text.toRawUTF8());
  417. }
  418. }
  419. }
  420. }
  421. return true;
  422. }
  423. // -----------------------------------------------------------------------
  424. // fillXmlStringFromStateSave
  425. void CarlaStateSave::dumpToMemoryStream(MemoryOutputStream& content) const
  426. {
  427. {
  428. MemoryOutputStream infoXml;
  429. infoXml << " <Info>\n";
  430. infoXml << " <Type>" << String(type != nullptr ? type : "") << "</Type>\n";
  431. infoXml << " <Name>" << xmlSafeString(name, true) << "</Name>\n";
  432. switch (getPluginTypeFromString(type))
  433. {
  434. case PLUGIN_NONE:
  435. break;
  436. case PLUGIN_INTERNAL:
  437. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  438. break;
  439. case PLUGIN_LADSPA:
  440. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  441. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  442. infoXml << " <UniqueID>" << juce::int64(uniqueId) << "</UniqueID>\n";
  443. break;
  444. case PLUGIN_DSSI:
  445. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  446. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  447. break;
  448. case PLUGIN_LV2:
  449. infoXml << " <URI>" << xmlSafeString(label, true) << "</URI>\n";
  450. break;
  451. case PLUGIN_VST2:
  452. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  453. infoXml << " <UniqueID>" << juce::int64(uniqueId) << "</UniqueID>\n";
  454. break;
  455. case PLUGIN_VST3:
  456. infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
  457. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  458. break;
  459. case PLUGIN_AU:
  460. infoXml << " <Identifier>" << xmlSafeString(label, true) << "</Identifier>\n";
  461. break;
  462. case PLUGIN_GIG:
  463. case PLUGIN_SF2:
  464. infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
  465. infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
  466. break;
  467. case PLUGIN_SFZ:
  468. infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
  469. break;
  470. }
  471. infoXml << " </Info>\n\n";
  472. content << infoXml;
  473. }
  474. content << " <Data>\n";
  475. #ifndef BUILD_BRIDGE
  476. {
  477. MemoryOutputStream dataXml;
  478. dataXml << " <Active>" << (active ? "Yes" : "No") << "</Active>\n";
  479. if (! carla_compareFloats(dryWet, 1.0f))
  480. dataXml << " <DryWet>" << String(dryWet, 7) << "</DryWet>\n";
  481. if (! carla_compareFloats(volume, 1.0f))
  482. dataXml << " <Volume>" << String(volume, 7) << "</Volume>\n";
  483. if (! carla_compareFloats(balanceLeft, -1.0f))
  484. dataXml << " <Balance-Left>" << String(balanceLeft, 7) << "</Balance-Left>\n";
  485. if (! carla_compareFloats(balanceRight, 1.0f))
  486. dataXml << " <Balance-Right>" << String(balanceRight, 7) << "</Balance-Right>\n";
  487. if (! carla_compareFloats(panning, 0.0f))
  488. dataXml << " <Panning>" << String(panning, 7) << "</Panning>\n";
  489. if (ctrlChannel < 0)
  490. dataXml << " <ControlChannel>N</ControlChannel>\n";
  491. else
  492. dataXml << " <ControlChannel>" << int(ctrlChannel+1) << "</ControlChannel>\n";
  493. dataXml << " <Options>0x" << String::toHexString(static_cast<int>(options)) << "</Options>\n";
  494. content << dataXml;
  495. }
  496. #endif
  497. for (ParameterItenerator it = parameters.begin(); it.valid(); it.next())
  498. {
  499. Parameter* const stateParameter(it.getValue(nullptr));
  500. CARLA_SAFE_ASSERT_CONTINUE(stateParameter != nullptr);
  501. MemoryOutputStream parameterXml;
  502. parameterXml << "\n";
  503. parameterXml << " <Parameter>\n";
  504. parameterXml << " <Index>" << String(stateParameter->index) << "</Index>\n";
  505. parameterXml << " <Name>" << xmlSafeString(stateParameter->name, true) << "</Name>\n";
  506. if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
  507. parameterXml << " <Symbol>" << xmlSafeString(stateParameter->symbol, true) << "</Symbol>\n";
  508. #ifndef BUILD_BRIDGE
  509. if (stateParameter->midiCC > 0)
  510. {
  511. parameterXml << " <MidiCC>" << stateParameter->midiCC << "</MidiCC>\n";
  512. parameterXml << " <MidiChannel>" << stateParameter->midiChannel+1 << "</MidiChannel>\n";
  513. }
  514. #endif
  515. if (! stateParameter->dummy)
  516. parameterXml << " <Value>" << String(stateParameter->value, 15) << "</Value>\n";
  517. parameterXml << " </Parameter>\n";
  518. content << parameterXml;
  519. }
  520. if (currentProgramIndex >= 0 && currentProgramName != nullptr && currentProgramName[0] != '\0')
  521. {
  522. // ignore 'default' program
  523. if (currentProgramIndex > 0 || ! String(currentProgramName).equalsIgnoreCase("default"))
  524. {
  525. MemoryOutputStream programXml;
  526. programXml << "\n";
  527. programXml << " <CurrentProgramIndex>" << currentProgramIndex+1 << "</CurrentProgramIndex>\n";
  528. programXml << " <CurrentProgramName>" << xmlSafeString(currentProgramName, true) << "</CurrentProgramName>\n";
  529. content << programXml;
  530. }
  531. }
  532. if (currentMidiBank >= 0 && currentMidiProgram >= 0)
  533. {
  534. MemoryOutputStream midiProgramXml;
  535. midiProgramXml << "\n";
  536. midiProgramXml << " <CurrentMidiBank>" << currentMidiBank+1 << "</CurrentMidiBank>\n";
  537. midiProgramXml << " <CurrentMidiProgram>" << currentMidiProgram+1 << "</CurrentMidiProgram>\n";
  538. content << midiProgramXml;
  539. }
  540. for (CustomDataItenerator it = customData.begin(); it.valid(); it.next())
  541. {
  542. CustomData* const stateCustomData(it.getValue(nullptr));
  543. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData != nullptr);
  544. CARLA_SAFE_ASSERT_CONTINUE(stateCustomData->isValid());
  545. MemoryOutputStream customDataXml;
  546. customDataXml << "\n";
  547. customDataXml << " <CustomData>\n";
  548. customDataXml << " <Type>" << xmlSafeString(stateCustomData->type, true) << "</Type>\n";
  549. customDataXml << " <Key>" << xmlSafeString(stateCustomData->key, true) << "</Key>\n";
  550. if (std::strcmp(stateCustomData->type, CUSTOM_DATA_TYPE_CHUNK) == 0 || std::strlen(stateCustomData->value) >= 128)
  551. {
  552. customDataXml << " <Value>\n";
  553. customDataXml << xmlSafeStringFast(stateCustomData->value, true);
  554. customDataXml << "\n </Value>\n";
  555. }
  556. else
  557. {
  558. customDataXml << " <Value>";
  559. customDataXml << xmlSafeStringFast(stateCustomData->value, true);
  560. customDataXml << "</Value>\n";
  561. }
  562. customDataXml << " </CustomData>\n";
  563. content << customDataXml;
  564. }
  565. if (chunk != nullptr && chunk[0] != '\0')
  566. {
  567. MemoryOutputStream chunkXml, chunkSplt;
  568. getNewLineSplittedString(chunkSplt, chunk);
  569. chunkXml << "\n <Chunk>\n";
  570. chunkXml << chunkSplt;
  571. chunkXml << "\n </Chunk>\n";
  572. content << chunkXml;
  573. }
  574. content << " </Data>\n";
  575. }
  576. // -----------------------------------------------------------------------
  577. CARLA_BACKEND_END_NAMESPACE