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.

129 lines
3.6KB

  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
  32. uint8_t midiChannel;
  33. int16_t midiCC;
  34. #endif
  35. Parameter() noexcept;
  36. ~Parameter() noexcept;
  37. CARLA_DECLARE_NON_COPY_STRUCT(Parameter)
  38. };
  39. typedef LinkedList<Parameter*> ParameterList;
  40. typedef LinkedList<Parameter*>::Itenerator ParameterItenerator;
  41. struct CustomData {
  42. const char* type;
  43. const char* key;
  44. const char* value;
  45. CustomData() noexcept;
  46. ~CustomData() noexcept;
  47. bool isValid() const noexcept;
  48. CARLA_DECLARE_NON_COPY_STRUCT(CustomData)
  49. };
  50. typedef LinkedList<CustomData*> CustomDataList;
  51. typedef LinkedList<CustomData*>::Itenerator CustomDataItenerator;
  52. const char* type;
  53. const char* name;
  54. const char* label;
  55. const char* binary;
  56. int64_t uniqueId;
  57. uint options;
  58. #ifndef BUILD_BRIDGE
  59. bool active;
  60. float dryWet;
  61. float volume;
  62. float balanceLeft;
  63. float balanceRight;
  64. float panning;
  65. int8_t ctrlChannel;
  66. #endif
  67. int32_t currentProgramIndex;
  68. const char* currentProgramName;
  69. int32_t currentMidiBank;
  70. int32_t currentMidiProgram;
  71. const char* chunk;
  72. ParameterList parameters;
  73. CustomDataList customData;
  74. CarlaStateSave() noexcept;
  75. ~CarlaStateSave() noexcept;
  76. void clear() noexcept;
  77. bool fillFromXmlElement(const water::XmlElement* const xmlElement);
  78. void dumpToMemoryStream(water::MemoryOutputStream& stream) const;
  79. CARLA_DECLARE_NON_COPY_STRUCT(CarlaStateSave)
  80. };
  81. static inline
  82. water::String xmlSafeString(const char* const cstring, const bool toXml)
  83. {
  84. water::String newString = water::String(water::CharPointer_UTF8(cstring));
  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. static inline
  91. water::String xmlSafeString(const water::String& string, const bool toXml)
  92. {
  93. water::String newString(string);
  94. if (toXml)
  95. return newString.replace("&","&amp;").replace("<","&lt;").replace(">","&gt;").replace("'","&apos;").replace("\"","&quot;");
  96. else
  97. return newString.replace("&lt;","<").replace("&gt;",">").replace("&apos;","'").replace("&quot;","\"").replace("&amp;","&");
  98. }
  99. // -----------------------------------------------------------------------
  100. CARLA_BACKEND_END_NAMESPACE
  101. #endif // CARLA_STATE_UTILS_HPP_INCLUDED