Add the output wave files into track list
[Faustine.git] / interpretor / faust-0.9.47mr3 / architecture / gui / FUI.h
1 #ifndef FAUST_FUI_H
2 #define FAUST_FUI_H
3
4 #include "UI.h"
5
6 #include <string>
7 #include <map>
8 #include <set>
9 #include <vector>
10 #include <stack>
11
12 #include <iostream>
13 #include <fstream>
14
15 using namespace std;
16
17 #if 1
18
19 /*******************************************************************************
20 * FUI : used to save and recall the state of the user interface
21 * This class provides essentially two new methods saveState() and recallState()
22 * used to save on file and recall from file the state of the user interface.
23 * The file is human readble and editable
24 ******************************************************************************/
25
26 class FUI : public UI
27 {
28 stack<string> fGroupStack;
29 vector<string> fNameList;
30 map<string, float*> fName2Zone;
31
32 protected:
33
34 // labels are normalized by replacing white spaces by underscores and by
35 // removing parenthesis
36 string normalizeLabel(const char* label)
37 {
38 string s;
39 char c;
40
41 while ((c=*label++)) {
42 if (isspace(c)) { s += '_'; }
43 //else if ((c == '(') | (c == ')') ) { }
44 else { s += c; }
45 }
46 return s;
47 }
48
49 // add an element by relating its full name and memory zone
50 virtual void addElement (const char* label, float* zone)
51 {
52 string fullname (fGroupStack.top() + '/' + normalizeLabel(label));
53 fNameList.push_back(fullname);
54 fName2Zone[fullname] = zone;
55 }
56
57 // keep track of full group names in a stack
58 virtual void pushGroupLabel(const char* label)
59 {
60 if (fGroupStack.empty()) {
61 fGroupStack.push(normalizeLabel(label));
62 } else {
63 fGroupStack.push(fGroupStack.top() + '/' + normalizeLabel(label));
64 }
65 }
66
67 virtual void popGroupLabel()
68 {
69 fGroupStack.pop();
70 };
71
72 public:
73
74 FUI() {}
75 virtual ~FUI() {}
76
77 // -- Save and recall methods
78
79 // save the zones values and full names
80 virtual void saveState(const char* filename)
81 {
82 ofstream f(filename);
83
84 for (unsigned int i=0; i<fNameList.size(); i++) {
85 string n = fNameList[i];
86 float* z = fName2Zone[n];
87 f << *z << ' ' << n << endl;
88 }
89
90 f << endl;
91 f.close();
92 }
93
94 // recall the zones values and full names
95 virtual void recallState(const char* filename)
96 {
97 ifstream f(filename);
98 float v;
99 string n;
100
101 while (f.good()) {
102 f >> v >> n;
103 if (fName2Zone.count(n)>0) {
104 *(fName2Zone[n]) = v;
105 } else {
106 cerr << "recallState : parameter not found : " << n << " with value : " << v << endl;
107 }
108 }
109 f.close();
110 }
111
112
113 // -- widget's layouts (just keep track of group labels)
114
115 virtual void openFrameBox(const char* label) { pushGroupLabel(label); }
116 virtual void openTabBox(const char* label) { pushGroupLabel(label); }
117 virtual void openHorizontalBox(const char* label) { pushGroupLabel(label); }
118 virtual void openVerticalBox(const char* label) { pushGroupLabel(label); }
119 virtual void closeBox() { popGroupLabel(); };
120
121 // -- active widgets (just add an element)
122
123 virtual void addButton(const char* label, float* zone) { addElement(label, zone); }
124 virtual void addToggleButton(const char* label, float* zone) { addElement(label, zone); }
125 virtual void addCheckButton(const char* label, float* zone) { addElement(label, zone); }
126 virtual void addVerticalSlider(const char* label, float* zone, float , float , float , float )
127 { addElement(label, zone); }
128 virtual void addHorizontalSlider(const char* label, float* zone, float , float , float , float )
129 { addElement(label, zone); }
130 virtual void addNumEntry(const char* label, float* zone, float , float , float , float )
131 { addElement(label, zone); }
132
133 // -- passive widgets (are ignored)
134
135 virtual void addNumDisplay(const char* , float* , int ) {};
136 virtual void addTextDisplay(const char* , float* , const char*[], float , float ) {};
137 virtual void addHorizontalBargraph(const char* , float* , float , float ) {};
138 virtual void addVerticalBargraph(const char* , float* , float , float ) {};
139
140 // -- metadata are not used
141
142 virtual void declare(float* , const char* , const char* ) {}
143 };
144 #endif
145
146 #endif
147