Debian Codegraph @

faudiostream/architecture/faust/gui/httpdUI.h

raw symbols SCIP
1 /*
2 Copyright (C) 2012 Grame - Lyon
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted.
6 */
7
8 #ifndef __httpdUI__
9 #define __httpdUI__
10
11 #include "faust/gui/HTTPDControler.h"
12 #include "faust/gui/GUI.h"
13
14 /******************************************************************************
15 *******************************************************************************
16
17 HTTPD USER INTERFACE
18
19 *******************************************************************************
20 *******************************************************************************/
21 /*
22
23 Note about URLs and the Faust UI names:
24 ----------------------------------------------------
25 Characters in a url could be:
26 1. Reserved: ; / ? : @ & = + $ ,
27 These characters delimit URL parts.
28 2. Unreserved: alphanum - _ . ! ~ * ' ( )
29 These characters have no special meaning and can be used as is.
30 3. Excluded: control characters, space, < > # % ", { } | \ ^ [ ] `
31
32 To solve potential conflicts between the Faust UI objects naming scheme and
33 the URL allowed characters, the reserved and excluded characters are replaced
34 with '-' (hyphen).
35 Space or tabulation are replaced with '_' (underscore)
36 */
37
38 using namespace std;
39
40 class httpdUI : public UI
41 {
42 httpdfaust::HTTPDControler* fCtrl;
43 const char* tr(const char* label) const;
44
45 public:
46
47 httpdUI(const char* applicationname, int argc, char *argv[])
48 {
49 fCtrl = new httpdfaust::HTTPDControler(argc, argv, applicationname);
50 }
51
52 virtual ~httpdUI() { delete fCtrl; }
53
54 // -- widget's layouts
55 virtual void openTabBox(const char* label) { fCtrl->opengroup( "tgroup", tr(label)); }
56 virtual void openHorizontalBox(const char* label) { fCtrl->opengroup( "hgroup", tr(label)); }
57 virtual void openVerticalBox(const char* label) { fCtrl->opengroup( "vgroup", tr(label)); }
58 virtual void closeBox() { fCtrl->closegroup(); }
59
60 // -- active widgets
61 virtual void addButton(const char* label, FAUSTFLOAT* zone) { fCtrl->addnode( "button", tr(label), zone); }
62 virtual void addCheckButton(const char* label, FAUSTFLOAT* zone) { fCtrl->addnode( "checkbox", tr(label), zone); }
63 virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
64 { fCtrl->addnode( "vslider", tr(label), zone, init, min, max, step); }
65 virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
66 { fCtrl->addnode( "hslider", tr(label), zone, init, min, max, step); }
67 virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
68 { fCtrl->addnode( "nentry", tr(label), zone, init, min, max, step); }
69
70 // -- passive widgets
71 virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
72 { fCtrl->addnode( "hbargraph", tr(label), zone, min, max); }
73 virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
74 { fCtrl->addnode( "vbargraph", tr(label), zone, min, max); }
75
76 virtual void declare (FAUSTFLOAT* , const char* key, const char* val ) { fCtrl->declare(key, val); }
77
78 void run() { fCtrl->run(); }
79 };
80
81
82 const char* httpdUI::tr(const char* label) const
83 {
84 static char buffer[1024];
85 char * ptr = buffer; int n=1;
86 while (*label && (n++ < 1024)) {
87 switch (*label) {
88 case ' ': case ' ':
89 *ptr++ = '_';
90 break;
91 case ';': case '/': case '?': case ':': case '@':
92 case '&': case '=': case '+': case '$': case ',':
93 case '<': case '>': case '#': case '%': case '"':
94 case '{': case '}': case '|': case '\\': case '^':
95 case '[': case ']': case '`':
96 *ptr++ = '_';
97 break;
98 default:
99 *ptr++ = *label;
100 }
101 label++;
102 }
103 *ptr = 0;
104 return buffer;
105 }
106
107 #endif