Add input csv files of examples to track list.
[Faustine.git] / interpreter / preprocessor / faust-0.9.47mr3 / architecture / gui / console.h
1 /************************************************************************
2
3 IMPORTANT NOTE : this file contains two clearly delimited sections :
4 the ARCHITECTURE section (in two parts) and the USER section. Each section
5 is governed by its own copyright and license. Please check individually
6 each section for license and copyright information.
7 *************************************************************************/
8
9 /*******************BEGIN ARCHITECTURE SECTION (part 1/2)****************/
10
11 /************************************************************************
12 FAUST Architecture File
13 Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale
14 ---------------------------------------------------------------------
15 This Architecture section is free software; you can redistribute it
16 and/or modify it under the terms of the GNU General Public License
17 as published by the Free Software Foundation; either version 3 of
18 the License, or (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; If not, see <http://www.gnu.org/licenses/>.
27
28 EXCEPTION : As a special exception, you may create a larger work
29 that contains this FAUST architecture section and distribute
30 that work under terms of your choice, so long as this FAUST
31 architecture section is not modified.
32
33
34 ************************************************************************
35 ************************************************************************/
36 #ifndef __faustconsole__
37 #define __faustconsole__
38
39 #include "GUI.h"
40
41 #include <stdlib.h>
42 #include <stdio.h>
43 #include <string.h>
44 #include <stack>
45 #include <string>
46 #include <map>
47 #include <iostream>
48
49 using namespace std;
50
51 /******************************************************************************
52 *******************************************************************************
53
54 USER INTERFACE
55
56 *******************************************************************************
57 *******************************************************************************/
58
59 struct param {
60 float* fZone; float fMin; float fMax;
61 param(float* z, float a, float b) : fZone(z), fMin(a), fMax(b) {}
62 };
63
64 class CMDUI : public GUI
65 {
66 int fArgc;
67 char** fArgv;
68 stack<string> fPrefix;
69 map<string, param> fKeyParam;
70
71 void addOption(const char* label, float* zone, float min, float max)
72 {
73 string fullname = fPrefix.top() + label;
74 fKeyParam.insert(make_pair(fullname, param(zone, min, max)));
75 }
76
77 void openAnyBox(const char* label)
78 {
79 string prefix;
80
81 if (label && label[0]) {
82 prefix = fPrefix.top() + "-" + label;
83 } else {
84 prefix = fPrefix.top();
85 }
86 fPrefix.push(prefix);
87 }
88
89 public:
90
91 CMDUI(int argc, char *argv[]) : GUI(), fArgc(argc), fArgv(argv) { fPrefix.push("--"); }
92 virtual ~CMDUI() {}
93
94 virtual void openFrameBox(const char* label) { openAnyBox(label); }
95 virtual void openTabBox(const char* label) { openAnyBox(label); }
96 virtual void openHorizontalBox(const char* label) { openAnyBox(label); }
97 virtual void openVerticalBox(const char* label) { openAnyBox(label); }
98 virtual void closeBox() { fPrefix.pop(); }
99
100 virtual void addButton(const char* label, float* zone) {};
101 virtual void addToggleButton(const char* label, float* zone) {};
102 virtual void addCheckButton(const char* label, float* zone) {};
103
104 virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step)
105 {
106 addOption(label,zone,min,max);
107 }
108
109 virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step)
110 {
111 addOption(label,zone,min,max);
112 }
113
114 virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step)
115 {
116 addOption(label,zone,min,max);
117 }
118
119 // -- passive widgets
120
121 virtual void addNumDisplay(const char* label, float* zone, int precision) {}
122 virtual void addTextDisplay(const char* label, float* zone, const char* names[], float min, float max) {}
123 virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) {}
124 virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) {}
125
126 virtual void show() {}
127 virtual void run()
128 {
129 char c;
130 printf("Type 'q' to quit\n");
131 while ((c = getchar()) != 'q') {
132 sleep(1);
133 }
134 }
135
136 void print()
137 {
138 map<string, param>::iterator i;
139 cout << fArgc << "\n";
140 cout << fArgv[0] << " option list : ";
141 for (i = fKeyParam.begin(); i != fKeyParam.end(); i++) {
142 cout << "[ " << i->first << " " << i->second.fMin << ".." << i->second.fMax <<" ] ";
143 }
144 }
145
146 void process_command()
147 {
148 map<string, param>::iterator p;
149 for (int i = 1; i < fArgc; i++) {
150 if (fArgv[i][0] == '-') {
151 p = fKeyParam.find(fArgv[i]);
152 if (p == fKeyParam.end()) {
153 cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n";
154 print();
155 exit(1);
156 }
157 char* end;
158 *(p->second.fZone) = float(strtod(fArgv[i+1], &end));
159 i++;
160 }
161 }
162 }
163
164 void process_init()
165 {
166 map<string, param>::iterator p;
167 for (int i = 1; i < fArgc; i++) {
168 if (fArgv[i][0] == '-') {
169 p = fKeyParam.find(fArgv[i]);
170 if (p == fKeyParam.end()) {
171 cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n";
172 exit(1);
173 }
174 char* end;
175 *(p->second.fZone) = float(strtod(fArgv[i+1], &end));
176 i++;
177 }
178 }
179 }
180 };
181
182 #endif
183
184 /********************END ARCHITECTURE SECTION (part 2/2)****************/