Added a helper function to modulate using CC values
This commit is contained in:
parent
21269e9f27
commit
2d94810af2
2 changed files with 54 additions and 0 deletions
|
|
@ -8,6 +8,8 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "SfzHelpers.h"
|
#include "SfzHelpers.h"
|
||||||
|
#include "CCMap.h"
|
||||||
|
#include "Range.h"
|
||||||
|
|
||||||
namespace sfz
|
namespace sfz
|
||||||
{
|
{
|
||||||
|
|
@ -103,6 +105,26 @@ public:
|
||||||
*/
|
*/
|
||||||
void resetAllControllers() noexcept;
|
void resetAllControllers() noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Modulate a value using the last entered CCs in the midiState
|
||||||
|
*
|
||||||
|
* @tparam T
|
||||||
|
* @tparam U
|
||||||
|
* @param value the base value
|
||||||
|
* @param modifiers the list of CC modifiers
|
||||||
|
* @param validRange a range to clamp the output
|
||||||
|
* @param lambda the function to apply for each modifier
|
||||||
|
* @return T
|
||||||
|
*/
|
||||||
|
template<class T, class U>
|
||||||
|
T modulate(T value, const CCMap<U>& modifiers, const Range<T>& validRange, const modFunction<T, U>& lambda = addToBase<T>) const noexcept
|
||||||
|
{
|
||||||
|
for (auto& mod: modifiers) {
|
||||||
|
lambda(value, getCCValue(mod.first) * mod.second);
|
||||||
|
}
|
||||||
|
return validRange.clamp(value);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<class T>
|
template<class T>
|
||||||
using MidiNoteArray = std::array<T, 128>;
|
using MidiNoteArray = std::array<T, 128>;
|
||||||
|
|
|
||||||
|
|
@ -172,5 +172,37 @@ bool findDefine(absl::string_view line, absl::string_view& variable, absl::strin
|
||||||
*/
|
*/
|
||||||
bool findInclude(absl::string_view line, std::string& path);
|
bool findInclude(absl::string_view line, std::string& path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Defines a function that modulates a base value with another one
|
||||||
|
*
|
||||||
|
* @tparam T
|
||||||
|
*/
|
||||||
|
template<class T, class U>
|
||||||
|
using modFunction = std::function<void(T&, U)>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Modulation helper that adds the modifier to the base value
|
||||||
|
*
|
||||||
|
* @tparam T
|
||||||
|
* @param base the base value
|
||||||
|
* @param modifier the modifier value
|
||||||
|
*/
|
||||||
|
template<class T>
|
||||||
|
constexpr void addToBase(T& base, T modifier)
|
||||||
|
{
|
||||||
|
base += modifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief multiply a value by a factor, in cents. To be used for pitch variations.
|
||||||
|
*
|
||||||
|
* @param base
|
||||||
|
* @param modifier
|
||||||
|
*/
|
||||||
|
constexpr void multiplyByCents(float& base, int modifier)
|
||||||
|
{
|
||||||
|
base *= centsFactor(modifier);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sfz
|
} // namespace sfz
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue