another round of fixing for note-to-y and y-to-note and note line setup

This commit is contained in:
Paul Davis
2025-06-09 09:29:52 -06:00
parent 658e8ad6bd
commit eefe584070
3 changed files with 7 additions and 20 deletions

View File

@@ -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<NoteType> new_note (new NoteType (chan, t, length, (uint8_t)note, velocity));
const std::shared_ptr<NoteType> new_note (new NoteType (chan, t, length, note, velocity));
if (_model->contains (new_note)) {
return;

View File

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

View File

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