LICENSE, MINES
[Faustine.git] / interpreter / preprocessor / faust-0.9.47mr3 / architecture / osclib / faust / src / nodes / FaustNode.cpp
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 "FaustNode.h"
25 #include "Message.h"
26 #include "OSCStream.h"
27
28 namespace oscfaust
29 {
30
31 //--------------------------------------------------------------------------
32 bool FaustNode::store( float val )
33 {
34 *fZone = fMapping.scale(val);
35 return true;
36 }
37
38 //--------------------------------------------------------------------------
39 bool FaustNode::accept( const Message* msg )
40 {
41 if (msg->size() == 1) { // checks for the message parameters count
42 // messages with a param count other than 1 are rejected
43 int ival; float fval;
44 if (msg->param(0, fval)) return store (fval); // accepts float values
45 else if (msg->param(0, ival)) return store (float(ival)); // but accepts also int values
46 }
47 return MessageDriven::accept(msg);
48 }
49
50
51 //--------------------------------------------------------------------------
52 void FaustNode::get (unsigned long ipdest ) const
53 {
54 unsigned long savedip = oscout.getAddress(); // saves the current destination IP
55 oscout.setAddress(ipdest); // sets the osc stream dest IP
56 // send a state message on 'get' request
57 oscout << OSCStart(getOSCAddress().c_str()) << *fZone << fMapping.fMinOut << fMapping.fMaxOut << OSCEnd();
58 oscout.setAddress(savedip); // and restores the destination IP
59 }
60
61 } // end namespoace