/usr/include/faust/gui/JSONUI.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 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | /************************************************************************
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 FAUST_JSONUI_H
#define FAUST_JSONUI_H
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
#include "faust/gui/UI.h"
#include "faust/gui/PathBuilder.h"
#include "faust/gui/meta.h"
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <sstream>
#include <assert.h>
/*******************************************************************************
* JSONUI : Faust User Interface
* This class produce a complete JSON decription of the DSP instance.
******************************************************************************/
class JSONUI : public PathBuilder, public Meta, public UI
{
protected:
std::stringstream fJSON;
std::stringstream fUI;
std::stringstream fMeta;
std::vector<std::pair <std::string, std::string> > fMetaAux;
std::string fName;
std::string fExpandedCode;
std::string fSHAKey;
char fCloseUIPar;
char fCloseMetaPar;
int fTab;
int fInputs, fOutputs;
void tab(int n, std::ostream& fout)
{
fout << '\n';
while (n-- > 0) {
fout << '\t';
}
}
void addMeta(int tab_val, bool quote = true)
{
if (fMetaAux.size() > 0) {
tab(tab_val, fUI); fUI << "\"meta\": [";
std::string sep = "";
for (size_t i = 0; i < fMetaAux.size(); i++) {
fUI << sep;
tab(tab_val + 1, fUI); fUI << "{ \"" << fMetaAux[i].first << "\": \"" << fMetaAux[i].second << "\" }";
sep = ",";
}
tab(tab_val, fUI); fUI << ((quote) ? "],": "]");
fMetaAux.clear();
}
}
void init(const std::string& name, int inputs, int outputs, const std::string& sha_key, const std::string& dsp_code)
{
fTab = 1;
// Start Meta generation
tab(fTab, fMeta); fMeta << "\"meta\": [";
fCloseMetaPar = ' ';
// Start UI generation
tab(fTab, fUI); fUI << "\"ui\": [";
fCloseUIPar = ' ';
fTab += 1;
fName = name;
fInputs = inputs;
fOutputs = outputs;
fExpandedCode = dsp_code;
fSHAKey = sha_key;
}
inline std::string flatten(const std::string& src)
{
std::stringstream dst;
for (size_t i = 0; i < src.size(); i++) {
switch (src[i]) {
case '\n':
case '\t':
dst << ' ';
break;
case '"':
dst << "\\" << '"';
break;
default:
dst << src[i];
break;
}
}
return dst.str();
}
public:
JSONUI(const std::string& name, int inputs, int outputs, const std::string& sha_key, const std::string& dsp_code)
{
init(name, inputs, outputs, sha_key, dsp_code);
}
JSONUI(const std::string& name, int inputs, int outputs)
{
init(name, inputs, outputs, "", "");
}
JSONUI(int inputs, int outputs)
{
init("", inputs, outputs, "", "");
}
JSONUI()
{
init("", -1, -1, "", "");
}
virtual ~JSONUI() {}
// -- widget's layouts
virtual void openGenericGroup(const char* label, const char* name)
{
fControlsLevel.push_back(label);
fUI << fCloseUIPar;
tab(fTab, fUI); fUI << "{";
fTab += 1;
tab(fTab, fUI); fUI << "\"type\": \"" << name << "\",";
tab(fTab, fUI); fUI << "\"label\": \"" << label << "\",";
addMeta(fTab + 1);
tab(fTab, fUI); fUI << "\"items\": [";
fCloseUIPar = ' ';
fTab += 1;
}
virtual void openTabBox(const char* label)
{
openGenericGroup(label, "tgroup");
}
virtual void openHorizontalBox(const char* label)
{
openGenericGroup(label, "hgroup");
}
virtual void openVerticalBox(const char* label)
{
openGenericGroup(label, "vgroup");
}
virtual void closeBox()
{
fControlsLevel.pop_back();
fTab -= 1;
tab(fTab, fUI); fUI << "]";
fTab -= 1;
tab(fTab, fUI); fUI << "}";
fCloseUIPar = ',';
}
// -- active widgets
virtual void addGenericButton(const char* label, const char* name)
{
fUI << fCloseUIPar;
tab(fTab, fUI); fUI << "{";
tab(fTab + 1, fUI); fUI << "\"type\": \"" << name << "\",";
tab(fTab + 1, fUI); fUI << "\"label\": \"" << label << "\"" << ",";
tab(fTab + 1, fUI); fUI << "\"address\": \"" << buildPath(label) << "\"" << ((fMetaAux.size() > 0) ? "," : "");
addMeta(fTab + 1, false);
tab(fTab, fUI); fUI << "}";
fCloseUIPar = ',';
}
virtual void addButton(const char* label, FAUSTFLOAT* zone)
{
addGenericButton(label, "button");
}
virtual void addCheckButton(const char* label, FAUSTFLOAT* zone)
{
addGenericButton(label, "checkbox");
}
virtual void addGenericEntry(const char* label, const char* name, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{
fUI << fCloseUIPar;
tab(fTab, fUI); fUI << "{";
tab(fTab + 1, fUI); fUI << "\"type\": \"" << name << "\",";
tab(fTab + 1, fUI); fUI << "\"label\": \"" << label << "\"" << ",";
tab(fTab + 1, fUI); fUI << "\"address\": \"" << buildPath(label) << "\"" << ",";
addMeta(fTab + 1);
tab(fTab + 1, fUI); fUI << "\"init\": \"" << init << "\",";
tab(fTab + 1, fUI); fUI << "\"min\": \"" << min << "\",";
tab(fTab + 1, fUI); fUI << "\"max\": \"" << max << "\",";
tab(fTab + 1, fUI); fUI << "\"step\": \"" << step << "\"";
tab(fTab, fUI); fUI << "}";
fCloseUIPar = ',';
}
virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{
addGenericEntry(label, "vslider", init, min, max, step);
}
virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{
addGenericEntry(label, "hslider", init, min, max, step);
}
virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{
addGenericEntry(label, "nentry", init, min, max, step);
}
// -- passive widgets
virtual void addGenericBargraph(const char* label, const char* name, FAUSTFLOAT min, FAUSTFLOAT max)
{
fUI << fCloseUIPar;
tab(fTab, fUI); fUI << "{";
tab(fTab + 1, fUI); fUI << "\"type\": \"" << name << "\",";
tab(fTab + 1, fUI); fUI << "\"label\": \"" << label << "\"" << ",";
tab(fTab + 1, fUI); fUI << "\"address\": \"" << buildPath(label) << "\"" << ",";
addMeta(fTab + 1);
tab(fTab + 1, fUI); fUI << "\"min\": \"" << min << "\",";
tab(fTab + 1, fUI); fUI << "\"max\": \"" << max << "\"";
tab(fTab, fUI); fUI << "}";
fCloseUIPar = ',';
}
virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
{
addGenericBargraph(label, "hbargraph", min, max);
}
virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
{
addGenericBargraph(label, "vbargraph", min, max);
}
// -- metadata declarations
virtual void declare(FAUSTFLOAT* zone, const char* key, const char* val)
{
fMetaAux.push_back(std::make_pair(key, val));
}
// Meta interface
virtual void declare(const char* key, const char* value)
{
fMeta << fCloseMetaPar;
if ((strcmp(key, "name") == 0) && (fName == "")) fName = value;
tab(fTab, fMeta); fMeta << "{ " << "\"" << key << "\"" << ": " << "\"" << value << "\" }";
fCloseMetaPar = ',';
}
std::string JSON(bool flat = false)
{
fTab = 0;
fJSON << "{";
fTab += 1;
tab(fTab, fJSON); fJSON << "\"name\": \"" << fName << "\",";
if (fSHAKey != "") { tab(fTab, fJSON); fJSON << "\"sha_key\": \"" << fSHAKey << "\","; }
if (fExpandedCode != "") { tab(fTab, fJSON); fJSON << "\"code\": \"" << fExpandedCode << "\","; }
tab(fTab, fJSON); fJSON << "\"inputs\": \"" << fInputs << "\",";
tab(fTab, fJSON); fJSON << "\"outputs\": \"" << fOutputs << "\",";
tab(fTab, fMeta); fMeta << "],";
tab(fTab, fUI); fUI << "]";
fTab -= 1;
if (fCloseMetaPar == ',') { // If "declare" has been called, fCloseMetaPar state is now ','
fJSON << fMeta.str() << fUI.str();
} else {
fJSON << fUI.str();
}
tab(fTab, fJSON); fJSON << "}" << std::endl;
return (flat) ? flatten(fJSON.str()) : fJSON.str();
}
};
#endif // FAUST_JSONUI_H
|