Set MIDI device mode to the first by default if unset.
authorDavid Robillard <d@drobilla.net>
Sat, 19 Jan 2013 20:15:15 +0000 (20:15 +0000)
committerDavid Robillard <d@drobilla.net>
Sat, 19 Jan 2013 20:15:15 +0000 (20:15 +0000)
Give up trying to hide mode selector when it's useless.
Fix display of program names for default mode.
Abstract out (non-crashy) MidiTimeAxisView::get_device_names().

git-svn-id: svn://localhost/ardour2/branches/3.0@13903 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/midi_region_view.cc
gtk2_ardour/midi_time_axis.cc
gtk2_ardour/midi_time_axis.h
libs/midi++2/midnam_patch.cc

index 48f942f2b54d797df85ab7053cc8d77969211c94..bfc0489d0f8e13371005ccee18eb227d8ac17bf8 100644 (file)
@@ -1232,7 +1232,7 @@ MidiRegionView::display_patch_changes_on_channel (uint8_t channel, bool active_c
                        continue;
                }
 
-               string patch_name = instrument_info().get_patch_name ((*i)->bank(), (*i)->program(), channel);
+               const string patch_name = instrument_info().get_patch_name ((*i)->bank(), (*i)->program(), channel);
                add_canvas_patch_change (*i, patch_name, active_channel);
        }
 }
index 973bbb77e57681b793f155efd4756b33c612f411..b9162cfe2b4902663145bc8b1b96813df7b2030d 100644 (file)
@@ -231,6 +231,15 @@ MidiTimeAxisView::set_route (boost::shared_ptr<Route> rt)
                set_gui_property (X_("midnam-model-name"), "Generic");
        }
 
+       if (gui_property (X_("midnam-custom-device-mode")).empty()) {
+               boost::shared_ptr<MIDI::Name::MasterDeviceNames> device_names = get_device_names(
+                       gui_property (X_("midnam-model-name")));
+               if (device_names) {
+                       set_gui_property (X_("midnam-custom-device-mode"),
+                                         *device_names->custom_device_mode_names().begin());
+               }
+       }
+
        _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")));
 
@@ -373,14 +382,9 @@ MidiTimeAxisView::model_changed()
 
        _midnam_custom_device_mode_selector.clear_items();
 
-       if (device_modes.size() < 2) {
-               _midnam_custom_device_mode_selector.hide();
-       } else {
-               _midnam_custom_device_mode_selector.show();
-               for (std::list<std::string>::const_iterator i = device_modes.begin();
-                    i != device_modes.end(); ++i) {
-                       _midnam_custom_device_mode_selector.append_text(*i);
-               }
+       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.set_active(0);
@@ -756,6 +760,19 @@ MidiTimeAxisView::add_multi_channel_controller_item(Menu_Helpers::MenuList& ctl_
        dynamic_cast<Label*> (ctl_items.back().get_child())->set_use_markup (true);
 }
 
+boost::shared_ptr<MIDI::Name::MasterDeviceNames>
+MidiTimeAxisView::get_device_names(const std::string& model)
+{
+       using namespace MIDI::Name;
+       boost::shared_ptr<MIDINameDocument> midnam = MidiPatchManager::instance()
+               .document_by_model(model);
+       if (midnam) {
+               return midnam->master_device_names(model);
+       } else {
+               return boost::shared_ptr<MasterDeviceNames>();
+       }
+}
+
 void
 MidiTimeAxisView::build_controller_menu ()
 {
@@ -790,15 +807,9 @@ MidiTimeAxisView::build_controller_menu ()
        }
 
        using namespace MIDI::Name;
-       const Glib::ustring model = _midnam_model_selector.get_active_text();
-       boost::shared_ptr<MIDINameDocument> midnam = MidiPatchManager::instance()
-               .document_by_model(model);
-       boost::shared_ptr<MasterDeviceNames> device_names;
+       boost::shared_ptr<MasterDeviceNames> device_names = get_device_names(
+               _midnam_model_selector.get_active_text());
 
-       if (midnam) {
-               device_names = midnam->master_device_names(model);
-       }
-       
        if (device_names && !device_names->controls().empty()) {
                /* Controllers names available in midnam file, generate fancy menu */
                unsigned n_items  = 0;
index 04e37913b5a49b85a3c41c68f60c760dabacbc4a..635d529d34a94439ac1c0cfede8d64bc7f9199ee 100644 (file)
@@ -111,6 +111,8 @@ class MidiTimeAxisView : public RouteTimeAxisView
        void build_automation_action_menu (bool);
        Gtk::Menu* build_note_mode_menu();
        Gtk::Menu* build_color_mode_menu();
+       
+       boost::shared_ptr<MIDI::Name::MasterDeviceNames> get_device_names(const std::string& model);
 
        void set_note_mode (ARDOUR::NoteMode mode, bool apply_to_selection = false);
        void set_color_mode (ARDOUR::ColorMode, bool force = false, bool redisplay = true, bool apply_to_selection = false);
index 82fc579d1a6026b8ed5b3a969c9b1bdd03aa6560..39238114c7ca2e75dd40c35548a25a47037991ce 100644 (file)
@@ -453,8 +453,6 @@ CustomDeviceMode::get_state(void)
 boost::shared_ptr<CustomDeviceMode> 
 MasterDeviceNames::custom_device_mode_by_name(std::string mode_name)
 {
-       // can't assert this, since in many of the patch files the mode name is empty
-       //assert(mode_name != "");
        return _custom_device_modes[mode_name];
 }