CLAM-Development  1.4.0
BinaryControlOp.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef __BINARYCONTROLOP__
23 #define __BINARYCONTROLOP__
24 
25 #include "Processing.hxx"
26 #include "InControl.hxx"
27 #include "OutControl.hxx"
28 #include <iosfwd>
29 
30 namespace CLAM {
31 
32 
34  {
35  public:
37  DYN_ATTRIBUTE (0, public, std::string, Name);
38 
39  protected:
40 
41  void DefaultInit()
42  {
43  AddName();
44  UpdateData();
45  }
46  };
47 
48  template < typename BinOp >
50  {
51  private:
52  TControlData mOutValue;
53  TControlData mFirstParmLastValue;
54  TControlData mSecondParmLastValue;
55  FloatOutControl mOutput;
56  BinaryControlOpConfig mConfig;
57  BinOp mOperation;
58 
59  inline const char *GetClassName() const;
60 
61  void HandleFirst( TControlData incoming_parm )
62  {
63  mFirstParmLastValue = incoming_parm;
64  mOutValue = DoOperation();
65  Do();
66  }
67 
68  void HandleSecond( TControlData incoming_parm )
69  {
70  mSecondParmLastValue = incoming_parm;
71  mOutValue = DoOperation();
72  Do();
73  }
74 
75  public:
79 
81  : mOutValue(0)
82  , mFirstParmLastValue( BinOp::IdentityElement )
83  , mSecondParmLastValue(BinOp::IdentityElement)
84  , mOutput( "output", this )
85  , mFirst( "first_parm", this, &BinaryControlOp::HandleFirst )
86  , mSecond( "second_parm", this, &BinaryControlOp::HandleSecond )
87  {
88  Configure(cfg);
89  }
90 
92  {
93  CopyAsConcreteConfig(mConfig, c);
94  return true;
95  }
96 
97  const ProcessingConfig &GetConfig() const { return mConfig;};
98 
100  {
101  return mOperation( mFirstParmLastValue, mSecondParmLastValue );
102  }
103 
104  bool Do()
105  {
106  mOutput.SendControl( mOutValue );
107  return true ;
108  }
109  };
110 
111  template < typename BinOp >
112  inline const char *BinaryControlOp<BinOp>::GetClassName() const { return "BinaryControlOperation"; }
113 
114 }
115 
116 #endif // BinaryControlOp.hxx
117