cmake: Install host-plugin/native-plugin/standalone pkgconfig files
[carla.git] / source / utils / CarlaStateUtils.hpp
blob2fc74bd3cf57f0805f76306bad3c2b7b30fc8a73
1 /*
2 * Carla State utils
3 * Copyright (C) 2012-2023 Filipe Coelho <falktx@falktx.com>
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.
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.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #ifndef CARLA_STATE_UTILS_HPP_INCLUDED
19 #define CARLA_STATE_UTILS_HPP_INCLUDED
21 #include "CarlaBackend.h"
22 #include "LinkedList.hpp"
24 #include "water/text/String.h"
26 CARLA_BACKEND_START_NAMESPACE
28 // -----------------------------------------------------------------------
30 struct CarlaStateSave {
31 struct Parameter {
32 bool dummy; // if true only midiChannel/CC are used
33 int32_t index;
34 const char* name;
35 const char* symbol;
36 float value;
37 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
38 int16_t mappedControlIndex;
39 uint8_t midiChannel;
40 bool mappedRangeValid;
41 float mappedMinimum;
42 float mappedMaximum;
43 #endif
45 Parameter() noexcept;
46 ~Parameter() noexcept;
48 CARLA_DECLARE_NON_COPYABLE(Parameter)
51 typedef LinkedList<Parameter*> ParameterList;
52 typedef LinkedList<Parameter*>::Itenerator ParameterItenerator;
54 struct CustomData {
55 const char* type;
56 const char* key;
57 const char* value;
59 CustomData() noexcept;
60 ~CustomData() noexcept;
61 bool isValid() const noexcept;
63 CARLA_DECLARE_NON_COPYABLE(CustomData)
66 typedef LinkedList<CustomData*> CustomDataList;
67 typedef LinkedList<CustomData*>::Itenerator CustomDataItenerator;
69 const char* type;
70 const char* name;
71 const char* label;
72 const char* binary;
73 int64_t uniqueId;
74 uint options;
76 // saved during clone, rename or similar
77 bool temporary;
79 #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
80 bool active;
81 float dryWet;
82 float volume;
83 float balanceLeft;
84 float balanceRight;
85 float panning;
86 int8_t ctrlChannel;
87 #endif
89 int32_t currentProgramIndex;
90 const char* currentProgramName;
91 int32_t currentMidiBank;
92 int32_t currentMidiProgram;
93 const char* chunk;
95 ParameterList parameters;
96 CustomDataList customData;
98 CarlaStateSave() noexcept;
99 ~CarlaStateSave() noexcept;
100 void clear() noexcept;
102 bool fillFromXmlElement(const water::XmlElement* const xmlElement);
103 void dumpToMemoryStream(water::MemoryOutputStream& stream) const;
105 CARLA_DECLARE_NON_COPYABLE(CarlaStateSave)
108 static inline
109 water::String xmlSafeString(const char* const cstring, const bool toXml)
111 water::String newString = water::String(water::CharPointer_UTF8(cstring));
113 if (toXml)
114 return newString.replace("&","&amp;").replace("<","&lt;").replace(">","&gt;").replace("'","&apos;").replace("\"","&quot;");
115 else
116 return newString.replace("&lt;","<").replace("&gt;",">").replace("&apos;","'").replace("&quot;","\"").replace("&amp;","&");
119 static inline
120 water::String xmlSafeString(const water::String& string, const bool toXml)
122 water::String newString(string);
124 if (toXml)
125 return newString.replace("&","&amp;").replace("<","&lt;").replace(">","&gt;").replace("'","&apos;").replace("\"","&quot;");
126 else
127 return newString.replace("&lt;","<").replace("&gt;",">").replace("&apos;","'").replace("&quot;","\"").replace("&amp;","&");
130 // -----------------------------------------------------------------------
132 CARLA_BACKEND_END_NAMESPACE
134 #endif // CARLA_STATE_UTILS_HPP_INCLUDED