From 9ad82787a13eb4d7cb107ae5e2f595e0cb6c0ef3 Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Fri, 4 Feb 2022 20:31:21 -0600 Subject: [PATCH] Instrument Selector: use a 3-way Disposition to disambiguate the uses of this widget --- gtk2_ardour/add_route_dialog.cc | 1 + gtk2_ardour/editor_canvas.cc | 2 +- gtk2_ardour/instrument_selector.cc | 14 ++++++++++---- gtk2_ardour/instrument_selector.h | 12 ++++++++++-- gtk2_ardour/recorder_ui.cc | 2 +- gtk2_ardour/sfdb_ui.cc | 2 +- gtk2_ardour/trigger_page.cc | 2 +- 7 files changed, 25 insertions(+), 10 deletions(-) diff --git a/gtk2_ardour/add_route_dialog.cc b/gtk2_ardour/add_route_dialog.cc index 71fa844658..0300465dfa 100644 --- a/gtk2_ardour/add_route_dialog.cc +++ b/gtk2_ardour/add_route_dialog.cc @@ -81,6 +81,7 @@ AddRouteDialog::AddRouteDialog () , mode_label (_("Record Mode:")) , instrument_label (_("Instrument:")) , last_route_count (1) + , instrument_combo (InstrumentSelector::ForTrackSelector) , route_count_set_by_template (false) , name_edited_by_user (false) { diff --git a/gtk2_ardour/editor_canvas.cc b/gtk2_ardour/editor_canvas.cc index 83ec521fce..9fd010a6de 100644 --- a/gtk2_ardour/editor_canvas.cc +++ b/gtk2_ardour/editor_canvas.cc @@ -432,7 +432,7 @@ Editor::drop_paths_part_two (const vector& paths, timepos_t const & p, d /* drop onto canvas background: create new tracks */ - InstrumentSelector is; // instantiation builds instrument-list and sets default. + InstrumentSelector is(InstrumentSelector::ForTrackDefault); // instantiation builds instrument-list and sets default. do_import (midi_paths, Editing::ImportDistinctFiles, ImportAsTrack, SrcBest, SMFTrackNumber, SMFTempoIgnore, pos, is.selected_instrument(), false); if (UIConfiguration::instance().get_only_copy_imported_files() || copy) { diff --git a/gtk2_ardour/instrument_selector.cc b/gtk2_ardour/instrument_selector.cc index 2b44ecd296..aad1e2c2ae 100644 --- a/gtk2_ardour/instrument_selector.cc +++ b/gtk2_ardour/instrument_selector.cc @@ -29,10 +29,10 @@ using namespace Gtk; using namespace ARDOUR; -InstrumentSelector::InstrumentSelector (bool allow_none) +InstrumentSelector::InstrumentSelector (InstrumentListDisposition disp) : _reasonable_synth_id (0) , _gmsynth_id (UINT32_MAX) - , _allow_none (allow_none) + , _disposition (disp) { refill (); @@ -122,17 +122,23 @@ InstrumentSelector::build_instrument_list() _instrument_list = ListStore::create(_instrument_list_columns); - if (_allow_none) { + if (_disposition==ForTrackSelector) { TreeModel::Row row = *(_instrument_list->append()); row[_instrument_list_columns.info_ptr] = PluginInfoPtr(); row[_instrument_list_columns.name] = _("-none-"); } - uint32_t n = _allow_none ? 1 : 0; + _longest_instrument_name = ""; + + uint32_t n = (_disposition==ForTrackSelector) ? 1 : 0; std::string prev; for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i, ++n) { PluginInfoPtr p = *i; + if (p->name.length() > _longest_instrument_name.length()) { + _longest_instrument_name = p->name; + } + std::string suffix; #ifdef MIXBUS diff --git a/gtk2_ardour/instrument_selector.h b/gtk2_ardour/instrument_selector.h index 15906b50df..d2e180c614 100644 --- a/gtk2_ardour/instrument_selector.h +++ b/gtk2_ardour/instrument_selector.h @@ -39,7 +39,13 @@ class Editor; class InstrumentSelector : public Gtk::ComboBox { public: - InstrumentSelector (bool allow_none = true); + enum InstrumentListDisposition { + ForAuditioner, /* this will always return some synth, never 'None' */ + ForTrackDefault, /* functionally same as ForAuditioner, but for tracks */ + ForTrackSelector /* this provides the 'None' option so the user can add a synth later */ + }; + + InstrumentSelector (InstrumentListDisposition); ARDOUR::PluginInfoPtr selected_instrument () const; std::string selected_instrument_name () const; @@ -57,11 +63,13 @@ private: void build_instrument_list(); void refill(); + std::string _longest_instrument_name; + Glib::RefPtr _instrument_list; InstrumentListColumns _instrument_list_columns; uint32_t _reasonable_synth_id; uint32_t _gmsynth_id; - bool _allow_none; + InstrumentListDisposition _disposition; PBD::ScopedConnection _update_connection; }; diff --git a/gtk2_ardour/recorder_ui.cc b/gtk2_ardour/recorder_ui.cc index a928dcefe6..959d9356c9 100644 --- a/gtk2_ardour/recorder_ui.cc +++ b/gtk2_ardour/recorder_ui.cc @@ -1094,7 +1094,7 @@ RecorderUI::new_track_for_port (DataType dt, string const& port_name) ArdourDialog d (_("Create track for input"), true, false); Entry track_name_entry; - InstrumentSelector instrument_combo; + InstrumentSelector instrument_combo(InstrumentSelector::ForTrackDefault); ComboBoxText strict_io_combo; string pn = AudioEngine::instance()->get_pretty_name_by_name (port_name); diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc index e2617f134f..64574a4d2b 100644 --- a/gtk2_ardour/sfdb_ui.cc +++ b/gtk2_ardour/sfdb_ui.cc @@ -1757,7 +1757,7 @@ SoundFileOmega::SoundFileOmega (string title, ARDOUR::Session* s, bool persistent, Editing::ImportMode mode_hint) : SoundFileBrowser (title, s, persistent) - , instrument_combo (false) + , instrument_combo (InstrumentSelector::ForTrackSelector) , copy_files_btn ( _("Copy files to session")) , smf_tempo_btn (_("Use MIDI Tempo Map (if defined)")) , smf_marker_btn (_("Import MIDI markers (if any)")) diff --git a/gtk2_ardour/trigger_page.cc b/gtk2_ardour/trigger_page.cc index 1288e21902..c738002348 100644 --- a/gtk2_ardour/trigger_page.cc +++ b/gtk2_ardour/trigger_page.cc @@ -742,7 +742,7 @@ TriggerPage::drop_paths_part_two (std::vector paths) audio_paths.push_back (*s); } } - InstrumentSelector is; // instantiation builds instrument-list and sets default. + InstrumentSelector is(InstrumentSelector::ForTrackDefault); // instantiation builds instrument-list and sets default. timepos_t pos (0); Editing::ImportDisposition disposition = Editing::ImportSerializeFiles; // or Editing::ImportDistinctFiles // TODO use drop modifier? config? PublicEditor::instance().do_import (midi_paths, disposition, Editing::ImportAsTrigger, SrcBest, SMFTrackNumber, SMFTempoIgnore, pos, is.selected_instrument (), false);