eacd9a03cfbe6b5b1ebaddee678889a7a748417c
1 //------------------------------------
2 // generation of an xml description
3 //------------------------------------
8 #include "description.hh"
12 * Extracts metdata from a label : 'vol [unit: dB]' -> 'vol' + metadata
14 void extractMetadata(const string
& fulllabel
, string
& label
, map
<string
, set
<string
> >& metadata
)
16 enum {kLabel
, kEscape1
, kEscape2
, kEscape3
, kKey
, kValue
};
17 int state
= kLabel
; int deep
= 0;
20 for (size_t i
=0; i
< fulllabel
.size(); i
++) {
21 char c
= fulllabel
[i
];
26 case '\\' : state
= kEscape1
; break;
27 case '[' : state
= kKey
; deep
++; break;
50 case '\\' : state
= kEscape2
;
57 case ':' : if (deep
== 1) {
65 metadata
[rmWhiteSpaces(key
)].insert("");
80 case '\\' : state
= kEscape3
;
89 metadata
[rmWhiteSpaces(key
)].insert(rmWhiteSpaces(value
));
102 cerr
<< "ERROR unrecognized state " << state
<< endl
;
105 label
= rmWhiteSpaces(label
);
108 //------------------------ specific schema -------------------------
110 string
extractName(Tree fulllabel
)
113 map
<string
, set
<string
> > metadata
;
115 extractMetadata(tree2str(fulllabel
), name
, metadata
);
121 * removes enclosing quotes and transforms '<', '>' and '&' characters
123 static string
xmlize(const string
& fullsrc
)
125 map
<string
, set
<string
> > metadata
;
129 extractMetadata(fullsrc
, src
, metadata
);
131 for (size_t i
=0; i
<src
.size(); i
++) {
132 if (src
[i
] == '"' & (i
==0 | i
==src
.size()-1)) {
133 // nothing to do just skip the quotes
136 case '<' : dst
+= "<"; break;
137 case '>' : dst
+= ">"; break;
138 case '&' : dst
+= "&"; break;
139 default : dst
+= src
[i
];
146 void Description::print(int n
, ostream
& fout
)
148 list
<string
>::iterator s
;
149 list
<int>::iterator t
;
151 tab(n
,fout
); fout
<< "<faust>";
153 tab(n
+1,fout
); fout
<< "<name>" << xmlize(fName
) << "</name>";
154 tab(n
+1,fout
); fout
<< "<author>" << xmlize(fAuthor
) << "</author>";
155 tab(n
+1,fout
); fout
<< "<copyright>" << xmlize(fCopyright
) << "</copyright>";
156 tab(n
+1,fout
); fout
<< "<license>" << xmlize(fLicense
) << "</license>";
157 tab(n
+1,fout
); fout
<< "<version>" << xmlize(fVersion
) << "</version>";
158 tab(n
+1,fout
); fout
<< "<inputs>" << fInputs
<< "</inputs>";
159 tab(n
+1,fout
); fout
<< "<outputs>" << fOutputs
<< "</outputs>";
161 tab(n
+1,fout
); fout
<< "<ui>";
163 // active widget list
164 tab(n
+2,fout
); fout
<< "<activewidgets>";
165 tab(n
+3,fout
); fout
<< "<count>" << fActiveWidgetCount
<< "</count>";
166 for (s
= fActiveLines
.begin(); s
!= fActiveLines
.end(); s
++) {
167 tab(n
+3, fout
); fout
<< *s
;
169 tab(n
+2,fout
); fout
<< "</activewidgets>";
173 // passive widget list
174 tab(n
+2,fout
); fout
<< "<passivewidgets>";
175 tab(n
+3,fout
); fout
<< "<count>" << fPassiveWidgetCount
<< "</count>";
176 for (s
= fPassiveLines
.begin(); s
!= fPassiveLines
.end(); s
++) {
177 tab(n
+3, fout
); fout
<< *s
;
179 tab(n
+2,fout
); fout
<< "</passivewidgets>";
185 tab(n
+2,fout
); fout
<< "<layout>";
186 for ( t
= fLayoutTabs
.begin(), s
= fLayoutLines
.begin();
187 s
!= fLayoutLines
.end(); t
++, s
++) {
188 tab(n
+3+*t
, fout
); fout
<< *s
;
190 tab(n
+2,fout
); fout
<< "</layout>";
192 tab(n
+1,fout
); fout
<< "</ui>";
195 tab(n
,fout
); fout
<< "</faust>" << endl
;
199 void Description::ui(Tree t
)
205 void Description::addGroup(int level
, Tree t
)
207 Tree label
, elements
, varname
, sig
;
208 const char* groupnames
[] = {"vgroup", "hgroup", "tgroup"};
210 if (isUiFolder(t
, label
, elements
)) {
212 const int orient
= tree2int(left(label
));
213 const char * str
= tree2str(right(label
));
215 addLayoutLine(level
, subst("<group type=\"$0\">", groupnames
[orient
]));
216 addLayoutLine(level
+1, subst("<label>$0</label>", xmlize(str
)));
217 while (!isNil(elements
)) {
218 addGroup(level
+1, right(hd(elements
)));
219 elements
= tl(elements
);
221 addLayoutLine(level
, "</group>");
223 } else if (isUiWidget(t
, label
, varname
, sig
)) {
225 int w
= addWidget(label
, varname
, sig
);
226 addLayoutLine(level
, subst("<widgetref id=\"$0\" />", T(w
)));
230 fprintf(stderr
, "error in user interface generation 2\n");
236 void Description::tab (int n
, ostream
& fout
)
239 while (n
--) fout
<< '\t';
242 int Description::addWidget(Tree label
, Tree varname
, Tree sig
)
244 Tree path
, c
, x
, y
, z
;
246 // add an active widget description
248 if ( isSigButton(sig
, path
) ) {
251 fActiveWidgetCount
++;
252 addActiveLine(subst("<widget type=\"button\" id=\"$0\">", T(fWidgetID
)));
253 addActiveLine(subst("\t<label>$0</label>", xmlize(tree2str(label
))));
254 addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname
)));
255 addActiveLine("</widget>");
257 } else if ( isSigCheckbox(sig
, path
) ) {
260 fActiveWidgetCount
++;
261 addActiveLine(subst("<widget type=\"checkbox\" id=\"$0\">", T(fWidgetID
)));
262 addActiveLine(subst("\t<label>$0</label>", xmlize(tree2str(label
))));
263 addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname
)));
264 addActiveLine("</widget>");
266 } else if ( isSigVSlider(sig
, path
,c
,x
,y
,z
) ) {
269 fActiveWidgetCount
++;
270 addActiveLine(subst("<widget type=\"vslider\" id=\"$0\">", T(fWidgetID
)));
271 addActiveLine(subst("\t<label>$0</label>", xmlize(tree2str(label
))));
272 addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname
)));
273 addActiveLine(subst("\t<init>$0</init>", T(tree2double(c
))));
274 addActiveLine(subst("\t<min>$0</min>", T(tree2double(x
))));
275 addActiveLine(subst("\t<max>$0</max>", T(tree2double(y
))));
276 addActiveLine(subst("\t<step>$0</step>", T(tree2double(z
))));
277 addActiveLine("</widget>");
279 } else if ( isSigHSlider(sig
, path
,c
,x
,y
,z
) ) {
282 fActiveWidgetCount
++;
283 addActiveLine(subst("<widget type=\"hslider\" id=\"$0\">", T(fWidgetID
)));
284 addActiveLine(subst("\t<label>$0</label>", xmlize(tree2str(label
))));
285 addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname
)));
286 addActiveLine(subst("\t<init>$0</init>", T(tree2double(c
))));
287 addActiveLine(subst("\t<min>$0</min>", T(tree2double(x
))));
288 addActiveLine(subst("\t<max>$0</max>", T(tree2double(y
))));
289 addActiveLine(subst("\t<step>$0</step>", T(tree2double(z
))));
290 addActiveLine("</widget>");
292 } else if ( isSigNumEntry(sig
, path
,c
,x
,y
,z
) ) {
295 fActiveWidgetCount
++;
296 addActiveLine(subst("<widget type=\"nentry\" id=\"$0\">", T(fWidgetID
)));
297 addActiveLine(subst("\t<label>$0</label>", xmlize(tree2str(label
))));
298 addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname
)));
299 addActiveLine(subst("\t<init>$0</init>", T(tree2double(c
))));
300 addActiveLine(subst("\t<min>$0</min>", T(tree2double(x
))));
301 addActiveLine(subst("\t<max>$0</max>", T(tree2double(y
))));
302 addActiveLine(subst("\t<step>$0</step>", T(tree2double(z
))));
303 addActiveLine("</widget>");
306 // add a passive widget description
308 } else if ( isSigVBargraph(sig
,path
,x
,y
,z
) ) {
311 fPassiveWidgetCount
++;
312 addPassiveLine(subst("<widget type=\"vbargraph\" id=\"$0\">", T(fWidgetID
)));
313 addPassiveLine(subst("\t<label>$0</label>", xmlize(tree2str(label
))));
314 addPassiveLine(subst("\t<varname>$0</varname>", tree2str(varname
)));
315 addPassiveLine(subst("\t<min>$0</min>", T(tree2double(x
))));
316 addPassiveLine(subst("\t<max>$0</max>", T(tree2double(y
))));
317 addPassiveLine("</widget>");
319 } else if ( isSigHBargraph(sig
,path
,x
,y
,z
) ) {
322 fPassiveWidgetCount
++;
323 addPassiveLine(subst("<widget type=\"hbargraph\" id=\"$0\">", T(fWidgetID
)));
324 addPassiveLine(subst("\t<label>$0</label>", xmlize(tree2str(label
))));
325 addPassiveLine(subst("\t<varname>$0</varname>", tree2str(varname
)));
326 addPassiveLine(subst("\t<min>$0</min>", T(tree2double(x
))));
327 addPassiveLine(subst("\t<max>$0</max>", T(tree2double(y
))));
328 addPassiveLine("</widget>");
331 fprintf(stderr
, "Error describing widget : unrecognized expression\n");