summaryrefslogtreecommitdiff
path: root/attic/muse_qt4_evolution/synti/zynaddsubfx/Misc/XMLwrapper.h
blob: 765622a23f0e97baada8ee983ae5ed874268dd69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
  ZynAddSubFX - a software synthesizer
 
  XML.h - XML wrapper
  Copyright (C) 2003-2005 Nasca Octavian Paul
  Author: Nasca Octavian Paul

  This program is free software; you can redistribute it and/or modify
  it under the terms of version 2 of the GNU General Public License 
  as published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License (version 2) for more details.

  You should have received a copy of the GNU General Public License (version 2)
  along with this program; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA

*/

#include <mxml.h>
#ifndef REALTYPE
#define REALTYPE float
#endif

#ifndef XML_WRAPPER_H
#define XML_WRAPPER_H

#define TMPSTR_SIZE 50

//the maxim tree depth
#define STACKSIZE 100

class XMLwrapper{
    public:
	XMLwrapper();
	~XMLwrapper();
	
	/********************************/
	/*         SAVE to XML          */
	/********************************/

	//returns 0 if ok or -1 if the file cannot be saved
	int saveXMLfile(char *filename);

	//returns the new allocated string that contains the XML data (used for clipboard)
	//the string is NULL terminated
	char *getXMLdata();
	
	//add simple parameter (name and value)
	void addpar(char *name,int val);
	void addparreal(char *name,REALTYPE val);
	
	//add boolean parameter (name and boolean value)
	//if the value is 0 => "yes", else "no"
	void addparbool(char *name,int val);

	//add string parameter (name and string)
	void addparstr(char *name,char *val);

	//add a branch
	void beginbranch(char *name);
	void beginbranch(char *name, int id);

	//this must be called after each branch (nodes that contains child nodes)
	void endbranch();

	/********************************/
	/*        LOAD from XML         */
	/********************************/
	
	//returns 0 if ok or -1 if the file cannot be loaded
	int loadXMLfile(const char *filename);

	//used by the clipboard
	bool putXMLdata(char *xmldata);
    
	//enter into the branch
	//returns 1 if is ok, or 0 otherwise
	int enterbranch(char *name);

		
	//enter into the branch with id
	//returns 1 if is ok, or 0 otherwise
	int enterbranch(char *name, int id);

	//exits from a branch
	void exitbranch();
	
	//get the the branch_id and limits it between the min and max
	//if min==max==0, it will not limit it
	//if there isn't any id, will return min
	//this must be called only imediately after enterbranch()
	int getbranchid(int min, int max);

	//it returns the parameter and limits it between min and max
	//if min==max==0, it will not limit it
	//if no parameter will be here, the defaultpar will be returned
	int getpar(char *name,int defaultpar,int min,int max);

	//the same as getpar, but the limits are 0 and 127
	int getpar127(char *name,int defaultpar);
	
	int getparbool(char *name,int defaultpar);

	void getparstr(char *name,char *par,int maxstrlen);
	REALTYPE getparreal(char *name,REALTYPE defaultpar);
	REALTYPE getparreal(char *name,REALTYPE defaultpar,REALTYPE min,REALTYPE max);

	bool minimal;//false if all parameters will be stored (used only for clipboard)
	
	struct {
	    bool PADsynth_used;
	}information;
	
	//opens a file and parse only the "information" data on it
	//returns "true" if all went ok or "false" on errors
	bool checkfileinformation(char *filename);
	
    private:
    
	int dosavefile(char *filename,int compression,char *xmldata);
	char *doloadfile(const char *filename);

    
	mxml_node_t *tree;//all xml data
	mxml_node_t *root;//xml data used by zynaddsubfx
	mxml_node_t *node;//current node
	mxml_node_t *info;//this node is used to store the information about the data
	
	//adds params like this:
	// <name>
	//returns the node
	mxml_node_t *addparams0(char *name);

	//adds params like this:
	// <name par1="val1">
	//returns the node
	mxml_node_t *addparams1(char *name,char *par1,char *val1);

	//adds params like this:
	// <name par1="val1" par2="val2">
	//returns the node
	mxml_node_t *addparams2(char *name,char *par1,char *val1,char *par2, char *val2);
	
	char *int2str(int x);
	char *real2str(REALTYPE x);
	
	int str2int(const char *str);
	REALTYPE str2real(const char *str);
	
	char tmpstr[TMPSTR_SIZE];	
	
	
	//this is used to store the parents
	mxml_node_t *parentstack[STACKSIZE];
	int stackpos;

	
	void push(mxml_node_t *node);
	mxml_node_t *pop();
	mxml_node_t *peek();

	//theese are used to store the values
	struct{
	    struct {
		int major,minor;
	    }xml_version;
	}values;
	
};

#endif