1 /*
2 
3   Copyright (C) 2012 Grame
4 
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9 
10   This library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14 
15   You should have received a copy of the GNU Lesser General Public
16   License along with this library; if not, write to the Free Software
17   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 
19   Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France
20   research@grame.fr
21 
22 */
23 
24 #ifndef __jsonui__
25 #define __jsonui__
26 
27 #include "jsonfactory.h"
28 
29 namespace httpdfaust
30 {
31 
32 class jsonfactory;
33 
34 template <typename C> class jsonui
35 {
36 	jsonfactory* fFactory;
37 	std::map<std::string, std::string>	fMeta;	// the current meta declarations
38 
39 	public:
jsonui(const char * name,const char * address,int port)40 				 jsonui(const char *name, const char* address, int port) { fFactory = new jsonfactory(name, address, port); }
~jsonui()41 		virtual ~jsonui()				{ delete fFactory; }
42 
43 		// -- widget's layouts
openTabBox(const char * label)44 		virtual void openTabBox(const char* label)					{ fFactory->opengroup("tgroup", label, fMeta); fMeta.clear(); }
openHorizontalBox(const char * label)45 		virtual void openHorizontalBox(const char* label)			{ fFactory->opengroup("hgroup", label, fMeta); fMeta.clear(); }
openVerticalBox(const char * label)46 		virtual void openVerticalBox(const char* label)				{ fFactory->opengroup("vgroup", label, fMeta); fMeta.clear(); }
closeBox()47 		virtual void closeBox()										{ fFactory->closegroup(); }
48 
49 		// -- active widgets
addButton(const char * label,C * zone)50 		virtual void addButton(const char* label, C* zone)			{ fFactory->addnode<C>( "button", label, fMeta); fMeta.clear(); }
addCheckButton(const char * label,C * zone)51 		virtual void addCheckButton(const char* label, C* zone)		{ fFactory->addnode<C>( "checkbox", label, fMeta); fMeta.clear(); }
addVerticalSlider(const char * label,C * zone,C init,C min,C max,C step)52 		virtual void addVerticalSlider(const char* label, C* zone, C init, C min, C max, C step)
53 							{ fFactory->addnode<C>( "vslider", label, init, min, max, step, fMeta); fMeta.clear(); }
addHorizontalSlider(const char * label,C * zone,C init,C min,C max,C step)54 		virtual void addHorizontalSlider(const char* label, C* zone, C init, C min, C max, C step)
55 							{ fFactory->addnode<C>( "hslider", label, init, min, max, step, fMeta); fMeta.clear(); }
addNumEntry(const char * label,C * zone,C init,C min,C max,C step)56 		virtual void addNumEntry(const char* label, C* zone, C init, C min, C max, C step)
57 							{ fFactory->addnode<C>( "nentry", label, init, min, max, step, fMeta); fMeta.clear(); }
58 
59 		// -- passive widgets
addHorizontalBargraph(const char * label,C * zone,C min,C max)60 		virtual void addHorizontalBargraph(const char* label, C* zone, C min, C max)		{ fFactory->addnode<C>( "hbargraph", label, min, max, fMeta); fMeta.clear();}
addVerticalBargraph(const char * label,C * zone,float min,float max)61 		virtual void addVerticalBargraph(const char* label, C* zone, float min, float max)	{ fFactory->addnode<C>( "vbargraph", label, min, max, fMeta); fMeta.clear();}
62 
63 		// -- metadata declarations
declare(C *,const char * key,const char * val)64 		virtual void declare(C* , const char* key, const char* val)		{ fMeta[key] = val; }
65 
66 		//--------------------------------------------
67 		// additionnal methods (not part of UI)
68 		//--------------------------------------------
numInput(int n)69 		void numInput(int n)								{ fFactory->root().setInputs(n); }
numOutput(int n)70 		void numOutput(int n)								{ fFactory->root().setOutputs(n); }
declare(const char * key,const char * val)71 		void declare(const char* key, const char* val)		{ fFactory->root().declare(key, val);}
72 
73 		//--------------------------------------------
74 		// and eventually how to get the json as a string
75 		//--------------------------------------------
json(bool flatten)76 		std::string json(bool flatten)				{ return fFactory->root().json(flatten); }
77 };
78 
79 } //end namespace
80 
81 #endif
82