diff --git a/gtk2_ardour/midi_view.cc b/gtk2_ardour/midi_view.cc index 8c1661b2e0..d0518311f5 100644 --- a/gtk2_ardour/midi_view.cc +++ b/gtk2_ardour/midi_view.cc @@ -1151,27 +1151,21 @@ MidiView::model_changed() NoteBase* cne; - if (_midi_context.visibility_range_style() == MidiViewBackground::ContentsRange) { - - uint8_t low_note = std::numeric_limits::max(); - uint8_t hi_note = std::numeric_limits::min(); - - for (MidiModel::Notes::iterator n = notes.begin(); n != notes.end(); ++n) { - if ((*n)->note() < low_note) { - low_note = (*n)->note(); - } - if ((*n)->note() > hi_note) { - hi_note = (*n)->note(); - } - } + uint8_t low_note = std::numeric_limits::max(); + uint8_t hi_note = std::numeric_limits::min(); + if (!notes.empty()) { + low_note = _model->lowest_note (); + hi_note = _model->highest_note (); + } else { /* Pick a reasonable default range if the model is mepty */ + low_note = UIConfiguration::instance().get_default_lower_midi_note(); + hi_note = UIConfiguration::instance().get_default_upper_midi_note(); + } - if (notes.empty()) { - low_note = UIConfiguration::instance().get_default_lower_midi_note(); - hi_note = UIConfiguration::instance().get_default_upper_midi_note(); - } + _midi_context.update_data_note_range (low_note, hi_note); + if (_midi_context.visibility_range_style() == MidiViewBackground::ContentsRange) { maybe_set_note_range (low_note, hi_note); } @@ -1755,8 +1749,8 @@ MidiView::note_in_region_range (const std::shared_ptr note, bool& visi const std::shared_ptr midi_reg = midi_region(); const bool outside = !note_in_region_time_range (note); - - visible = (note->note() >= _midi_context.lowest_note()) && (note->note() <= _midi_context.highest_note()); + const int y = _midi_context.note_to_y (note->note()); + visible = (y >= 0) && (y <= _midi_context.contents_height()); return !outside; } @@ -1931,7 +1925,7 @@ MidiView::region_update_sustained (Note *ev, double& x0, double& x1, double& y0, x1 = std::max(1., _editing_context.duration_to_pixels (_midi_region->length())); } - y1 = y0 + std::max(1., floor(note_height()) - 1); + y1 = std::min ((double) _midi_context.contents_height(), y0 + std::max(1., floor(note_height()) - 1)); } diff --git a/gtk2_ardour/midi_view_background.cc b/gtk2_ardour/midi_view_background.cc index 6fa63d4769..91a3a18404 100644 --- a/gtk2_ardour/midi_view_background.cc +++ b/gtk2_ardour/midi_view_background.cc @@ -275,10 +275,20 @@ MidiViewBackground::apply_note_range (uint8_t lowest, uint8_t highest, bool to_c float uiscale = UIConfiguration::instance().get_ui_scale(); - int const range = _highest_note - _lowest_note; - int nh = std::max (5, std::min ((int) (UIConfiguration::instance().get_max_note_height() * uiscale), (int) ceil ((double) contents_height() / range))); + int range = _highest_note - _lowest_note; + int apparent_note_height = (int) ceil ((double) contents_height() / range); + int nh = std::min ((int) (UIConfiguration::instance().get_max_note_height() * uiscale), apparent_note_height); int additional_notes = 0; + if (nh < 3) { + /* range does not fit, so center on the data range */ + nh = 3; + range = _data_note_max - _data_note_min; + int center = _data_note_min + (range /2); + highest = center + ((contents_height() / nh) / 2); + lowest = center - ((contents_height() / nh) / 2); + } + if (note_range_set) { /* how many notes do we need to add or remove to adequately * fill contents_height() with note lines? @@ -360,6 +370,7 @@ bool MidiViewBackground::update_data_note_range (uint8_t min, uint8_t max) { bool dirty = false; + if (min < _data_note_min) { _data_note_min = min; dirty = true; diff --git a/gtk2_ardour/midi_view_background.h b/gtk2_ardour/midi_view_background.h index 36501344bd..e9ea7bf576 100644 --- a/gtk2_ardour/midi_view_background.h +++ b/gtk2_ardour/midi_view_background.h @@ -137,6 +137,8 @@ class MidiViewBackground : public virtual ViewBackground sigc::signal NoteVisibilityShouldChange; + bool update_data_note_range (uint8_t min, uint8_t max); + protected: EditingContext& _editing_context; bool _range_dirty; @@ -156,7 +158,6 @@ class MidiViewBackground : public virtual ViewBackground void parameter_changed (std::string const &); void note_range_adjustment_changed(); void setup_note_lines(); - bool update_data_note_range (uint8_t min, uint8_t max); void update_contents_height (); virtual void apply_note_range_to_children () = 0; virtual bool updates_suspended() const { return false; }