Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2014 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 "Timer.h" 00020 #include "../common_source.h" 00021 00022 using namespace Marsyas; 00023 00024 Timer::Timer(mrs_string name):MarSystem("Timer", name) 00025 { 00026 addControls(); 00027 } 00028 00029 Timer::Timer(const Timer& a) : MarSystem(a) 00030 { 00031 ctrl_time_ = getctrl("mrs_real/time"); 00032 ctrl_trigger_ = getctrl("mrs_bool/trigger"); 00033 } 00034 00035 Timer::~Timer() 00036 { 00037 } 00038 00039 MarSystem* 00040 Timer::clone() const 00041 { 00042 return new Timer(*this); 00043 } 00044 00045 void 00046 Timer::addControls() 00047 { 00048 //Add specific controls needed by this MarSystem. 00049 addctrl("mrs_real/time", 0.0, ctrl_time_); 00050 addctrl("mrs_bool/trigger", false, ctrl_trigger_); 00051 } 00052 00053 00054 void 00055 Timer::myUpdate(MarControlPtr sender) 00056 { 00057 // no change to network flow 00058 MarSystem::myUpdate(sender); 00059 } 00060 00061 void 00062 Timer::myProcess(realvec& in, realvec& out) 00063 { 00064 00065 if (trigger_duration_ == 0.0) 00066 ctrl_trigger_->setValue(false); 00067 00068 time_ += inSamples_ / israte_; 00069 ctrl_time_->setValue(time_); 00070 trigger_duration_ += inSamples_ / israte_; 00071 00072 00073 if (trigger_duration_ > 2.0) 00074 { 00075 ctrl_trigger_->setValue(true); 00076 trigger_duration_ = 0.0; 00077 // time_ = 0.0; 00078 } 00079 00080 00081 00082 for (mrs_natural o=0; o < inObservations_; o++) 00083 { 00084 for (mrs_natural t = 0; t < inSamples_; t++) 00085 { 00086 out(o,t) = in(o,t); 00087 } 00088 } 00089 }