Marsyas
0.6.0-alpha
|
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 // 00020 // Brought to you by sness@sness.net 00021 // 00022 00023 #include "Selector.h" 00024 #include "../common_source.h" 00025 00026 #include <algorithm> 00027 00028 using namespace std; 00029 using namespace Marsyas; 00030 00031 Selector::Selector(mrs_string name):MarSystem("Selector", name) 00032 { 00033 addControls(); 00034 } 00035 00036 Selector::Selector(const Selector& a) : MarSystem(a) 00037 { 00038 ctrl_enabled_ = getctrl("mrs_realvec/enabled"); 00039 } 00040 00041 Selector::~Selector() 00042 { 00043 } 00044 00045 00046 MarSystem* 00047 Selector::clone() const 00048 { 00049 return new Selector(*this); 00050 } 00051 00052 void 00053 Selector::addControls() 00054 { 00055 addctrl("mrs_natural/disable", -1); 00056 setctrlState("mrs_natural/disable", true); 00057 addctrl("mrs_natural/enable", -1); 00058 setctrlState("mrs_natural/enable", true); 00059 00060 addControl("mrs_realvec/enableRange", realvec()); 00061 setControlState("mrs_realvec/enableRange", true); 00062 addControl("mrs_realvec/disableRange", realvec()); 00063 setControlState("mrs_realvec/disableRange", true); 00064 00065 addctrl("mrs_realvec/enabled", realvec(), ctrl_enabled_); 00066 } 00067 00068 void 00069 Selector::myUpdate(MarControlPtr sender) 00070 { 00071 (void) sender; //suppress warning of unused parameter(s) 00072 MRSDIAG("Selector.cpp - Selector:myUpdate"); 00073 00074 MarControlAccessor acc(ctrl_enabled_); 00075 mrs_realvec& mask = acc.to<mrs_realvec>(); 00076 00077 // 00078 // Disable any observations that the user asks to be disabled 00079 // 00080 mrs_natural input_to_disable = getctrl("mrs_natural/disable")->to<mrs_natural>(); 00081 set_enabled(mask, input_to_disable, false); 00082 setctrl("mrs_natural/disable", -1); 00083 00084 const realvec & range_to_disable = getControl("mrs_realvec/disableRange")->to<mrs_realvec>(); 00085 if (range_to_disable.getSize() >= 2) 00086 { 00087 mrs_natural min = static_cast<mrs_natural>( range_to_disable(0) ); 00088 mrs_natural max = static_cast<mrs_natural>( range_to_disable(1) ); 00089 set_enabled_range(mask, min, max, false); 00090 } 00091 setControl("mrs_realvec/disableRange", realvec()); 00092 00093 // 00094 // Enable any observations that the user asks to be enabled 00095 // 00096 mrs_natural input_to_enable = getctrl("mrs_natural/enable")->to<mrs_natural>(); 00097 set_enabled(mask, input_to_enable, true); 00098 setctrl("mrs_natural/enable", -1); 00099 00100 const realvec & range_to_enable = getControl("mrs_realvec/enableRange")->to<mrs_realvec>(); 00101 if (range_to_enable.getSize() >= 2) 00102 { 00103 mrs_natural min = static_cast<mrs_natural>( range_to_enable(0) ); 00104 mrs_natural max = static_cast<mrs_natural>( range_to_enable(1) ); 00105 set_enabled_range(mask, min, max, true); 00106 } 00107 setControl("mrs_realvec/enableRange", realvec()); 00108 00109 // Count how many of the input observations are enabled 00110 mrs_natural total_enabled = enabled_count(mask, inObservations_); 00111 00112 // Set output format 00113 ctrl_onObservations_->setValue(total_enabled, NOUPDATE); 00114 ctrl_onSamples_->setValue(ctrl_inSamples_, NOUPDATE); 00115 ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE); 00116 } 00117 00118 void 00119 Selector::myProcess(realvec& in, realvec& out) 00120 { 00121 const mrs_realvec & mask = ctrl_enabled_->to<realvec>(); 00122 00123 // 00124 // Copy all the input observations and samples to the output except 00125 // for any observations that are not enabled. 00126 // 00127 mrs_natural outIndex = 0; 00128 for (mrs_natural o=0; o < inObservations_; o++) 00129 { 00130 if (is_enabled(mask, o)) 00131 { 00132 for (mrs_natural t = 0; t < inSamples_; t++) 00133 { 00134 out(outIndex,t) = in(o,t); 00135 } 00136 outIndex++; 00137 } 00138 } 00139 }