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.

132 lines
3.8KB

  1. /*
  2. * Carla State utils
  3. * Copyright (C) 2012-2017 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_COPY_STRUCT(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_COPY_STRUCT(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. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  62. bool active;
  63. float dryWet;
  64. float volume;
  65. float balanceLeft;
  66. float balanceRight;
  67. float panning;
  68. int8_t ctrlChannel;
  69. #endif
  70. int32_t currentProgramIndex;
  71. const char* currentProgramName;
  72. int32_t currentMidiBank;
  73. int32_t currentMidiProgram;
  74. const char* chunk;
  75. ParameterList parameters;
  76. CustomDataList customData;
  77. CarlaStateSave() noexcept;
  78. ~CarlaStateSave() noexcept;
  79. void clear() noexcept;
  80. bool fillFromXmlElement(const water::XmlElement* const xmlElement);
  81. void dumpToMemoryStream(water::MemoryOutputStream& stream) const;
  82. CARLA_DECLARE_NON_COPY_STRUCT(CarlaStateSave)
  83. };
  84. static inline
  85. water::String xmlSafeString(const char* const cstring, const bool toXml)
  86. {
  87. water::String newString = water::String(water::CharPointer_UTF8(cstring));
  88. if (toXml)
  89. return newString.replace("&","&amp;").replace("<","&lt;").replace(">","&gt;").replace("'","&apos;").replace("\"","&quot;");
  90. else
  91. return newString.replace("&lt;","<").replace("&gt;",">").replace("&apos;","'").replace("&quot;","\"").replace("&amp;","&");
  92. }
  93. static inline
  94. water::String xmlSafeString(const water::String& string, const bool toXml)
  95. {
  96. water::String newString(string);
  97. if (toXml)
  98. return newString.replace("&","&amp;").replace("<","&lt;").replace(">","&gt;").replace("'","&apos;").replace("\"","&quot;");
  99. else
  100. return newString.replace("&lt;","<").replace("&gt;",">").replace("&apos;","'").replace("&quot;","\"").replace("&amp;","&");
  101. }
  102. // -----------------------------------------------------------------------
  103. CARLA_BACKEND_END_NAMESPACE
  104. #endif // CARLA_STATE_UTILS_HPP_INCLUDED