Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2005 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 <marsyas/sched/TmSampleCount.h> 00020 #include <marsyas/sched/Scheduler.h> 00021 #include <marsyas/system/MarSystem.h> 00022 00023 using namespace std; 00024 using namespace Marsyas; 00025 00026 TmSampleCount::TmSampleCount() : TmTimer("TmSampleCount","Virtual") 00027 { 00028 setReadCtrl(NULL,"mrs_natural/inSamples"); 00029 } 00030 00031 TmSampleCount::TmSampleCount(std::string name) : TmTimer("TmSampleCount",name) 00032 { 00033 setReadCtrl(NULL,"mrs_natural/inSamples"); 00034 } 00035 00036 TmSampleCount::TmSampleCount(MarSystem* ms, std::string cname) : TmTimer("TmSampleCount","Virtual") 00037 { 00038 setReadCtrl(ms,cname); 00039 } 00040 00041 TmSampleCount::TmSampleCount(const TmSampleCount& s) : TmTimer(s) 00042 { 00043 setReadCtrl(s.read_src_,s.read_cname_); 00044 } 00045 00046 TmSampleCount::~TmSampleCount() { } 00047 00048 void 00049 TmSampleCount::setReadCtrl(MarSystem* ms, std::string cname) 00050 { 00051 read_src_=ms; 00052 read_cname_=cname; 00053 if (read_src_!=NULL) 00054 read_ctrl_=read_src_->getctrl(cname); 00055 } 00056 00057 void 00058 TmSampleCount::setSource(MarSystem* ms) 00059 { 00060 read_src_=ms; 00061 if(read_src_!=NULL && read_cname_!="") 00062 read_ctrl_=read_src_->getctrl(read_cname_); 00063 // setReadCtrl(ms,read_cname_); 00064 } 00065 00066 void 00067 TmSampleCount::setSourceCtrl(std::string cname) 00068 { 00069 read_cname_=cname; 00070 if(read_src_!=NULL) 00071 read_ctrl_=read_src_->getctrl(read_cname_); 00072 // setReadCtrl(read_src_,cname); 00073 } 00074 00075 mrs_natural 00076 TmSampleCount::readTimeSrc() 00077 { 00078 if (read_src_==NULL) { 00079 MRSWARN("TmSampleCount::readTimeSrc() time source is NULL"); 00080 return 0; 00081 } 00082 mrs_natural m = read_ctrl_->to<mrs_natural>(); 00083 return m; 00084 // return (read_src_->getctrl(read_cname_)).toNatural() + getTime(); 00085 } 00086 00087 mrs_natural TmSampleCount::intervalsize(std::string interval) 00088 { 00089 return (read_src_==NULL) ? 0 : 00090 time2samples(interval,read_src_->getctrl("mrs_real/israte")->to<mrs_real>()); 00091 } 00092 00093 void 00094 TmSampleCount::updtimer(std::string cname, TmControlValue value) 00095 { 00096 bool type_error=false; 00097 if (cname=="MarSystem/source") { 00098 if (value.getType()==tmcv_marsystem) { 00099 setSource(value.toMarSystem()); 00100 } 00101 else type_error=true; 00102 } 00103 else if (cname=="mrs_string/control") { 00104 if (value.getType()==tmcv_string) { 00105 setSourceCtrl(value.toString()); 00106 } 00107 else type_error=true; 00108 } 00109 else { 00110 MRSWARN("TmSampleCount::updtimer(string,TmControlValue) unsupported control"); 00111 } 00112 if (type_error) { 00113 MRSWARN("TmSampleCount::updtimer(string,TmControlValue) wrong type to "+cname); 00114 } 00115 } 00116