00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "common.h"
00020 #include "RealvecSink.h"
00021
00022 using namespace std;
00023 using namespace Marsyas;
00024
00025 RealvecSink::RealvecSink(mrs_string name):MarSystem("RealvecSink",name)
00026 {
00027
00028
00029 oriName_ = "MARSYAS_EMPTY";
00030 count_= 0;
00031 write_ = 0 ;
00032 addControls();
00033 }
00034
00035 RealvecSink::RealvecSink(const RealvecSink& a):MarSystem(a)
00036 {
00037 count_ = 0;
00038 write_ = 0 ;
00039 oriName_ = "MARSYAS_EMPTY";
00040 ctrl_data_ = getctrl("mrs_realvec/data");
00041 }
00042
00043
00044 RealvecSink::~RealvecSink()
00045 {
00046 }
00047
00048
00049 MarSystem*
00050 RealvecSink::clone() const
00051 {
00052 return new RealvecSink(*this);
00053 }
00054
00055 void
00056 RealvecSink::addControls()
00057 {
00058 addctrl("mrs_bool/done", false);
00059 setctrlState("mrs_bool/done", true);
00060 addctrl("mrs_realvec/data", realvec(), ctrl_data_);
00061 setctrlState("mrs_real/israte", true);
00062 addctrl("mrs_string/fileName", "MARSYAS_EMPTY");
00063 setctrlState("mrs_string/fileName", true);
00064 }
00065
00066
00067 void
00068 RealvecSink::myUpdate(MarControlPtr sender)
00069 {
00070 (void) sender;
00071 MRSDIAG("RealvecSink.cpp - RealvecSink:myUpdate");
00072
00073 setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations")->to<mrs_natural>());
00074 setctrl("mrs_natural/onSamples", getctrl("mrs_natural/inSamples")->to<mrs_natural>());
00075 setctrl("mrs_real/osrate", getctrl("mrs_real/israte")->to<mrs_real>());
00076
00077 if( getctrl("mrs_bool/done")->isTrue()){
00078 if(write_)
00079 {
00080
00081 outputFile_.close();
00082
00083 mrs_string tmp = oriName_.c_str();
00084 tmp+="tmp";
00085 ofstream out;
00086 out.open(tmp.c_str(), ios::out);
00087 ifstream in;
00088 in.open(oriName_.c_str(), ios::in);
00089 out << in.rdbuf();
00090 in.close();
00091 out.close();
00092
00093
00094 out.open(oriName_.c_str(), ios::out);
00095
00096 out << "# MARSYAS mrs_realvec" << endl;
00097 out << "# Size = " << inObservations_*count_ << endl << endl;
00098 out << endl;
00099
00100
00101 out << "# type: matrix" << endl;
00102 out << "# rows: " << count_ << endl;
00103 out << "# columns: " << inObservations_ << endl;
00104
00105 in.open(tmp.c_str(), ios::in);
00106 out << in.rdbuf();
00107 in.close();
00108
00109 #ifdef MARSYAS_WIN32
00110 _unlink(tmp.c_str());
00111 #else
00112 unlink(tmp.c_str());
00113 #endif
00114
00115 out << endl;
00116 out << "# Size = " << inObservations_*count_ << endl;
00117 out << "# MARSYAS mrs_realvec" << endl;
00118 out.close();
00119 }
00120 else
00121 {
00122 MarControlAccessor acc(ctrl_data_, NOUPDATE);
00123 realvec& data = acc.to<mrs_realvec>();
00124 data.stretch(0);
00125 }
00126 count_=0;
00127 setctrl("mrs_bool/done", false);
00128 }
00129
00130
00131 if(getctrl("mrs_string/fileName")->to<mrs_string>().compare(oriName_))
00132 {
00133 if(write_)
00134 outputFile_.close();
00135 oriName_ = getctrl("mrs_string/fileName")->to<mrs_string>();
00136 outputFile_.open(oriName_.c_str(), ios::out);
00137 write_ = 1;
00138 }
00139 }
00140
00141 void
00142 RealvecSink::myProcess(realvec& in, realvec& out)
00143 {
00144 mrs_natural o,t;
00145 out=in;
00146
00147 if(write_)
00148 {
00149 for (t=0; t < inSamples_; t++)
00150 {
00151 for (o=0 ; o<inObservations_ ; o++)
00152 outputFile_ << in(o, t) << " " ;
00153 outputFile_ << endl;
00154 }
00155 }
00156 else
00157 {
00158 MarControlAccessor acc(ctrl_data_);
00159 realvec& data = acc.to<mrs_realvec>();
00160 data.stretch(inObservations_, count_+inSamples_);
00161
00162 for (o=0; o < inObservations_; o++)
00163 for (t=0; t < inSamples_; t++)
00164 data(o, count_+t) = in(o, t);
00165
00166
00167 }
00168
00169 count_+=inSamples_;
00170 }