Clamp output of y_to_note so that it doesn't return out-of-range values. Should...
authorCarl Hetherington <carl@carlh.net>
Mon, 7 Mar 2011 17:17:11 +0000 (17:17 +0000)
committerCarl Hetherington <carl@carlh.net>
Mon, 7 Mar 2011 17:17:11 +0000 (17:17 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@9096 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/midi_streamview.cc
gtk2_ardour/midi_streamview.h

index ed60b14256480551fde8ef9a8977f0e402adf281..56e34c8a798ca0da25c9da614fe450425b3b4954 100644 (file)
@@ -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;
+}
index 0774fd61bd08385f754525eb44a9b1d4a1d83109..a939d8ea7d5e76b511784e65bfe819a339789e5a 100644 (file)
@@ -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(); }