Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/Annotator.cpp
Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 1998-2006 George Tzanetakis <gtzan@cs.uvic.ca>
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #include "Annotator.h"
00020 #include "../common_source.h"
00021 
00022 using std::ostringstream;
00023 using namespace Marsyas;
00024 
00025 Annotator::Annotator(mrs_string name):MarSystem("Annotator", name)
00026 {
00027   addControls();
00028 }
00029 
00030 
00031 Annotator::Annotator(const Annotator& a):MarSystem(a)
00032 {
00033   ctrl_label_ = getControl("mrs_real/label");
00034   ctrl_labelInFront_ = getControl("mrs_bool/labelInFront");
00035   ctrl_annotationName_ = getControl("mrs_string/annotationName");
00036 }
00037 
00038 Annotator::~Annotator()
00039 {
00040 }
00041 
00042 MarSystem*
00043 Annotator::clone() const
00044 {
00045   return new Annotator(*this);
00046 }
00047 
00048 void
00049 Annotator::addControls()
00050 {
00051   addControl("mrs_real/label", 0.0, ctrl_label_);
00052   addControl("mrs_bool/labelInFront", false, ctrl_labelInFront_);
00053   addControl("mrs_string/annotationName", "annotation", ctrl_annotationName_);
00054 }
00055 
00056 void
00057 Annotator::myUpdate(MarControlPtr sender)
00058 {
00059   MRSDIAG("Annotator.cpp - Annotator:myUpdate");
00060 
00061   // Do the default MarSystem configuration ...
00062   MarSystem::myUpdate(sender);
00063 
00064   // ... but add one to the number of output observations.
00065   ctrl_onObservations_->setValue(ctrl_inObservations_->to<mrs_natural>() + 1, NOUPDATE);
00066 
00067   // Should the label go in front or at the back of the observations?
00068   labelInFront_ = ctrl_labelInFront_->to<mrs_bool>();
00069 
00070 
00071   // Add the annotation name to onObsNames.
00072   mrs_string annotationName = ctrl_annotationName_->to<mrs_string>();
00073   mrs_string onObsNames = ctrl_inObsNames_->to<mrs_string>();
00074   if (labelInFront_)
00075   {
00076     onObsNames = annotationName + mrs_string(",") + onObsNames;
00077   }
00078   else
00079   {
00080     onObsNames = onObsNames + mrs_string(",") + annotationName;
00081   }
00082   ctrl_onObsNames_->setValue(onObsNames, NOUPDATE);
00083 
00084 }
00085 
00086 void
00087 Annotator::myProcess(realvec& in, realvec& out)
00088 {
00089   mrs_natural o,t;
00090   // Get the label to annotate the feature stream with.
00091   const mrs_real& label = ctrl_label_->to<mrs_real>();
00092 
00093   // Copy the input observations to the output and add the label.
00094   for (t = 0; t < inSamples_; t++)
00095   {
00096     for (o = 0; o < inObservations_; o++)
00097     {
00098       out((int)(labelInFront_) + o, t) =  in(o, t);
00099     }
00100     out(labelInFront_ ? 0 : onObservations_ - 1, t) = label;
00101   }
00102 }