Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2010 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #include "../common_source.h" 00020 #include "MarSystemTemplateBasic.h" 00021 00022 using std::ostringstream; 00023 using namespace Marsyas; 00024 00025 MarSystemTemplateBasic::MarSystemTemplateBasic(mrs_string name) : MarSystem("MarSystemTemplateBasic", name) 00026 { 00028 // Default controls that all MarSystems should have (like "inSamples" 00029 // and "onObservations"), are already added by MarSystem::addControl(), 00030 // which is already called by the constructor MarSystem::MarSystem(name). 00031 // If no specific controls are needed by a MarSystem there is no need to 00032 // implement and call this addControl() method (see for e.g. Rms.cpp) 00033 addControls(); 00034 } 00035 00036 MarSystemTemplateBasic::MarSystemTemplateBasic(const MarSystemTemplateBasic& a) : MarSystem(a) 00037 { 00038 // IMPORTANT! 00041 // Otherwise this would result in trying to deallocate them twice! 00042 ctrl_gain_EXAMPLE_ = getctrl("mrs_real/gain"); 00043 } 00044 00045 00046 MarSystemTemplateBasic::~MarSystemTemplateBasic() 00047 { 00048 } 00049 00050 MarSystem* 00051 MarSystemTemplateBasic::clone() const 00052 { 00053 // Every MarSystem should do this. 00054 return new MarSystemTemplateBasic(*this); 00055 } 00056 00057 void 00058 MarSystemTemplateBasic::addControls() 00059 { 00061 00062 // Let's start by adding a dummy control (for which we 00063 // will not use a pointer, just to illustrate the 00064 // "traditional", yet not so efficient way of using 00065 // controls) 00066 addctrl("mrs_bool/dummyEXAMPLE", false); 00067 // In this case this control should have state, since 00068 // other controls will depend on it. (i.e. any change 00069 // to it will call MarSystem::update() which then calls 00070 // myUpdate(MarControlPtr sender)) 00071 setctrlState("mrs_bool/dummyEXAMPLE", true); 00072 00073 // If a pointer to a control is to be used (for 00074 // efficiency purposes - see myProcess() bellow), it 00075 // should be passed as the last argument to addctrl() 00076 addctrl("mrs_real/gain", 1.0, ctrl_gain_EXAMPLE_); 00077 00078 // IMPORTANT NOTE: 00079 // in the above case, since the control value is 00080 // supposed to be a mrs_real, the default value also has 00081 // to be a mrs_real! if not (e.g. initializing with "1" 00082 // instead of "1.0"), the control will in fact have a 00083 // mrs_natural value despite of the "mrs_real/..." name. 00084 } 00085 00086 void 00087 MarSystemTemplateBasic::myUpdate(MarControlPtr sender) 00088 { 00089 MRSDIAG("MarSystemTemplateBasic.cpp - MarSystemTemplateBasic:myUpdate"); 00090 00092 MarSystem::myUpdate(sender); 00093 } 00094 00095 void 00096 MarSystemTemplateBasic::myProcess(realvec& in, realvec& out) 00097 { 00098 mrs_natural t,o; 00099 const mrs_real& gainValueEXAMPLE = ctrl_gain_EXAMPLE_->to<mrs_real>(); 00100 // This is equivalent (although slightly more efficient) than: 00101 // 00102 // mrs_real& gainValue = ctrl_gain_EXAMPLE_->to<mrs_real>(); 00103 // // ::toReal() calls ::to<mrs_real>() 00104 // 00105 // This reference will not allow writing directly to the 00106 // control, but avoids a copy (which can hurt if the 00107 // control is a big realvec) and even if by some means 00108 // the control value is modified elsewhere (e.g. by a 00109 // different thread), it's always in sync with the 00110 // actual control value. 00111 00113 for (o = 0; o < inObservations_; o++) 00114 { 00115 for (t = 0; t < inSamples_; t++) 00116 { 00117 out(o, t) = gainValueEXAMPLE * in(o, t); 00118 } 00119 } 00120 }