38173b8af56155af305d4d267b4015e3704fde46
[Faustine.git] / interpretor / faust-0.9.47mr3 / architecture / gui / OSCUI.h
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 "OSCControler.h"
9 #include "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(float* zone, float init, float min, float max)
56 {
57 for (unsigned int i=0; i<fAlias.size(); i++) {
58 fCtrl->addfullpathnode(fAlias[i], zone, 0, 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 // -- active widgets
74 virtual void addButton(const char* label, float* zone) { addalias(zone, 0, 0, 1); fCtrl->addnode( tr(label), zone, 0, 0, 1); }
75 virtual void addToggleButton(const char* label, float* zone) { addalias(zone, 0, 0, 1); fCtrl->addnode( tr(label), zone, 0, 0, 1); }
76 virtual void addCheckButton(const char* label, float* zone) { addalias(zone, 0, 0, 1); fCtrl->addnode( tr(label), zone, 0, 0, 1); }
77 virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float /*step*/) { addalias(zone, init, min, max); fCtrl->addnode( tr(label), zone, init, min, max); }
78 virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float /*step*/) { addalias(zone, init, min, max); fCtrl->addnode( tr(label), zone, init, min, max); }
79 virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float /*step*/) { addalias(zone, init, min, max); fCtrl->addnode( tr(label), zone, init, min, max); }
80
81 // -- passive widgets
82
83 virtual void addNumDisplay(const char* /*label*/, float* /*zone*/, int /*precision*/) {}
84 virtual void addTextDisplay(const char* /*label*/, float* /*zone*/, const char* /*names*/[], float /*min*/, float /*max*/) {}
85 virtual void addHorizontalBargraph(const char* /*label*/, float* /*zone*/, float /*min*/, float /*max*/) {}
86 virtual void addVerticalBargraph(const char* /*label*/, float* /*zone*/, float /*min*/, float /*max*/) {}
87
88 virtual void openFrameBox(const char* label) { fCtrl->opengroup( tr(label)); }
89 virtual void openTabBox(const char* label) { fCtrl->opengroup( tr(label)); }
90 virtual void openHorizontalBox(const char* label) { fCtrl->opengroup( tr(label)); }
91 virtual void openVerticalBox(const char* label) { fCtrl->opengroup( tr(label)); }
92 virtual void closeBox() { fCtrl->closegroup(); }
93
94 virtual void declare(float* , const char* key , const char* alias)
95 {
96 if (strcasecmp(key,"OSC")==0) fAlias.push_back(alias);
97 }
98
99
100 virtual void show() {}
101
102 void run() { fCtrl->run(); }
103 const char* getRootName() { return fCtrl->getRootName(); }
104 };
105
106
107 const char* OSCUI::tr(const char* label) const
108 {
109 static char buffer[1024];
110 char * ptr = buffer; int n=1;
111 while (*label && (n++ < 1024)) {
112 switch (*label) {
113 case ' ': case ' ':
114 *ptr++ = '_';
115 break;
116 case '#': case '*': case ',': case '/': case '?':
117 case '[': case ']': case '{': case '}':
118 *ptr++ = '_';
119 break;
120 default:
121 *ptr++ = *label;
122 }
123 label++;
124 }
125 *ptr = 0;
126 return buffer;
127 }