From d604852f6785890efa033eff442f19b1419b79be Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 30 Apr 2014 10:10:31 -0400 Subject: use per-channel signals to pick up scene changes, rather than global ones --- libs/ardour/ardour/midi_scene_changer.h | 7 +++---- libs/ardour/midi_scene_change.cc | 6 +++--- libs/ardour/midi_scene_changer.cc | 32 ++++++++++---------------------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/libs/ardour/ardour/midi_scene_changer.h b/libs/ardour/ardour/midi_scene_changer.h index 2cc0464bec..369e47d9ea 100644 --- a/libs/ardour/ardour/midi_scene_changer.h +++ b/libs/ardour/ardour/midi_scene_changer.h @@ -59,12 +59,11 @@ class MIDISceneChanger : public SceneChanger void jump_to (int bank, int program); void deliver (MidiBuffer&, framepos_t, boost::shared_ptr); - void bank_change_input (MIDI::Parser&, unsigned short); - void program_change_input (MIDI::Parser&, MIDI::byte); + void bank_change_input (MIDI::Parser&, unsigned short, int channel); + void program_change_input (MIDI::Parser&, MIDI::byte, int channel); void locations_changed (Locations::Change); - PBD::ScopedConnection incoming_bank_change_connection; - PBD::ScopedConnection incoming_program_change_connection; + PBD::ScopedConnectionList incoming_connections; }; } // namespace diff --git a/libs/ardour/midi_scene_change.cc b/libs/ardour/midi_scene_change.cc index 81a74911a9..d0a14cba50 100644 --- a/libs/ardour/midi_scene_change.cc +++ b/libs/ardour/midi_scene_change.cc @@ -65,7 +65,7 @@ MIDISceneChange::get_bank_msb_message (uint8_t* buf, size_t size) const buf[0] = 0xB0 | (_channel & 0xf); buf[1] = 0x0; - buf[2] = (_bank & 0xf700) >> 8; + buf[2] = (_bank >> 7) & 0x7f; return 3; } @@ -79,7 +79,7 @@ MIDISceneChange::get_bank_lsb_message (uint8_t* buf, size_t size) const buf[0] = 0xB0 | (_channel & 0xf); buf[1] = 0x20; - buf[2] = (_bank & 0xf7); + buf[2] = _bank & 0x7f; return 3; } @@ -92,7 +92,7 @@ MIDISceneChange::get_program_message (uint8_t* buf, size_t size) const } buf[0] = 0xC0 | (_channel & 0xf); - buf[1] = _program & 0xf7; + buf[1] = _program & 0x7f; return 2; } diff --git a/libs/ardour/midi_scene_changer.cc b/libs/ardour/midi_scene_changer.cc index 49e835ca80..65503cb0c1 100644 --- a/libs/ardour/midi_scene_changer.cc +++ b/libs/ardour/midi_scene_changer.cc @@ -18,6 +18,7 @@ */ #include "evoral/MIDIEvent.hpp" +#include "midi++/channel.h" #include "midi++/parser.h" #include "midi++/port.h" @@ -147,8 +148,7 @@ MIDISceneChanger::set_input_port (MIDI::Port* mp) { input_port = mp; - incoming_bank_change_connection.disconnect (); - incoming_program_change_connection.disconnect (); + incoming_connections.drop_connections(); if (input_port) { @@ -157,8 +157,10 @@ MIDISceneChanger::set_input_port (MIDI::Port* mp) * and thus invoke our callbacks as necessary. */ - input_port->parser()->bank_change.connect_same_thread (incoming_bank_change_connection, boost::bind (&MIDISceneChanger::bank_change_input, this, _1, _2)); - input_port->parser()->program_change.connect_same_thread (incoming_program_change_connection, boost::bind (&MIDISceneChanger::program_change_input, this, _1, _2)); + for (int channel = 0; channel < 16; ++channel) { + input_port->parser()->channel_bank_change[channel].connect_same_thread (incoming_connections, boost::bind (&MIDISceneChanger::bank_change_input, this, _1, _2, channel)); + input_port->parser()->channel_program_change[channel].connect_same_thread (incoming_connections, boost::bind (&MIDISceneChanger::program_change_input, this, _1, _2, channel)); + } } } @@ -181,26 +183,24 @@ MIDISceneChanger::recording() const } void -MIDISceneChanger::bank_change_input (MIDI::Parser& parser, unsigned short bank) +MIDISceneChanger::bank_change_input (MIDI::Parser& parser, unsigned short, int) { if (!recording()) { return; } last_bank_message_time = parser.get_timestamp (); - current_bank = bank; } void -MIDISceneChanger::program_change_input (MIDI::Parser& parser, MIDI::byte program) +MIDISceneChanger::program_change_input (MIDI::Parser& parser, MIDI::byte program, int channel) { framecnt_t time = parser.get_timestamp (); - frameoffset_t delta = time - last_program_message_time; last_program_message_time = time; if (!recording()) { - jump_to (current_bank, program); + jump_to (input_port->channel (channel)->bank(), program); return; } @@ -227,19 +227,7 @@ MIDISceneChanger::program_change_input (MIDI::Parser& parser, MIDI::byte program new_mark = true; } - uint8_t bank; - uint8_t channel = (program & 0xf0) >> 8; - - /* if we received a bank change message within the last 2 msec, use the - * current bank value, otherwise lookup the current bank number and use - * that. - */ - - if (time - last_bank_message_time < (2 * _session.frame_rate() / 1000.0)) { - bank = current_bank; - } else { - bank = -1; - } + unsigned short bank = input_port->channel (channel)->bank(); MIDISceneChange* msc =new MIDISceneChange (loc->start(), channel, bank, program & 0x7f); -- cgit v1.2.3