|
CLAM-Development
1.3
|
00001 /* 00002 * Copyright (c) 2009 Fundacio Barcelona Media Universitat Pompeu Fabra. 00003 * 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 * 00019 */ 00020 #include "ControlIntervalMapper.hxx" 00021 #include "ProcessingFactory.hxx" 00022 00023 namespace CLAM 00024 { 00025 namespace Hidden 00026 { 00027 static const char * metadata[] = { 00028 "key", "ControlIntervalMapper", 00029 "category", "Controls", 00030 "description", "Receives a control and maps it using two intervals, the interval of the incoming value and the interval of the new value", 00031 0 00032 }; 00033 static FactoryRegistrator<ProcessingFactory, ControlIntervalMapper> reg = metadata; 00034 } 00035 00036 void ControlIntervalMapperConfig::DefaultInit() 00037 { 00038 AddAll(); 00039 UpdateData(); 00040 SetInputMin( 0.0 ); 00041 SetInputMax( 1.0 ); 00042 SetOutputMin( 0.0 ); 00043 SetOutputMax( 1.0 ); 00044 } 00045 00046 ControlIntervalMapper::ControlIntervalMapper() 00047 : _inControl( "input_control", this , &ControlIntervalMapper::InControlCallback ) 00048 , _outControl( "mapped_control", this ) 00049 , _min(0.) 00050 , _max(1.) 00051 , _newmin(0.) 00052 , _newmax(1.) 00053 { 00054 Configure( _config ); 00055 } 00056 00057 ControlIntervalMapper::ControlIntervalMapper( const ControlIntervalMapperConfig& cfg ) 00058 : _inControl( "input_control", this , &ControlIntervalMapper::InControlCallback ) 00059 , _outControl( "mapped_control", this ) 00060 , _min(0.) 00061 , _max(1.) 00062 , _newmin(0.) 00063 , _newmax(1.) 00064 { 00065 Configure( cfg ); 00066 } 00067 00068 bool ControlIntervalMapper::ConcreteConfigure( const ProcessingConfig& cfg ) 00069 { 00070 CopyAsConcreteConfig( _config, cfg ); 00071 _min = _config.GetInputMin(); 00072 _max = _config.GetInputMax(); 00073 _newmin = _config.GetOutputMin(); 00074 _newmax = _config.GetOutputMax(); 00075 _inControl.SetBounds(_min,_max); 00076 return true; 00077 } 00078 00079 void ControlIntervalMapper::InControlCallback(const TControlData & value) 00080 { 00081 TControlData newval = (( value - _min) / (_max - _min)) * 00082 ( _newmax - _newmin) + _newmin; 00083 _outControl.SendControl( newval ); 00084 } 00085 00086 bool ControlIntervalMapper::Do() 00087 { 00088 return true; 00089 } 00090 } 00091
1.7.6.1