1 /************************************************************************
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 *************************************************************************/
9 /*******************BEGIN ARCHITECTURE SECTION (part 1/2)****************/
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.
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.
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/>.
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.
34 ************************************************************************
35 ************************************************************************/
36 #ifndef __faustconsole__
37 #define __faustconsole__
51 /******************************************************************************
52 *******************************************************************************
56 *******************************************************************************
57 *******************************************************************************/
60 float* fZone
; float fMin
; float fMax
;
61 param(float* z
, float a
, float b
) : fZone(z
), fMin(a
), fMax(b
) {}
64 class CMDUI
: public GUI
68 stack
<string
> fPrefix
;
69 map
<string
, param
> fKeyParam
;
71 void addOption(const char* label
, float* zone
, float min
, float max
)
73 string fullname
= fPrefix
.top() + label
;
74 fKeyParam
.insert(make_pair(fullname
, param(zone
, min
, max
)));
77 void openAnyBox(const char* label
)
81 if (label
&& label
[0]) {
82 prefix
= fPrefix
.top() + "-" + label
;
84 prefix
= fPrefix
.top();
91 CMDUI(int argc
, char *argv
[]) : GUI(), fArgc(argc
), fArgv(argv
) { fPrefix
.push("--"); }
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(); }
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
) {};
104 virtual void addVerticalSlider(const char* label
, float* zone
, float init
, float min
, float max
, float step
)
106 addOption(label
,zone
,min
,max
);
109 virtual void addHorizontalSlider(const char* label
, float* zone
, float init
, float min
, float max
, float step
)
111 addOption(label
,zone
,min
,max
);
114 virtual void addNumEntry(const char* label
, float* zone
, float init
, float min
, float max
, float step
)
116 addOption(label
,zone
,min
,max
);
119 // -- passive widgets
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
) {}
126 virtual void show() {}
130 printf("Type 'q' to quit\n");
131 while ((c
= getchar()) != 'q') {
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
<<" ] ";
146 void process_command()
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";
158 *(p
->second
.fZone
) = float(strtod(fArgv
[i
+1], &end
));
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";
175 *(p
->second
.fZone
) = float(strtod(fArgv
[i
+1], &end
));
184 /********************END ARCHITECTURE SECTION (part 2/2)****************/