Debian Codegraph @

audio/faudiostream/architecture/faust/gui/console.h

raw symbols SCIP
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
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <stack>
44 #include <string>
45 #include <map>
46 #include <iostream>
47
48 #include "faust/gui/GUI.h"
49
50 using namespace std;
51
52 /******************************************************************************
53 *******************************************************************************
54
55 USER INTERFACE
56
57 *******************************************************************************
58 *******************************************************************************/
59
60 struct param {
61 FAUSTFLOAT* fZone; FAUSTFLOAT fMin; FAUSTFLOAT fMax;
62 param(FAUSTFLOAT* z, FAUSTFLOAT a, FAUSTFLOAT b) : fZone(z), fMin(a), fMax(b) {}
63 };
64
65 class CMDUI : public GUI
66 {
67 int fArgc;
68 char** fArgv;
69 stack<string> fPrefix;
70 map<string, param> fKeyParam;
71
72 void addOption(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
73 {
74 string fullname = fPrefix.top() + label;
75 fKeyParam.insert(make_pair(fullname, param(zone, min, max)));
76 }
77
78 void openAnyBox(const char* label)
79 {
80 string prefix;
81
82 if (label && label[0]) {
83 prefix = fPrefix.top() + "-" + label;
84 } else {
85 prefix = fPrefix.top();
86 }
87 fPrefix.push(prefix);
88 }
89
90 public:
91
92 CMDUI(int argc, char *argv[]) : GUI(), fArgc(argc), fArgv(argv) { fPrefix.push("--"); }
93 virtual ~CMDUI() {}
94
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, FAUSTFLOAT* zone) {};
101 virtual void addCheckButton(const char* label, FAUSTFLOAT* zone) {};
102
103 virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
104 {
105 addOption(label,zone,min,max);
106 }
107
108 virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
109 {
110 addOption(label,zone,min,max);
111 }
112
113 virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
114 {
115 addOption(label,zone,min,max);
116 }
117
118 // -- passive widgets
119
120 virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) {}
121 virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) {}
122
123 virtual void show() {}
124 virtual void run()
125 {
126 char c;
127 printf("Type 'q' to quit\n");
128 while ((c = getchar()) != 'q') {
129 sleep(1);
130 }
131 }
132
133 void print()
134 {
135 map<string, param>::iterator i;
136 cout << fArgc << "\n";
137 cout << fArgv[0] << " option list : ";
138 for (i = fKeyParam.begin(); i != fKeyParam.end(); i++) {
139 cout << "[ " << i->first << " " << i->second.fMin << ".." << i->second.fMax <<" ] ";
140 }
141 cout << endl;
142 }
143
144 void process_command()
145 {
146 map<string, param>::iterator p;
147 for (int i = 1; i < fArgc; i++) {
148 if (fArgv[i][0] == '-') {
149 p = fKeyParam.find(fArgv[i]);
150 if (p == fKeyParam.end()) {
151 cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n";
152 print();
153 exit(1);
154 }
155 char* end;
156 *(p->second.fZone) = FAUSTFLOAT(strtod(fArgv[i+1], &end));
157 i++;
158 }
159 }
160 }
161
162 void process_init()
163 {
164 map<string, param>::iterator p;
165 for (int i = 1; i < fArgc; i++) {
166 if (fArgv[i][0] == '-') {
167 p = fKeyParam.find(fArgv[i]);
168 if (p == fKeyParam.end()) {
169 cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n";
170 exit(1);
171 }
172 char* end;
173 *(p->second.fZone) = FAUSTFLOAT(strtod(fArgv[i+1], &end));
174 i++;
175 }
176 }
177 }
178 };
179
180 #endif
181
182 /********************END ARCHITECTURE SECTION (part 2/2)****************/