sfizz/sources/LinearEnvelope.h

31 lines
859 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 23:39:26 +02:00
#include <absl/types/span.h>
2019-08-25 14:01:03 +02:00
#include <functional>
#include <type_traits>
2019-08-22 22:37:31 +02:00
2019-08-25 14:01:03 +02:00
namespace sfz {
2019-08-21 01:00:07 +02:00
2019-08-25 14:01:03 +02:00
template <class Type>
class LinearEnvelope {
2019-08-21 01:00:07 +02:00
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();
2019-08-25 14:01:03 +02:00
void reset(Type value = 0.0);
2019-08-22 23:39:26 +02:00
void getBlock(absl::Span<Type> output);
2019-08-25 14:01:03 +02:00
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
};
}