better handling of MidiView::apply_note_range()

In particular, keep the MidiViewBackground's sense of the data range intact,
use MidiModel::{highest,lowest}_note(), center ranges that don't fit
on the data range
This commit is contained in:
Paul Davis 2025-07-01 17:31:35 -06:00
parent 6a4f4e4710
commit 5767c8f62e
3 changed files with 29 additions and 23 deletions

View file

@ -1151,27 +1151,21 @@ MidiView::model_changed()
NoteBase* cne;
if (_midi_context.visibility_range_style() == MidiViewBackground::ContentsRange) {
uint8_t low_note = std::numeric_limits<uint8_t>::max();
uint8_t hi_note = std::numeric_limits<uint8_t>::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();
}
}
if (!notes.empty()) {
low_note = _model->lowest_note ();
hi_note = _model->highest_note ();
} else {
/* Pick a reasonable default range if the model is mepty */
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<NoteType> note, bool& visi
const std::shared_ptr<ARDOUR::MidiRegion> 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));
}

View file

@ -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;

View file

@ -137,6 +137,8 @@ class MidiViewBackground : public virtual ViewBackground
sigc::signal<void,bool> 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; }