InControl.hxx

Go to the documentation of this file.
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 _InControl_
00023 #define _InControl_
00024 
00025 #include <sstream>
00026 #include <string>
00027 #include <list>
00028 
00029 namespace CLAM {
00030 
00031 // Forward Declaration:
00032 class Processing;
00033 class OutControl;
00034 
00036 typedef float TControlData;
00037 
00044 class InControl
00045 {
00046 // Attributes:
00047 protected:
00048         std::list<OutControl*> mLinks;
00049         TControlData mLastValue;
00050         std::string mName;
00051         Processing * mParent;
00052         TControlData mDefaultValue;
00053         TControlData mUpperBound;
00054         TControlData mLowerBound;
00055 
00056         bool mBounded;
00057         bool mHasDefaultValue;
00058 
00059 // Methods:
00060 public:
00065         virtual int DoControl(TControlData val) { mLastValue = val; return 0; };
00067         const TControlData& GetLastValue() const { return mLastValue; };
00069         bool GetLastValueAsBoolean() const 
00070         { 
00071                 return (mLastValue > 0) ? mLastValue>0.01 : mLastValue<-0.01;
00072         };
00074         int GetLastValueAsInteger() const { return (int)(mLastValue+0.5f); };
00075         const std::string& GetName() const { return mName; }
00076         bool IsConnectedTo( OutControl & );
00077         bool IsConnected() const;
00078         bool IsBounded() const;
00079         TControlData UpperBound() const;
00080         TControlData LowerBound() const;
00082         TControlData DefaultValue() const;
00083         void SetDefaultValue(TControlData val);
00084         void SetBounds(TControlData lower, TControlData upper);
00085 
00086         Processing * GetProcessing() const { return mParent; }
00087         
00089         void OutControlInterface_AddLink(OutControl & outControl);
00091         void OutControlInterface_RemoveLink(OutControl & outControl);
00092 
00093 //Constructor/Destructor
00098         InControl(const std::string &name, Processing* parent=0, const bool publish=true);
00099         virtual ~InControl();
00100 };
00101 
00108 template<class ProcObj>
00109 class InControlTmpl : public InControl
00110 {
00111 public:
00112         typedef int (ProcObj::*TPtrMemberFunc)(TControlData);
00113         typedef int (ProcObj::*TPtrMemberFuncId)(int,TControlData);
00114 
00115 private:
00116         TPtrMemberFunc   mFunc;
00117         TPtrMemberFuncId mFuncId;
00118         ProcObj* mProcObj;
00119         int mId;
00120 
00121 public:
00122         // redeclaration
00123         int DoControl(TControlData val);
00124 
00125         bool ExistMemberFunc() { return (mFunc==0); };
00126         void SetMemberFunc(TPtrMemberFunc f) { mFunc = f; };
00127 
00128         int GetId(void) const { return mId; }
00129 
00130 //Constructor/Destructor
00131 
00146         InControlTmpl(const std::string &name, ProcObj* parent, TPtrMemberFunc f = 0,const bool publish=true )  :
00147                 InControl(name,parent,publish),
00148                 mFunc(f),
00149                 mFuncId(0),
00150                 mProcObj(parent)
00151 
00152                 {
00153 //                      if (publish) mProcObj->PublishInControl(this);
00154                 };
00155 
00156         InControlTmpl(int id,const std::string &name, ProcObj* parent, TPtrMemberFuncId f,const bool publish=true )     :
00157                 InControl(name,parent,publish),
00158                 mFunc(0),
00159                 mFuncId(f),
00160                 mProcObj(parent),
00161                 mId(id)
00162                 {
00163 //                      if (publish && mProcObj) mProcObj->PublishInControl(this);
00164                 };
00165 
00166         ~InControlTmpl(){};
00167         
00168 };
00169 
00170 
00172 //  Implementation of class InControlTmpl
00173 //
00174 
00175 template<class ProcObj>
00176 int InControlTmpl<ProcObj>::DoControl(TControlData val)
00177 {
00178         InControl::DoControl(val);
00179         if(mFunc)
00180                 return (mProcObj->*mFunc)(val);
00181         else if (mFuncId)
00182                 return (mProcObj->*mFuncId)(mId,val);
00183         else
00184                 return 0;
00185 }
00186 
00187 
00188 
00189 } // namespace CLAM
00190 
00191 #endif //_InControl_
00192 

Generated on Tue Aug 12 22:33:43 2008 for CLAM by  doxygen 1.5.5