Highlight note in piano roll - #6510
authorRobin Gareus <robin@gareus.org>
Sat, 15 Aug 2015 01:08:55 +0000 (03:08 +0200)
committerRobin Gareus <robin@gareus.org>
Sat, 15 Aug 2015 01:08:55 +0000 (03:08 +0200)
gtk2_ardour/midi_region_view.cc
gtk2_ardour/midi_time_axis.cc
gtk2_ardour/midi_time_axis.h
gtk2_ardour/piano_roll_header.cc
gtk2_ardour/piano_roll_header.h

index 47e5510664991640a478817f41e9bd8feac063a2..917999405c9b52d4bf8859293f7166647c0edf6c 100644 (file)
@@ -485,6 +485,11 @@ MidiRegionView::leave_internal()
        if (frame_handle_end) {
                frame_handle_end->raise_to_top();
        }
+
+       MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*>(&trackview);
+       if (mtv) {
+               mtv->set_note_highlight (NO_MIDI_NOTE);
+       }
 }
 
 bool
@@ -4006,7 +4011,7 @@ MidiRegionView::show_verbose_cursor (boost::shared_ptr<NoteType> n) const
 
        std::string name;
 
-       MidiTimeAxisView* const mtv = dynamic_cast<MidiTimeAxisView*>(&trackview);
+       MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*>(&trackview);
        if (mtv) {
                boost::shared_ptr<MasterDeviceNames> device_names(mtv->get_device_names());
                if (device_names) {
@@ -4018,6 +4023,7 @@ MidiRegionView::show_verbose_cursor (boost::shared_ptr<NoteType> n) const
                                                       patch_key.program(),
                                                       n->note());
                }
+               mtv->set_note_highlight (n->note());
        }
 
        char buf[128];
index e412b82c32d10f5ef569b0d0c78b9e7ebba4eb32..53ef92c30a4430ded442e753fd8a79334bf8bd1c 100644 (file)
@@ -123,6 +123,11 @@ MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session* sess, ArdourCanva
 {
 }
 
