2 Copyright (C) 2011 Grame - Lyon
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted.
8 #include "OSCControler.h"
12 /******************************************************************************
13 *******************************************************************************
15 OSC (Open Sound Control) USER INTERFACE
17 *******************************************************************************
18 *******************************************************************************/
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:
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)
41 This solution is implemented in the proposed OSC UI;
46 //class oscfaust::OSCIO;
47 class OSCUI
: public GUI
49 oscfaust::OSCControler
* fCtrl
;
50 vector
<const char*> fAlias
;
52 const char* tr(const char* label
) const;
54 // add all accumulated alias
55 void addalias(float* zone
, float init
, float min
, float max
)
57 for (unsigned int i
=0; i
<fAlias
.size(); i
++) {
58 fCtrl
->addfullpathnode(fAlias
[i
], zone
, 0, 1, init
, min
, max
);
65 OSCUI(char* /*applicationname*/, int argc
, char *argv
[], oscfaust::OSCIO
* io
=0) : GUI()
67 fCtrl
= new oscfaust::OSCControler(argc
, argv
, io
);
68 // fCtrl->opengroup(applicationname);
71 virtual ~OSCUI() { delete fCtrl
; }
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
); }
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*/) {}
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(); }
94 virtual void declare(float* , const char* key
, const char* alias
)
96 if (strcasecmp(key
,"OSC")==0) fAlias
.push_back(alias
);
100 virtual void show() {}
102 void run() { fCtrl
->run(); }
103 const char* getRootName() { return fCtrl
->getRootName(); }
107 const char* OSCUI::tr(const char* label
) const
109 static char buffer
[1024];
110 char * ptr
= buffer
; int n
=1;
111 while (*label
&& (n
++ < 1024)) {
116 case '#': case '*': case ',': case '/': case '?':
117 case '[': case ']': case '{': case '}':