diff --git a/gtk2_ardour/midi_view.cc b/gtk2_ardour/midi_view.cc index 5290648519..0ca6d1ceaf 100644 --- a/gtk2_ardour/midi_view.cc +++ b/gtk2_ardour/midi_view.cc @@ -357,6 +357,21 @@ MidiView::set_region (std::shared_ptr mr) set_model (_midi_region->midi_source (0)->model()); } +int +MidiView::pick_visible_channel () const +{ + int n = 0; + + while (n < 16) { + if (_model->channels_present() & (1 << n)) { + return n; + } + ++n; + } + + return n; +} + void MidiView::set_model (std::shared_ptr m) { @@ -374,22 +389,7 @@ MidiView::set_model (std::shared_ptr m) //set_height (trackview.current_height()); - if (_show_source) { - int n = 0; - - while (n < 16) { - if (_model->channels_present() & (1 << n)) { - set_visible_channel (n); - break; - } - ++n; - } - - if (n == 16) { - /* No channel data in model, use channel 0 (1) */ - set_visible_channel (0); - } - } + set_visible_channel (pick_visible_channel()); _model->ContentsChanged.connect (connections_requiring_model, invalidator (*this), std::bind (&MidiView::model_changed, this), gui_context()); @@ -5359,6 +5359,10 @@ MidiView::set_visibility_note_range (MidiViewBackground::VisibleNoteRange nvr, b void MidiView::set_visible_channel (int chn, bool clear_selection) { + if (!_show_source) { + return; + } + _visible_channel = chn; VisibleChannelChanged(); /* EMIT SIGNAL */ diff --git a/gtk2_ardour/midi_view.h b/gtk2_ardour/midi_view.h index 8409a26842..43665098a8 100644 --- a/gtk2_ardour/midi_view.h +++ b/gtk2_ardour/midi_view.h @@ -378,6 +378,7 @@ class MidiView : public virtual sigc::trackable, public LineMerger int visible_channel() const { return _visible_channel; } void set_visible_channel (int, bool clear_selection = true); + int pick_visible_channel () const; PBD::Signal VisibleChannelChanged; protected: diff --git a/gtk2_ardour/pianoroll.cc b/gtk2_ardour/pianoroll.cc index bbb77b2615..129714401a 100644 --- a/gtk2_ardour/pianoroll.cc +++ b/gtk2_ardour/pianoroll.cc @@ -2564,6 +2564,8 @@ Pianoroll::set_region (std::shared_ptr r) view->show_start (true); view->show_end (true); + set_visible_channel (view->pick_visible_channel()); + r->DropReferences.connect (object_connections, invalidator (*this), std::bind (&Pianoroll::unset, this, false), gui_context()); r->PropertyChanged.connect (object_connections, invalidator (*this), std::bind (&Pianoroll::region_prop_change, this, _1), gui_context());