use new TrackingText for verbose cursor
[ardour.git] / gtk2_ardour / midi_region_view.cc
index a1ae03f253f3a5d62f7261a65e52971d49484357..a738b3c0c47236c2b862cd464abdabab5087a4d1 100644 (file)
@@ -44,6 +44,7 @@
 #include "evoral/midi_util.h"
 
 #include "canvas/debug.h"
+#include "canvas/text.h"
 
 #include "automation_region_view.h"
 #include "automation_time_axis.h"
@@ -68,7 +69,6 @@
 #include "rgb_macros.h"
 #include "selection.h"
 #include "streamview.h"
-#include "utils.h"
 #include "patch_change_dialog.h"
 #include "verbose_cursor.h"
 #include "ardour_ui.h"
@@ -88,13 +88,13 @@ PBD::Signal1<void, MidiRegionView *> MidiRegionView::SelectionCleared;
 
 #define MIDI_BP_ZERO ((Config->get_first_midi_bank_is_zero())?0:1)
 
-MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv,
-                                boost::shared_ptr<MidiRegion> r, double spu, Gdk::Color const & basic_color)
+MidiRegionView::MidiRegionView (ArdourCanvas::Container *parent, RouteTimeAxisView &tv,
+                                boost::shared_ptr<MidiRegion> r, double spu, uint32_t basic_color)
        : RegionView (parent, tv, r, spu, basic_color)
        , _current_range_min(0)
        , _current_range_max(0)
        , _active_notes(0)
-       , _note_group (new ArdourCanvas::Group (group))
+       , _note_group (new ArdourCanvas::Container (group))
        , _note_diff_command (0)
        , _ghost_note(0)
        , _step_edit_cursor (0)
@@ -124,14 +124,14 @@ MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &
        SelectionCleared.connect (_selection_cleared_connection, invalidator (*this), boost::bind (&MidiRegionView::selection_cleared, this, _1), gui_context ());
 }
 
-MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv,
-                                boost::shared_ptr<MidiRegion> r, double spu, Gdk::Color& basic_color,
+MidiRegionView::MidiRegionView (ArdourCanvas::Container *parent, RouteTimeAxisView &tv,
+                                boost::shared_ptr<MidiRegion> r, double spu, uint32_t basic_color,
                                 TimeAxisViewItem::Visibility visibility)
        : RegionView (parent, tv, r, spu, basic_color, false, visibility)
        , _current_range_min(0)
        , _current_range_max(0)
        , _active_notes(0)
-       , _note_group (new ArdourCanvas::Group (parent))
+       , _note_group (new ArdourCanvas::Container (parent))
        , _note_diff_command (0)
        , _ghost_note(0)
        , _step_edit_cursor (0)
