|
|
@ -29,6 +29,7 @@ namespace BALibrary { |
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
constexpr int LINEAR_SLOPE = 0; |
|
|
|
constexpr int LINEAR_SLOPE = 0; |
|
|
|
constexpr float EXPONENTIAL_K = 5.0f; |
|
|
|
constexpr float EXPONENTIAL_K = 5.0f; |
|
|
|
|
|
|
|
constexpr float EXP_EXPONENTIAL_K = expf(EXPONENTIAL_K); |
|
|
|
|
|
|
|
|
|
|
|
template <class T> |
|
|
|
template <class T> |
|
|
|
ParameterAutomation<T>::ParameterAutomation() |
|
|
|
ParameterAutomation<T>::ParameterAutomation() |
|
|
@ -99,11 +100,18 @@ T ParameterAutomation<T>::getNextValue() |
|
|
|
|
|
|
|
|
|
|
|
m_currentValueX += m_slopeX; |
|
|
|
m_currentValueX += m_slopeX; |
|
|
|
float value; |
|
|
|
float value; |
|
|
|
|
|
|
|
float returnValue; |
|
|
|
|
|
|
|
|
|
|
|
switch(m_function) { |
|
|
|
switch(m_function) { |
|
|
|
case Function::EXPONENTIAL : |
|
|
|
case Function::EXPONENTIAL : |
|
|
|
// f(x) = exp(-k*x)
|
|
|
|
|
|
|
|
|
|
|
|
if (m_positiveSlope) { |
|
|
|
|
|
|
|
// Growth: f(x) = exp(k*x) / exp(k)
|
|
|
|
|
|
|
|
value = expf(EXPONENTIAL_K*m_currentValueX) / EXP_EXPONENTIAL_K; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// Decay: f(x) = 1 - exp(-k*x)
|
|
|
|
value = 1.0f - expf(-EXPONENTIAL_K*m_currentValueX); |
|
|
|
value = 1.0f - expf(-EXPONENTIAL_K*m_currentValueX); |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Function::PARABOLIC : |
|
|
|
case Function::PARABOLIC : |
|
|
|
value = m_currentValueX*m_currentValueX; |
|
|
|
value = m_currentValueX*m_currentValueX; |
|
|
@ -122,7 +130,7 @@ T ParameterAutomation<T>::getNextValue() |
|
|
|
return m_endValue; |
|
|
|
return m_endValue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
float returnValue; |
|
|
|
|
|
|
|
if (m_positiveSlope) { |
|
|
|
if (m_positiveSlope) { |
|
|
|
returnValue = m_startValue + (m_scaleY*value); |
|
|
|
returnValue = m_startValue + (m_scaleY*value); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -169,7 +177,7 @@ ParameterAutomationSequence<T>::~ParameterAutomationSequence() |
|
|
|
template <class T> |
|
|
|
template <class T> |
|
|
|
void ParameterAutomationSequence<T>::setupParameter(int index, T startValue, T endValue, size_t durationSamples, typename ParameterAutomation<T>::Function function) |
|
|
|
void ParameterAutomationSequence<T>::setupParameter(int index, T startValue, T endValue, size_t durationSamples, typename ParameterAutomation<T>::Function function) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Serial.println("setupParameter() called"); |
|
|
|
Serial.println(String("setupParameter() called with samples: ") + durationSamples); |
|
|
|
m_paramArray[index]->reconfigure(startValue, endValue, durationSamples, function); |
|
|
|
m_paramArray[index]->reconfigure(startValue, endValue, durationSamples, function); |
|
|
|
m_currentIndex = 0; |
|
|
|
m_currentIndex = 0; |
|
|
|
} |
|
|
|
} |
|
|
@ -177,7 +185,7 @@ void ParameterAutomationSequence<T>::setupParameter(int index, T startValue, T e |
|
|
|
template <class T> |
|
|
|
template <class T> |
|
|
|
void ParameterAutomationSequence<T>::setupParameter(int index, T startValue, T endValue, float durationMilliseconds, typename ParameterAutomation<T>::Function function) |
|
|
|
void ParameterAutomationSequence<T>::setupParameter(int index, T startValue, T endValue, float durationMilliseconds, typename ParameterAutomation<T>::Function function) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Serial.println("setupParameter() called"); |
|
|
|
Serial.print(String("setupParameter() called with time: ")); Serial.println(durationMilliseconds, 6); |
|
|
|
m_paramArray[index]->reconfigure(startValue, endValue, durationMilliseconds, function); |
|
|
|
m_paramArray[index]->reconfigure(startValue, endValue, durationMilliseconds, function); |
|
|
|
m_currentIndex = 0; |
|
|
|
m_currentIndex = 0; |
|
|
|
} |
|
|
|
} |
|
|
@ -208,6 +216,7 @@ T ParameterAutomationSequence<T>::getNextValue() |
|
|
|
|
|
|
|
|
|
|
|
if (m_currentIndex >= m_numStages) { |
|
|
|
if (m_currentIndex >= m_numStages) { |
|
|
|
// Last stage already finished
|
|
|
|
// Last stage already finished
|
|
|
|
|
|
|
|
Serial.println("Last stage finished"); |
|
|
|
m_running = false; |
|
|
|
m_running = false; |
|
|
|
m_currentIndex = 0; |
|
|
|
m_currentIndex = 0; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -223,15 +232,7 @@ T ParameterAutomationSequence<T>::getNextValue() |
|
|
|
template <class T> |
|
|
|
template <class T> |
|
|
|
bool ParameterAutomationSequence<T>::isFinished() |
|
|
|
bool ParameterAutomationSequence<T>::isFinished() |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool finished = true; |
|
|
|
return !m_running; |
|
|
|
for (int i=0; i<m_numStages; i++) { |
|
|
|
|
|
|
|
if (!m_paramArray[i]->isFinished()) { |
|
|
|
|
|
|
|
finished = false; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
m_running = !finished; |
|
|
|
|
|
|
|
return finished; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Template instantiation
|
|
|
|
// Template instantiation
|
|
|
|