+void
+MidiTimeAxisView::set_note_highlight (uint8_t note) {
+       _piano_roll_header->set_note_highlight (note);
+}
+
 void
 MidiTimeAxisView::set_route (boost::shared_ptr<Route> rt)
 {
index f9b81470d086cc0d1ec6899e04ab04c63e0b3f29..fb95ae94fb3bbaf35c446e968c69ab8d007ab23e 100644 (file)
@@ -68,6 +68,8 @@ class StepEntry;
 class StepEditor;
 class MidiChannelSelectorWindow;
 
+#define NO_MIDI_NOTE 0xff
+
 class MidiTimeAxisView : public RouteTimeAxisView
 {
 public:
@@ -102,6 +104,7 @@ public:
        void check_step_edit ();
 
        void first_idle ();
+       void set_note_highlight (uint8_t note);
 
        uint8_t get_channel_for_add () const;
 
index 54cc8026015744446b5df42c6b641f8a7645bb68..c6e0b94224e83d3c176895e3cc602ff57d011023 100644 (file)
 #include "midi_streamview.h"
 #include "public_editor.h"
 
-const int no_note = 0xff;
-
 using namespace std;
 using namespace Gtkmm2ext;
 
 PianoRollHeader::Color PianoRollHeader::white = PianoRollHeader::Color(0.77f, 0.78f, 0.76f);
-PianoRollHeader::Color PianoRollHeader::white_highlight = PianoRollHeader::Color(0.87f, 0.88f, 0.86f);
+PianoRollHeader::Color PianoRollHeader::white_highlight = PianoRollHeader::Color(1.00f, 0.50f, 0.50f);
 PianoRollHeader::Color PianoRollHeader::white_shade_light = PianoRollHeader::Color(0.95f, 0.95f, 0.95f);
 PianoRollHeader::Color PianoRollHeader::white_shade_dark = PianoRollHeader::Color(0.56f, 0.56f, 0.56f);
 
 PianoRollHeader::Color PianoRollHeader::black = PianoRollHeader::Color(0.24f, 0.24f, 0.24f);
-PianoRollHeader::Color PianoRollHeader::black_highlight = PianoRollHeader::Color(0.30f, 0.30f, 0.30f);
+PianoRollHeader::Color PianoRollHeader::black_highlight = PianoRollHeader::Color(0.50f, 0.10f, 0.10f);
 PianoRollHeader::Color PianoRollHeader::black_shade_light = PianoRollHeader::Color(0.46f, 0.46f, 0.46f);
 PianoRollHeader::Color PianoRollHeader::black_shade_dark = PianoRollHeader::Color(0.1f, 0.1f, 0.1f);
 
@@ -67,8 +65,8 @@ PianoRollHeader::Color::set(const PianoRollHeader::Color& c)
 
 PianoRollHeader::PianoRollHeader(MidiStreamView& v)
        : _view(v)
-       , _highlighted_note(no_note)
-       , _clicked_note(no_note)
+       , _highlighted_note(NO_MIDI_NOTE)
+       , _clicked_note(NO_MIDI_NOTE)
        , _dragging(false)
 {
        add_events (Gdk::BUTTON_PRESS_MASK |
@@ -463,9 +461,10 @@ PianoRollHeader::on_expose_event (GdkEventExpose* ev)
 bool
 PianoRollHeader::on_motion_notify_event (GdkEventMotion* ev)
 {
-       if (_dragging) {
+       int note = _view.y_to_note(ev->y);
+       set_note_highlight (note);
 
-               int note = _view.y_to_note(ev->y);
+       if (_dragging) {
 
                if ( false /*editor().current_mouse_mode() == Editing::MouseRange*/ ) {   //ToDo:  fix this.  this mode is buggy, and of questionable utility anyway
                        
@@ -476,21 +475,9 @@ PianoRollHeader::on_motion_notify_event (GdkEventMotion* ev)
                        }
 
                } else {
-                       
                        /* play notes */
-
-                       if (_highlighted_note != no_note) {
-                               if (note > _highlighted_note) {
-                                       invalidate_note_range(_highlighted_note, note);
-                               } else {
-                                       invalidate_note_range(note, _highlighted_note);
-                               }
-                               
-                               _highlighted_note = note;
-                       }
-                       
-                       /* redraw already taken care of above */
-                       if (_clicked_note != no_note && _clicked_note != note) {
+                       /* redraw already taken care of above in set_note_highlight */
+                       if (_clicked_note != NO_MIDI_NOTE && _clicked_note != note) {
                                _active_notes[_clicked_note] = false;
                                send_note_off(_clicked_note);
                                
@@ -569,12 +556,27 @@ PianoRollHeader::on_button_release_event (GdkEventButton* ev)
        return true;
 }
 
+void
+PianoRollHeader::set_note_highlight (uint8_t note) {
+       if (_highlighted_note != NO_MIDI_NOTE) {
+               if (note > _highlighted_note) {
+                       invalidate_note_range (_highlighted_note, note);
+               } else {
+                       invalidate_note_range (note, _highlighted_note);
+               }
+       }
+
+       _highlighted_note = note;
+
+       if (_highlighted_note != NO_MIDI_NOTE) {
+               invalidate_note_range (_highlighted_note, _highlighted_note);
+       }
+}
+
 bool
 PianoRollHeader::on_enter_notify_event (GdkEventCrossing* ev)
 {
-       _highlighted_note = _view.y_to_note(ev->y);
-
-       invalidate_note_range(_highlighted_note, _highlighted_note);
+       set_note_highlight (_view.y_to_note(ev->y));
        return true;
 }
 
@@ -583,11 +585,11 @@ PianoRollHeader::on_leave_notify_event (GdkEventCrossing*)
 {
        invalidate_note_range(_highlighted_note, _highlighted_note);
 
-       if (_clicked_note != no_note) {
+       if (_clicked_note != NO_MIDI_NOTE) {
                reset_clicked_note(_clicked_note, _clicked_note != _highlighted_note);
        }
 
-       _highlighted_note = no_note;
+       _highlighted_note = NO_MIDI_NOTE;
        return true;
 }
 
@@ -702,7 +704,7 @@ void
 PianoRollHeader::reset_clicked_note (uint8_t note, bool invalidate)
 {
        _active_notes[note] = false;
-       _clicked_note = no_note;
+       _clicked_note = NO_MIDI_NOTE;
        send_note_off (note);
        if (invalidate) {
                invalidate_note_range (note, note);
index bb87d36e4dd341917dc9b929a5545d18650e1d25..2dac6f42174d9caa16ebdc9a1aafc9a8602259b4 100644 (file)
@@ -48,6 +48,7 @@ public:
        void on_size_allocate(Gtk::Allocation& a);
 
        void note_range_changed();
+       void set_note_highlight (uint8_t note);
 
        struct Color {
                Color();