From dc131da53b2603189dc0fb00109b77178c971fc4 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 11 Jul 2019 22:58:27 +0200 Subject: [PATCH] Hide "Add MIDI Port" in the GUI if there is already one --- gtk2_ardour/mixer_strip.cc | 23 +++++++++++++++++++---- gtk2_ardour/port_matrix.cc | 15 +++++++++++++-- gtk2_ardour/port_matrix.h | 1 + 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/gtk2_ardour/mixer_strip.cc b/gtk2_ardour/mixer_strip.cc index 35801cbd0f..316430c7bc 100644 --- a/gtk2_ardour/mixer_strip.cc +++ b/gtk2_ardour/mixer_strip.cc @@ -934,10 +934,15 @@ MixerStrip::output_press (GdkEventButton *ev) citems.pop_back (); } - if (!ARDOUR::Profile->get_mixbus()) { - citems.push_back (SeparatorElem()); + citems.push_back (SeparatorElem()); + if (!ARDOUR::Profile->get_mixbus()) { + bool need_separator = false; for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) { + if (!_route->output()->can_add_port (*i)) { + continue; + } + need_separator = true; citems.push_back ( MenuElem ( string_compose (_("Add %1 port"), (*i).to_i18n_string()), @@ -945,9 +950,11 @@ MixerStrip::output_press (GdkEventButton *ev) ) ); } + if (need_separator) { + citems.push_back (SeparatorElem()); + } } - citems.push_back (SeparatorElem()); citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*(static_cast(this)), &RouteUI::edit_output_configuration))); Gtkmm2ext::anchored_menu_popup(&output_menu, &output_button, "", @@ -1040,7 +1047,13 @@ MixerStrip::input_press (GdkEventButton *ev) } citems.push_back (SeparatorElem()); + + bool need_separator = false; for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) { + if (!_route->input()->can_add_port (*i)) { + continue; + } + need_separator = true; citems.push_back ( MenuElem ( string_compose (_("Add %1 port"), (*i).to_i18n_string()), @@ -1048,8 +1061,10 @@ MixerStrip::input_press (GdkEventButton *ev) ) ); } + if (need_separator) { + citems.push_back (SeparatorElem()); + } - citems.push_back (SeparatorElem()); citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*(static_cast(this)), &RouteUI::edit_input_configuration))); Gtkmm2ext::anchored_menu_popup(&input_menu, &input_button, "", diff --git a/gtk2_ardour/port_matrix.cc b/gtk2_ardour/port_matrix.cc index 23e9acaf62..b5e7cb008d 100644 --- a/gtk2_ardour/port_matrix.cc +++ b/gtk2_ardour/port_matrix.cc @@ -446,7 +446,7 @@ PortMatrix::popup_menu (BundleChannel column, BundleChannel row, uint32_t t) if (can_add_channels (bc[dim].bundle)) { /* Start off with options for the `natural' port type */ for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) { - if (should_show (*i)) { + if (should_show (*i) && can_add_channel_proxy (w, *i)) { snprintf (buf, sizeof (buf), _("Add %s %s"), (*i).to_i18n_string(), channel_noun().c_str()); sub.push_back (MenuElem (buf, sigc::bind (sigc::mem_fun (*this, &PortMatrix::add_channel_proxy), w, *i))); } @@ -454,7 +454,7 @@ PortMatrix::popup_menu (BundleChannel column, BundleChannel row, uint32_t t) /* Now add other ones */ for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) { - if (!should_show (*i)) { + if (!should_show (*i) && can_add_channel_proxy (w, *i)) { snprintf (buf, sizeof (buf), _("Add %s %s"), (*i).to_i18n_string(), channel_noun().c_str()); sub.push_back (MenuElem (buf, sigc::bind (sigc::mem_fun (*this, &PortMatrix::add_channel_proxy), w, *i))); } @@ -790,6 +790,17 @@ PortMatrix::remove_all_channels (boost::weak_ptr w) } } +bool +PortMatrix::can_add_channel_proxy (boost::weak_ptr w, DataType t) const +{ + boost::shared_ptr b = w.lock (); + if (!b) { + return false; + } + boost::shared_ptr io = io_from_bundle (b); + return io->can_add_port (t); +} + void PortMatrix::add_channel_proxy (boost::weak_ptr w, DataType t) { diff --git a/gtk2_ardour/port_matrix.h b/gtk2_ardour/port_matrix.h index 09c334b5ef..5fc0bd221f 100644 --- a/gtk2_ardour/port_matrix.h +++ b/gtk2_ardour/port_matrix.h @@ -182,6 +182,7 @@ private: void routes_changed (); void reconnect_to_routes (); void select_arrangement (); + bool can_add_channel_proxy (boost::weak_ptr, ARDOUR::DataType) const; void add_channel_proxy (boost::weak_ptr, ARDOUR::DataType); void remove_channel_proxy (boost::weak_ptr, uint32_t); void rename_channel_proxy (boost::weak_ptr, uint32_t);