summaryrefslogtreecommitdiff
path: root/src/inputprocessor.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-06-14 21:13:28 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-06-14 21:13:28 +0200
commit9453078f2d66fad806ee104e7c6993bba1043c6a (patch)
tree3b1ffe1e7b67c7d626336d835b44203f2c2c6ac5 /src/inputprocessor.cc
parent1bc07f860fa7f01763586f45b7fb2e53cd1c2557 (diff)
New input processor filter system. Moved processing from Instrument calss to new input processing filter system and prepared for new latency filter.
Diffstat (limited to 'src/inputprocessor.cc')
-rw-r--r--src/inputprocessor.cc47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc
index b83855f..b59f0e5 100644
--- a/src/inputprocessor.cc
+++ b/src/inputprocessor.cc
@@ -32,17 +32,28 @@
#include "instrument.h"
-InputProcessor::InputProcessor(DrumKit& kit, std::list<Event*>* activeevents)
+#include "staminafilter.h"
+#include "latencyfilter.h"
+
+#include "cpp11fix.h"
+
+InputProcessor::InputProcessor(Settings& settings,
+ DrumKit& kit,
+ std::list<Event*>* activeevents)
: kit(kit)
, activeevents(activeevents)
, is_stopping(false)
{
-
+ // Build filter list
+ filters.emplace_back(std::make_unique<StaminaFilter>(settings));
+ filters.emplace_back(std::make_unique<LatencyFilter>(settings));
}
-bool InputProcessor::process(const std::vector<event_t>& events, size_t pos, double resample_ratio)
+bool InputProcessor::process(std::vector<event_t>& events,
+ std::size_t pos,
+ double resample_ratio)
{
- for(const auto& event: events)
+ for(auto& event: events)
{
if(event.type == TYPE_ONSET)
{
@@ -63,16 +74,26 @@ bool InputProcessor::process(const std::vector<event_t>& events, size_t pos, dou
std::size_t InputProcessor::getLatency() const
{
- return 0;
+ std::size_t latency = 0;
+
+ for(const auto& filter : filters)
+ {
+ latency += filter->getLatency();
+ }
+
+ return latency;
}
-bool InputProcessor::processOnset(const event_t& event, size_t pos, double resample_ratio)
+bool InputProcessor::processOnset(event_t& event,
+ std::size_t pos,
+ double resample_ratio)
{
- if(!kit.isValid()) {
+ if(!kit.isValid())
+ {
return false;
}
- size_t ev_instr = event.instrument;
+ std::size_t ev_instr = event.instrument;
Instrument* instr = nullptr;
if(ev_instr < kit.instruments.size())
@@ -109,6 +130,14 @@ bool InputProcessor::processOnset(const event_t& event, size_t pos, double resam
}
}
+ for(auto& filter : filters)
+ {
+ if(!filter->filter(event, event.offset + pos))
+ {
+ return false; // Skip event completely
+ }
+ }
+
Sample* sample = instr->sample(event.velocity, event.offset + pos);
if(sample == nullptr)
@@ -136,7 +165,7 @@ bool InputProcessor::processOnset(const event_t& event, size_t pos, double resam
return true;
}
-bool InputProcessor::processStop(const event_t& event)
+bool InputProcessor::processStop(event_t& event)
{
if(event.type == TYPE_STOP)
{