sfizz/sources/LinearEnvelope.h

32 lines
855 B
C
Raw Normal View History

2019-08-22 23:39:26 +02:00
#pragma once
2019-08-21 01:00:07 +02:00
#include "Globals.h"
#include "Helpers.h"
2019-08-22 22:37:31 +02:00
#include <type_traits>
#include <functional>
2019-08-22 23:39:26 +02:00
#include <absl/types/span.h>
2019-08-22 22:37:31 +02:00
2019-08-21 01:00:07 +02:00
namespace sfz
{
2019-08-22 22:37:31 +02:00
template<class Type>
2019-08-21 01:00:07 +02:00
class LinearEnvelope
{
public:
2019-08-22 23:39:26 +02:00
LinearEnvelope();
LinearEnvelope(int maxCapacity, std::function<Type(Type)> function);
void setMaxCapacity(int maxCapacity);
void setFunction(std::function<Type(Type)> function);
void registerEvent(int timestamp, Type inputValue);
void clear();
void reset(Type value=0.0);
void getBlock(absl::Span<Type> output);
2019-08-22 22:37:31 +02:00
private:
std::function<Type(Type)> function { [](Type input) { return input; } };
2019-08-22 23:39:26 +02:00
static_assert(std::is_arithmetic<Type>::value);
std::vector<std::pair<int, Type>> events;
2019-08-22 22:37:31 +02:00
int maxCapacity { config::defaultSamplesPerBlock };
2019-08-22 23:39:26 +02:00
Type currentValue { 0.0 };
LEAK_DETECTOR(LinearEnvelope);
2019-08-21 01:00:07 +02:00
};
}