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.

121 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. int8_t ctrlChannel;
  57. #endif
  58. int32_t currentProgramIndex;
  59. const char* currentProgramName;
  60. int32_t currentMidiBank;
  61. int32_t currentMidiProgram;
  62. const char* chunk;
  63. ParameterList parameters;
  64. CustomDataList customData;
  65. CarlaStateSave() noexcept;
  66. ~CarlaStateSave() noexcept;
  67. void clear() noexcept;
  68. bool fillFromXmlElement(const water::XmlElement* const xmlElement);
  69. void dumpToMemoryStream(water::MemoryOutputStream& stream) const;
  70. CARLA_DECLARE_NON_COPYABLE(CarlaStateSave)
  71. };
  72. static inline
  73. water::String xmlSafeString(const char* const cstring, const bool toXml)
  74. {
  75. water::String newString = water::String(water::CharPointer_UTF8(cstring));
  76. if (toXml)
  77. return newString.replace("&","&amp;").replace("<","&lt;").replace(">","&gt;").replace("'","&apos;").replace("\"","&quot;");
  78. else
  79. return newString.replace("&lt;","<").replace("&gt;",">").replace("&apos;","'").replace("&quot;","\"").replace("&amp;","&");
  80. }
  81. static inline
  82. water::String xmlSafeString(const water::String& string, const bool toXml)
  83. {
  84. water::String newString(string);
  85. if (toXml)
  86. return newString.replace("&","&amp;").replace("<","&lt;").replace(">","&gt;").replace("'","&apos;").replace("\"","&quot;");
  87. else
  88. return newString.replace("&lt;","<").replace("&gt;",">").replace("&apos;","'").replace("&quot;","\"").replace("&amp;","&");
  89. }
  90. // -----------------------------------------------------------------------
  91. CARLA_BACKEND_END_NAMESPACE
  92. #endif // CARLA_STATE_UTILS_HPP_INCLUDED