1 /*
2
3 Copyright (C) 2011 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 #include <iostream>
25 #include <sstream>
26
27 #include "faust/osc/FaustFactory.h"
28 #include "faust/osc/MessageDriven.h"
29 #include "faust/osc/RootNode.h"
30 #include "OSCAddress.h"
31
32 using namespace std;
33
34 namespace oscfaust
35 {
36
FaustFactory(GUI * ui,JSONUI * json,OSCIO * io)37 FaustFactory::FaustFactory(GUI* ui, JSONUI* json, OSCIO* io) : fIO(io), fGUI(ui), fJSON(json) {}
~FaustFactory()38 FaustFactory::~FaustFactory() {}
39
40 /**
41 * Open a group in the current group and place it on the top of the stack.
42 * Takes into account that due to alias, a group can been previously created.
43 */
opengroup(const char * label)44 void FaustFactory::opengroup(const char* label)
45 {
46 if (fNodes.size() == 0) {
47 // the stack is empty: creates a root node
48 // and gives the root node a possible OSCIO controler
49 fRoot = RootNode::create(label, fJSON, fIO);
50 fNodes.push(fRoot);
51
52 } else {
53 // only create a group if not previously created
54 SMessageDriven node = fNodes.top();
55 int i = 0; while ((i < node->size()) && (node->subnode(i)->name() != label)) i++;
56
57 if (i < node->size()) {
58 // found, make it top of stack
59 fNodes.push(node->subnode(i));
60 } else {
61 // not found, create a new group and make it top of stack
62 SMessageDriven group = MessageDriven::create(label, node->getOSCAddress().c_str());
63 node->add(group);
64 fNodes.push(group);
65 }
66 }
67 }
68
69 //--------------------------------------------------------------------------
root() const70 SRootNode FaustFactory::root() const { return fRoot; }
71
72 //--------------------------------------------------------------------------
73 // add an alias to the root node
74 //--------------------------------------------------------------------------
addAlias(const char * alias,const char * address,float imin,float imax,float omin,float omax)75 void FaustFactory::addAlias(const char* alias, const char* address, float imin, float imax, float omin, float omax)
76 {
77 if (fRoot) fRoot->addAlias(alias, address, imin, imax, omin, omax);
78 }
79
addAlias(const char * alias,const char * address,double imin,double imax,double omin,double omax)80 void FaustFactory::addAlias(const char* alias, const char* address, double imin, double imax, double omin, double omax)
81 {
82 if (fRoot) fRoot->addAlias(alias, address, imin, imax, omin, omax);
83 }
84
85 //--------------------------------------------------------------------------
addressFirst(const string & address) const86 string FaustFactory::addressFirst(const string& address) const { return OSCAddress::addressFirst(address); }
addressTail(const string & address) const87 string FaustFactory::addressTail(const string& address) const { return OSCAddress::addressTail(address); }
88
89 //--------------------------------------------------------------------------
closegroup()90 void FaustFactory::closegroup()
91 {
92 fNodes.pop();
93 }
94
95 } // end namespoace
96