Debian Codegraph @

audio/faudiostream/architecture/faust/gui/OSCUI.h

raw symbols SCIP
1 /*
2 Copyright (C) 2011 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 #include "faust/gui/OSCControler.h"
9 #include "faust/gui/GUI.h"
10 #include <vector>
11
12 /******************************************************************************
13 *******************************************************************************
14
15 OSC (Open Sound Control) USER INTERFACE
16
17 *******************************************************************************
18 *******************************************************************************/
19 /*
20
21 Note about the OSC addresses and the Faust UI names:
22 ----------------------------------------------------
23 There are potential conflicts between the Faust UI objects naming scheme and
24 the OSC address space. An OSC symbolic names is an ASCII string consisting of
25 printable characters other than the following:
26 space
27 # number sign
28 * asterisk
29 , comma
30 / forward
31 ? question mark
32 [ open bracket
33 ] close bracket
34 { open curly brace
35 } close curly brace
36
37 a simple solution to address the problem consists in replacing
38 space or tabulation with '_' (underscore)
39 all the other osc excluded characters with '-' (hyphen)
40
41 This solution is implemented in the proposed OSC UI;
42 */
43
44 using namespace std;
45
46 //class oscfaust::OSCIO;
47 class OSCUI : public GUI
48 {
49 oscfaust::OSCControler* fCtrl;
50 vector<const char*> fAlias;
51
52 const char* tr(const char* label) const;
53
54 // add all accumulated alias
55 void addalias(FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max)
56 {
57 for (unsigned int i=0; i<fAlias.size(); i++) {
58 fCtrl->addfullpathnode(fAlias[i], zone, (FAUSTFLOAT)0, (FAUSTFLOAT)1, init, min, max);
59 }
60 fAlias.clear();
61 }
62
63 public:
64
65 OSCUI(char* /*applicationname*/, int argc, char *argv[], oscfaust::OSCIO* io=0) : GUI()
66 {
67 fCtrl = new oscfaust::OSCControler(argc, argv, io);
68 // fCtrl->opengroup(applicationname);
69 }
70
71 virtual ~OSCUI() { delete fCtrl; }
72
73 // -- widget's layouts
74
75 virtual void openTabBox(const char* label) { fCtrl->opengroup( tr(label)); }
76 virtual void openHorizontalBox(const char* label) { fCtrl->opengroup( tr(label)); }
77 virtual void openVerticalBox(const char* label) { fCtrl->opengroup( tr(label)); }
78 virtual void closeBox() { fCtrl->closegroup(); }
79
80
81 // -- active widgets
82 virtual void addButton(const char* label, FAUSTFLOAT* zone) { addalias(zone, 0, 0, 1); fCtrl->addnode( tr(label), zone, (FAUSTFLOAT)0, (FAUSTFLOAT)0, (FAUSTFLOAT)1); }
83 virtual void addCheckButton(const char* label, FAUSTFLOAT* zone) { addalias(zone, 0, 0, 1); fCtrl->addnode( tr(label), zone, (FAUSTFLOAT)0, (FAUSTFLOAT)0, (FAUSTFLOAT)1); }
84 virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT /*step*/) { addalias(zone, init, min, max); fCtrl->addnode( tr(label), zone, init, min, max); }
85 virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT /*step*/) { addalias(zone, init, min, max); fCtrl->addnode( tr(label), zone, init, min, max); }
86 virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT /*step*/) { addalias(zone, init, min, max); fCtrl->addnode( tr(label), zone, init, min, max); }
87
88 // -- passive widgets
89
90 virtual void addHorizontalBargraph(const char* /*label*/, FAUSTFLOAT* /*zone*/, FAUSTFLOAT /*min*/, FAUSTFLOAT /*max*/) {}
91 virtual void addVerticalBargraph(const char* /*label*/, FAUSTFLOAT* /*zone*/, FAUSTFLOAT /*min*/, FAUSTFLOAT /*max*/) {}
92
93 // -- metadata declarations
94
95 virtual void declare(FAUSTFLOAT* , const char* key , const char* alias)
96 {
97 if (strcasecmp(key,"OSC")==0) fAlias.push_back(alias);
98 }
99
100 virtual void show() {}
101
102 void run() { fCtrl->run(); }
103 const char* getRootName() { return fCtrl->getRootName(); }
104 };
105
106 const char* OSCUI::tr(const char* label) const
107 {
108 static char buffer[1024];
109 char * ptr = buffer; int n=1;
110 while (*label && (n++ < 1024)) {
111 switch (*label) {
112 case ' ': case ' ':
113 *ptr++ = '_';
114 break;
115 case '#': case '*': case ',': case '/': case '?':
116 case '[': case ']': case '{': case '}':
117 *ptr++ = '_';
118 break;
119 default:
120 *ptr++ = *label;
121 }
122 label++;
123 }
124 *ptr = 0;
125 return buffer;
126 }