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.

135 lines
3.8KB

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