diff options
| -rw-r--r-- | plugin/drumgizmo_plugin.cc | 32 | ||||
| m--------- | plugin/plugingizmo | 0 | ||||
| -rw-r--r-- | src/event.h | 1 | ||||
| -rw-r--r-- | src/inputprocessor.cc | 66 | ||||
| -rw-r--r-- | src/inputprocessor.h | 1 | 
5 files changed, 93 insertions, 7 deletions
| diff --git a/plugin/drumgizmo_plugin.cc b/plugin/drumgizmo_plugin.cc index 3328f6b..67436af 100644 --- a/plugin/drumgizmo_plugin.cc +++ b/plugin/drumgizmo_plugin.cc @@ -372,15 +372,33 @@ void DrumGizmoPlugin::Input::run(size_t pos, size_t len, std::vector<event_t>& e  	for(auto& event : *plugin.input_events)  	{ -		if(event.type !=  MidiEventType::NoteOn) +		switch(event.type)  		{ -			continue; -		} +		case MidiEventType::NoteOn: +			{ +				int i = mmap.lookup(event.key); +				if(event.velocity != 0 && (i != -1)) +				{ +					events.push_back({EventType::OnSet, (size_t)i, +					                  (size_t)event.getTime(), event.velocity / 127.0f}); +				} +			} +			break; -		int i = mmap.lookup(event.key); -		if(event.velocity && (i != -1)) -		{ -			events.push_back({EventType::OnSet, (size_t)i, (size_t)event.getTime(), event.velocity / 127.0f}); +		case MidiEventType::Aftertouch: +			{ +				int i = mmap.lookup(event.key); +				if(event.velocity == 0 && i != -1) +				{ +					events.push_back({EventType::Choke, (size_t)i, +					                  (size_t)event.getTime(), .0f}); +				} +			} +			break; + +		case MidiEventType::NoteOff: +		case MidiEventType::Unknown: +			break;  		}  	}  } diff --git a/plugin/plugingizmo b/plugin/plugingizmo -Subproject cf2311b09f788447d1c079274405477992eee9e +Subproject 34bfc5046bd297311a38dace8914c51905ca9d2 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; | 
