/usr/include/faust/dsp/proxy-dsp.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 | /************************************************************************
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 __proxy_dsp__
#define __proxy_dsp__
#include <vector>
#include <map>
#include "faust/dsp/dsp.h"
#include "faust/gui/SimpleParser.h"
#include "faust/gui/JSONUI.h"
#ifdef _WIN32
#include <windows.h>
#define snprintf _snprintf
#endif
inline FAUSTFLOAT STR2REAL(const std::string& s) { return (strtod(s.c_str(), NULL)); }
//-------------------------------------------------------------------
// Decode a dsp JSON description and implement 'buildUserInterface'
//-------------------------------------------------------------------
struct JSONUIDecoder {
std::string fName;
std::map<std::string, std::string> fMetadatas;
std::vector<itemInfo*> fUiItems;
FAUSTFLOAT* fInControl;
FAUSTFLOAT* fOutControl;
std::string fJSON;
int fNumInputs, fNumOutputs;
int fInputItems, fOutputItems;
JSONUIDecoder(const std::string& json)
{
fJSON = json;
const char* p = fJSON.c_str();
parseJson(p, fMetadatas, fUiItems);
// fMetadatas will contain the "meta" section as well as <name : val>, <inputs : val>, <ouputs : val> pairs
if (fMetadatas.find("name") != fMetadatas.end()) {
fName = fMetadatas["name"];
fMetadatas.erase("name");
} else {
fName = "";
}
if (fMetadatas.find("inputs") != fMetadatas.end()) {
fNumInputs = atoi(fMetadatas["inputs"].c_str());
fMetadatas.erase("inputs");
} else {
fNumInputs = -1;
}
if (fMetadatas.find("outputs") != fMetadatas.end()) {
fNumOutputs = atoi(fMetadatas["outputs"].c_str());
fMetadatas.erase("outputs");
} else {
fNumOutputs = -1;
}
vector<itemInfo*>::iterator it;
fInputItems = 0;
fOutputItems = 0;
for (it = fUiItems.begin(); it != fUiItems.end(); it++) {
string type = (*it)->type;
if (type == "vslider" || type == "hslider" || type == "nentry" || type == "button") {
fInputItems++;
} else if (type == "hbargraph" || type == "vbargraph") {
fOutputItems++;
}
}
fInControl = new FAUSTFLOAT[fInputItems];
fOutControl = new FAUSTFLOAT[fOutputItems];
}
virtual ~JSONUIDecoder()
{
vector<itemInfo*>::iterator it;
for (it = fUiItems.begin(); it != fUiItems.end(); it++) {
delete(*it);
}
delete [] fInControl;
delete [] fOutControl;
}
void metadata(Meta* m)
{
std::map<std::string, std::string>::iterator it;
for (it = fMetadatas.begin(); it != fMetadatas.end(); it++) {
m->declare((*it).first.c_str(), (*it).second.c_str());
}
}
void buildUserInterface(UI* ui)
{
// To be sure the floats are correctly encoded
char* tmp_local = setlocale(LC_ALL, NULL);
setlocale(LC_ALL, "C");
int counterIn = 0;
int counterOut = 0;
vector<itemInfo*>::iterator it;
for (it = fUiItems.begin(); it != fUiItems.end(); it++) {
bool isInItem = false;
bool isOutItem = false;
string type = (*it)->type;
FAUSTFLOAT init = STR2REAL((*it)->init);
FAUSTFLOAT min = STR2REAL((*it)->min);
FAUSTFLOAT max = STR2REAL((*it)->max);
FAUSTFLOAT step = STR2REAL((*it)->step);
if (type == "vslider" || type == "hslider" || type == "nentry" || type == "button") {
isInItem = true;
} else if (type == "hbargraph" || type == "vbargraph") {
isOutItem = true;
}
// Meta data declaration for input items
if ((*it)->type.find("group") == string::npos && (*it)->type.find("bargraph") == string::npos && (*it)->type != "close") {
fInControl[counterIn] = init;
for (int i = 0; i < (*it)->meta.size(); i++) {
ui->declare(&fInControl[counterIn], (*it)->meta[i].first.c_str(), (*it)->meta[i].second.c_str());
}
}
// Meta data declaration for output items
else if ((*it)->type.find("bargraph") != string::npos) {
fOutControl[counterOut] = init;
for (int i = 0; i < (*it)->meta.size(); i++) {
ui->declare(&fOutControl[counterOut], (*it)->meta[i].first.c_str(), (*it)->meta[i].second.c_str());
}
}
// Meta data declaration for group opening or closing
else {
for (int i = 0; i < (*it)->meta.size(); i++) {
ui->declare(0, (*it)->meta[i].first.c_str(), (*it)->meta[i].second.c_str());
}
}
if (type == "hgroup") {
ui->openHorizontalBox((*it)->label.c_str());
} else if (type == "vgroup") {
ui->openVerticalBox((*it)->label.c_str());
} else if (type == "tgroup") {
ui->openTabBox((*it)->label.c_str());
} else if (type == "vslider") {
ui->addVerticalSlider((*it)->label.c_str(), &fInControl[counterIn], init, min, max, step);
} else if (type == "hslider") {
ui->addHorizontalSlider((*it)->label.c_str(), &fInControl[counterIn], init, min, max, step);
} else if (type == "checkbox") {
ui->addCheckButton((*it)->label.c_str(), &fInControl[counterIn]);
} else if (type == "hbargraph") {
ui->addHorizontalBargraph((*it)->label.c_str(), &fOutControl[counterOut], min, max);
} else if (type == "vbargraph") {
ui->addVerticalBargraph((*it)->label.c_str(), &fOutControl[counterOut], min, max);
} else if (type == "nentry") {
ui->addNumEntry((*it)->label.c_str(), &fInControl[counterIn], init, min, max, step);
} else if (type == "button") {
ui->addButton((*it)->label.c_str(), &fInControl[counterIn]);
} else if (type == "close") {
ui->closeBox();
}
if (isInItem) {
counterIn++;
}
if (isOutItem) {
counterOut++;
}
}
setlocale(LC_ALL, tmp_local);
}
};
//----------------------------------------------------------------
// Proxy dsp definition created from the DSP JSON description
// This class allows a 'proxy' dsp to control a real dsp
// possibly running somewhere else.
//----------------------------------------------------------------
class proxy_dsp : public dsp {
private:
int fSamplingFreq;
JSONUIDecoder* fDecoder;
public:
proxy_dsp(const string& json)
{
fDecoder = new JSONUIDecoder(json);
fSamplingFreq = -1;
}
proxy_dsp(dsp* dsp)
{
JSONUI builder(dsp->getNumInputs(), dsp->getNumOutputs());
dsp->metadata(&builder);
dsp->buildUserInterface(&builder);
fSamplingFreq = dsp->getSampleRate();
fDecoder = new JSONUIDecoder(builder.JSON());
}
virtual ~proxy_dsp()
{
delete fDecoder;
}
virtual int getNumInputs() { return fDecoder->fNumInputs; }
virtual int getNumOutputs() { return fDecoder->fNumOutputs; }
virtual void buildUserInterface(UI* ui) { fDecoder->buildUserInterface(ui); }
// To possibly implement in a concrete proxy dsp
virtual void init(int samplingRate) { fSamplingFreq = samplingRate; }
virtual void instanceInit(int samplingRate) {}
virtual void instanceConstants(int samplingRate) {}
virtual void instanceResetUserInterface() {}
virtual void instanceClear() {}
virtual int getSampleRate() { return fSamplingFreq; }
virtual proxy_dsp* clone() { return new proxy_dsp(fDecoder->fJSON); }
virtual void metadata(Meta* m) { fDecoder->metadata(m); }
virtual void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) {}
virtual void compute(double date_usec, int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) {}
};
#endif
|