LMMS
Loading...
Searching...
No Matches
CarlaStateUtils.cpp
Go to the documentation of this file.
1/*
2 * Carla State utils
3 * Copyright (C) 2012-2023 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
18#include "CarlaStateUtils.hpp"
19
20#include "CarlaBackendUtils.hpp"
21#include "CarlaMathUtils.hpp"
22#include "CarlaMIDI.h"
23
26
27#include <string>
28
30using water::String;
32
33CARLA_BACKEND_START_NAMESPACE
34
35// -----------------------------------------------------------------------
36// getNewLineSplittedString
37
38static void getNewLineSplittedString(MemoryOutputStream& stream, const String& string)
39{
40 static const int kLineWidth = 120;
41
42 int i = 0;
43 const int length = string.length();
44 const char* const raw = string.toUTF8();
45
46 stream.preallocate(static_cast<std::size_t>(length + length/kLineWidth + 3));
47
48 for (; i+kLineWidth < length; i += kLineWidth)
49 {
50 stream.write(raw+i, kLineWidth);
51 stream.writeByte('\n');
52 }
53
54 stream << (raw+i);
55}
56
57// -----------------------------------------------------------------------
58// xmlSafeStringFast
59
60/* Based on some code by James Kanze from stackoverflow
61 * https://stackoverflow.com/questions/7724011/in-c-whats-the-fastest-way-to-replace-all-occurrences-of-a-substring-within */
62
63static std::string replaceStdString(const std::string& original, const std::string& before, const std::string& after)
64{
65 std::string::const_iterator current = original.begin(), end = original.end(), next;
66 std::string retval;
67
68 for (; (next = std::search(current, end, before.begin(), before.end())) != end;)
69 {
70 retval.append(current, next);
71 retval.append(after);
72 current = next + static_cast<ssize_t>(before.size());
73 }
74 retval.append(current, next);
75 return retval;
76}
77
78static std::string xmlSafeStringFast(const char* const cstring, const bool toXml)
79{
80 std::string string(cstring);
81
82 if (toXml)
83 {
84 string = replaceStdString(string, "&","&amp;");
85 string = replaceStdString(string, "<","&lt;");
86 string = replaceStdString(string, ">","&gt;");
87 string = replaceStdString(string, "'","&apos;");
88 string = replaceStdString(string, "\"","&quot;");
89 }
90 else
91 {
92 string = replaceStdString(string, "&lt;","<");
93 string = replaceStdString(string, "&gt;",">");
94 string = replaceStdString(string, "&apos;","'");
95 string = replaceStdString(string, "&quot;","\"");
96 string = replaceStdString(string, "&amp;","&");
97 }
98
99 return string;
100}
101
102// -----------------------------------------------------------------------
103// xmlSafeStringCharDup
104
105/*
106static const char* xmlSafeStringCharDup(const char* const cstring, const bool toXml)
107{
108 return carla_strdup(xmlSafeString(cstring, toXml).toRawUTF8());
109}
110*/
111
112static const char* xmlSafeStringCharDup(const String& string, const bool toXml)
113{
114 return carla_strdup(xmlSafeString(string, toXml).toRawUTF8());
115}
116
117// -----------------------------------------------------------------------
118// StateParameter
119
120CarlaStateSave::Parameter::Parameter() noexcept
121 : dummy(true),
122 index(-1),
123 name(nullptr),
124 symbol(nullptr),
125 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
126 value(0.0f),
127 mappedControlIndex(CONTROL_INDEX_NONE),
128 midiChannel(0),
129 mappedRangeValid(false),
130 mappedMinimum(0.0f),
131 mappedMaximum(1.0f) {}
132 #else
133 value(0.0f) {}
134 #endif
135
136CarlaStateSave::Parameter::~Parameter() noexcept
137{
138 if (name != nullptr)
139 {
140 delete[] name;
141 name = nullptr;
142 }
143 if (symbol != nullptr)
144 {
145 delete[] symbol;
146 symbol = nullptr;
147 }
148}
149
150// -----------------------------------------------------------------------
151// StateCustomData
152
153CarlaStateSave::CustomData::CustomData() noexcept
154 : type(nullptr),
155 key(nullptr),
156 value(nullptr) {}
157
158CarlaStateSave::CustomData::~CustomData() noexcept
159{
160 if (type != nullptr)
161 {
162 delete[] type;
163 type = nullptr;
164 }
165 if (key != nullptr)
166 {
167 delete[] key;
168 key = nullptr;
169 }
170 if (value != nullptr)
171 {
172 delete[] value;
173 value = nullptr;
174 }
175}
176
177bool CarlaStateSave::CustomData::isValid() const noexcept
178{
179 if (type == nullptr || type[0] == '\0') return false;
180 if (key == nullptr || key [0] == '\0') return false;
181 if (value == nullptr) return false;
182 return true;
183}
184
185// -----------------------------------------------------------------------
186// StateSave
187
188CarlaStateSave::CarlaStateSave() noexcept
189 : type(nullptr),
190 name(nullptr),
191 label(nullptr),
192 binary(nullptr),
193 uniqueId(0),
194 options(PLUGIN_OPTIONS_NULL),
195 temporary(false),
196 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
197 active(false),
198 dryWet(1.0f),
199 volume(1.0f),
200 balanceLeft(-1.0f),
201 balanceRight(1.0f),
202 panning(0.0f),
203 ctrlChannel(-1),
204 #endif
205 currentProgramIndex(-1),
206 currentProgramName(nullptr),
207 currentMidiBank(-1),
208 currentMidiProgram(-1),
209 chunk(nullptr),
210 parameters(),
211 customData() {}
212
213CarlaStateSave::~CarlaStateSave() noexcept
214{
215 clear();
216}
217
218void CarlaStateSave::clear() noexcept
219{
220 if (type != nullptr)
221 {
222 delete[] type;
223 type = nullptr;
224 }
225 if (name != nullptr)
226 {
227 delete[] name;
228 name = nullptr;
229 }
230 if (label != nullptr)
231 {
232 delete[] label;
233 label = nullptr;
234 }
235 if (binary != nullptr)
236 {
237 delete[] binary;
238 binary = nullptr;
239 }
240 if (currentProgramName != nullptr)
241 {
242 delete[] currentProgramName;
243 currentProgramName = nullptr;
244 }
245 if (chunk != nullptr)
246 {
247 delete[] chunk;
248 chunk = nullptr;
249 }
250
251 uniqueId = 0;
252 options = PLUGIN_OPTIONS_NULL;
253
254 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
255 active = false;
256 dryWet = 1.0f;
257 volume = 1.0f;
258 balanceLeft = -1.0f;
259 balanceRight = 1.0f;
260 panning = 0.0f;
261 ctrlChannel = -1;
262 #endif
263
264 currentProgramIndex = -1;
265 currentMidiBank = -1;
266 currentMidiProgram = -1;
267
268 for (ParameterItenerator it = parameters.begin2(); it.valid(); it.next())
269 {
270 Parameter* const stateParameter(it.getValue(nullptr));
271 delete stateParameter;
272 }
273
274 for (CustomDataItenerator it = customData.begin2(); it.valid(); it.next())
275 {
276 CustomData* const stateCustomData(it.getValue(nullptr));
277 delete stateCustomData;
278 }
279
280 parameters.clear();
281 customData.clear();
282}
283
284// -----------------------------------------------------------------------
285// fillFromXmlElement
286
287bool CarlaStateSave::fillFromXmlElement(const XmlElement* const xmlElement)
288{
289 CARLA_SAFE_ASSERT_RETURN(xmlElement != nullptr, false);
290
291 clear();
292
293 for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
294 {
295 const String& tagName(elem->getTagName());
296
297 // ---------------------------------------------------------------
298 // Info
299
300 if (tagName == "Info")
301 {
302 for (XmlElement* xmlInfo = elem->getFirstChildElement(); xmlInfo != nullptr; xmlInfo = xmlInfo->getNextElement())
303 {
304 const String& tag(xmlInfo->getTagName());
305 const String text(xmlInfo->getAllSubText().trim());
306
307 /**/ if (tag == "Type")
309 else if (tag == "Name")
311 else if (tag == "Label" || tag == "URI" || tag == "Identifier" || tag == "Setup")
313 else if (tag == "Binary" || tag == "Filename")
314 binary = xmlSafeStringCharDup(text, false);
315 else if (tag == "UniqueID")
316 uniqueId = text.getLargeIntValue();
317 }
318 }
319
320 // ---------------------------------------------------------------
321 // Data
322
323 else if (tagName == "Data")
324 {
325 for (XmlElement* xmlData = elem->getFirstChildElement(); xmlData != nullptr; xmlData = xmlData->getNextElement())
326 {
327 const String& tag(xmlData->getTagName());
328 const String text(xmlData->getAllSubText().trim());
329
330 // -------------------------------------------------------
331 // Internal Data
332
333 /**/ if (tag == "Options")
334 {
335 const int value(text.getHexValue32());
336 if (value > 0)
337 options = static_cast<uint>(value);
338 }
339 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
340 else if (tag == "Active")
341 {
342 active = (text == "Yes");
343 }
344 else if (tag == "DryWet")
345 {
346 dryWet = carla_fixedValue(0.0f, 1.0f, text.getFloatValue());
347 }
348 else if (tag == "Volume")
349 {
350 volume = carla_fixedValue(0.0f, 1.27f, text.getFloatValue());
351 }
352 else if (tag == "Balance-Left")
353 {
354 balanceLeft = carla_fixedValue(-1.0f, 1.0f, text.getFloatValue());
355 }
356 else if (tag == "Balance-Right")
357 {
358 balanceRight = carla_fixedValue(-1.0f, 1.0f, text.getFloatValue());
359 }
360 else if (tag == "Panning")
361 {
362 panning = carla_fixedValue(-1.0f, 1.0f, text.getFloatValue());
363 }
364 else if (tag == "ControlChannel")
365 {
366 if (! text.startsWithIgnoreCase("n"))
367 {
368 const int value(text.getIntValue());
369 if (value >= 1 && value <= MAX_MIDI_CHANNELS)
370 ctrlChannel = static_cast<int8_t>(value-1);
371 }
372 }
373 #endif
374
375 // -------------------------------------------------------
376 // Program (current)
377
378 else if (tag == "CurrentProgramIndex")
379 {
380 const int value(text.getIntValue());
381 if (value >= 1)
382 currentProgramIndex = value-1;
383 }
384 else if (tag == "CurrentProgramName")
385 {
386 currentProgramName = xmlSafeStringCharDup(text, false);
387 }
388
389 // -------------------------------------------------------
390 // Midi Program (current)
391
392 else if (tag == "CurrentMidiBank")
393 {
394 const int value(text.getIntValue());
395 if (value >= 1)
396 currentMidiBank = value-1;
397 }
398 else if (tag == "CurrentMidiProgram")
399 {
400 const int value(text.getIntValue());
401 if (value >= 1)
402 currentMidiProgram = value-1;
403 }
404
405 // -------------------------------------------------------
406 // Parameters
407
408 else if (tag == "Parameter")
409 {
410 Parameter* const stateParameter(new Parameter());
411 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
412 bool hasMappedMinimum = false, hasMappedMaximum = false;
413 #endif
414
415 for (XmlElement* xmlSubData = xmlData->getFirstChildElement(); xmlSubData != nullptr; xmlSubData = xmlSubData->getNextElement())
416 {
417 const String& pTag(xmlSubData->getTagName());
418 const String pText(xmlSubData->getAllSubText().trim());
419
420 /**/ if (pTag == "Index")
421 {
422 const int index(pText.getIntValue());
423 if (index >= 0)
424 stateParameter->index = index;
425 }
426 else if (pTag == "Name")
427 {
428 stateParameter->name = xmlSafeStringCharDup(pText, false);
429 }
430 else if (pTag == "Symbol" || pTag == "Identifier")
431 {
432 stateParameter->symbol = xmlSafeStringCharDup(pText, false);
433 }
434 else if (pTag == "Value")
435 {
436 stateParameter->dummy = false;
437 stateParameter->value = pText.getFloatValue();
438 }
439 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
440 else if (pTag == "MidiChannel")
441 {
442 const int channel(pText.getIntValue());
443 if (channel >= 1 && channel <= MAX_MIDI_CHANNELS)
444 stateParameter->midiChannel = static_cast<uint8_t>(channel-1);
445 }
446 else if (pTag == "MidiCC")
447 {
448 const int cc(pText.getIntValue());
449 if (cc > 0 && cc < MAX_MIDI_CONTROL)
450 stateParameter->mappedControlIndex = static_cast<int16_t>(cc);
451 }
452 else if (pTag == "MappedControlIndex")
453 {
454 const int ctrl(pText.getIntValue());
455 if (ctrl > CONTROL_INDEX_NONE && ctrl <= CONTROL_INDEX_MAX_ALLOWED)
456 if (ctrl != CONTROL_INDEX_MIDI_LEARN)
457 stateParameter->mappedControlIndex = static_cast<int16_t>(ctrl);
458 }
459 else if (pTag == "MappedMinimum")
460 {
461 hasMappedMinimum = true;
462 stateParameter->mappedMinimum = pText.getFloatValue();
463 }
464 else if (pTag == "MappedMaximum")
465 {
466 hasMappedMaximum = true;
467 stateParameter->mappedMaximum = pText.getFloatValue();
468 }
469 #endif
470 }
471
472 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
473 if (hasMappedMinimum && hasMappedMaximum)
474 stateParameter->mappedRangeValid = true;
475 #endif
476
477 parameters.append(stateParameter);
478 }
479
480 // -------------------------------------------------------
481 // Custom Data
482
483 else if (tag == "CustomData")
484 {
485 CustomData* const stateCustomData(new CustomData());
486
487 // find type first
488 for (XmlElement* xmlSubData = xmlData->getFirstChildElement(); xmlSubData != nullptr; xmlSubData = xmlSubData->getNextElement())
489 {
490 const String& cTag(xmlSubData->getTagName());
491
492 if (cTag != "Type")
493 continue;
494
495 stateCustomData->type = xmlSafeStringCharDup(xmlSubData->getAllSubText().trim(), false);
496 break;
497 }
498
499 if (stateCustomData->type == nullptr || stateCustomData->type[0] == '\0')
500 {
501 carla_stderr("Reading CustomData type failed");
502 delete stateCustomData;
503 continue;
504 }
505
506 // now fill in key and value, knowing what the type is
507 for (XmlElement* xmlSubData = xmlData->getFirstChildElement(); xmlSubData != nullptr; xmlSubData = xmlSubData->getNextElement())
508 {
509 const String& cTag(xmlSubData->getTagName());
510 String cText(xmlSubData->getAllSubText());
511
512 /**/ if (cTag == "Key")
513 {
514 stateCustomData->key = xmlSafeStringCharDup(cText.trim(), false);
515 }
516 else if (cTag == "Value")
517 {
518 // save operation adds a newline and newline+space around the string in some cases
519 const int len = cText.length();
520 if (std::strcmp(stateCustomData->type, CUSTOM_DATA_TYPE_CHUNK) == 0 || len >= 128+6)
521 {
523 cText = cText.substring(1, len - 5);
524 }
525
526 stateCustomData->value = xmlSafeStringCharDup(cText, false);
527 }
528 }
529
530 if (stateCustomData->isValid())
531 {
532 customData.append(stateCustomData);
533 }
534 else
535 {
536 carla_stderr("Reading CustomData property failed, missing data");
537 delete stateCustomData;
538 }
539 }
540
541 // -------------------------------------------------------
542 // Chunk
543
544 else if (tag == "Chunk")
545 {
546 chunk = carla_strdup(text.toRawUTF8());
547 }
548 }
549 }
550 }
551
552 return true;
553}
554
555// -----------------------------------------------------------------------
556// fillXmlStringFromStateSave
557
558void CarlaStateSave::dumpToMemoryStream(MemoryOutputStream& content) const
559{
560 const PluginType pluginType = getPluginTypeFromString(type);
561
562 {
563 MemoryOutputStream infoXml;
564
565 infoXml << " <Info>\n";
566 infoXml << " <Type>" << String(type != nullptr ? type : "") << "</Type>\n";
567 infoXml << " <Name>" << xmlSafeString(name, true) << "</Name>\n";
568
569 switch (pluginType)
570 {
571 case PLUGIN_NONE:
572 break;
573 case PLUGIN_INTERNAL:
574 infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
575 break;
576 case PLUGIN_LADSPA:
577 infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
578 infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
579 infoXml << " <UniqueID>" << water::int64(uniqueId) << "</UniqueID>\n";
580 break;
581 case PLUGIN_DSSI:
582 infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
583 infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
584 break;
585 case PLUGIN_LV2:
586 infoXml << " <URI>" << xmlSafeString(label, true) << "</URI>\n";
587 break;
588 case PLUGIN_VST2:
589 infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
590 infoXml << " <UniqueID>" << water::int64(uniqueId) << "</UniqueID>\n";
591 break;
592 case PLUGIN_VST3:
593 infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
594 infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
595 break;
596 case PLUGIN_AU:
597 infoXml << " <Identifier>" << xmlSafeString(label, true) << "</Identifier>\n";
598 break;
599 case PLUGIN_CLAP:
600 infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
601 infoXml << " <Identifier>" << xmlSafeString(label, true) << "</Identifier>\n";
602 break;
603 case PLUGIN_DLS:
604 case PLUGIN_GIG:
605 case PLUGIN_SF2:
606 case PLUGIN_JSFX:
607 infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
608 infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
609 break;
610 case PLUGIN_SFZ:
611 infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
612 break;
613 case PLUGIN_JACK:
614 infoXml << " <Filename>" << xmlSafeString(binary, true) << "</Filename>\n";
615 infoXml << " <Setup>" << xmlSafeString(label, true) << "</Setup>\n";
616 break;
618 break;
619 }
620
621 infoXml << " </Info>\n\n";
622
623 content << infoXml;
624 }
625
626 content << " <Data>\n";
627
628 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
629 {
630 MemoryOutputStream dataXml;
631
632 dataXml << " <Active>" << (active ? "Yes" : "No") << "</Active>\n";
633
634 if (carla_isNotEqual(dryWet, 1.0f))
635 dataXml << " <DryWet>" << String(dryWet, 7) << "</DryWet>\n";
636 if (carla_isNotEqual(volume, 1.0f))
637 dataXml << " <Volume>" << String(volume, 7) << "</Volume>\n";
638 if (carla_isNotEqual(balanceLeft, -1.0f))
639 dataXml << " <Balance-Left>" << String(balanceLeft, 7) << "</Balance-Left>\n";
640 if (carla_isNotEqual(balanceRight, 1.0f))
641 dataXml << " <Balance-Right>" << String(balanceRight, 7) << "</Balance-Right>\n";
642 if (carla_isNotEqual(panning, 0.0f))
643 dataXml << " <Panning>" << String(panning, 7) << "</Panning>\n";
644
645 if (ctrlChannel < 0)
646 dataXml << " <ControlChannel>N</ControlChannel>\n";
647 else
648 dataXml << " <ControlChannel>" << int(ctrlChannel+1) << "</ControlChannel>\n";
649
650 dataXml << " <Options>0x" << String::toHexString(static_cast<int>(options)) << "</Options>\n";
651
652 content << dataXml;
653 }
654 #endif
655
656 for (ParameterItenerator it = parameters.begin2(); it.valid(); it.next())
657 {
658 Parameter* const stateParameter(it.getValue(nullptr));
659 CARLA_SAFE_ASSERT_CONTINUE(stateParameter != nullptr);
660
661 MemoryOutputStream parameterXml;
662
663 parameterXml << "\n";
664 parameterXml << " <Parameter>\n";
665 parameterXml << " <Index>" << String(stateParameter->index) << "</Index>\n";
666 parameterXml << " <Name>" << xmlSafeString(stateParameter->name, true) << "</Name>\n";
667
668 if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0')
669 {
670 if (pluginType == PLUGIN_CLAP)
671 parameterXml << " <Identifier>" << xmlSafeString(stateParameter->symbol, true) << "</Identifier>\n";
672 else
673 parameterXml << " <Symbol>" << xmlSafeString(stateParameter->symbol, true) << "</Symbol>\n";
674 }
675
676 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
677 if (stateParameter->mappedControlIndex > CONTROL_INDEX_NONE && stateParameter->mappedControlIndex <= CONTROL_INDEX_MAX_ALLOWED)
678 {
679 parameterXml << " <MidiChannel>" << stateParameter->midiChannel+1 << "</MidiChannel>\n";
680 parameterXml << " <MappedControlIndex>" << stateParameter->mappedControlIndex << "</MappedControlIndex>\n";
681
682 if (stateParameter->mappedRangeValid)
683 {
684 parameterXml << " <MappedMinimum>" << String(stateParameter->mappedMinimum, 15) << "</MappedMinimum>\n";
685 parameterXml << " <MappedMaximum>" << String(stateParameter->mappedMaximum, 15) << "</MappedMaximum>\n";
686 }
687
688 // backwards compatibility for older carla versions
689 if (stateParameter->mappedControlIndex > 0 && stateParameter->mappedControlIndex < MAX_MIDI_CONTROL)
690 parameterXml << " <MidiCC>" << stateParameter->mappedControlIndex << "</MidiCC>\n";
691 }
692 #endif
693
694 if (! stateParameter->dummy)
695 parameterXml << " <Value>" << String(stateParameter->value, 15) << "</Value>\n";
696
697 parameterXml << " </Parameter>\n";
698
699 content << parameterXml;
700 }
701
702 if (currentProgramIndex >= 0 && currentProgramName != nullptr && currentProgramName[0] != '\0')
703 {
704 // ignore 'default' program
705 if (currentProgramIndex > 0 || ! String(currentProgramName).equalsIgnoreCase("default"))
706 {
707 MemoryOutputStream programXml;
708
709 programXml << "\n";
710 programXml << " <CurrentProgramIndex>" << currentProgramIndex+1 << "</CurrentProgramIndex>\n";
711 programXml << " <CurrentProgramName>" << xmlSafeString(currentProgramName, true) << "</CurrentProgramName>\n";
712
713 content << programXml;
714 }
715 }
716
717 if (currentMidiBank >= 0 && currentMidiProgram >= 0)
718 {
719 MemoryOutputStream midiProgramXml;
720
721 midiProgramXml << "\n";
722 midiProgramXml << " <CurrentMidiBank>" << currentMidiBank+1 << "</CurrentMidiBank>\n";
723 midiProgramXml << " <CurrentMidiProgram>" << currentMidiProgram+1 << "</CurrentMidiProgram>\n";
724
725 content << midiProgramXml;
726 }
727
728 for (CustomDataItenerator it = customData.begin2(); it.valid(); it.next())
729 {
730 CustomData* const stateCustomData(it.getValue(nullptr));
731 CARLA_SAFE_ASSERT_CONTINUE(stateCustomData != nullptr);
732 CARLA_SAFE_ASSERT_CONTINUE(stateCustomData->isValid());
733
734 MemoryOutputStream customDataXml;
735
736 customDataXml << "\n";
737 customDataXml << " <CustomData>\n";
738 customDataXml << " <Type>" << xmlSafeString(stateCustomData->type, true) << "</Type>\n";
739 customDataXml << " <Key>" << xmlSafeString(stateCustomData->key, true) << "</Key>\n";
740
741 if (std::strcmp(stateCustomData->type, CUSTOM_DATA_TYPE_CHUNK) == 0 || std::strlen(stateCustomData->value) >= 128)
742 {
743 customDataXml << " <Value>\n";
744 customDataXml << xmlSafeStringFast(stateCustomData->value, true);
745 customDataXml << "\n </Value>\n";
746 }
747 else
748 {
749 customDataXml << " <Value>";
750 customDataXml << xmlSafeStringFast(stateCustomData->value, true);
751 customDataXml << "</Value>\n";
752 }
753
754 customDataXml << " </CustomData>\n";
755
756 content << customDataXml;
757 }
758
759 if (chunk != nullptr && chunk[0] != '\0')
760 {
761 MemoryOutputStream chunkXml, chunkSplt;
762 getNewLineSplittedString(chunkSplt, chunk);
763
764 chunkXml << "\n <Chunk>\n";
765 chunkXml << chunkSplt;
766 chunkXml << "\n </Chunk>\n";
767
768 content << chunkXml;
769 }
770
771 content << " </Data>\n";
772}
773
774// -----------------------------------------------------------------------
775
776CARLA_BACKEND_END_NAMESPACE
#define CARLA_SAFE_ASSERT_CONTINUE(cond)
Definition CarlaDefines.h:189
#define CARLA_SAFE_ASSERT_RETURN(cond, ret)
Definition CarlaDefines.h:190
unsigned int uint
Definition CarlaDefines.h:327
#define MAX_MIDI_CONTROL
Definition CarlaMIDI.h:24
#define MAX_MIDI_CHANNELS
Definition CarlaMIDI.h:21
static std::string xmlSafeStringFast(const char *const cstring, const bool toXml)
Definition CarlaStateUtils.cpp:78
static const char * xmlSafeStringCharDup(const String &string, const bool toXml)
Definition CarlaStateUtils.cpp:112
static std::string replaceStdString(const std::string &original, const std::string &before, const std::string &after)
Definition CarlaStateUtils.cpp:63
static CARLA_BACKEND_START_NAMESPACE void getNewLineSplittedString(MemoryOutputStream &stream, const String &string)
Definition CarlaStateUtils.cpp:38
#define noexcept
Definition DistrhoDefines.h:72
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
static String toHexString(int number)
Definition String.cpp:1830
Definition MemoryOutputStream.h:42
void preallocate(size_t bytesToPreallocate)
Definition MemoryOutputStream.cpp:65
bool write(const void *, size_t) override
Definition MemoryOutputStream.cpp:92
virtual bool writeByte(char byte)
Definition OutputStream.cpp:51
Definition String.h:48
Definition XmlElement.h:145
XmlElement * getNextElement() const noexcept
Definition XmlElement.h:464
XmlElement * getFirstChildElement() const noexcept
Definition XmlElement.h:436
register unsigned i
Definition inflate.c:1575
int retval
Definition inflate.c:947
PluginType
Definition CarlaBackend.h:614
struct _CustomData CustomData
Definition CarlaStateUtils.cpp:153
@ PLUGIN_CLAP
Definition CarlaBackend.h:689
@ PLUGIN_TYPE_COUNT
Definition CarlaBackend.h:694
@ PLUGIN_LV2
Definition CarlaBackend.h:638
@ PLUGIN_VST2
Definition CarlaBackend.h:643
@ PLUGIN_SFZ
Definition CarlaBackend.h:674
@ PLUGIN_JACK
Definition CarlaBackend.h:679
@ PLUGIN_INTERNAL
Definition CarlaBackend.h:623
@ PLUGIN_DLS
Definition CarlaBackend.h:659
@ PLUGIN_SF2
Definition CarlaBackend.h:669
@ PLUGIN_NONE
Definition CarlaBackend.h:618
@ PLUGIN_LADSPA
Definition CarlaBackend.h:628
@ PLUGIN_GIG
Definition CarlaBackend.h:664
@ PLUGIN_DSSI
Definition CarlaBackend.h:633
@ PLUGIN_AU
Definition CarlaBackend.h:654
@ PLUGIN_VST3
Definition CarlaBackend.h:648
@ PLUGIN_JSFX
Definition CarlaBackend.h:684
@ CONTROL_INDEX_MAX_ALLOWED
Definition CarlaBackend.h:877
@ CONTROL_INDEX_NONE
Definition CarlaBackend.h:857
@ CONTROL_INDEX_MIDI_LEARN
Definition CarlaBackend.h:872
static constexpr const char *const CUSTOM_DATA_TYPE_CHUNK
Definition CarlaBackend.h:497
static constexpr const uint PLUGIN_OPTIONS_NULL
Definition CarlaBackend.h:289
static PuglViewHint int value
Definition pugl.h:1708
static const char * name
Definition pugl.h:1582
short int16_t
Definition mid.cpp:96
unsigned char uint8_t
Definition mid.cpp:98
signed char int8_t
Definition mid.cpp:95
void clear(void *s)
Definition juce_FixedSizeFunction.h:71
@ label
Definition juce_AccessibilityRole.h:44
long long int64
Definition water.h:100
static float volume(float level)
Definition nekobee_voice_render.c:99
#define true
Definition ordinals.h:82
#define false
Definition ordinals.h:83
png_uint_32 length
Definition png.c:2247
const char * text
Definition swell-functions.h:167
ZCONST char * key
Definition crypt.c:587
typedef int(UZ_EXP MsgFn)()
#define const
Definition zconf.h:137