|
CLAM-Development
1.3
|
00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 00022 #ifndef __BINARYCONTROLOP__ 00023 #define __BINARYCONTROLOP__ 00024 00025 #include "Processing.hxx" 00026 #include "InControl.hxx" 00027 #include "OutControl.hxx" 00028 #include <iosfwd> 00029 00030 namespace CLAM { 00031 00032 00033 class BinaryControlOpConfig: public ProcessingConfig 00034 { 00035 public: 00036 DYNAMIC_TYPE_USING_INTERFACE (BinaryControlOpConfig, 1,ProcessingConfig); 00037 DYN_ATTRIBUTE (0, public, std::string, Name); 00038 00039 protected: 00040 00041 void DefaultInit() 00042 { 00043 AddName(); 00044 UpdateData(); 00045 } 00046 }; 00047 00048 template < typename BinOp > 00049 class BinaryControlOp:public Processing 00050 { 00051 private: 00052 TControlData mOutValue; 00053 TControlData mFirstParmLastValue; 00054 TControlData mSecondParmLastValue; 00055 FloatOutControl mOutput; 00056 BinaryControlOpConfig mConfig; 00057 BinOp mOperation; 00058 00059 inline const char *GetClassName() const; 00060 00061 void HandleFirst( TControlData incoming_parm ) 00062 { 00063 mFirstParmLastValue = incoming_parm; 00064 mOutValue = DoOperation(); 00065 Do(); 00066 } 00067 00068 void HandleSecond( TControlData incoming_parm ) 00069 { 00070 mSecondParmLastValue = incoming_parm; 00071 mOutValue = DoOperation(); 00072 Do(); 00073 } 00074 00075 public: 00076 typedef BinaryControlOpConfig Config; 00077 FloatInControl mFirst; 00078 FloatInControl mSecond; 00079 00080 BinaryControlOp(const BinaryControlOpConfig& cfg = Config()) 00081 : mOutValue(0) 00082 , mFirstParmLastValue( BinOp::IdentityElement ) 00083 , mSecondParmLastValue(BinOp::IdentityElement) 00084 , mOutput( "output", this ) 00085 , mFirst( "first_parm", this, &BinaryControlOp::HandleFirst ) 00086 , mSecond( "second_parm", this, &BinaryControlOp::HandleSecond ) 00087 { 00088 Configure(cfg); 00089 } 00090 00091 bool ConcreteConfigure(const ProcessingConfig& c) 00092 { 00093 CopyAsConcreteConfig(mConfig, c); 00094 return true; 00095 } 00096 00097 const ProcessingConfig &GetConfig() const { return mConfig;}; 00098 00099 TControlData DoOperation() 00100 { 00101 return mOperation( mFirstParmLastValue, mSecondParmLastValue ); 00102 } 00103 00104 bool Do() 00105 { 00106 mOutput.SendControl( mOutValue ); 00107 return true ; 00108 } 00109 }; 00110 00111 template < typename BinOp > 00112 inline const char *BinaryControlOp<BinOp>::GetClassName() const { return "BinaryControlOperation"; } 00113 00114 } 00115 00116 #endif // BinaryControlOp.hxx 00117
1.7.6.1