CLAM-Development  1.4.0
ControlFade.cxx
Go to the documentation of this file.
1 #include "ControlFade.hxx"
2 #include "ProcessingFactory.hxx"
3 
4 namespace CLAM
5 {
6 namespace Hidden
7 {
8  static const char * metadata[] = {
9  "key", "ControlFade",
10  "category", "Controls",
11  "description", "ControlFade",
12  0
13  };
14  static FactoryRegistrator<ProcessingFactory, ControlFade> reg = metadata;
15 }
16 
17 void ControlFadeConfig::DefaultInit()
18 {
19  AddAll();
20  UpdateData();
21  SetFadeTimeInMs( 0.0 );
22 }
24  : _inControlValue( "Input Value", this , &ControlFade::InControlValueCallback )
25  , _inControlDelay( "Delay Time in Ms", this , &ControlFade::InControlDelayCallback )
26  , _outControlValue( "Output Value", this )
27  , _bufferTime(0)
28  , _counterTime(0)
29  , _initValue(0)
30  , _lastValue(0)
31  , _delayTime(0)
32 {
33  Configure( _config );
34 }
35 
37  : _inControlValue( "Input Values", this , &ControlFade::InControlValueCallback )
38  , _inControlDelay( "Delay Time in Ms", this , &ControlFade::InControlDelayCallback )
39  , _outControlValue( "Output Value", this )
40  , _bufferTime(0)
41  , _counterTime(0)
42  , _initValue(0)
43  , _lastValue(0)
44  , _delayTime(0)
45 {
46  Configure( cfg );
47 }
48 
50 {
51  CopyAsConcreteConfig( _config, cfg );
52  _inControlDelay.DoControl(_config.GetFadeTimeInMs());
53  _bufferTime = 1000. * (float)BackendBufferSize() / (float)BackendSampleRate();
54  _initValue=_lastValue=0;
55 // std::cout<<"Buffer Time: "<<_bufferTime<<std::endl;
56  _counterTime=0;
57  return true;
58 }
59 
60 void ControlFade::InControlDelayCallback(const TControlData & value)
61 {
62  _delayTime=value;
63 }
64 void ControlFade::InControlValueCallback(const TControlData & value)
65 {
66  _counterTime=0;
67  _initValue=_lastValue;
68  _lastValue=_inControlValue.GetLastValue();
69 }
70 
72 {
73  if (_initValue==_lastValue)
74  return true;
75  double a=(_inControlValue.GetLastValue() - _initValue)/_delayTime;
76  float newValue=a * _counterTime + _initValue;
77  _counterTime += _bufferTime;
78  if (((newValue <= _lastValue) and (_lastValue > _initValue)) or ((newValue>=_lastValue) and (_lastValue<_initValue)))
79  {
80 // std::cout<<"DoControl! value: "<<newValue<<std::endl;
81  _outControlValue.SendControl(newValue);
82  }
83  if (((newValue >= _lastValue) and (_lastValue > _initValue)) or ((newValue<=_lastValue) and (_lastValue<_initValue)))
84  {
85  _initValue = _lastValue;
86  _outControlValue.SendControl(_lastValue);
87 // std::cout<<"lastvalue: "<<_lastValue<<std::endl;
88  }
89  return true;
90 }
91 }
92