From eefe584070ba0e201d26bfe40ebac1fd2d6713b6 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 9 Jun 2025 09:29:52 -0600 Subject: [PATCH] another round of fixing for note-to-y and y-to-note and note line setup --- gtk2_ardour/midi_view.cc | 4 ++-- gtk2_ardour/midi_view_background.cc | 21 ++++----------------- gtk2_ardour/midi_view_background.h | 2 +- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/gtk2_ardour/midi_view.cc b/gtk2_ardour/midi_view.cc index 5f61aede6f..5290648519 100644 --- a/gtk2_ardour/midi_view.cc +++ b/gtk2_ardour/midi_view.cc @@ -847,11 +847,11 @@ MidiView::create_note_at (timepos_t const & source_relative_start, double y, Tem Temporal::Beats t = source_relative_start.beats(); - const double note = y_to_note(y); + const int note = y_to_note(y); const uint8_t chan = get_channel_for_add (t); const uint8_t velocity = get_velocity_for_add (t); - const std::shared_ptr new_note (new NoteType (chan, t, length, (uint8_t)note, velocity)); + const std::shared_ptr new_note (new NoteType (chan, t, length, note, velocity)); if (_model->contains (new_note)) { return; diff --git a/gtk2_ardour/midi_view_background.cc b/gtk2_ardour/midi_view_background.cc index 51703dcbad..991c894b4b 100644 --- a/gtk2_ardour/midi_view_background.cc +++ b/gtk2_ardour/midi_view_background.cc @@ -110,7 +110,7 @@ MidiViewBackground::note_range_adjustment_changed() uint8_t MidiViewBackground::y_to_note (int y) const { - int const n = floor (((contents_height() - (double) y) / contents_height() * (double) ( contents_note_range() + 1))) + lowest_note(); + int const n = highest_note() - (floor ((double) y / note_height())); if (n < 0) { return 0; @@ -150,7 +150,6 @@ MidiViewBackground::setup_note_lines() return; } - double y; Gtkmm2ext::Color black = UIConfiguration::instance().color_mod ("piano roll black", "piano roll black"); Gtkmm2ext::Color white = UIConfiguration::instance().color_mod ("piano roll white", "piano roll white"); Gtkmm2ext::Color divider = UIConfiguration::instance().color ("piano roll black outline"); @@ -168,11 +167,7 @@ MidiViewBackground::setup_note_lines() */ int h = note_height(); - int ch = contents_height(); - - if (h < 1) { - return; - } + double y = 0; for (int i = highest_note(); i >= lowest_note(); --i) { @@ -180,16 +175,6 @@ MidiViewBackground::setup_note_lines() continue; } - y = note_to_y (i); - - /* if note is outside the range of our container, do not add it - * to _note_lines. - */ - - if (y + h <= 0 || y >= ch) { - continue; - } - /* add a thicker line/bar which covers the entire vertical height of this note. */ switch (i % 12) { @@ -211,6 +196,8 @@ MidiViewBackground::setup_note_lines() } _note_lines->add_rect (i, ArdourCanvas::Rect (0., y, ArdourCanvas::COORD_MAX, y + h), color); + + y += h; } } diff --git a/gtk2_ardour/midi_view_background.h b/gtk2_ardour/midi_view_background.h index 6a7b385caa..11423fd935 100644 --- a/gtk2_ardour/midi_view_background.h +++ b/gtk2_ardour/midi_view_background.h @@ -102,7 +102,7 @@ class MidiViewBackground : public virtual ViewBackground int note_to_y (uint8_t note) const { /* Note: this effectively rounds down (truncates) due to integer arithmetic */ - return contents_height() - ((note - lowest_note()) * note_height()); + return (highest_note() - note) * note_height(); } uint8_t y_to_note (int y) const;