From 41b2de41d69c2ecc381867e502e4760267275425 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 7 Dec 2015 12:02:42 -0500 Subject: change API for accessing session MIDI ports so that (1) boost::shared_ptr<> is used all the time (2) we avoid using multiple functions to return different subclass versions of some ports --- libs/ardour/midi_scene_changer.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'libs/ardour/midi_scene_changer.cc') diff --git a/libs/ardour/midi_scene_changer.cc b/libs/ardour/midi_scene_changer.cc index f586206ba7..7f6c865922 100644 --- a/libs/ardour/midi_scene_changer.cc +++ b/libs/ardour/midi_scene_changer.cc @@ -226,13 +226,16 @@ MIDISceneChanger::locate (framepos_t pos) } void -MIDISceneChanger::set_input_port (MIDI::Port* mp) +MIDISceneChanger::set_input_port (boost::shared_ptr mp) { - input_port = mp; - incoming_connections.drop_connections(); + input_port.reset (); + + boost::shared_ptr async = boost::dynamic_pointer_cast (mp); + + if (async) { - if (input_port) { + input_port = mp; /* midi port is asynchronous. MIDI parsing will be carried out * by the MIDI UI thread which will emit the relevant signals @@ -240,8 +243,8 @@ MIDISceneChanger::set_input_port (MIDI::Port* mp) */ 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)); + async->parser()->channel_bank_change[channel].connect_same_thread (incoming_connections, boost::bind (&MIDISceneChanger::bank_change_input, this, _1, _2, channel)); + async->parser()->channel_program_change[channel].connect_same_thread (incoming_connections, boost::bind (&MIDISceneChanger::program_change_input, this, _1, _2, channel)); } } } @@ -286,7 +289,7 @@ MIDISceneChanger::program_change_input (MIDI::Parser& parser, MIDI::byte program int bank = -1; if (have_seen_bank_changes) { - bank = input_port->channel (channel)->bank(); + bank = boost::dynamic_pointer_cast(input_port)->channel (channel)->bank(); } jump_to (bank, program); @@ -317,7 +320,7 @@ MIDISceneChanger::program_change_input (MIDI::Parser& parser, MIDI::byte program int bank = -1; if (have_seen_bank_changes) { - bank = input_port->channel (channel)->bank(); + bank = boost::dynamic_pointer_cast(input_port)->channel (channel)->bank(); } MIDISceneChange* msc =new MIDISceneChange (channel, bank, program & 0x7f); -- cgit v1.2.3