@@ -164,7 +164,7 @@ MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &
 void
 MidiRegionView::parameter_changed (std::string const & p)
 {
-       if (p == "diplay-first-midi-bank-as-zero") {
+       if (p == "display-first-midi-bank-as-zero") {
                if (_enable_display) {
                        redisplay_model();
                }
@@ -177,7 +177,7 @@ MidiRegionView::MidiRegionView (const MidiRegionView& other)
        , _current_range_min(0)
        , _current_range_max(0)
        , _active_notes(0)
-       , _note_group (new ArdourCanvas::Group (get_canvas_group()))
+       , _note_group (new ArdourCanvas::Container (get_canvas_group()))
        , _note_diff_command (0)
        , _ghost_note(0)
        , _step_edit_cursor (0)
@@ -197,13 +197,7 @@ MidiRegionView::MidiRegionView (const MidiRegionView& other)
        , pre_press_cursor (0)
        , _note_player (0)
 {
-       Gdk::Color c;
-       int r,g,b,a;
-
-       UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
-       c.set_rgb_p (r/255.0, g/255.0, b/255.0);
-
-       init (c, false);
+       init (false);
 }
 
 MidiRegionView::MidiRegionView (const MidiRegionView& other, boost::shared_ptr<MidiRegion> region)
@@ -211,7 +205,7 @@ MidiRegionView::MidiRegionView (const MidiRegionView& other, boost::shared_ptr<M
        , _current_range_min(0)
        , _current_range_max(0)
        , _active_notes(0)
-       , _note_group (new ArdourCanvas::Group (get_canvas_group()))
+       , _note_group (new ArdourCanvas::Container (get_canvas_group()))
        , _note_diff_command (0)
        , _ghost_note(0)
        , _step_edit_cursor (0)
@@ -231,17 +225,11 @@ MidiRegionView::MidiRegionView (const MidiRegionView& other, boost::shared_ptr<M
        , pre_press_cursor (0)
        , _note_player (0)
 {
-       Gdk::Color c;
-       int r,g,b,a;
-
-       UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
-       c.set_rgb_p (r/255.0, g/255.0, b/255.0);
-
-       init (c, true);
+       init (true);
 }
 
 void
-MidiRegionView::init (Gdk::Color const & basic_color, bool wfd)
+MidiRegionView::init (bool wfd)
 {
        PublicEditor::DropDownKeys.connect (sigc::mem_fun (*this, &MidiRegionView::drop_down_keys));
 
@@ -256,9 +244,7 @@ MidiRegionView::init (Gdk::Color const & basic_color, bool wfd)
        _model = midi_region()->midi_source(0)->model();
        _enable_display = false;
 
-       RegionView::init (basic_color, false);
-
-       compute_colors (basic_color);
+       RegionView::init (false);
 
        set_height (trackview.current_height());
 
@@ -650,9 +636,13 @@ MidiRegionView::motion (GdkEventMotion* ev)
 
        default:
                break;
+
        }
 
-       return false;
+       /* we may be dragging some non-note object (eg. patch-change, sysex) 
+        */
+
+       return editor.drags()->motion_handler ((GdkEvent *) ev, false);
 }
 
 
@@ -1111,7 +1101,7 @@ MidiRegionView::redisplay_model()
        MidiModel::Notes& notes (_model->notes());
        _optimization_iterator = _events.begin();
 
-       bool empty_when_starting = !_events.empty();
+       bool empty_when_starting = _events.empty();
 
        for (MidiModel::Notes::iterator n = notes.begin(); n != notes.end(); ++n) {
 
@@ -1120,8 +1110,8 @@ MidiRegionView::redisplay_model()
                bool visible;
 
                if (note_in_region_range (note, visible)) {
-
-                       if (empty_when_starting && (cne = find_canvas_note (note)) != 0) {
+                       
+                       if (!empty_when_starting && (cne = find_canvas_note (note)) != 0) {
 
                                cne->validate ();
 
@@ -1146,8 +1136,8 @@ MidiRegionView::redisplay_model()
                        }
 
                } else {
-
-                       if (empty_when_starting && (cne = find_canvas_note (note)) != 0) {
+                       
+                       if (!empty_when_starting && (cne = find_canvas_note (note)) != 0) {
                                cne->validate ();
                                cne->hide ();
                        }
@@ -1157,7 +1147,7 @@ MidiRegionView::redisplay_model()
 
        /* remove note items that are no longer valid */
 
-       if (empty_when_starting) {
+       if (!empty_when_starting) {
                for (Events::iterator i = _events.begin(); i != _events.end(); ) {
                        if (!(*i)->valid ()) {
                                
@@ -1372,14 +1362,12 @@ MidiRegionView::reset_width_dependent_items (double pixel_width)
 void
 MidiRegionView::set_height (double height)
 {
-       static const double FUDGE = 2.0;
-       const double old_height = _height;
+       double old_height = _height;
        RegionView::set_height(height);
-       _height = height - FUDGE;
 
-       apply_note_range(midi_stream_view()->lowest_note(),
-                        midi_stream_view()->highest_note(),
-                        height != old_height + FUDGE);
+       apply_note_range (midi_stream_view()->lowest_note(),
+                         midi_stream_view()->highest_note(),
+                         height != old_height);
 
        if (name_text) {
                name_text->raise_to_top();
@@ -1432,10 +1420,7 @@ MidiRegionView::apply_note_range (uint8_t min, uint8_t max, bool force)
                        cnote->set_y1 (y1);
 
                } else if (Hit* chit = dynamic_cast<Hit*>(event)) {
-
-                       const double diamond_size = update_hit (chit);
-
-                       chit->set_height (diamond_size);
+                       update_hit (chit);
                }
        }
 }
@@ -1519,8 +1504,9 @@ MidiRegionView::resolve_note(uint8_t note, double end_time)
                const framepos_t end_time_frames = region_beats_to_region_frames(end_time);
 
                _active_notes[note]->set_x1 (trackview.editor().sample_to_pixel(end_time_frames));
-               _active_notes[note]->set_outline_what (0xf);
+               _active_notes[note]->set_outline_all ();
                _active_notes[note] = 0;
+
        }
 }
 
@@ -1650,15 +1636,18 @@ MidiRegionView::update_note (Note* ev, bool update_ghost_regions)
                                Note* const old_rect = _active_notes[note->note()];
                                boost::shared_ptr<NoteType> old_note = old_rect->note();
                                old_rect->set_x1 (x);
-                               old_rect->set_outline_what (0xF);
+                               old_rect->set_outline_all ();
                        }
                        _active_notes[note->note()] = ev;
                }
                /* outline all but right edge */
-               ev->set_outline_what (0x1 & 0x4 & 0x8);
+               ev->set_outline_what (ArdourCanvas::Rectangle::What (
+                                             ArdourCanvas::Rectangle::TOP|
+                                             ArdourCanvas::Rectangle::LEFT|
+                                             ArdourCanvas::Rectangle::BOTTOM));
        } else {
                /* outline all edges */
-               ev->set_outline_what (0xF);
+               ev->set_outline_all ();
        }
        
        if (update_ghost_regions) {
@@ -1671,19 +1660,18 @@ MidiRegionView::update_note (Note* ev, bool update_ghost_regions)
        }
 }
 
-double
+void
 MidiRegionView::update_hit (Hit* ev)
 {
        boost::shared_ptr<NoteType> note = ev->note();
 
        const framepos_t note_start_frames = source_beats_to_region_frames(note->time());
        const double x = trackview.editor().sample_to_pixel(note_start_frames);
-       const double diamond_size = midi_stream_view()->note_height() / 2.0;
-       const double y = midi_stream_view()->note_to_y(note->note()) + ((diamond_size-2) / 4.0);
+       const double diamond_size = midi_stream_view()->note_height();
+       const double y = midi_stream_view()->note_to_y(note->note()) + (diamond_size/2.0);
 
        ev->set_position (ArdourCanvas::Duple (x, y));
-
-       return diamond_size;
+       ev->set_height (diamond_size);
 }
 
 /** Add a MIDI note to the view (with length).
@@ -1697,8 +1685,6 @@ MidiRegionView::add_note(const boost::shared_ptr<NoteType> note, bool visible)
 {
        NoteBase* event = 0;
 
-       //ArdourCanvas::Group* const group = (ArdourCanvas::Group*) get_canvas_group();
-
        if (midi_view()->note_mode() == Sustained) {
 
                Note* ev_rect = new Note (*this, _note_group, note);
@@ -3624,7 +3610,7 @@ void
 MidiRegionView::show_step_edit_cursor (Evoral::MusicalTime pos)
 {
        if (_step_edit_cursor == 0) {
-               ArdourCanvas::Group* const group = (ArdourCanvas::Group*)get_canvas_group();
+               ArdourCanvas::Item* const group = get_canvas_group();
 
                _step_edit_cursor = new ArdourCanvas::Rectangle (group);
                _step_edit_cursor->set_y0 (0);
@@ -3739,7 +3725,7 @@ MidiRegionView::trim_front_starting ()
        /* Reparent the note group to the region view's parent, so that it doesn't change
           when the region view is trimmed.
        */
-       _temporary_note_group = new ArdourCanvas::Group (group->parent ());
+       _temporary_note_group = new ArdourCanvas::Container (group->parent ());
        _temporary_note_group->move (group->position ());
        _note_group->reparent (_temporary_note_group);
 }
@@ -3824,28 +3810,9 @@ MidiRegionView::show_verbose_cursor (boost::shared_ptr<NoteType> n) const
 void
 MidiRegionView::show_verbose_cursor (string const & text, double xoffset, double yoffset) const
 {
-       double wx, wy;
-
-       trackview.editor().verbose_cursor()->set_text (text);
-       trackview.editor().get_pointer_position (wx, wy);
-
-       wx += xoffset;
-       wy += yoffset;
-
-       /* Flip the cursor above the mouse pointer if it would overlap the bottom of the canvas */
-
-       boost::optional<ArdourCanvas::Rect> bbo = trackview.editor().verbose_cursor()->item().bounding_box();
-
-       assert (bbo);
-       
-       ArdourCanvas::Rect bb = bbo.get();
-
-       if ((wy + bb.y1 - bb.y0) > trackview.editor().visible_canvas_height()) {
-               wy -= (bb.y1 - bb.y0) + 2 * yoffset;
-       }
-
-       trackview.editor().verbose_cursor()->set_position (wx, wy);
+       trackview.editor().verbose_cursor()->set (text);
        trackview.editor().verbose_cursor()->show ();
+       trackview.editor().verbose_cursor()->set_offset (ArdourCanvas::Duple (xoffset, yoffset));
 }
 
 /** @param p A session framepos.