Show correct ghost hit for percussive tracks.
authorDavid Robillard <d@drobilla.net>
Mon, 29 Dec 2014 01:23:52 +0000 (20:23 -0500)
committerDavid Robillard <d@drobilla.net>
Mon, 29 Dec 2014 01:23:52 +0000 (20:23 -0500)
gtk2_ardour/hit.cc
gtk2_ardour/hit.h
gtk2_ardour/midi_region_view.cc
gtk2_ardour/midi_region_view.h
gtk2_ardour/note_base.h

index ab47dee6e8ff7ba1d5a950e55da57f03283deb63..62d0b0baf60f6a747d21e6264e611caeeba4442e 100644 (file)
@@ -125,3 +125,9 @@ Hit::y1 () const
        /* bottom vertex */
        return _polygon->position().y + _polygon->get()[3].y;
 }
+
+void
+Hit::set_ignore_events (bool ignore)
+{
+       _polygon->set_ignore_events (ignore);
+}
index f13a0ef27c054032f8440984ca2478ed56c6b72f..d9f16db772a05d505c1b1ce503dfbeb3b98df58b 100644 (file)
@@ -54,6 +54,8 @@ public:
        void set_outline_color (uint32_t);
        void set_fill_color (uint32_t);
 
+       void set_ignore_events (bool);
+
        void move_event (double, double);
 
         /* no trimming of percussive hits */
index b690fa6649c2faeddafca8625ec61e689df478bb..514d1369206381fd8be93e0dcb92ca8054e5dd85 100644 (file)
@@ -1144,15 +1144,7 @@ MidiRegionView::redisplay_model()
                        if (!empty_when_starting && (cne = find_canvas_note (note)) != 0) {
 
                                cne->validate ();
-
-                               Note* cn;
-                               Hit* ch;
-
-                               if ((cn = dynamic_cast<Note*>(cne)) != 0) {
-                                       update_note (cn);
-                               } else if ((ch = dynamic_cast<Hit*>(cne)) != 0) {
-                                       update_hit (ch);
-                               }
+                               update_note (cne);
 
                                if (visible) {
                                        cne->show ();
@@ -1627,12 +1619,24 @@ MidiRegionView::note_in_region_range (const boost::shared_ptr<NoteType> note, bo
        return !outside;
 }
 
+void
+MidiRegionView::update_note (NoteBase* note, bool update_ghost_regions)
+{
+       Note* sus = NULL;
+       Hit*  hit = NULL;
+       if ((sus = dynamic_cast<Note*>(note))) {
+               update_sustained(sus, update_ghost_regions);
+       } else if ((hit = dynamic_cast<Hit*>(note))) {
+               update_hit(hit, update_ghost_regions);
+       }
+}
+
 /** Update a canvas note's size from its model note.
  *  @param ev Canvas note to update.
  *  @param update_ghost_regions true to update the note in any ghost regions that we have, otherwise false.
  */
 void
-MidiRegionView::update_note (Note* ev, bool update_ghost_regions)
+MidiRegionView::update_sustained (Note* ev, bool update_ghost_regions)
 {
        boost::shared_ptr<NoteType> note = ev->note();
        const double x = trackview.editor().sample_to_pixel (source_beats_to_region_frames (note->time()));
@@ -1689,7 +1693,7 @@ MidiRegionView::update_note (Note* ev, bool update_ghost_regions)
 }
 
 void
-MidiRegionView::update_hit (Hit* ev)
+MidiRegionView::update_hit (Hit* ev, bool update_ghost_regions)
 {
        boost::shared_ptr<NoteType> note = ev->note();
 
@@ -1700,6 +1704,19 @@ MidiRegionView::update_hit (Hit* ev)
 
        ev->set_position (ArdourCanvas::Duple (x, y));
        ev->set_height (diamond_size);
+
+       // Update color in case velocity has changed
+       ev->set_fill_color(ev->base_color());
+       ev->set_outline_color(ev->calculate_outline(ev->base_color(), ev->selected()));
+
+       if (update_ghost_regions) {
+               for (std::vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
+                       MidiGhostRegion* gr = dynamic_cast<MidiGhostRegion*> (*i);
+                       if (gr) {
+                               gr->update_note (ev);
+                       }
+               }
+       }
 }
 
 /** Add a MIDI note to the view (with length).
@@ -3555,7 +3572,11 @@ MidiRegionView::create_ghost_note (double x, double y)
        remove_ghost_note ();
 
        boost::shared_ptr<NoteType> g (new NoteType);
-       _ghost_note = new Note (*this, _note_group, g);
+       if (midi_view()->note_mode() == Sustained) {
+               _ghost_note = new Note (*this, _note_group, g);
+       } else {
+               _ghost_note = new Hit (*this, _note_group, 10, g);
+       }
        _ghost_note->set_ignore_events (true);
        _ghost_note->set_outline_color (0x000000aa);
        update_ghost_note (x, y);
index 1cc833c91a4a83b44c2d7357c52acc0d3dc867b0..36e198abfa7818d7776a39b87de38500548d0a2b 100644 (file)
@@ -410,7 +410,7 @@ private:
        Note**                               _active_notes;
        ArdourCanvas::Container*             _note_group;
        ARDOUR::MidiModel::NoteDiffCommand*  _note_diff_command;
-       Note*                                _ghost_note;
+       NoteBase*                            _ghost_note;
        double                               _last_ghost_x;
        double                               _last_ghost_y;
        ArdourCanvas::Rectangle*             _step_edit_cursor;
@@ -450,8 +450,10 @@ private:
        NoteBase* find_canvas_note (boost::shared_ptr<NoteType>);
        Events::iterator _optimization_iterator;
 
-       void update_note (Note *, bool update_ghost_regions = true);
-        void update_hit (Hit *);
+       void update_note (NoteBase*, bool update_ghost_regions = true);
+       void update_sustained (Note *, bool update_ghost_regions = true);
+       void update_hit (Hit *, bool update_ghost_regions = true);
+
        void create_ghost_note (double, double);
        void update_ghost_note (double, double);
 
index d426a7b59d3d278ef41175316a1c4323bf058c91..150837e193c25ba3031929dea734be38dbdfe10d 100644 (file)
@@ -41,7 +41,7 @@ namespace ArdourCanvas {
        class Text;
 }
 
-/** This manages all the event handling for any MIDI event on the canvas.
+/** Base class for canvas notes (sustained note rectangles and hit diamonds).
  *
  * This is not actually a canvas item itself to avoid the dreaded diamond
  * inheritance pattern, since various types of canvas items (Note (rect), Hit
@@ -51,7 +51,6 @@ namespace ArdourCanvas {
  * Note: Because of this, derived classes need to manually bounce events to
  * on_event, it won't happen automatically.
  */
-
 class NoteBase : public sigc::trackable
 {
   public:
@@ -91,6 +90,8 @@ class NoteBase : public sigc::trackable
        virtual void set_outline_color(uint32_t c) = 0;
        virtual void set_fill_color(uint32_t c) = 0;
 
+       virtual void set_ignore_events(bool ignore) = 0;
+
        virtual ArdourCanvas::Coord x0 () const = 0;
        virtual ArdourCanvas::Coord y0 () const = 0;
        virtual ArdourCanvas::Coord x1 () const = 0;