triggerbox: add MIDITrigger channel mapping

This commit is contained in:
Paul Davis
2022-02-03 12:37:49 -07:00
parent ead02f50b1
commit bce4eb36ad
2 changed files with 42 additions and 0 deletions

View File

@@ -501,6 +501,11 @@ class LIBARDOUR_API MIDITrigger : public Trigger {
void unset_all_patch_changes ();
bool patch_change_set (uint8_t channel) const;
void set_channel_map (int channel, int target);
void unset_channel_map (int channel);
int channel_map (int channel);
std::vector<int> const & channel_map() const { return _channel_map; }
protected:
void retrigger ();
@@ -520,6 +525,7 @@ class LIBARDOUR_API MIDITrigger : public Trigger {
boost::shared_ptr<MidiModel> model;
Evoral::PatchChange<MidiBuffer::TimeType> _patch_change[16];
std::vector<int> _channel_map;
int load_data (boost::shared_ptr<MidiRegion>);
void compute_and_set_length ();

View File

@@ -1706,12 +1706,44 @@ MIDITrigger::MIDITrigger (uint32_t n, TriggerBox& b)
{
Evoral::PatchChange<MidiBuffer::TimeType> pc (0, 0, 12, 0);
set_patch_change (pc);
_channel_map.assign (16, -1);
}
MIDITrigger::~MIDITrigger ()
{
}
void
MIDITrigger::set_channel_map (int channel, int target)
{
if (channel < 0 || channel >= 16) {
return;
}
if (target < 0 || target >= 16) {
return;
}
_channel_map[channel] = target;
}
void
MIDITrigger::unset_channel_map (int channel)
{
if (channel < 0 || channel >= 16) {
return;
}
_channel_map[channel] = -1;
}
int
MIDITrigger::channel_map (int channel)
{
if (channel < 0 || channel >= 16) {
return -1;
}
return _channel_map[channel];
}
void
MIDITrigger::set_patch_change (Evoral::PatchChange<MidiBuffer::TimeType> const & pc)
{
@@ -2124,6 +2156,10 @@ MIDITrigger::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sam
ev.scale_velocity (_gain);
}
if (_channel_map[ev.channel()] > 0) {
ev.set_channel (_channel_map[ev.channel()]);
}
if (ev.is_pgm_change() || (ev.is_cc() && ((ev.cc_number() == MIDI_CTL_LSB_BANK) || (ev.cc_number() == MIDI_CTL_MSB_BANK)))) {
if (_patch_change[ev.channel()].is_set()) {
/* skip pgm change info in data because trigger has its own */