00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "CollectionFileSource.h"
00020
00021 using std::ostringstream;
00022 using namespace Marsyas;
00023
00024 CollectionFileSource::CollectionFileSource(mrs_string name):AbsSoundFileSource("CollectionFileSource", name)
00025 {
00026 addControls();
00027 iHasData_ = false;
00028 iLastTickWithData_ = true;
00029 iNewFile_ = true;
00030 }
00031
00032 CollectionFileSource::CollectionFileSource(const CollectionFileSource& a):AbsSoundFileSource(a)
00033 {
00034 ctrl_currentlyPlaying_ = getctrl("mrs_string/currentlyPlaying");
00035 ctrl_previouslyPlaying_ = getctrl("mrs_string/previouslyPlaying");
00036 ctrl_regression_ = getctrl("mrs_bool/regression");
00037 ctrl_currentLabel_ = getctrl("mrs_real/currentLabel");
00038 ctrl_previousLabel_ = getctrl("mrs_real/previousLabel");
00039 ctrl_labelNames_ = getctrl("mrs_string/labelNames");
00040 ctrl_nLabels_ = getctrl("mrs_natural/nLabels");
00041 iHasData_ = false;
00042 iLastTickWithData_ = true;
00043 iNewFile_ = true;
00044 }
00045
00046 CollectionFileSource::~CollectionFileSource()
00047 {
00048 delete isrc_;
00049 delete downsampler_;
00050 }
00051
00052 MarSystem*
00053 CollectionFileSource::clone() const
00054 {
00055 return new CollectionFileSource(*this);
00056 }
00057
00058 void
00059 CollectionFileSource::addControls()
00060 {
00061 addctrl("mrs_bool/hasData", true);
00062 hasData_ = true;
00063
00064 addctrl("mrs_bool/lastTickWithData", false);
00065 lastTickWithData_ = false;
00066
00067
00068 addctrl("mrs_natural/pos", (mrs_natural)0);
00069 setctrlState("mrs_natural/pos", true);
00070
00071 addctrl("mrs_natural/loopPos", (mrs_natural)0);
00072 setctrlState("mrs_natural/pos", true);
00073
00074 addctrl("mrs_string/filename", "daufile");
00075 setctrlState("mrs_string/filename", true);
00076 addctrl("mrs_natural/size", (mrs_natural)0);
00077 addctrl("mrs_string/filetype", "mf");
00078 addctrl("mrs_natural/cindex", 0);
00079 setctrlState("mrs_natural/cindex", true);
00080
00081 addctrl("mrs_string/allfilenames", "collectionFileSource");
00082 setctrlState("mrs_string/allfilenames", true);
00083 addctrl("mrs_natural/numFiles", 0);
00084
00085 addctrl("mrs_real/repetitions", 1.0);
00086 setctrlState("mrs_real/repetitions", true);
00087 addctrl("mrs_real/duration", -1.0);
00088 setctrlState("mrs_real/duration", true);
00089
00090 addctrl("mrs_natural/advance", 0);
00091 setctrlState("mrs_natural/advance", true);
00092
00093 addctrl("mrs_bool/shuffle", false);
00094 setctrlState("mrs_bool/shuffle", true);
00095
00096 addctrl("mrs_natural/cindex", 0);
00097 setctrlState("mrs_natural/cindex", true);
00098
00099 addctrl("mrs_string/currentlyPlaying", "daufile", ctrl_currentlyPlaying_);
00100 addctrl("mrs_string/previouslyPlaying", "daufile", ctrl_previouslyPlaying_);
00101 addctrl("mrs_bool/regression", false, ctrl_regression_);
00102 addctrl("mrs_real/currentLabel", 0.0, ctrl_currentLabel_);
00103 addctrl("mrs_real/previousLabel", 0.0, ctrl_previousLabel_);
00104 addctrl("mrs_string/labelNames", ",", ctrl_labelNames_);
00105 addctrl("mrs_natural/nLabels", 0, ctrl_nLabels_);
00106 mngCreated_ = false;
00107 }
00108
00109 void
00110 CollectionFileSource::getHeader(mrs_string filename)
00111 {
00112 col_.clear();
00113 col_.store_labels(!ctrl_regression_->isTrue());
00114 col_.read(filename);
00115 updControl("mrs_string/allfilenames", col_.toLongString());
00116 updControl("mrs_natural/numFiles", (mrs_natural)col_.getSize());
00117
00118 cindex_ = 0;
00119 setctrl("mrs_natural/cindex", 0);
00120 setctrl("mrs_bool/hasData", true);
00121 setctrl("mrs_bool/lastTickWithData", false);
00122 ctrl_currentlyPlaying_->setValue(col_.entry(0), NOUPDATE);
00123
00124
00125
00126 if (col_.hasLabels())
00127 {
00128 if (ctrl_regression_->isTrue()) {
00129 ctrl_currentLabel_->setValue(col_.regression_label(0), NOUPDATE);
00130 ctrl_previousLabel_->setValue(col_.regression_label(0), NOUPDATE);
00131 ctrl_labelNames_->setValue("", NOUPDATE);
00132 ctrl_nLabels_->setValue(0, NOUPDATE);
00133 } else {
00134 ctrl_currentLabel_->setValue((mrs_real)col_.labelNum(col_.labelEntry(0)), NOUPDATE);
00135 ctrl_previousLabel_->setValue((mrs_real)col_.labelNum(col_.labelEntry(0)), NOUPDATE);
00136 ctrl_labelNames_->setValue(col_.getLabelNames(), NOUPDATE);
00137 ctrl_nLabels_->setValue(col_.getNumLabels(), NOUPDATE);
00138 }
00139 }
00140
00141
00142
00143 addctrl("mrs_natural/size", 1);
00144 setctrl("mrs_natural/pos", 0);
00145 pos_ = 0;
00146 }
00147
00148 void
00149 CollectionFileSource::myUpdate(MarControlPtr sender)
00150 {
00151 (void) sender;
00152
00153
00154 inSamples_ = getctrl("mrs_natural/inSamples")->to<mrs_natural>();
00155 inObservations_ = getctrl("mrs_natural/inObservations")->to<mrs_natural>();
00156
00157 filename_ = getctrl("mrs_string/filename")->to<mrs_string>();
00158 pos_ = getctrl("mrs_natural/pos")->to<mrs_natural>();
00159
00160 if (mngCreated_ == false)
00161 {
00162 isrc_ = new SoundFileSource("isrc");
00163 mngCreated_ = true;
00164 downsampler_ = new DownSampler("downsampler_");
00165 }
00166
00167 repetitions_ = getctrl("mrs_real/repetitions")->to<mrs_real>();
00168 duration_ = getctrl("mrs_real/duration")->to<mrs_real>();
00169 advance_ = getctrl("mrs_natural/advance")->to<mrs_natural>();
00170 setctrl("mrs_natural/advance", 0);
00171 cindex_ = getctrl("mrs_natural/cindex")->to<mrs_natural>();
00172 if (getctrl("mrs_bool/shuffle")->isTrue())
00173 {
00174 col_.shuffle();
00175 setctrl("mrs_bool/shuffle", false);
00176 }
00177
00178 if (cindex_ < (mrs_natural)col_.size())
00179 {
00180 isrc_->updControl("mrs_string/filename", col_.entry(cindex_));
00181 isrc_->updControl("mrs_natural/pos", 0);
00182 ctrl_currentlyPlaying_->setValue(col_.entry(cindex_), NOUPDATE);
00183 ctrl_previouslyPlaying_->setValue(col_.entry((cindex_-1)%col_.size()), NOUPDATE);
00184
00185
00186 if (col_.hasLabels())
00187 {
00188 if (ctrl_regression_->isTrue()) {
00189 ctrl_currentLabel_->setValue( col_.regression_label(cindex_), NOUPDATE);
00190 ctrl_previousLabel_->setValue( col_.regression_label((cindex_-1) % col_.size()), NOUPDATE);
00191 } else {
00192 ctrl_currentLabel_->setValue((mrs_real)col_.labelNum(col_.labelEntry(cindex_)), NOUPDATE);
00193 ctrl_previousLabel_->setValue((mrs_real)col_.labelNum(col_.labelEntry((cindex_-1)%col_.size())), NOUPDATE);
00194 }
00195 }
00196 ctrl_labelNames_->setValue(col_.getLabelNames(), NOUPDATE);
00197 ctrl_nLabels_->setValue(col_.getNumLabels(), NOUPDATE);
00198 }
00199
00200 myIsrate_ = isrc_->getctrl("mrs_real/israte")->to<mrs_real>();
00201 onObservations_ = isrc_->getctrl("mrs_natural/onObservations")->to<mrs_natural>();
00202
00203 setctrl("mrs_real/israte", myIsrate_);
00204 setctrl("mrs_real/osrate", myIsrate_);
00205 setctrl("mrs_natural/onObservations", onObservations_);
00206
00207 isrc_->updControl("mrs_natural/inSamples", inSamples_);
00208 setctrl("mrs_natural/onSamples", inSamples_);
00209 setctrl("mrs_real/israte", myIsrate_);
00210 setctrl("mrs_real/osrate", myIsrate_);
00211 setctrl("mrs_natural/onObservations", onObservations_);
00212 temp_.create(inObservations_, inSamples_);
00213
00214 isrc_->updControl("mrs_real/repetitions", repetitions_);
00215 isrc_->updControl("mrs_natural/pos", pos_);
00216 isrc_->updControl("mrs_real/duration", duration_);
00217 isrc_->updControl("mrs_natural/advance", advance_);
00218 isrc_->updControl("mrs_natural/cindex", cindex_);
00219
00220 cindex_ = getctrl("mrs_natural/cindex")->to<mrs_natural>();
00221
00222
00223 if (advance_)
00224 {
00225
00226
00227 setctrl("mrs_string/currentlyPlaying", col_.entry((cindex_+advance_) % col_.size()));
00228 setctrl("mrs_string/previouslyPlaying", col_.entry((cindex_+advance_-1) % col_.size()));
00229
00230 if (col_.hasLabels())
00231 {
00232 if (ctrl_regression_->isTrue()) {
00233 setctrl("mrs_real/currentLabel", col_.regression_label((cindex_+advance_) % col_.size()));
00234 ctrl_currentLabel_->setValue( col_.regression_label((cindex_+advance_) % col_.size()), NOUPDATE);
00235 setctrl("mrs_real/previousLabel", col_.regression_label((cindex_-1+advance_) % col_.size()));
00236 ctrl_previousLabel_->setValue( col_.regression_label((cindex_-1+advance_) % col_.size()), NOUPDATE);
00237 } else {
00238 setctrl("mrs_real/currentLabel", (mrs_real) (col_.labelNum(col_.labelEntry((cindex_+advance_) % col_.size()))));
00239 ctrl_currentLabel_->setValue( (mrs_real) (col_.labelNum(col_.labelEntry((cindex_+advance_) % col_.size()))), NOUPDATE);
00240
00241 setctrl("mrs_real/previousLabel", (mrs_real) (col_.labelNum(col_.labelEntry((cindex_-1+advance_) % col_.size()))));
00242 ctrl_previousLabel_->setValue( (mrs_real) (col_.labelNum(col_.labelEntry((cindex_-1+advance_) % col_.size()))), NOUPDATE);
00243 }
00244
00245 }
00246
00247 if (cindex_ + advance_ >= (mrs_natural)col_.size())
00248 {
00249 setctrl("mrs_bool/hasData", false);
00250 hasData_ = false;
00251 setctrl("mrs_bool/lastTickWithData", true);
00252 lastTickWithData_ = true;
00253 advance_ = 0;
00254 cindex_ = 0;
00255
00256 }
00257 }
00258
00259
00260 }
00261
00262 void
00263 CollectionFileSource::myProcess(realvec& in, realvec &out)
00264 {
00265
00266 if (advance_)
00267 {
00268
00269 cindex_ = (cindex_ + advance_) % col_.size();
00270 setctrl("mrs_natural/cindex", cindex_);
00271 isrc_->updControl("mrs_string/filename", col_.entry(cindex_));
00272 isrc_->updControl("mrs_natural/pos", 0);
00273
00274
00275 myIsrate_ = isrc_->getctrl("mrs_real/israte")->to<mrs_real>();
00276 onObservations_ = isrc_->getctrl("mrs_natural/onObservations")->to<mrs_natural>();
00277
00278 setctrl("mrs_real/israte", myIsrate_);
00279 setctrl("mrs_real/osrate", myIsrate_);
00280 setctrl("mrs_natural/onObservations", onObservations_);
00281 setctrl("mrs_string/currentlyPlaying", col_.entry(cindex_));
00282 setctrl("mrs_string/previouslyPlaying", col_.entry((cindex_-1) % col_.size()));
00283
00284
00285 ctrl_currentlyPlaying_->setValue(col_.entry(cindex_), NOUPDATE);
00286 ctrl_previouslyPlaying_->setValue(col_.entry((cindex_-1) % col_.size()));
00287 if (col_.hasLabels())
00288 {
00289 if (ctrl_regression_->isTrue()) {
00290 setctrl("mrs_real/currentLabel", col_.regression_label(cindex_));
00291 ctrl_currentLabel_->setValue( col_.regression_label(cindex_), NOUPDATE);
00292
00293 setctrl("mrs_real/previousLabel", col_.regression_label((cindex_-1)% col_.size()));
00294 ctrl_previousLabel_->setValue( col_.regression_label((cindex_-1)%col_.size()), NOUPDATE);
00295 } else {
00296 setctrl("mrs_real/currentLabel", (mrs_real) (col_.labelNum(col_.labelEntry(cindex_))));
00297 ctrl_currentLabel_->setValue( (mrs_real) (col_.labelNum(col_.labelEntry(cindex_))), NOUPDATE);
00298
00299 setctrl("mrs_real/previousLabel", (mrs_real) (col_.labelNum(col_.labelEntry((cindex_-1)% col_.size()))));
00300 ctrl_previousLabel_->setValue( (mrs_real) (col_.labelNum(col_.labelEntry((cindex_-1)%col_.size()))), NOUPDATE);
00301 }
00302 }
00303
00304 ctrl_labelNames_->setValue(col_.getLabelNames(), NOUPDATE);
00305 ctrl_nLabels_->setValue(col_.getNumLabels(), NOUPDATE);
00306
00307
00308
00309
00310 isrc_->process(in,out);
00311
00312
00313
00314 setctrl("mrs_natural/pos", isrc_->getctrl("mrs_natural/pos"));
00315 setctrl("mrs_bool/hasData", isrc_->getctrl("mrs_bool/hasData"));
00316 setctrl("mrs_bool/lastTickWithData", isrc_->getctrl("mrs_bool/lastTickWithData"));
00317 iNewFile_ = true;
00318
00319 if (cindex_ > (mrs_natural)col_.size()-1)
00320 {
00321 setctrl("mrs_bool/hasData", false);
00322 hasData_ = false;
00323 setctrl("mrs_bool/lastTickWithData", true);
00324 lastTickWithData_ = true;
00325 advance_ = 0;
00326 setctrl("mrs_natural/advance", 0);
00327 return;
00328 }
00329
00330
00331 setctrl("mrs_natural/advance", 0);
00332 advance_ = 0;
00333
00334
00335
00336
00337 }
00338 else
00339 {
00340
00341
00342 if (!isrc_->getctrl("mrs_bool/hasData")->isTrue())
00343 {
00344
00345 if (cindex_ < (mrs_natural)col_.size() -1)
00346 {
00347 cindex_ = cindex_ + 1;
00348 setctrl("mrs_natural/cindex", cindex_);
00349
00350
00351 isrc_->updControl("mrs_string/filename", SOUNDFILESOURCE_UNDEFINEDFILENAME);
00352 isrc_->updControl("mrs_string/filename", col_.entry(cindex_));
00353 isrc_->updControl("mrs_natural/pos", 0);
00354
00355
00356 pos_ = 0;
00357 myIsrate_ = isrc_->getctrl("mrs_real/israte")->to<mrs_real>();
00358 onObservations_ = isrc_->getctrl("mrs_natural/onObservations")->to<mrs_natural>();
00359
00360 setctrl("mrs_real/israte", myIsrate_);
00361 setctrl("mrs_real/osrate", myIsrate_);
00362 setctrl("mrs_natural/onObservations", onObservations_);
00363 setctrl("mrs_string/currentlyPlaying", col_.entry(cindex_));
00364 setctrl("mrs_string/previouslyPlaying", col_.entry((cindex_-1)%col_.size()));
00365
00366
00367 ctrl_currentlyPlaying_->setValue(col_.entry(cindex_), NOUPDATE);
00368 ctrl_previouslyPlaying_->setValue(col_.entry((cindex_-1) % col_.size()), NOUPDATE);
00369
00370
00371 if (col_.hasLabels())
00372 {
00373 if (ctrl_regression_->isTrue()) {
00374 setctrl("mrs_real/currentLabel", col_.regression_label(cindex_));
00375 ctrl_currentLabel_->setValue( col_.regression_label(cindex_), NOUPDATE);
00376 setctrl("mrs_real/previousLabel", col_.regression_label((cindex_-1)%col_.size()));
00377 ctrl_previousLabel_->setValue( col_.regression_label((cindex_-1) % col_.size()), NOUPDATE);
00378 } else {
00379 setctrl("mrs_real/currentLabel", (mrs_real) col_.labelNum(col_.labelEntry(cindex_)));
00380 ctrl_currentLabel_->setValue( (mrs_real) col_.labelNum(col_.labelEntry(cindex_)), NOUPDATE);
00381
00382
00383 setctrl("mrs_real/previousLabel", (mrs_real) (col_.labelNum(col_.labelEntry((cindex_-1)%col_.size()))));
00384 ctrl_previousLabel_->setValue( (mrs_real) (col_.labelNum(col_.labelEntry((cindex_-1) % col_.size()))), NOUPDATE);
00385 }
00386 }
00387
00388 ctrl_labelNames_->setValue(col_.getLabelNames(), NOUPDATE);
00389 ctrl_nLabels_->setValue(col_.getNumLabels(), NOUPDATE);
00390 iNewFile_ = true;
00391 }
00392 else
00393 {
00394
00395 cindex_ = cindex_ + 1;
00396 setctrl("mrs_natural/cindex", cindex_);
00397 ctrl_previouslyPlaying_->setValue(col_.entry((cindex_-1) % col_.size()), NOUPDATE);
00398 setctrl("mrs_string/previouslyPlaying", col_.entry((cindex_-1)%col_.size()));
00399
00400 setctrl("mrs_real/previousLabel", (mrs_real) (col_.labelNum(col_.labelEntry((cindex_-1)%col_.size()))));
00401 ctrl_previousLabel_->setValue( (mrs_real) (col_.labelNum(col_.labelEntry((cindex_-1) % col_.size()))), NOUPDATE);
00402
00403
00404 setctrl("mrs_bool/hasData", false);
00405 hasData_ = false;
00406
00407 setctrl("mrs_bool/lastTickWithData", true);
00408 lastTickWithData_ = true;
00409
00410 iNewFile_ = true;
00411 }
00412 } else
00413 {
00414 if (isrc_->getctrl("mrs_natural/pos")->to<mrs_natural>() > 0)
00415 iNewFile_ = false;
00416 }
00417 isrc_->process(in,out);
00418 setctrl("mrs_natural/pos", isrc_->getctrl("mrs_natural/pos"));
00419 setctrl("mrs_bool/hasData", isrc_->getctrl("mrs_bool/hasData"));
00420 setctrl("mrs_bool/lastTickWithData", isrc_->getctrl("mrs_bool/lastTickWithData"));
00421
00422
00423 iHasData_ = isrc_->getctrl("mrs_bool/hasData")->to<mrs_bool>();
00424 iLastTickWithData_ = isrc_->getctrl("mrs_bool/lastTickWithData")->to<mrs_bool>();
00425 if (! iHasData_ ) {
00426
00427
00428
00429 if (cindex_ == (mrs_natural)col_.size() - 1) {
00430 setctrl("mrs_bool/hasData", false);
00431 hasData_ = false;
00432 }
00433 }
00434
00435
00436 if (iLastTickWithData_ ) {
00437
00438
00439
00440 if (cindex_ == (mrs_natural)col_.size() - 1) {
00441 setctrl("mrs_bool/lastTickWithData", true);
00442 lastTickWithData_ = true;
00443 }
00444 }
00445
00446
00447
00448
00449
00450
00451 }
00452
00453
00454
00455
00456 }