Bug fixed in the Makefile.
[Faustine.git] / interpretor / faust-0.9.47mr3 / architecture / osclib / faust / src / nodes / FaustNode.h
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
25 #ifndef __FaustNode__
26 #define __FaustNode__
27
28 #include <string>
29 #include <vector>
30
31 #include "MessageDriven.h"
32
33 namespace oscfaust
34 {
35
36 class FaustNode;
37 typedef class SMARTP<FaustNode> SFaustNode;
38
39 /**
40 * map (rescale) input values to output values
41 */
42 struct mapping
43 {
44 const float fMinIn;
45 const float fMaxIn;
46 const float fMinOut;
47 const float fMaxOut;
48 const float fScale;
49
50 mapping(float imin, float imax, float omin, float omax) : fMinIn(imin), fMaxIn(imax),
51 fMinOut(omin), fMaxOut(omax),
52 fScale( (fMaxOut-fMinOut)/(fMaxIn-fMinIn) ) {}
53 float scale (float x) { float z = (x < fMinIn) ? fMinIn : (x > fMaxIn) ? fMaxIn : x; return fMinOut + (z - fMinIn) * fScale; }
54 };
55
56
57 //--------------------------------------------------------------------------
58 /*!
59 \brief a faust node is a terminal node and represents a faust parameter controler
60 */
61 class FaustNode : public MessageDriven
62 {
63 float * fZone; // the parameter memory zone
64 mapping fMapping;
65
66 bool store (float val);
67
68 protected:
69 FaustNode(const char *name, float* zone, float init, float min, float max, const char* prefix)
70 : MessageDriven (name, prefix), fZone(zone), fMapping(min, max, min, max)
71 { *zone = init; }
72
73 FaustNode(const char *name, float* zone, float imin, float imax, float init, float min, float max, const char* prefix)
74 : MessageDriven (name, prefix), fZone(zone), fMapping(imin, imax, min, max)
75 { *zone = init; }
76 virtual ~FaustNode() {}
77
78 public:
79 static SFaustNode create (const char* name, float* zone, float init, float min, float max, const char* prefix)
80 { return new FaustNode(name, zone, init, min, max, prefix); }
81 static SFaustNode create (const char* name, float* zone, float imin, float imax, float init, float min, float max, const char* prefix)
82 { return new FaustNode(name, zone, imin, imax, init, min, max, prefix); }
83
84
85 virtual bool accept( const Message* msg ); ///< handler for the 'accept' message
86 virtual void get (unsigned long ipdest) const; ///< handler for the 'get' message
87 };
88
89 } // end namespoace
90
91 #endif