+void
+MidiTimeAxisView::add_channel_command_menu_item (Menu_Helpers::MenuList& items, const string& label, AutomationType auto_type, uint8_t cmd)
+{
+ using namespace Menu_Helpers;
+
+ /* count the number of selected channels because we will build a different menu structure if there is more than 1 selected.
+ */
+
+ uint16_t selected_channels = _channel_selector.get_selected_channels();
+ int chn_cnt = 0;
+
+ for (uint8_t chn = 0; chn < 16; chn++) {
+ if (selected_channels & (0x0001 << chn)) {
+ if (++chn_cnt > 1) {
+ break;
+ }
+ }
+ }
+
+ 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());
+ Evoral::Parameter param_without_channel (auto_type, 0, cmd);
+
+ /* add a couple of items to hide/show all of them */
+
+ 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 (auto_type, chn, cmd);
+ 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<AutomationTimeAxisView> track = automation_child (fully_qualified_param);
+ bool visible = false;
+
+ if (track) {
+ if (track->marked_for_display()) {
+ visible = true;
+ }
+ }
+
+ CheckMenuItem* cmi = static_cast<CheckMenuItem*>(&chn_items.back());
+ _channel_command_menu_map[fully_qualified_param] = cmi;
+ cmi->set_active (visible);
+ }
+ }
+
+ /* now create an item in the parent menu that has the per-channel list as a submenu */
+
+ items.push_back (MenuElem (label, *chn_menu));
+
+ } else {
+
+ /* just one channel - create a single menu item for this command+channel combination*/
+
+ for (uint8_t chn = 0; chn < 16; chn++) {
+ if (selected_channels & (0x0001 << chn)) {
+
+ Evoral::Parameter fully_qualified_param (auto_type, chn, cmd);
+ items.push_back (CheckMenuElem (label,
+ sigc::bind (sigc::mem_fun (*this, &RouteTimeAxisView::toggle_automation_track),
+ fully_qualified_param)));
+
+ boost::shared_ptr<AutomationTimeAxisView> track = automation_child (fully_qualified_param);
+ bool visible = false;
+
+ if (track) {
+ if (track->marked_for_display()) {
+ visible = true;
+ }
+ }
+
+ CheckMenuItem* cmi = static_cast<CheckMenuItem*>(&items.back());
+ _channel_command_menu_map[fully_qualified_param] = cmi;
+ cmi->set_active (visible);
+
+ /* one channel only */
+ break;
+ }
+ }
+ }
+}
+
+void
+MidiTimeAxisView::build_controller_menu ()
+{
+ using namespace Menu_Helpers;
+
+ if (controller_menu) {
+ /* it exists and has not been invalidated by a channel mode change, so just return it */
+ return;
+ }
+
+ controller_menu = new Menu; // explicitly managed by us
+ MenuList& items (controller_menu->items());
+
+ /* create several "top level" menu items for sets of controllers (16 at a time), and populate each one with a submenu
+ for each controller+channel combination covering the currently selected channels for this track
+ */
+
+ uint16_t selected_channels = _channel_selector.get_selected_channels();
+
+ /* count the number of selected channels because we will build a different menu structure if there is more than 1 selected.
+ */
+
+ int chn_cnt = 0;
+
+ for (uint8_t chn = 0; chn < 16; chn++) {
+ if (selected_channels & (0x0001 << chn)) {
+ if (++chn_cnt > 1) {
+ break;
+ }
+ }
+ }
+
+ /* 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<AutomationTimeAxisView> track = automation_child (fully_qualified_param);
+ bool visible = false;
+
+ if (track) {
+ if (track->marked_for_display()) {
+ visible = true;
+ }
+ }
+
+ CheckMenuItem* cmi = static_cast<CheckMenuItem*>(&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 ("<b>%1</b>: %2", ctl, midi_name (ctl)), *chn_menu));
+ dynamic_cast<Label*> (ctl_items.back().get_child())->set_use_markup (true);
+
+ } 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 (_route->describe_parameter (fully_qualified_param),
+ sigc::bind (sigc::mem_fun (*this, &RouteTimeAxisView::toggle_automation_track),
+ fully_qualified_param)));
+
+ boost::shared_ptr<AutomationTimeAxisView> track = automation_child (fully_qualified_param);
+ bool visible = false;
+
+ if (track) {
+ if (track->marked_for_display()) {
+ visible = true;
+ }
+ }
+
+ CheckMenuItem* cmi = static_cast<CheckMenuItem*>(&ctl_items.back());
+ _controller_menu_map[fully_qualified_param] = cmi;
+ cmi->set_active (visible);
+
+ /* one channel only */
+ break;
+ }
+ }
+ }
+ }
+
+ /* add the menu for this block of controllers to the overall controller menu */
+
+ items.push_back (MenuElem (string_compose (_("Controllers %1-%2"), i, i+15), *ctl_menu));
+ }