From e64486acfad5c366f33d13ccd9b1303e0767fbe9 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 7 Mar 2011 17:17:11 +0000 Subject: [PATCH] Clamp output of y_to_note so that it doesn't return out-of-range values. Should fix #3823. git-svn-id: svn://localhost/ardour2/branches/3.0@9096 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/midi_streamview.cc | 14 ++++++++++++++ gtk2_ardour/midi_streamview.h | 5 +---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/gtk2_ardour/midi_streamview.cc b/gtk2_ardour/midi_streamview.cc index ed60b14256..56e34c8a79 100644 --- a/gtk2_ardour/midi_streamview.cc +++ b/gtk2_ardour/midi_streamview.cc @@ -628,3 +628,17 @@ MidiStreamView::update_rec_box () mrv->extend_active_notes (); } +uint8_t +MidiStreamView::y_to_note (double y) const +{ + int const n = ((contents_height() - y - 1) / contents_height() * (double)contents_note_range()) + + lowest_note(); + + if (n < 0) { + return 0; + } else if (n > 127) { + return 127; + } + + return n; +} diff --git a/gtk2_ardour/midi_streamview.h b/gtk2_ardour/midi_streamview.h index 0774fd61bd..a939d8ea7d 100644 --- a/gtk2_ardour/midi_streamview.h +++ b/gtk2_ardour/midi_streamview.h @@ -83,10 +83,7 @@ class MidiStreamView : public StreamView { return contents_height() - (note + 1 - lowest_note()) * note_height() + 1; } - inline uint8_t y_to_note(double y) const - { return (uint8_t)((contents_height() - y - 1) - / contents_height() * (double)contents_note_range()) - + lowest_note(); } + uint8_t y_to_note(double y) const; inline double note_height() const { return contents_height() / (double)contents_note_range(); }