X-Git-Url: https://scm.cri.ensmp.fr/git/Faustine.git/blobdiff_plain/1059e1cc0c2ecfa237406949aa26155b6a5b9154..66f23d4fabf89ad09adbd4dfc15ac6b5b2b7da83:/interpreter/preprocessor/faust-0.9.47mr3/architecture/gui/FUI.h diff --git a/interpreter/preprocessor/faust-0.9.47mr3/architecture/gui/FUI.h b/interpreter/preprocessor/faust-0.9.47mr3/architecture/gui/FUI.h new file mode 100644 index 0000000..07593b2 --- /dev/null +++ b/interpreter/preprocessor/faust-0.9.47mr3/architecture/gui/FUI.h @@ -0,0 +1,147 @@ +#ifndef FAUST_FUI_H +#define FAUST_FUI_H + +#include "UI.h" + +#include +#include +#include +#include +#include + +#include +#include + +using namespace std; + +#if 1 + +/******************************************************************************* + * FUI : used to save and recall the state of the user interface + * This class provides essentially two new methods saveState() and recallState() + * used to save on file and recall from file the state of the user interface. + * The file is human readble and editable + ******************************************************************************/ + +class FUI : public UI +{ + stack fGroupStack; + vector fNameList; + map fName2Zone; + + protected: + + // labels are normalized by replacing white spaces by underscores and by + // removing parenthesis + string normalizeLabel(const char* label) + { + string s; + char c; + + while ((c=*label++)) { + if (isspace(c)) { s += '_'; } + //else if ((c == '(') | (c == ')') ) { } + else { s += c; } + } + return s; + } + + // add an element by relating its full name and memory zone + virtual void addElement (const char* label, float* zone) + { + string fullname (fGroupStack.top() + '/' + normalizeLabel(label)); + fNameList.push_back(fullname); + fName2Zone[fullname] = zone; + } + + // keep track of full group names in a stack + virtual void pushGroupLabel(const char* label) + { + if (fGroupStack.empty()) { + fGroupStack.push(normalizeLabel(label)); + } else { + fGroupStack.push(fGroupStack.top() + '/' + normalizeLabel(label)); + } + } + + virtual void popGroupLabel() + { + fGroupStack.pop(); + }; + + public: + + FUI() {} + virtual ~FUI() {} + + // -- Save and recall methods + + // save the zones values and full names + virtual void saveState(const char* filename) + { + ofstream f(filename); + + for (unsigned int i=0; i> v >> n; + if (fName2Zone.count(n)>0) { + *(fName2Zone[n]) = v; + } else { + cerr << "recallState : parameter not found : " << n << " with value : " << v << endl; + } + } + f.close(); + } + + + // -- widget's layouts (just keep track of group labels) + + virtual void openFrameBox(const char* label) { pushGroupLabel(label); } + virtual void openTabBox(const char* label) { pushGroupLabel(label); } + virtual void openHorizontalBox(const char* label) { pushGroupLabel(label); } + virtual void openVerticalBox(const char* label) { pushGroupLabel(label); } + virtual void closeBox() { popGroupLabel(); }; + + // -- active widgets (just add an element) + + virtual void addButton(const char* label, float* zone) { addElement(label, zone); } + virtual void addToggleButton(const char* label, float* zone) { addElement(label, zone); } + virtual void addCheckButton(const char* label, float* zone) { addElement(label, zone); } + virtual void addVerticalSlider(const char* label, float* zone, float , float , float , float ) + { addElement(label, zone); } + virtual void addHorizontalSlider(const char* label, float* zone, float , float , float , float ) + { addElement(label, zone); } + virtual void addNumEntry(const char* label, float* zone, float , float , float , float ) + { addElement(label, zone); } + + // -- passive widgets (are ignored) + + virtual void addNumDisplay(const char* , float* , int ) {}; + virtual void addTextDisplay(const char* , float* , const char*[], float , float ) {}; + virtual void addHorizontalBargraph(const char* , float* , float , float ) {}; + virtual void addVerticalBargraph(const char* , float* , float , float ) {}; + + // -- metadata are not used + + virtual void declare(float* , const char* , const char* ) {} +}; +#endif + +#endif +