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.

272 lines
9.0KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. XMLwrapper.h - XML wrapper
  4. Copyright (C) 2003-2005 Nasca Octavian Paul
  5. Copyright (C) 2009-2009 Mark McCurry
  6. Author: Nasca Octavian Paul
  7. Mark McCurry
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of version 2 of the GNU General Public License
  10. as published by the Free Software Foundation.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License (version 2 or later) for more details.
  15. You should have received a copy of the GNU General Public License (version 2)
  16. along with this program; if not, write to the Free Software Foundation,
  17. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <mxml.h>
  20. #include <string>
  21. #ifndef float
  22. #define float float
  23. #endif
  24. #ifndef XML_WRAPPER_H
  25. #define XML_WRAPPER_H
  26. /**Mxml wrapper*/
  27. class XMLwrapper
  28. {
  29. public:
  30. /**
  31. * Constructor.
  32. * Will Construct the object and fill in top level branch
  33. * */
  34. XMLwrapper();
  35. /**Destructor*/
  36. ~XMLwrapper();
  37. /**
  38. * Saves the XML to a file.
  39. * @param filename the name of the destination file.
  40. * @returns 0 if ok or -1 if the file cannot be saved.
  41. */
  42. int saveXMLfile(const std::string &filename) const;
  43. /**
  44. * Return XML tree as a string.
  45. * Note: The string must be freed with free() to deallocate
  46. * @returns a newly allocated NULL terminated string of the XML data.
  47. */
  48. char *getXMLdata() const;
  49. /**
  50. * Add simple parameter.
  51. * @param name The name of the mXML node.
  52. * @param val The string value of the mXml node
  53. */
  54. void addpar(const std::string &name, int val);
  55. /**
  56. * Adds a realtype parameter.
  57. * @param name The name of the mXML node.
  58. * @param val The float value of the node.
  59. */
  60. void addparreal(const std::string &name, float val);
  61. /**
  62. * Add boolean parameter.
  63. * \todo Fix this reverse boolean logic.
  64. * @param name The name of the mXML node.
  65. * @param val The boolean value of the node (0->"yes";else->"no").
  66. */
  67. void addparbool(const std::string &name, int val);
  68. /**
  69. * Add string parameter.
  70. * @param name The name of the mXML node.
  71. * @param val The string value of the node.
  72. */
  73. void addparstr(const std::string &name, const std::string &val);
  74. /**
  75. * Create a new branch.
  76. * @param name Name of new branch
  77. * @see void endbranch()
  78. */
  79. void beginbranch(const std::string &name);
  80. /**
  81. * Create a new branch.
  82. * @param name Name of new branch
  83. * @param id "id" value of branch
  84. * @see void endbranch()
  85. */
  86. void beginbranch(const std::string &name, int id);
  87. /**Closes new branches.
  88. * This must be called to exit each branch created by beginbranch( ).
  89. * @see void beginbranch(const std::string &name)
  90. * @see void beginbranch(const std::string &name, int id)
  91. */
  92. void endbranch();
  93. /**
  94. * Loads file into XMLwrapper.
  95. * @param filename file to be loaded
  96. * @returns 0 if ok or -1 if the file cannot be loaded
  97. */
  98. int loadXMLfile(const std::string &filename);
  99. /**
  100. * Loads string into XMLwrapper.
  101. * @param xmldata NULL terminated string of XML data.
  102. * @returns true if successful.
  103. */
  104. bool putXMLdata(const char *xmldata);
  105. /**
  106. * Enters the branch.
  107. * @param name Name of branch.
  108. * @returns 1 if is ok, or 0 otherwise.
  109. */
  110. int enterbranch(const std::string &name);
  111. /**
  112. * Enter into the branch \c name with id \c id.
  113. * @param name Name of branch.
  114. * @param id Value of branch's "id".
  115. * @returns 1 if is ok, or 0 otherwise.
  116. */
  117. int enterbranch(const std::string &name, int id);
  118. /**Exits from a branch*/
  119. void exitbranch();
  120. /**Get the the branch_id and limits it between the min and max.
  121. * if min==max==0, it will not limit it
  122. * if there isn't any id, will return min
  123. * this must be called only imediately after enterbranch()
  124. */
  125. int getbranchid(int min, int max) const;
  126. /**
  127. * Returns the integer value stored in node name.
  128. * It returns the integer value between the limits min and max.
  129. * If min==max==0, then the value will not be limited.
  130. * If there is no location named name, then defaultpar will be returned.
  131. * @param name The parameter name.
  132. * @param defaultpar The default value if the real value is not found.
  133. * @param min The minimum return value.
  134. * @param max The maximum return value.
  135. */
  136. int getpar(const std::string &name, int defaultpar, int min,
  137. int max) const;
  138. /**
  139. * Returns the integer value stored in the node with range [0,127].
  140. * @param name The parameter name.
  141. * @param defaultpar The default value if the real value is not found.
  142. */
  143. int getpar127(const std::string &name, int defaultpar) const;
  144. /**
  145. * Returns the boolean value stored in the node.
  146. * @param name The parameter name.
  147. * @param defaultpar The default value if the real value is not found.
  148. */
  149. int getparbool(const std::string &name, int defaultpar) const;
  150. /**
  151. * Get the string value stored in the node.
  152. * @param name The parameter name.
  153. * @param par Pointer to destination string
  154. * @param maxstrlen Max string length for destination
  155. */
  156. void getparstr(const std::string &name, char *par, int maxstrlen) const;
  157. /**
  158. * Get the string value stored in the node.
  159. * @param name The parameter name.
  160. * @param defaultpar The default value if the real value is not found.
  161. */
  162. std::string getparstr(const std::string &name,
  163. const std::string &defaultpar) const;
  164. /**
  165. * Returns the real value stored in the node.
  166. * @param name The parameter name.
  167. * @param defaultpar The default value if the real value is not found.
  168. */
  169. float getparreal(const char *name, float defaultpar) const;
  170. /**
  171. * Returns the real value stored in the node.
  172. * @param name The parameter name.
  173. * @param defaultpar The default value if the real value is not found.
  174. * @param min The minimum value
  175. * @param max The maximum value
  176. */
  177. float getparreal(const char *name,
  178. float defaultpar,
  179. float min,
  180. float max) const;
  181. bool minimal; /**<false if all parameters will be stored (used only for clipboard)*/
  182. /**
  183. * Sets the current tree's PAD Synth usage
  184. */
  185. void setPadSynth(bool enabled);
  186. /**
  187. * Checks the current tree for PADsynth usage
  188. */
  189. bool hasPadSynth() const;
  190. private:
  191. /**
  192. * Save the file.
  193. * @param filename File to save to
  194. * @param compression Level of gzip compression
  195. * @param xmldata String to be saved
  196. */
  197. int dosavefile(const char *filename,
  198. int compression,
  199. const char *xmldata) const;
  200. /**
  201. * Loads specified file and returns data.
  202. *
  203. * Will load a gziped file or an uncompressed file.
  204. * @param filename the file
  205. * @return The decompressed data
  206. */
  207. char *doloadfile(const std::string &filename) const;
  208. mxml_node_t *tree; /**<all xml data*/
  209. mxml_node_t *root; /**<xml data used by zynaddsubfx*/
  210. mxml_node_t *node; /**<current subtree in parsing or writing */
  211. mxml_node_t *info; /**<Node used to store the information about the data*/
  212. /**
  213. * Create mxml_node_t with specified name and parameters
  214. *
  215. * Results should look like:
  216. * <name optionalParam1="value1" optionalParam2="value2" ...>
  217. *
  218. * @param name The name of the xml node
  219. * @param params The number of the attributes
  220. * @param ... const char * pairs that are in the format attribute_name,
  221. * attribute_value
  222. */
  223. mxml_node_t *addparams(const char *name, unsigned int params,
  224. ...) const;
  225. /**@todo keep these numbers up to date*/
  226. struct {
  227. int Major; /**<major version number.*/
  228. int Minor; /**<minor version number.*/
  229. int Revision; /**<version revision number.*/
  230. } version;
  231. };
  232. #endif