WIP - Further development work checking

pull/1/head
Steve Lascos 7 years ago
parent 808aedf8c0
commit ec4a6b26d5
  1. 27
      src/LibBasicFunctions.h
  2. 87
      src/common/ParameterAutomation.cpp

@ -316,16 +316,17 @@ class ParameterAutomation
{ {
public: public:
enum class Function : unsigned { enum class Function : unsigned {
LINEAR = 0, ///< f(x) = x NOT_CONFIGURED = 0, ///< Initial, unconfigured stage
LINEAR, ///< f(x) = x
EXPONENTIAL, ///< f(x) = e^x EXPONENTIAL, ///< f(x) = e^x
LOGARITHMIC, ///< f(x) = ln(x) LOGARITHMIC, ///< f(x) = ln(x)
PARABOLIC, ///< f(x) = x^2 PARABOLIC, ///< f(x) = x^2
LOOKUP_TABLE ///< f(x) = lut(x) LOOKUP_TABLE ///< f(x) = lut(x)
}; };
ParameterAutomation() = delete; ParameterAutomation();
ParameterAutomation(T startValue, T endValue, size_t durationSamples, Function function = Function::LINEAR); ParameterAutomation(T startValue, T endValue, size_t durationSamples, Function function = Function::LINEAR);
ParameterAutomation(T startValue, T endValue, float durationMilliseconds, Function function = Function::LINEAR); ParameterAutomation(T startValue, T endValue, float durationMilliseconds, Function function = Function::LINEAR);
~ParameterAutomation(); virtual ~ParameterAutomation();
/// set the start and end values for the automation /// set the start and end values for the automation
/// @param function select which automation curve (function) to use /// @param function select which automation curve (function) to use
@ -342,6 +343,8 @@ public:
/// @returns the calculated parameter value of templated type T /// @returns the calculated parameter value of templated type T
T getNextValue(); T getNextValue();
bool isFinished() { return !m_running; }
private: private:
Function m_function; Function m_function;
T m_startValue; T m_startValue;
@ -355,10 +358,28 @@ private:
// TODO: initialize with const number of sequences with null type that automatically skips // TODO: initialize with const number of sequences with null type that automatically skips
// then register each new sequence. // then register each new sequence.
constexpr int MAX_PARAMETER_SEQUENCES = 32;
template <typename T> template <typename T>
class ParameterAutomationSequence class ParameterAutomationSequence
{ {
public:
ParameterAutomationSequence() = delete;
ParameterAutomationSequence(int numStages);
virtual ~ParameterAutomationSequence();
void setupParameter(int index, T startValue, T endValue, size_t durationSamples, typename ParameterAutomation<T>::Function function);
void setupParameter(int index, T startValue, T endValue, float durationMilliseconds, typename ParameterAutomation<T>::Function function);
/// Trigger a the automation sequence until numStages is reached or a Function is ParameterAutomation<T>::Function::NOT_CONFIGURED
void trigger();
T getNextValue();
bool isFinished();
private:
ParameterAutomation<T> *m_paramArray[MAX_PARAMETER_SEQUENCES];
int m_currentIndex = 0;
int m_numStages = 0;
}; };
} // BALibrary } // BALibrary

@ -24,7 +24,15 @@ using namespace BAGuitar;
namespace BALibrary { namespace BALibrary {
///////////////////////////////////////////////////////////////////////////////
// ParameterAutomation
///////////////////////////////////////////////////////////////////////////////
constexpr int LINEAR_SLOPE = 0; constexpr int LINEAR_SLOPE = 0;
template <class T>
ParameterAutomation<T>::ParameterAutomation()
{
reconfigure(0.0f, 0.0f, static_cast<size_t>(0), Function::NOT_CONFIGURED);
}
template <class T> template <class T>
ParameterAutomation<T>::ParameterAutomation(T startValue, T endValue, float durationMilliseconds, Function function) ParameterAutomation<T>::ParameterAutomation(T startValue, T endValue, float durationMilliseconds, Function function)
@ -38,6 +46,12 @@ ParameterAutomation<T>::ParameterAutomation(T startValue, T endValue, size_t dur
reconfigure(startValue, endValue, durationSamples, function); reconfigure(startValue, endValue, durationSamples, function);
} }
template <class T>
ParameterAutomation<T>::~ParameterAutomation()
{
}
template <class T> template <class T>
void ParameterAutomation<T>::reconfigure(T startValue, T endValue, float durationMilliseconds, Function function) void ParameterAutomation<T>::reconfigure(T startValue, T endValue, float durationMilliseconds, Function function)
{ {
@ -52,6 +66,7 @@ void ParameterAutomation<T>::reconfigure(T startValue, T endValue, size_t durati
m_endValue = endValue; m_endValue = endValue;
m_currentValueX = startValue; m_currentValueX = startValue;
m_duration = durationSamples; m_duration = durationSamples;
m_running = false;
// Pre-compute any necessary coefficients // Pre-compute any necessary coefficients
switch(m_function) { switch(m_function) {
@ -107,4 +122,76 @@ T ParameterAutomation<T>::getNextValue()
return m_currentValueX; return m_currentValueX;
} }
// Template instantiation
//template class MyStack<int, 6>;
template class ParameterAutomation<float>;
///////////////////////////////////////////////////////////////////////////////
// ParameterAutomationSequence
///////////////////////////////////////////////////////////////////////////////
template <class T>
ParameterAutomationSequence<T>::ParameterAutomationSequence(int numStages)
{
//m_paramArray = malloc(sizeof(ParameterAutomation<T>*) * numStages);
if (numStages < MAX_PARAMETER_SEQUENCES) {
for (int i=0; i<numStages; i++) {
m_paramArray[i] = new ParameterAutomation<T>();
}
for (int i=numStages; i<MAX_PARAMETER_SEQUENCES; i++) {
m_paramArray[i] = nullptr;
}
m_numStages = numStages;
}
}
template <class T>
ParameterAutomationSequence<T>::~ParameterAutomationSequence()
{
//if (m_paramArray) {
for (int i=0; i<m_numStages; i++) {
if (m_paramArray[i]) {
delete m_paramArray[i];
}
}
// delete m_paramArray;
//}
}
template <class T>
void ParameterAutomationSequence<T>::setupParameter(int index, T startValue, T endValue, size_t durationSamples, typename ParameterAutomation<T>::Function function)
{
m_paramArray[index]->reconfigure(startValue, endValue, durationSamples, function);
}
template <class T>
void ParameterAutomationSequence<T>::setupParameter(int index, T startValue, T endValue, float durationMilliseconds, typename ParameterAutomation<T>::Function function)
{
m_paramArray[index]->reconfigure(startValue, endValue, durationMilliseconds, function);
}
template <class T>
void ParameterAutomationSequence<T>::trigger(void)
{
m_currentIndex = 0;
for (int i=0; i<m_numStages; i++) {
m_paramArray[i]->trigger();
}
}
template <class T>
bool ParameterAutomationSequence<T>::isFinished()
{
bool finished = true;
for (int i=0; i<m_numStages; i++) {
if (!m_paramArray[i]->isFinished()) {
finished = false;
break;
}
}
return finished;
}
// Template instantiation
template class ParameterAutomationSequence<float>;
} }

Loading…
Cancel
Save