diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc index 82faf1890c..a0bd56e04a 100644 --- a/gtk2_ardour/midi_time_axis.cc +++ b/gtk2_ardour/midi_time_axis.cc @@ -227,14 +227,8 @@ MidiTimeAxisView::set_route (boost::shared_ptr rt) } _midnam_model_selector.set_active_text (gui_property (X_("midnam-model-name"))); - model_changed(); _midnam_custom_device_mode_selector.set_active_text (gui_property (X_("midnam-custom-device-mode"))); - _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)); - ARDOUR_UI::instance()->set_tip (_midnam_model_selector, _("External MIDI Device")); ARDOUR_UI::instance()->set_tip (_midnam_custom_device_mode_selector, _("External Device Mode")); @@ -258,6 +252,15 @@ MidiTimeAxisView::set_route (boost::shared_ptr rt) _midi_controls_box.attach(_channel_selector, 0, 1, 0, 1); } + 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)); + + controls_vbox.pack_start(_midi_controls_box, false, false); // restore channel selector settings @@ -354,7 +357,7 @@ MidiTimeAxisView::model_changed() const Glib::ustring model = _midnam_model_selector.get_active_text(); set_gui_property (X_("midnam-model-name"), model); - std::list device_modes = MIDI::Name::MidiPatchManager::instance() + const std::list device_modes = MIDI::Name::MidiPatchManager::instance() .custom_device_mode_names_by_model(model); _midnam_custom_device_mode_selector.clear_items(); @@ -643,6 +646,105 @@ MidiTimeAxisView::add_channel_command_menu_item (Menu_Helpers::MenuList& items, } } +/** Add a single menu item for a controller on one channel. */ +void +MidiTimeAxisView::add_single_channel_controller_item(Menu_Helpers::MenuList& ctl_items, + int ctl, + const std::string& name) +{ + using namespace Menu_Helpers; + + const uint16_t selected_channels = _channel_selector.get_selected_channels(); + for (uint8_t chn = 0; chn < 16; chn++) { + if (selected_channels & (0x0001 << chn)) { + + Evoral::Parameter fully_qualified_param (MidiCCAutomation, chn, ctl); + ctl_items.push_back ( + CheckMenuElem ( + string_compose ("%1: %2 [%3]", ctl, name, int (chn)), + sigc::bind ( + sigc::mem_fun (*this, &RouteTimeAxisView::toggle_automation_track), + fully_qualified_param))); + dynamic_cast (ctl_items.back().get_child())->set_use_markup (true); + + boost::shared_ptr track = automation_child ( + fully_qualified_param); + + bool visible = false; + if (track) { + if (track->marked_for_display()) { + visible = true; + } + } + + CheckMenuItem* cmi = static_cast(&ctl_items.back()); + _controller_menu_map[fully_qualified_param] = cmi; + cmi->set_active (visible); + + /* one channel only */ + break; + } + } +} + +/** Add a submenu with 1 item per channel for a controller on many channels. */ +void +MidiTimeAxisView::add_multi_channel_controller_item(Menu_Helpers::MenuList& ctl_items, + int ctl, + const std::string& name) +{ + using namespace Menu_Helpers; + + const uint16_t selected_channels = _channel_selector.get_selected_channels(); + + Menu* chn_menu = manage (new Menu); + MenuList& chn_items (chn_menu->items()); + + /* add a couple of items to hide/show this controller on all channels */ + + Evoral::Parameter param_without_channel (MidiCCAutomation, 0, ctl); + chn_items.push_back ( + MenuElem (_("Hide all channels"), + sigc::bind (sigc::mem_fun (*this, &MidiTimeAxisView::change_all_channel_tracks_visibility), + false, param_without_channel))); + chn_items.push_back ( + MenuElem (_("Show all channels"), + sigc::bind (sigc::mem_fun (*this, &MidiTimeAxisView::change_all_channel_tracks_visibility), + true, param_without_channel))); + + for (uint8_t chn = 0; chn < 16; chn++) { + if (selected_channels & (0x0001 << chn)) { + + /* for each selected channel, add a menu item for this controller */ + + Evoral::Parameter fully_qualified_param (MidiCCAutomation, chn, ctl); + chn_items.push_back ( + CheckMenuElem (string_compose (_("Channel %1"), chn+1), + sigc::bind (sigc::mem_fun (*this, &RouteTimeAxisView::toggle_automation_track), + fully_qualified_param))); + + boost::shared_ptr track = automation_child ( + fully_qualified_param); + bool visible = false; + + if (track) { + if (track->marked_for_display()) { + visible = true; + } + } + + CheckMenuItem* cmi = static_cast(&chn_items.back()); + _controller_menu_map[fully_qualified_param] = cmi; + cmi->set_active (visible); + } + } + + /* add the per-channel menu to the list of controllers, with the name of the controller */ + ctl_items.push_back (MenuElem (string_compose ("%1: %2", ctl, name), + *chn_menu)); + dynamic_cast (ctl_items.back().get_child())->set_use_markup (true); +} + void MidiTimeAxisView::build_controller_menu () { @@ -680,146 +782,76 @@ MidiTimeAxisView::build_controller_menu () const Glib::ustring model = _midnam_model_selector.get_active_text(); boost::shared_ptr midnam = MidiPatchManager::instance() .document_by_model(model); - boost::shared_ptr device_names; - if (midnam && !midnam->master_device_names_by_model().empty()) { - device_names = boost::shared_ptr( - midnam->master_device_names_by_model().begin()->second); - } + boost::shared_ptr device_names = midnam->master_device_names( + model); if (device_names && !device_names->controls().empty()) { - /* Controllers names available from the midnam file, - generate a custom controller menu */ + /* Controllers names available in midnam file, generate fancy menu */ + unsigned n_items = 0; + unsigned n_groups = 0; for (MasterDeviceNames::ControlNameLists::const_iterator l = device_names->controls().begin(); l != device_names->controls().end(); ++l) { boost::shared_ptr name_list = *l; - - int chn = 0; // TODO - Menu* group_menu = manage(new Menu()); - MenuList& group_items(group_menu->items()); + Menu* ctl_menu = NULL; for (ControlNameList::Controls::const_iterator c = (*l)->controls().begin(); c != (*l)->controls().end(); ++c) { - Evoral::Parameter fully_qualified_param(MidiCCAutomation, chn, atoi((*c)->number().c_str())); - group_items.push_back( - CheckMenuElem(string_compose("%1: %2 [%3]", - (*c)->number(), (*c)->name(), int(chn)), - sigc::bind( - sigc::mem_fun(*this, &RouteTimeAxisView::toggle_automation_track), - fully_qualified_param))); - dynamic_cast (group_items.back().get_child())->set_use_markup (true); - } - items.push_back(MenuElem(name_list->name(), *group_menu)); - } - return; - } - - /* loop over all 127 MIDI controllers, in groups of 16; except don't offer - bank select controllers, as they are handled by the `patch' code */ - - for (int i = 0; i < 127; i += 16) { - - Menu* ctl_menu = manage (new Menu); - MenuList& ctl_items (ctl_menu->items()); - - /* for each controller, consider whether to create a submenu or a single item */ - - for (int ctl = i; ctl < i+16; ++ctl) { - - if (ctl == MIDI_CTL_MSB_BANK || ctl == MIDI_CTL_LSB_BANK) { - continue; - } - - if (chn_cnt > 1) { - - /* multiple channels - create a submenu, with 1 item per channel */ - - Menu* chn_menu = manage (new Menu); - MenuList& chn_items (chn_menu->items()); - - /* add a couple of items to hide/show this controller on all channels */ - - Evoral::Parameter param_without_channel (MidiCCAutomation, 0, ctl); - chn_items.push_back ( - MenuElem (_("Hide all channels"), - sigc::bind (sigc::mem_fun (*this, &MidiTimeAxisView::change_all_channel_tracks_visibility), - false, param_without_channel))); - chn_items.push_back ( - MenuElem (_("Show all channels"), - sigc::bind (sigc::mem_fun (*this, &MidiTimeAxisView::change_all_channel_tracks_visibility), - true, param_without_channel))); - - for (uint8_t chn = 0; chn < 16; chn++) { - if (selected_channels & (0x0001 << chn)) { - - /* for each selected channel, add a menu item for this controller */ - - Evoral::Parameter fully_qualified_param (MidiCCAutomation, chn, ctl); - chn_items.push_back ( - CheckMenuElem (string_compose (_("Channel %1"), chn+1), - sigc::bind (sigc::mem_fun (*this, &RouteTimeAxisView::toggle_automation_track), - fully_qualified_param))); - - boost::shared_ptr track = automation_child ( - fully_qualified_param); - bool visible = false; - - if (track) { - if (track->marked_for_display()) { - visible = true; - } - } - - CheckMenuItem* cmi = static_cast(&chn_items.back()); - _controller_menu_map[fully_qualified_param] = cmi; - cmi->set_active (visible); - } + const int ctl = atoi((*c)->number().c_str()); + if (ctl == MIDI_CTL_MSB_BANK || ctl == MIDI_CTL_LSB_BANK) { + /* Skip bank select controllers since they're handled specially */ + continue; } - /* add the per-channel menu to the list of controllers, with the name of the controller */ - ctl_items.push_back (MenuElem (string_compose ("%1: %2", ctl, midi_name (ctl)), - *chn_menu)); - dynamic_cast (ctl_items.back().get_child())->set_use_markup (true); + if (n_items == 0) { + /* Create a new submenu */ + ctl_menu = manage (new Menu); + } - } else { - - /* just one channel - create a single menu item for this ctl+channel combination */ - - for (uint8_t chn = 0; chn < 16; chn++) { - if (selected_channels & (0x0001 << chn)) { - - Evoral::Parameter fully_qualified_param (MidiCCAutomation, chn, ctl); - ctl_items.push_back ( - CheckMenuElem ( - string_compose ("%1: %2 [%3]", ctl, midi_name (ctl), int (chn)), - sigc::bind ( - sigc::mem_fun (*this, &RouteTimeAxisView::toggle_automation_track), - fully_qualified_param))); - dynamic_cast (ctl_items.back().get_child())->set_use_markup (true); - - boost::shared_ptr track = automation_child ( - fully_qualified_param); - - bool visible = false; - if (track) { - if (track->marked_for_display()) { - visible = true; - } - } - - CheckMenuItem* cmi = static_cast(&ctl_items.back()); - _controller_menu_map[fully_qualified_param] = cmi; - cmi->set_active (visible); - - /* one channel only */ - break; - } + MenuList& ctl_items (ctl_menu->items()); + if (chn_cnt > 1) { + add_multi_channel_controller_item(ctl_items, ctl, (*c)->name()); + } else { + add_single_channel_controller_item(ctl_items, ctl, (*c)->name()); + } + + if (++n_items == 16 || c == (*l)->controls().end()) { + /* Submenu has 16 items, add it to controller menu and reset */ + items.push_back( + MenuElem(string_compose(_("Controllers %1-%2"), + (16 * n_groups), (16 * n_groups) + n_items - 1), + *ctl_menu)); + ctl_menu = NULL; + n_items = 0; + ++n_groups; } } } + } else { + /* No controllers names, generate generic numeric menu */ + for (int i = 0; i < 127; i += 16) { + Menu* ctl_menu = manage (new Menu); + MenuList& ctl_items (ctl_menu->items()); - /* add the menu for this block of controllers to the overall controller menu */ + for (int ctl = i; ctl < i+16; ++ctl) { + if (ctl == MIDI_CTL_MSB_BANK || ctl == MIDI_CTL_LSB_BANK) { + /* Skip bank select controllers since they're handled specially */ + continue; + } - items.push_back (MenuElem (string_compose (_("Controllers %1-%2"), i, i+15), *ctl_menu)); + if (chn_cnt > 1) { + add_multi_channel_controller_item( + ctl_items, ctl, string_compose(_("Controller %1"), ctl)); + } else { + add_single_channel_controller_item( + ctl_items, ctl, string_compose(_("Controller %1"), ctl)); + } + } + + /* Add submenu for this block of controllers to controller menu */ + items.push_back ( + MenuElem (string_compose (_("Controllers %1-%2"), i, i + 15), + *ctl_menu)); + } } } diff --git a/gtk2_ardour/midi_time_axis.h b/gtk2_ardour/midi_time_axis.h index 10ad5f8f10..04e37913b5 100644 --- a/gtk2_ardour/midi_time_axis.h +++ b/gtk2_ardour/midi_time_axis.h @@ -143,6 +143,9 @@ class MidiTimeAxisView : public RouteTimeAxisView void add_channel_command_menu_item (Gtk::Menu_Helpers::MenuList& items, const std::string& label, ARDOUR::AutomationType auto_type, uint8_t cmd); Gtk::Menu* controller_menu; + + void add_single_channel_controller_item (Gtk::Menu_Helpers::MenuList& ctl_items, int ctl, const std::string& name); + void add_multi_channel_controller_item (Gtk::Menu_Helpers::MenuList& ctl_items, int ctl, const std::string& name); void build_controller_menu (); void set_channel_mode (ARDOUR::ChannelMode, uint16_t); diff --git a/libs/midi++2/midi++/midnam_patch.h b/libs/midi++2/midi++/midnam_patch.h index bae5241f98..a759e503dd 100644 --- a/libs/midi++2/midi++/midnam_patch.h +++ b/libs/midi++2/midi++/midnam_patch.h @@ -387,6 +387,8 @@ public: const std::string& author() const { return _author; } void set_author(const std::string an_author) { _author = an_author; } + boost::shared_ptr master_device_names(const std::string& model); + const MasterDeviceNamesList& master_device_names_by_model() const { return _master_device_names_list; } const MasterDeviceNames::Models& all_models() const { return _all_models; } diff --git a/libs/midi++2/midnam_patch.cc b/libs/midi++2/midnam_patch.cc index 1608b418b0..3509d1e021 100644 --- a/libs/midi++2/midnam_patch.cc +++ b/libs/midi++2/midnam_patch.cc @@ -216,9 +216,11 @@ ControlNameList::set_state (const XMLTree& tree, const XMLNode& node) for (XMLNodeList::const_iterator i = node.children().begin(); i != node.children().end(); ++i) { - boost::shared_ptr control(new Control()); - control->set_state (tree, *(*i)); - _controls.push_back(control); + if ((*i)->name() != "comment") { + boost::shared_ptr control(new Control()); + control->set_state (tree, *(*i)); + _controls.push_back(control); + } } return 0; @@ -646,6 +648,16 @@ MIDINameDocument::get_state(void) return nothing; } +boost::shared_ptr +MIDINameDocument::master_device_names(const std::string& model) +{ + MasterDeviceNamesList::const_iterator m = _master_device_names_list.find(model); + if (m != _master_device_names_list.end()) { + return boost::shared_ptr(m->second); + } + return boost::shared_ptr(); +} + const char* general_midi_program_names[128] = { "Acoustic Grand Piano", "Bright Acoustic Piano", diff --git a/patchfiles/Standard_Midi.midnam b/patchfiles/Standard_Midi.midnam new file mode 100644 index 0000000000..cb3b948eeb --- /dev/null +++ b/patchfiles/Standard_Midi.midnam @@ -0,0 +1,282 @@ + + + + David Robillard + + MMA + Standard MIDI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +