00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "PeakViewSink.h"
00020 #include "peakView.h"
00021
00022
00023 using std::ostringstream;
00024 using std::ifstream;
00025 using std::ios;
00026 using std::endl;
00027 using std::cout;
00028 using std::istringstream;
00029
00030
00031
00032 using namespace Marsyas;
00033
00034 PeakViewSink::PeakViewSink(mrs_string name):MarSystem("PeakViewSink",name)
00035 {
00036 count_= 0;
00037 tmpFilename_ = "defaultfile.tmp";
00038 addControls();
00039 }
00040
00041 PeakViewSink::PeakViewSink(const PeakViewSink& a):MarSystem(a)
00042 {
00043 count_ = a.count_;
00044 tmpFilename_ ="defaultfile.tmp";
00045
00046 ctrl_accumulate2Disk_ = getctrl("mrs_bool/accumulate2Disk");
00047 ctrl_fs_ = getctrl("mrs_real/fs");
00048 ctrl_frameSize_ = getctrl("mrs_natural/frameSize");
00049 ctrl_filename_ = getctrl("mrs_string/filename");
00050 ctrl_done_ = getctrl("mrs_bool/done");
00051 }
00052
00053 PeakViewSink::~PeakViewSink()
00054 {
00055 if(tmpFile_.is_open())
00056 tmpFile_.close();
00057 }
00058
00059 MarSystem*
00060 PeakViewSink::clone() const
00061 {
00062 return new PeakViewSink(*this);
00063 }
00064
00065 void
00066 PeakViewSink::addControls()
00067 {
00068 addctrl("mrs_bool/done", false, ctrl_done_);
00069 ctrl_done_->setState(true);
00070
00071 addctrl("mrs_string/filename", "defaultfile.peak", ctrl_filename_);
00072
00073 addctrl("mrs_bool/accumulate2Disk", true, ctrl_accumulate2Disk_);
00074 addctrl("mrs_real/fs", 0.0, ctrl_fs_);
00075 addctrl("mrs_natural/frameSize", 0, ctrl_frameSize_);
00076 }
00077
00078 void
00079 PeakViewSink::done()
00080 {
00081 mrs_natural t,o;
00082 if(ctrl_accumulate2Disk_->isTrue())
00083 {
00084
00085
00086 if(tmpFile_.is_open())
00087 {
00088
00089 tmpFile_.close();
00090
00091
00092 ifstream tmpFile;
00093 tmpFile.open(tmpFilename_.c_str(), ios::in);
00094
00095
00096 accumData_.create(inObservations_, count_);
00097
00098
00099 char myline[2048];
00100
00101 for(t=0; t < count_; ++t)
00102 {
00103 tmpFile.getline(myline, 2048);
00104 istringstream iss(myline);
00105 for(o=0; o < inObservations_; ++o)
00106 {
00107
00108 iss >> accumData_(o,t);
00109 }
00110 }
00111
00112
00113 tmpFile.close();
00114
00115 count_ = 0;
00116 }
00117 else
00118 accumData_.create(0,0);
00119 }
00120
00121
00122 if(accumData_.getSize() != 0)
00123 {
00124 peakView accumDataView(accumData_);
00125 accumDataView.peakWrite(ctrl_filename_->to<mrs_string>(),
00126 ctrl_fs_->to<mrs_real>(), ctrl_frameSize_->to<mrs_natural>());
00127 }
00128
00129
00130 accumData_.create(0, 0);
00131 ctrl_done_->setValue(false, NOUPDATE);
00132 }
00133
00134 void
00135 PeakViewSink::myUpdate(MarControlPtr sender)
00136 {
00137 (void) sender;
00138 MRSDIAG("PeakViewSink.cpp - PeakViewSink:myUpdate");
00139
00140 ctrl_onObservations_->setValue(ctrl_inObservations_, NOUPDATE);
00141 ctrl_onSamples_->setValue(ctrl_inSamples_, NOUPDATE);
00142 ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE);
00143 ctrl_onObsNames_->setValue(ctrl_inObsNames_, NOUPDATE);
00144
00145 if(ctrl_done_->isTrue())
00146 done();
00147 }
00148
00149 void
00150 PeakViewSink::myProcess(realvec& in, realvec& out)
00151 {
00152 out = in;
00153 mrs_natural o,t;
00154
00155
00156
00157 if(ctrl_accumulate2Disk_->isTrue())
00158 {
00159
00160
00161
00162
00163 if(!tmpFile_.is_open())
00164 {
00165 tmpFilename_ = this->getType() + "_" + this->getName() + ".tmp";
00166 tmpFile_.open(tmpFilename_.c_str(), ios::out | ios::trunc);
00167 count_ = 0;
00168 }
00169
00170
00171 for (t=0; t < inSamples_; t++)
00172 {
00173 for (o=0 ; o<inObservations_ ; o++)
00174 tmpFile_ << in(o, t) << " " ;
00175 tmpFile_ << endl;
00176 }
00177 count_ += inSamples_;
00178 }
00179 else
00180 {
00181
00182 mrs_natural cols = accumData_.getCols();
00183 accumData_.stretch(inObservations_, cols+inSamples_);
00184 for (o=0; o < inObservations_; o++)
00185 for (t=0; t < inSamples_; t++)
00186 {
00187 accumData_(o, cols+t) = in(o, t);
00188 }
00189 }
00190 }