diff options
author | David Robillard <d@drobilla.net> | 2014-12-28 20:23:52 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2014-12-28 20:23:52 -0500 |
commit | 606efb601c15fa966a3b34cbda07b2d05be8c5b0 (patch) | |
tree | 17879a763ec4dc09d01e04ac88b3995a6251f6f3 /gtk2_ardour | |
parent | 12b18da8f6f27b804b36169927ec01d688de8d2c (diff) |
Show correct ghost hit for percussive tracks.
Diffstat (limited to 'gtk2_ardour')
-rw-r--r-- | gtk2_ardour/hit.cc | 6 | ||||
-rw-r--r-- | gtk2_ardour/hit.h | 2 | ||||
-rw-r--r-- | gtk2_ardour/midi_region_view.cc | 45 | ||||
-rw-r--r-- | gtk2_ardour/midi_region_view.h | 8 | ||||
-rw-r--r-- | gtk2_ardour/note_base.h | 5 |
5 files changed, 49 insertions, 17 deletions
diff --git a/gtk2_ardour/hit.cc b/gtk2_ardour/hit.cc index ab47dee6e8..62d0b0baf6 100644 --- a/gtk2_ardour/hit.cc +++ b/gtk2_ardour/hit.cc @@ -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); +} diff --git a/gtk2_ardour/hit.h b/gtk2_ardour/hit.h index f13a0ef27c..d9f16db772 100644 --- a/gtk2_ardour/hit.h +++ b/gtk2_ardour/hit.h @@ -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 */ diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index b690fa6649..514d136920 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -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); diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index 1cc833c91a..36e198abfa 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -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); diff --git a/gtk2_ardour/note_base.h b/gtk2_ardour/note_base.h index d426a7b59d..150837e193 100644 --- a/gtk2_ardour/note_base.h +++ b/gtk2_ardour/note_base.h @@ -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; |