00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "Cascade.h"
00020
00021
00022 using std::ostringstream;
00023 using std::vector;
00024
00025 using namespace Marsyas;
00026
00027 Cascade::Cascade(mrs_string name):MarSystem("Cascade", name)
00028 {
00029 isComposite_ = true;
00030 }
00031
00032 Cascade::~Cascade()
00033 {
00034 deleteSlices();
00035 }
00036
00037 void
00038 Cascade::deleteSlices()
00039 {
00040 vector<realvec *>::const_iterator iter;
00041 for (iter = slices_.begin(); iter != slices_.end(); iter++) {
00042 delete *(iter);
00043 }
00044 slices_.clear();
00045 }
00046
00047 MarSystem*
00048 Cascade::clone() const
00049 {
00050 return new Cascade(*this);
00051 }
00052
00053 void
00054 Cascade::myUpdate(MarControlPtr sender)
00055 {
00056 if (marsystemsSize_ != 0)
00057 {
00058
00059 marsystems_[0]->setctrl("mrs_natural/inObservations", inObservations_);
00060 marsystems_[0]->setctrl("mrs_natural/inSamples", inSamples_);
00061 marsystems_[0]->setctrl("mrs_real/israte", israte_);
00062 marsystems_[0]->setctrl("mrs_string/inObsNames", inObsNames_);
00063 marsystems_[0]->update();
00064
00065
00066 ostringstream oss;
00067 oss << marsystems_[0]->getctrl("mrs_string/onObsNames");
00068 mrs_natural onObservations = marsystems_[0]->getctrl("mrs_natural/onObservations")->to<mrs_natural>();
00069 for (mrs_natural i=1; i < marsystemsSize_; ++i)
00070 {
00071 marsystems_[i]->setctrl("mrs_natural/inSamples", marsystems_[i-1]->getctrl("mrs_natural/onSamples"));
00072 marsystems_[i]->setctrl("mrs_natural/inObservations", marsystems_[i-1]->getctrl("mrs_natural/onObservations"));
00073 marsystems_[i]->setctrl("mrs_real/israte", marsystems_[i-1]->getctrl("mrs_real/osrate"));
00074 marsystems_[i]->update();
00075 oss << marsystems_[i]->getctrl("mrs_string/onObsNames");
00076 onObservations += marsystems_[i]->getctrl("mrs_natural/onObservations")->to<mrs_natural>();
00077 }
00078
00079
00080 setctrl(ctrl_onSamples_, marsystems_[0]->getctrl("mrs_natural/onSamples"));
00081 setctrl(ctrl_onObservations_, onObservations);
00082 setctrl(ctrl_osrate_, marsystems_[0]->getctrl("mrs_real/osrate"));
00083 setctrl(ctrl_onObsNames_, oss.str());
00084
00085
00086 if ((mrs_natural)slices_.size() < marsystemsSize_)
00087 {
00088 slices_.resize(marsystemsSize_, NULL);
00089 }
00090
00091 for (mrs_natural i = 0; i < marsystemsSize_; ++i)
00092 {
00093 if (slices_[i] != NULL)
00094 {
00095 if ((slices_[i])->getRows() != marsystems_[i]->getctrl("mrs_natural/onObservations")->to<mrs_natural>() ||
00096 (slices_[i])->getCols() != marsystems_[i]->getctrl("mrs_natural/onSamples")->to<mrs_natural>())
00097 {
00098 delete slices_[i];
00099 slices_[i] = new realvec(marsystems_[i]->getctrl("mrs_natural/onObservations")->to<mrs_natural>(),
00100 marsystems_[i]->getctrl("mrs_natural/onSamples")->to<mrs_natural>());
00101 }
00102 }
00103 else
00104 {
00105 slices_[i] = new realvec(marsystems_[i]->getctrl("mrs_natural/onObservations")->to<mrs_natural>(),
00106 marsystems_[i]->getctrl("mrs_natural/onSamples")->to<mrs_natural>());
00107 }
00108
00109 (slices_[i])->setval(0.0);
00110 }
00111 }
00112 else
00113 MarSystem::myUpdate(sender);
00114 }
00115
00116 void
00117 Cascade::myProcess(realvec& in, realvec& out)
00118 {
00119 mrs_natural o,t;
00120 mrs_natural outIndex = 0;
00121 mrs_natural localIndex = 0;
00122
00123 if (marsystemsSize_ == 1)
00124 {
00125 marsystems_[0]->process(in, out);
00126 }
00127 else if (marsystemsSize_ > 1)
00128 {
00129 marsystems_[0]->process(in, *(slices_[0]));
00130 localIndex = marsystems_[0]->getctrl("mrs_natural/onObservations")->to<mrs_natural>();
00131 for (o = 0; o < localIndex; o++)
00132 {
00133 for (t = 0; t < onSamples_; t++)
00134 {
00135 out(outIndex + o,t) = (*(slices_[0]))(o,t);
00136 }
00137 }
00138 outIndex += localIndex;
00139 for (mrs_natural i = 1; i < marsystemsSize_; ++i)
00140 {
00141 marsystems_[i]->process(*(slices_[i-1]), *(slices_[i]));
00142 localIndex = marsystems_[i]->getctrl("mrs_natural/onObservations")->to<mrs_natural>();
00143 for (o = 0; o < localIndex; o++)
00144 {
00145 for (t = 0; t < onSamples_; t++)
00146 {
00147 out(outIndex + o,t) = (*(slices_[i]))(o,t);
00148 }
00149 }
00150 outIndex += localIndex;
00151 }
00152 }
00153 else if(marsystemsSize_ == 0)
00154 {
00155 MRSWARN("Cascade::process: composite has no children MarSystems - passing input to output without changes.");
00156 out = in;
00157 }
00158 }