Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/Series.cpp
Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 1998-2007 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 "Series.h"
00020 
00021 using namespace std;
00022 using namespace Marsyas;
00023 
00024 Series::Series(mrs_string name):MarSystem("Series",name)
00025 {
00026   isComposite_ = true;
00027   addControls();
00028 }
00029 
00030 Series::~Series()
00031 {
00032 }
00033 
00034 MarSystem*
00035 Series::clone() const
00036 {
00037   return new Series(*this);
00038 }
00039 
00040 void
00041 Series::addControls()
00042 {
00043 }
00044 
00045 
00046 void
00047 Series::myUpdate(MarControlPtr sender)
00048 {
00049   child_count_t child_count = marsystems_.size();
00050   if (child_count)
00051   {
00052     //propagate in flow controls to first child
00053     marsystems_[0]->setctrl("mrs_natural/inObservations", inObservations_);
00054     marsystems_[0]->setctrl("mrs_natural/inSamples", inSamples_);
00055     marsystems_[0]->setctrl("mrs_real/israte", israte_);
00056     marsystems_[0]->setctrl("mrs_string/inObsNames", inObsNames_);
00057     marsystems_[0]->setctrl("mrs_natural/inStabilizingDelay", inStabilizingDelay_);
00058     marsystems_[0]->update();
00059 
00060     // update dataflow component MarSystems in order
00061     for (child_count_t i=1; i < child_count; ++i)
00062     {
00063       marsystems_[i]->setctrl(marsystems_[i]->ctrl_inObsNames_,
00064                               marsystems_[i-1]->ctrl_onObsNames_);
00065       marsystems_[i]->setctrl(marsystems_[i]->ctrl_inObservations_,
00066                               marsystems_[i-1]->ctrl_onObservations_);
00067       marsystems_[i]->setctrl(marsystems_[i]->ctrl_inSamples_,
00068                               marsystems_[i-1]->ctrl_onSamples_);
00069       marsystems_[i]->setctrl(marsystems_[i]->ctrl_israte_,
00070                               marsystems_[i-1]->ctrl_osrate_);
00071       marsystems_[i]->setctrl(marsystems_[i]->ctrl_inStabilizingDelay_,
00072                               marsystems_[i-1]->ctrl_onStabilizingDelay_);
00073       marsystems_[i]->update();
00074     }
00075 
00076     //forward flow propagation
00077     updControl(ctrl_onObsNames_, marsystems_[child_count-1]->ctrl_onObsNames_, NOUPDATE);
00078     updControl(ctrl_onSamples_, marsystems_[child_count-1]->ctrl_onSamples_, NOUPDATE);
00079     updControl(ctrl_onObservations_, marsystems_[child_count-1]->ctrl_onObservations_, NOUPDATE);
00080     updControl(ctrl_osrate_, marsystems_[child_count-1]->ctrl_osrate_, NOUPDATE);
00081     updControl(ctrl_onStabilizingDelay_, marsystems_[child_count-1]->ctrl_onStabilizingDelay_, NOUPDATE);
00082 
00083     for (child_count_t i=0; i< child_count-1; ++i)
00084     {
00085       MarControlAccessor acc(marsystems_[i]->ctrl_processedData_, NOUPDATE);
00086       realvec& processedData = acc.to<mrs_realvec>();
00087 
00088       if (processedData.getRows() != marsystems_[i]->ctrl_onObservations_->to<mrs_natural>()  ||
00089           processedData.getCols() != marsystems_[i]->ctrl_onSamples_->to<mrs_natural>())
00090       {
00091         processedData.create(marsystems_[i]->ctrl_onObservations_->to<mrs_natural>(),
00092                              marsystems_[i]->ctrl_onSamples_->to<mrs_natural>());
00093       }
00094     }
00095   }
00096   else //if composite is empty...
00097     MarSystem::myUpdate(sender);
00098 }
00099 
00100 void
00101 Series::myProcess(realvec& in, realvec& out)
00102 {
00103   // Add assertions about sizes [!]
00104 
00105   child_count_t child_count = marsystems_.size();
00106   if (child_count == 1)
00107     marsystems_[0]->process(in,out);
00108   else if(child_count > 1)
00109   {
00110     for (child_count_t i = 0; i < child_count; ++i)
00111     {
00112       if (i==0)
00113       {
00114         MarControlAccessor acc(marsystems_[i]->ctrl_processedData_);
00115         realvec& slice = acc.to<mrs_realvec>();
00116         marsystems_[i]->process(in, slice);
00117       }
00118       else if (i == child_count-1)
00119       {
00120         MarControlAccessor acc(marsystems_[i-1]->ctrl_processedData_, true, true);
00121         realvec& slice = acc.to<mrs_realvec>();
00122         marsystems_[i]->process(slice, out);
00123       }
00124       else
00125       {
00126         MarControlAccessor acc1(marsystems_[i-1]->ctrl_processedData_, true, true);
00127         realvec& slice1 = acc1.to<mrs_realvec>();
00128         MarControlAccessor acc2(marsystems_[i]->ctrl_processedData_);
00129         realvec& slice2 = acc2.to<mrs_realvec>();
00130         marsystems_[i]->process(slice1, slice2);
00131       }
00132     }
00133   }
00134   else if(child_count == 0) //composite has no children!
00135   {
00136     MRSWARN("Series::process: composite has no children MarSystems - passing input to output without changes.");
00137     out = in;
00138   }
00139 
00140 
00141 }