CLAM-Development  1.4.0
ControlIntervalMapper.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 Fundacio Barcelona Media Universitat Pompeu Fabra.
3  *
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  */
21 #include "ProcessingFactory.hxx"
22 
23 namespace CLAM
24 {
25 namespace Hidden
26 {
27  static const char * metadata[] = {
28  "key", "ControlIntervalMapper",
29  "category", "Controls",
30  "description", "Receives a control and maps it using two intervals, the interval of the incoming value and the interval of the new value",
31  0
32  };
33  static FactoryRegistrator<ProcessingFactory, ControlIntervalMapper> reg = metadata;
34 }
35 
36 void ControlIntervalMapperConfig::DefaultInit()
37 {
38  AddAll();
39  UpdateData();
40  SetInputMin( 0.0 );
41  SetInputMax( 1.0 );
42  SetOutputMin( 0.0 );
43  SetOutputMax( 1.0 );
44 }
45 
47  : _inControl( "input_control", this , &ControlIntervalMapper::InControlCallback )
48  , _outControl( "mapped_control", this )
49  , _min(0.)
50  , _max(1.)
51  , _newmin(0.)
52  , _newmax(1.)
53 {
54  Configure( _config );
55 }
56 
58  : _inControl( "input_control", this , &ControlIntervalMapper::InControlCallback )
59  , _outControl( "mapped_control", this )
60  , _min(0.)
61  , _max(1.)
62  , _newmin(0.)
63  , _newmax(1.)
64 {
65  Configure( cfg );
66 }
67 
69 {
70  CopyAsConcreteConfig( _config, cfg );
71  _min = _config.GetInputMin();
72  _max = _config.GetInputMax();
73  _newmin = _config.GetOutputMin();
74  _newmax = _config.GetOutputMax();
75  _inControl.SetBounds(_min,_max);
76  return true;
77 }
78 
79 void ControlIntervalMapper::InControlCallback(const TControlData & value)
80 {
81  TControlData newval = (( value - _min) / (_max - _min)) *
82  ( _newmax - _newmin) + _newmin;
83  _outControl.SendControl( newval );
84 }
85 
87 {
88  return true;
89 }
90 }
91