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