summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2019-04-01 20:22:14 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2019-04-08 18:08:42 +0200
commit10d483417fa70bb4c357d598f3bdfcf4f0b75f21 (patch)
tree08f3055d0432511e8e9fbd362bd05307d95c9f5c /src
parentaa6ef7e42966e36db74a4d15367379cbff37bbc8 (diff)
Add midi aftertouch choke for plugins.
Diffstat (limited to 'src')
-rw-r--r--src/event.h1
-rw-r--r--src/inputprocessor.cc66
-rw-r--r--src/inputprocessor.h1
3 files changed, 68 insertions, 0 deletions
diff --git a/src/event.h b/src/event.h
index 2b10e44..737fb18 100644
--- a/src/event.h
+++ b/src/event.h
@@ -32,6 +32,7 @@
enum class EventType
{
OnSet,
+ Choke,
Stop,
};
diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc
index 1a3246c..3e779f6 100644
--- a/src/inputprocessor.cc
+++ b/src/inputprocessor.cc
@@ -65,6 +65,14 @@ bool InputProcessor::process(std::vector<event_t>& events,
}
}
+ if(event.type == EventType::Choke)
+ {
+ if(!processChoke(event, pos, resample_ratio))
+ {
+ continue;
+ }
+ }
+
if(!processStop(event))
{
return false;
@@ -205,6 +213,64 @@ bool InputProcessor::processOnset(event_t& event,
return true;
}
+bool InputProcessor::processChoke(event_t& event,
+ std::size_t pos,
+ double resample_ratio)
+{
+ if(!kit.isValid())
+ {
+ return false;
+ }
+
+ std::size_t instrument_id = event.instrument;
+ Instrument* instr = nullptr;
+
+ if(instrument_id < kit.instruments.size())
+ {
+ instr = kit.instruments[instrument_id].get();
+ }
+
+ if(instr == nullptr || !instr->isValid())
+ {
+ ERR(inputprocessor, "Missing Instrument %d.\n", (int)instrument_id);
+ return false;
+ }
+
+ for(auto& filter : filters)
+ {
+ // This line might change the 'event' variable
+ bool keep = filter->filter(event, event.offset + pos);
+
+ if(!keep)
+ {
+ return false; // Skip event completely
+ }
+ }
+
+ // Add event to ramp down all existing events with the same groupname.
+ for(const auto& ch : kit.channels)
+ {
+ for(auto active_event : activeevents[ch.num])
+ {
+ if(active_event->getType() == Event::sample)
+ {
+ auto& event_sample = *static_cast<EventSample*>(active_event);
+ if(event_sample.instrument_id != instrument_id &&
+ event_sample.rampdown_count == -1) // Only if not already ramping.
+ {
+ // Fixed group rampdown time of 68ms, independent of samplerate
+ std::size_t ramp_length = (68./1000.)*settings.samplerate.load();
+ event_sample.rampdown_count = ramp_length;
+ event_sample.rampdown_offset = event.offset;
+ event_sample.ramp_length = ramp_length;
+ }
+ }
+ }
+ }
+
+ return true;
+}
+
bool InputProcessor::processStop(event_t& event)
{
if(event.type == EventType::Stop)
diff --git a/src/inputprocessor.h b/src/inputprocessor.h
index 794ca54..2101a25 100644
--- a/src/inputprocessor.h
+++ b/src/inputprocessor.h
@@ -59,6 +59,7 @@ private:
bool is_stopping; ///< Is set to true when a EventType::Stop event has been seen.
bool processOnset(event_t& event, std::size_t pos, double resample_ratio);
+ bool processChoke(event_t& event, std::size_t pos, double resample_ratio);
bool processStop(event_t& event);
std::vector<std::unique_ptr<InputFilter>> filters;