00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "Annotator.h"
00020
00021 using std::ostringstream;
00022 using namespace Marsyas;
00023
00024 Annotator::Annotator(mrs_string name):MarSystem("Annotator", name)
00025 {
00026 addControls();
00027 }
00028
00029
00030 Annotator::Annotator(const Annotator& a):MarSystem(a)
00031 {
00032 ctrl_label_ = getControl("mrs_real/label");
00033 ctrl_labelInFront_ = getControl("mrs_bool/labelInFront");
00034 ctrl_annotationName_ = getControl("mrs_string/annotationName");
00035 }
00036
00037 Annotator::~Annotator()
00038 {
00039 }
00040
00041 MarSystem*
00042 Annotator::clone() const
00043 {
00044 return new Annotator(*this);
00045 }
00046
00047 void
00048 Annotator::addControls()
00049 {
00050 addControl("mrs_real/label", 0.0, ctrl_label_);
00051 addControl("mrs_bool/labelInFront", false, ctrl_labelInFront_);
00052 addControl("mrs_string/annotationName", "annotation", ctrl_annotationName_);
00053 }
00054
00055 void
00056 Annotator::myUpdate(MarControlPtr sender)
00057 {
00058 MRSDIAG("Annotator.cpp - Annotator:myUpdate");
00059
00060
00061 MarSystem::myUpdate(sender);
00062
00063
00064 ctrl_onObservations_->setValue(ctrl_inObservations_->to<mrs_natural>() + 1, NOUPDATE);
00065
00066
00067 labelInFront_ = ctrl_labelInFront_->to<mrs_bool>();
00068
00069
00070
00071 mrs_string annotationName = ctrl_annotationName_->to<mrs_string>();
00072 mrs_string onObsNames = ctrl_inObsNames_->to<mrs_string>();
00073 if (labelInFront_)
00074 {
00075 onObsNames = annotationName + mrs_string(",") + onObsNames;
00076 }
00077 else
00078 {
00079 onObsNames = onObsNames + mrs_string(",") + annotationName;
00080 }
00081 ctrl_onObsNames_->setValue(onObsNames, NOUPDATE);
00082
00083 }
00084
00085 void
00086 Annotator::myProcess(realvec& in, realvec& out)
00087 {
00088 mrs_natural o,t;
00089
00090 const mrs_real& label = ctrl_label_->to<mrs_real>();
00091
00092
00093 for (t = 0; t < inSamples_; t++)
00094 {
00095 for (o = 0; o < inObservations_; o++)
00096 {
00097 out((int)(labelInFront_) + o, t) = in(o, t);
00098 }
00099 out(labelInFront_ ? 0 : onObservations_ - 1, t) = label;
00100 }
00101 }