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.

130 lines
3.7KB

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