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.

122 lines
3.3KB

  1. // SPDX-FileCopyrightText: 2011-2025 Filipe Coelho <falktx@falktx.com>
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #ifndef CARLA_STATE_UTILS_HPP_INCLUDED
  4. #define CARLA_STATE_UTILS_HPP_INCLUDED
  5. #include "CarlaBackend.h"
  6. #include "LinkedList.hpp"
  7. #include "water/text/String.h"
  8. CARLA_BACKEND_START_NAMESPACE
  9. // -----------------------------------------------------------------------
  10. struct CarlaStateSave {
  11. struct Parameter {
  12. bool dummy; // if true only midiChannel/CC are used
  13. int32_t index;
  14. const char* name;
  15. const char* symbol;
  16. float value;
  17. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  18. int16_t mappedControlIndex;
  19. uint8_t midiChannel;
  20. bool mappedRangeValid;
  21. float mappedMinimum;
  22. float mappedMaximum;
  23. #endif
  24. Parameter() noexcept;
  25. ~Parameter() noexcept;
  26. CARLA_DECLARE_NON_COPYABLE(Parameter)
  27. };
  28. typedef LinkedList<Parameter*> ParameterList;
  29. typedef LinkedList<Parameter*>::Itenerator ParameterItenerator;
  30. struct CustomData {
  31. const char* type;
  32. const char* key;
  33. const char* value;
  34. CustomData() noexcept;
  35. ~CustomData() noexcept;
  36. bool isValid() const noexcept;
  37. CARLA_DECLARE_NON_COPYABLE(CustomData)
  38. };
  39. typedef LinkedList<CustomData*> CustomDataList;
  40. typedef LinkedList<CustomData*>::Itenerator CustomDataItenerator;
  41. const char* type;
  42. const char* name;
  43. const char* label;
  44. const char* binary;
  45. int64_t uniqueId;
  46. uint options;
  47. // saved during clone, rename or similar
  48. bool temporary;
  49. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  50. bool active;
  51. float dryWet;
  52. float volume;
  53. float balanceLeft;
  54. float balanceRight;
  55. float panning;
  56. float forth;
  57. int8_t ctrlChannel;
  58. #endif
  59. int32_t currentProgramIndex;
  60. const char* currentProgramName;
  61. int32_t currentMidiBank;
  62. int32_t currentMidiProgram;
  63. const char* chunk;
  64. ParameterList parameters;
  65. CustomDataList customData;
  66. CarlaStateSave() noexcept;
  67. ~CarlaStateSave() noexcept;
  68. void clear() noexcept;
  69. bool fillFromXmlElement(const water::XmlElement* const xmlElement);
  70. void dumpToMemoryStream(water::MemoryOutputStream& stream) const;
  71. CARLA_DECLARE_NON_COPYABLE(CarlaStateSave)
  72. };
  73. static inline
  74. water::String xmlSafeString(const char* const cstring, const bool toXml)
  75. {
  76. water::String newString = water::String(water::CharPointer_UTF8(cstring));
  77. if (toXml)
  78. return newString.replace("&","&amp;").replace("<","&lt;").replace(">","&gt;").replace("'","&apos;").replace("\"","&quot;");
  79. else
  80. return newString.replace("&lt;","<").replace("&gt;",">").replace("&apos;","'").replace("&quot;","\"").replace("&amp;","&");
  81. }
  82. static inline
  83. water::String xmlSafeString(const water::String& string, const bool toXml)
  84. {
  85. water::String newString(string);
  86. if (toXml)
  87. return newString.replace("&","&amp;").replace("<","&lt;").replace(">","&gt;").replace("'","&apos;").replace("\"","&quot;");
  88. else
  89. return newString.replace("&lt;","<").replace("&gt;",">").replace("&apos;","'").replace("&quot;","\"").replace("&amp;","&");
  90. }
  91. // -----------------------------------------------------------------------
  92. CARLA_BACKEND_END_NAMESPACE
  93. #endif // CARLA_STATE_UTILS_HPP_INCLUDED