summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Fischer <corrados@users.noreply.github.com>2021-08-08 17:27:03 +0200
committerVolker Fischer <corrados@users.noreply.github.com>2021-08-08 17:27:03 +0200
commit4f24f595207ffca61292af8e0d343b5ba1b35e44 (patch)
treeaeb03f72811e50533c910b7a82fd0930fbe8556e
parentd4d0011d3833d979b44f2116a628b10bb75b64a4 (diff)
proof of concept of using varying choke times of open hi-hat to support continuous hi-hat pedal changes
-rw-r--r--src/audioinputenginemidi.cc31
-rw-r--r--src/inputprocessor.cc23
2 files changed, 48 insertions, 6 deletions
diff --git a/src/audioinputenginemidi.cc b/src/audioinputenginemidi.cc
index 00b6569..503a5c3 100644
--- a/src/audioinputenginemidi.cc
+++ b/src/audioinputenginemidi.cc
@@ -108,6 +108,11 @@ static const std::uint8_t TypeMask = 0xF0;
// See:
// https://www.midi.org/specifications-old/item/table-1-summary-of-midi-message
+
+// TODO better implementation: use member variable for controller value, set MIDI key on command line
+int hihat_controller = 0; // open hi-hat
+int hihat_midi_key = 26;
+
void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer,
std::size_t midi_buffer_length,
std::size_t offset,
@@ -135,6 +140,18 @@ void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer,
auto centered_velocity = (velocity-.5f)/127.0f;
events.push_back({ EventType::OnSet, (std::size_t)instrument_idx,
offset, centered_velocity, positional_information });
+
+// quick hack, add 1000000 to offset to transport hi-hat controller value
+auto instrument_idx1 = mmap.lookup(hihat_midi_key);
+if(instrument_idx == instrument_idx1)
+{
+ if(hihat_controller < 100) // quick hack: hard-coded value
+ {
+ events.push_back({ EventType::Choke, (std::size_t)instrument_idx,
+ 1000000 + hihat_controller, .0f, .0f });
+ }
+}
+
}
}
break;
@@ -164,6 +181,20 @@ void AudioInputEngineMidi::processNote(const std::uint8_t* midi_buffer,
// Return here to prevent reset of cached positional information.
return;
}
+
+ if(controller_number == 4) // hi-hat pedal
+ {
+
+// quick hack: if hi-hat control pedal is down, choke hi-hat instrument
+auto instrument_idx = mmap.lookup(hihat_midi_key);
+hihat_controller = value;
+if(value > 100 && instrument_idx != -1) // quick hack: hard-coded value
+{
+ events.push_back({ EventType::Choke, (std::size_t)instrument_idx,
+ offset, .0f, .0f });
+}
+
+ }
}
break;
diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc
index d8a7ff9..285daaa 100644
--- a/src/inputprocessor.cc
+++ b/src/inputprocessor.cc
@@ -168,8 +168,8 @@ static void applyChokeGroup(Settings& settings, DrumKit& kit,
for(auto& event_sample : events_ds.iterateOver<SampleEvent>(ch.num))
{
if(event_sample.group == instr.getGroup() &&
- event_sample.instrument_id != instrument_id &&
- event_sample.rampdown_count == -1) // Only if not already ramping.
+ 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
applyChoke(settings, event_sample, 68, event.offset);
@@ -190,8 +190,8 @@ static void applyDirectedChoke(Settings& settings, DrumKit& kit,
{
for(auto& event_sample : events_ds.iterateOver<SampleEvent>(ch.num))
{
- if(choke.instrument_id == event_sample.instrument_id &&
- event_sample.rampdown_count == -1) // Only if not already ramping.
+ if(choke.instrument_id == event_sample.instrument_id /*&&
+ event_sample.rampdown_count == -1*/) // Only if not already ramping.
{
// choke.choketime is in ms
applyChoke(settings, event_sample, choke.choketime, event.offset);
@@ -355,11 +355,22 @@ bool InputProcessor::processChoke(event_t& event,
{
for(auto& event_sample : events_ds.iterateOver<SampleEvent>(ch.num))
{
- if(event_sample.instrument_id == instrument_id &&
- event_sample.rampdown_count == -1) // Only if not already ramping.
+ 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
+
+// quick hack: all "Only if not already ramping" must be disabled for hi-hat pedal to work
+if(event.offset >= 1000000) // quick hack: added 1000000 to offset to transport hi-hat controller value
+{
+ int hihat_controller = event.offset - 1000000;
+ int rampdown_time = static_cast<int>(std::max(100.0, pow(10.0, (127.0 - hihat_controller) / 38.0))); // TODO optimize
+ applyChoke(settings, event_sample, rampdown_time, 0);
+}
+else
+{
applyChoke(settings, event_sample, 68, event.offset);
+}
}
}
}