Use ArdourDropdown for MIDI device selector.
authorDavid Robillard <d@drobilla.net>
Sat, 13 Dec 2014 04:38:41 +0000 (23:38 -0500)
committerDavid Robillard <d@drobilla.net>
Sat, 13 Dec 2014 04:38:41 +0000 (23:38 -0500)
gtk2_ardour/ardour_dropdown.cc
gtk2_ardour/ardour_dropdown.h
gtk2_ardour/midi_time_axis.cc
gtk2_ardour/midi_time_axis.h

index d98a9878a340dc032c1477ac0b5592e4881bd783..cd1bfefed35ef71aa1b66675d7b8ad5b9d55f4ce 100644 (file)
@@ -69,6 +69,11 @@ ArdourDropdown::on_button_press_event (GdkEventButton*)
        return true;
 }
 
+void
+ArdourDropdown::clear_items ()
+{
+       _menu.items ().clear ();
+}
 
 void
 ArdourDropdown::AddMenuElem (Menu_Helpers::MenuElem e)
index 9d96e575f09440da3781833cfc1a61705c35fae7..b27b930037c7e10cf1eb8162194d85016f9a02f6 100644 (file)
@@ -38,10 +38,11 @@ class ArdourDropdown : public ArdourButton
 
        bool on_button_press_event (GdkEventButton*);
 
+       void clear_items ();
        void AddMenuElem (Gtk::Menu_Helpers::MenuElem e);
 
   private:
        Gtk::Menu      _menu;
 };
 
-#endif /* __gtk2_ardour_ardour_menu_h__ */
+#endif /* __gtk2_ardour_ardour_dropdown_h__ */
index f51746c1eca66da00b9126a1b3e1ff52582169e0..c2d2a36ab1b5034f85c1e1a20d947e59df91e58a 100644 (file)
@@ -270,7 +270,10 @@ MidiTimeAxisView::set_route (boost::shared_ptr<Route> rt)
 
        MIDI::Name::MasterDeviceNames::Models::const_iterator m = patch_manager.all_models().begin();
        for (; m != patch_manager.all_models().end(); ++m) {
-               _midnam_model_selector.append_text(m->c_str());
+               _midnam_model_selector.AddMenuElem(
+                       Gtk::Menu_Helpers::MenuElem(m->c_str(),
+                                                   sigc::bind(sigc::mem_fun(*this, &MidiTimeAxisView::model_changed),
+                                                              m->c_str())));
        }
 
        if (gui_property (X_("midnam-model-name")).empty()) {
@@ -285,9 +288,6 @@ MidiTimeAxisView::set_route (boost::shared_ptr<Route> rt)
                }
        }
 
-       _midnam_model_selector.set_active_text (gui_property (X_("midnam-model-name")));
-       _midnam_custom_device_mode_selector.set_active_text (gui_property (X_("midnam-custom-device-mode")));
-
        ARDOUR_UI::instance()->set_tip (_midnam_model_selector, _("External MIDI Device"));
        ARDOUR_UI::instance()->set_tip (_midnam_custom_device_mode_selector, _("External Device Mode"));
 
@@ -326,13 +326,8 @@ MidiTimeAxisView::set_route (boost::shared_ptr<Route> rt)
                _midi_controls_box.pack_start (_midnam_custom_device_mode_selector, false, false, 2);
        } 
 
-       model_changed();
-       custom_device_mode_changed();
-
-       _midnam_model_selector.signal_changed().connect(
-               sigc::mem_fun(*this, &MidiTimeAxisView::model_changed));
-       _midnam_custom_device_mode_selector.signal_changed().connect(
-               sigc::mem_fun(*this, &MidiTimeAxisView::custom_device_mode_changed));
+       model_changed(gui_property(X_("midnam-model-name")));
+       custom_device_mode_changed(gui_property(X_("midnam-custom-device-mode")));
 
        controls_vbox.pack_start(_midi_controls_box, false, false);
 
@@ -419,26 +414,35 @@ MidiTimeAxisView::check_step_edit ()
 }
 
 void
