|
CLAM-Development
1.3
|
00001 #include "ControlFade.hxx" 00002 #include "ProcessingFactory.hxx" 00003 00004 namespace CLAM 00005 { 00006 namespace Hidden 00007 { 00008 static const char * metadata[] = { 00009 "key", "ControlFade", 00010 "category", "Controls", 00011 "description", "ControlFade", 00012 0 00013 }; 00014 static FactoryRegistrator<ProcessingFactory, ControlFade> reg = metadata; 00015 } 00016 00017 void ControlFadeConfig::DefaultInit() 00018 { 00019 AddAll(); 00020 UpdateData(); 00021 SetFadeTimeInMs( 0.0 ); 00022 } 00023 ControlFade::ControlFade() 00024 : _inControlValue( "Input Value", this , &ControlFade::InControlValueCallback ) 00025 , _inControlDelay( "Delay Time in Ms", this , &ControlFade::InControlDelayCallback ) 00026 , _outControlValue( "Output Value", this ) 00027 , _bufferTime(0) 00028 , _counterTime(0) 00029 , _initValue(0) 00030 , _lastValue(0) 00031 , _delayTime(0) 00032 { 00033 Configure( _config ); 00034 } 00035 00036 ControlFade::ControlFade( const ControlFadeConfig& cfg ) 00037 : _inControlValue( "Input Values", this , &ControlFade::InControlValueCallback ) 00038 , _inControlDelay( "Delay Time in Ms", this , &ControlFade::InControlDelayCallback ) 00039 , _outControlValue( "Output Value", this ) 00040 , _bufferTime(0) 00041 , _counterTime(0) 00042 , _initValue(0) 00043 , _lastValue(0) 00044 , _delayTime(0) 00045 { 00046 Configure( cfg ); 00047 } 00048 00049 bool ControlFade::ConcreteConfigure( const ProcessingConfig& cfg ) 00050 { 00051 CopyAsConcreteConfig( _config, cfg ); 00052 _inControlDelay.DoControl(_config.GetFadeTimeInMs()); 00053 _bufferTime = 1000. * (float)BackendBufferSize() / (float)BackendSampleRate(); 00054 _initValue=_lastValue=0; 00055 // std::cout<<"Buffer Time: "<<_bufferTime<<std::endl; 00056 _counterTime=0; 00057 return true; 00058 } 00059 00060 void ControlFade::InControlDelayCallback(const TControlData & value) 00061 { 00062 _delayTime=value; 00063 } 00064 void ControlFade::InControlValueCallback(const TControlData & value) 00065 { 00066 _counterTime=0; 00067 _initValue=_lastValue; 00068 _lastValue=_inControlValue.GetLastValue(); 00069 } 00070 00071 bool ControlFade::Do() 00072 { 00073 if (_initValue==_lastValue) 00074 return true; 00075 double a=(_inControlValue.GetLastValue() - _initValue)/_delayTime; 00076 float newValue=a * _counterTime + _initValue; 00077 _counterTime += _bufferTime; 00078 if (((newValue <= _lastValue) and (_lastValue > _initValue)) or ((newValue>=_lastValue) and (_lastValue<_initValue))) 00079 { 00080 // std::cout<<"DoControl! value: "<<newValue<<std::endl; 00081 _outControlValue.SendControl(newValue); 00082 } 00083 if (((newValue >= _lastValue) and (_lastValue > _initValue)) or ((newValue<=_lastValue) and (_lastValue<_initValue))) 00084 { 00085 _initValue = _lastValue; 00086 _outControlValue.SendControl(_lastValue); 00087 // std::cout<<"lastvalue: "<<_lastValue<<std::endl; 00088 } 00089 return true; 00090 } 00091 } 00092
1.7.6.1