/usr/include/faust/gui/console.h is in faust-common 0.9.95~repack1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | /************************************************************************
IMPORTANT NOTE : this file contains two clearly delimited sections :
the ARCHITECTURE section (in two parts) and the USER section. Each section
is governed by its own copyright and license. Please check individually
each section for license and copyright information.
*************************************************************************/
/*******************BEGIN ARCHITECTURE SECTION (part 1/2)****************/
/************************************************************************
FAUST Architecture File
Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************
************************************************************************/
#ifndef __faustconsole__
#define __faustconsole__
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stack>
#include <string>
#include <map>
#include <vector>
#include <iostream>
#include "faust/gui/UI.h"
/******************************************************************************
*******************************************************************************
USER INTERFACE
*******************************************************************************
*******************************************************************************/
struct param {
FAUSTFLOAT* fZone; FAUSTFLOAT fMin; FAUSTFLOAT fMax;
param(FAUSTFLOAT* z, FAUSTFLOAT init, FAUSTFLOAT a, FAUSTFLOAT b) : fZone(z), fMin(a), fMax(b) { *z = init; }
};
class CMDUI : public UI
{
int fArgc;
char** fArgv;
std::vector<char*> fFiles;
std::stack<std::string> fPrefix;
std::map<std::string, param> fKeyParam;
void openAnyBox(const char* label)
{
std::string prefix;
if (label && label[0]) {
prefix = fPrefix.top() + "-" + label;
} else {
prefix = fPrefix.top();
}
fPrefix.push(prefix);
}
std::string simplify(const std::string& src)
{
int i = 0;
int level = 0;
std::string dst;
while (src[i] ) {
switch (level) {
case 0 :
case 1 :
case 2 :
// Skip the begin of the label "--foo-"
// until 3 '-' have been read
if (src[i]=='-') { level++; }
break;
case 3 :
// copy the content, but skip non alphnum
// and content in parenthesis
switch (src[i]) {
case '(' :
case '[' :
level++;
break;
case '-' :
dst += '-';
break;
default :
if (isalnum(src[i])) {
dst+= tolower(src[i]);
}
}
break;
default :
// here we are inside parenthesis and
// we skip the content until we are back to
// level 3
switch (src[i]) {
case '(' :
case '[' :
level++;
break;
case ')' :
case ']' :
level--;
break;
default :
break;
}
}
i++;
}
return dst;
}
public:
CMDUI(int argc, char *argv[]) : UI(), fArgc(argc), fArgv(argv) { fPrefix.push("-"); }
virtual ~CMDUI() {}
void addOption(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max)
{
std::string fullname = "-" + simplify(fPrefix.top() + "-" + label);
fKeyParam.insert(make_pair(fullname, param(zone, init, min, max)));
}
virtual void addButton(const char* label, FAUSTFLOAT* zone)
{
addOption(label,zone,0,0,1);
}
virtual void addCheckButton(const char* label, FAUSTFLOAT* zone)
{
addOption(label,zone,0,0,1);
}
virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{
addOption(label,zone,init,min,max);
}
virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{
addOption(label,zone,init,min,max);
}
virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{
addOption(label,zone,init,min,max);
}
// -- passive widgets
virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) {}
virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) {}
virtual void openTabBox(const char* label) { openAnyBox(label); }
virtual void openHorizontalBox(const char* label) { openAnyBox(label); }
virtual void openVerticalBox(const char* label) { openAnyBox(label); }
virtual void closeBox() { fPrefix.pop(); }
virtual void show() {}
virtual bool run()
{
char c;
printf("Type 'q' to quit\n");
while ((c = getchar()) != 'q') {
sleep(1);
}
return true;
}
void printhelp_command()
{
std::map<std::string, param>::iterator i;
std::cout << fArgc << "\n";
std::cout << fArgv[0] << " option list : ";
for (i = fKeyParam.begin(); i != fKeyParam.end(); i++) {
std::cout << "[ " << i->first << " " << i->second.fMin << ".." << i->second.fMax <<" ] ";
}
std::cout << " infile outfile\n";
}
void printhelp_init()
{
std::map<std::string, param>::iterator i;
std::cout << fArgc << "\n";
std::cout << fArgv[0] << " option list : ";
for (i = fKeyParam.begin(); i != fKeyParam.end(); i++) {
std::cout << "[ " << i->first << " " << i->second.fMin << ".." << i->second.fMax <<" ] ";
}
std::cout << std::endl;
}
void process_command()
{
std::map<std::string, param>::iterator p;
for (int i = 1; i < fArgc; i++) {
if (fArgv[i][0] == '-') {
if ((strcmp(fArgv[i], "-help") == 0)
|| (strcmp(fArgv[i], "-h") == 0)
|| (strcmp(fArgv[i], "--help") == 0)) {
printhelp_command();
exit(1);
}
p = fKeyParam.find(fArgv[i]);
if (p == fKeyParam.end()) {
std::cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n";
printhelp_command();
exit(1);
}
char* end;
*(p->second.fZone) = FAUSTFLOAT(strtod(fArgv[i+1], &end));
i++;
} else {
fFiles.push_back(fArgv[i]);
}
}
}
unsigned long files() { return fFiles.size(); }
char* file (int n) { return fFiles[n]; }
char* input_file () { std::cout << "input file " << fFiles[0] << "\n"; return fFiles[0]; }
char* output_file() { std::cout << "output file " << fFiles[1] << "\n"; return fFiles[1]; }
void process_init()
{
std::map<std::string, param>::iterator p;
for (int i = 1; i < fArgc; i++) {
if (fArgv[i][0] == '-') {
if ((strcmp(fArgv[i], "-help") == 0)
|| (strcmp(fArgv[i], "-h") == 0)
|| (strcmp(fArgv[i], "--help") == 0)) {
printhelp_init();
exit(1);
}
p = fKeyParam.find(fArgv[i]);
if (p == fKeyParam.end()) {
std::cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n";
printhelp_init();
exit(1);
}
char* end;
*(p->second.fZone) = FAUSTFLOAT(strtod(fArgv[i+1], &end));
i++;
}
}
}
};
#endif
/********************END ARCHITECTURE SECTION (part 2/2)****************/
|