-MidiTimeAxisView::model_changed()
+MidiTimeAxisView::model_changed(const std::string& model)
 {
-       const Glib::ustring model = _midnam_model_selector.get_active_text();
        set_gui_property (X_("midnam-model-name"), model);
 
        const std::list<std::string> device_modes = MIDI::Name::MidiPatchManager::instance()
                .custom_device_mode_names_by_model(model);
 
+       _midnam_model_selector.set_text(model);
        _midnam_custom_device_mode_selector.clear_items();
 
        for (std::list<std::string>::const_iterator i = device_modes.begin();
             i != device_modes.end(); ++i) {
-               _midnam_custom_device_mode_selector.append_text(*i);
+               _midnam_custom_device_mode_selector.AddMenuElem(
+                       Gtk::Menu_Helpers::MenuElem(
+                               *i, sigc::bind(sigc::mem_fun(*this, &MidiTimeAxisView::custom_device_mode_changed),
+                                              *i)));
        }
 
-       _midnam_custom_device_mode_selector.set_active(0);
-       
-       _route->instrument_info().set_external_instrument (
-               _midnam_model_selector.get_active_text(),
-               _midnam_custom_device_mode_selector.get_active_text());
+       if (!device_modes.empty()) {
+               custom_device_mode_changed(device_modes.front());
+       }
+
+       if (device_modes.size() > 1) {
+               _midnam_custom_device_mode_selector.show();
+       } else {
+               _midnam_custom_device_mode_selector.hide();
+       }
+
+       _route->instrument_info().set_external_instrument (model, device_modes.front());
 
        // Rebuild controller menu
        _controller_menu_map.clear ();
@@ -448,12 +452,13 @@ MidiTimeAxisView::model_changed()
 }
 
 void
-MidiTimeAxisView::custom_device_mode_changed()
+MidiTimeAxisView::custom_device_mode_changed(const std::string& mode)
 {
-       const Glib::ustring mode = _midnam_custom_device_mode_selector.get_active_text();
+       const std::string model = gui_property (X_("midnam-model-name"));
+
        set_gui_property (X_("midnam-custom-device-mode"), mode);
-       _route->instrument_info().set_external_instrument (
-               _midnam_model_selector.get_active_text(), mode);
+       _midnam_custom_device_mode_selector.set_text(mode);
+       _route->instrument_info().set_external_instrument (model, mode);
 }
 
 MidiStreamView*
@@ -1119,7 +1124,7 @@ MidiTimeAxisView::show_all_automation (bool apply_to_selection)
                        boost::shared_ptr<MasterDeviceNames> device_names = get_device_names();
                        if (gui_property (X_("midnam-model-name")) != "Generic" &&
                             device_names && !device_names->controls().empty()) {
-                               const std::string device_mode       = _midnam_custom_device_mode_selector.get_active_text();
+                               const std::string device_mode       = gui_property (X_("midnam-custom-device-mode"));
                                const uint16_t    selected_channels = midi_track()->get_playback_channel_mask();
                                for (uint32_t chn = 0; chn < 16; ++chn) {
                                        if ((selected_channels & (0x0001 << chn)) == 0) {
index c99ab68851ac4cbe1d007e27acea6de431825d02..f8f77244d0b74df9a5dc2572c57221077e3107bb 100644 (file)
@@ -34,6 +34,7 @@
 #include "ardour/region.h"
 
 #include "ardour_dialog.h"
+#include "ardour_dropdown.h"
 #include "route_ui.h"
 #include "enums.h"
 #include "route_time_axis.h"
@@ -107,8 +108,8 @@ class MidiTimeAxisView : public RouteTimeAxisView
        private:
        sigc::signal<void, std::string, std::string>  _midi_patch_settings_changed;
 
-       void model_changed();
-       void custom_device_mode_changed();
+       void model_changed(const std::string& model);
+       void custom_device_mode_changed(const std::string& mode);
 
        void append_extra_display_menu_items ();
        void build_automation_action_menu (bool);
@@ -138,8 +139,8 @@ class MidiTimeAxisView : public RouteTimeAxisView
        Gtk::HBox                    _channel_status_box;
        Gtk::VBox                    _midi_controls_box;
        MidiChannelSelectorWindow*   _channel_selector;
-       Gtk::ComboBoxText            _midnam_model_selector;
-       Gtk::ComboBoxText            _midnam_custom_device_mode_selector;
+       ArdourDropdown               _midnam_model_selector;
+       ArdourDropdown               _midnam_custom_device_mode_selector;
 
        Gtk::CheckMenuItem*          _step_edit_item;
        Gtk::Menu*                    default_channel_menu;