From 169296862737c16107e2d4855234946869c75739 Mon Sep 17 00:00:00 2001 From: nick_m Date: Sun, 16 Oct 2016 03:11:05 +1100 Subject: Slightly improve note update performance, fix note resizing for non-4.0 meter divisors. --- gtk2_ardour/ghostregion.cc | 37 ++++++++++++++++++++++--------------- gtk2_ardour/ghostregion.h | 3 ++- gtk2_ardour/midi_region_view.cc | 29 +++++++++++++++-------------- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/gtk2_ardour/ghostregion.cc b/gtk2_ardour/ghostregion.cc index ef0e020dcf..1936609e8a 100644 --- a/gtk2_ardour/ghostregion.cc +++ b/gtk2_ardour/ghostregion.cc @@ -375,28 +375,35 @@ MidiGhostRegion::clear_events() * @param parent The CanvasNote from the parent MidiRegionView. */ void -MidiGhostRegion::update_note (NoteBase* parent) +MidiGhostRegion::update_note (Note* note) { - GhostEvent* ev = find_event (parent); + GhostEvent* ev = find_event (note); if (!ev) { return; } - Note* note = NULL; ArdourCanvas::Rectangle* rect = NULL; - Hit* hit = NULL; + if ((rect = dynamic_cast(ev->item))) { + rect->set (ArdourCanvas::Rect (note->x0(), rect->y0(), note->x1(), rect->y1())); + } +} +/** Update the x positions of our representation of a parent's hit. + * @param hit The CanvasHit from the parent MidiRegionView. + */ +void +MidiGhostRegion::update_hit (Hit* hit) +{ + GhostEvent* ev = find_event (hit); + if (!ev) { + return; + } + ArdourCanvas::Polygon* poly = NULL; - if ((note = dynamic_cast(parent))) { - if ((rect = dynamic_cast(ev->item))) { - rect->set (ArdourCanvas::Rect (parent->x0(), rect->y0(), parent->x1(), rect->y1())); - } - } else if ((hit = dynamic_cast(parent))) { - if ((poly = dynamic_cast(ev->item))) { - ArdourCanvas::Duple ppos = hit->position(); - ArdourCanvas::Duple gpos = poly->position(); - gpos.x = ppos.x; - poly->set_position(gpos); - } + if ((poly = dynamic_cast(ev->item))) { + ArdourCanvas::Duple ppos = hit->position(); + ArdourCanvas::Duple gpos = poly->position(); + gpos.x = ppos.x; + poly->set_position(gpos); } } diff --git a/gtk2_ardour/ghostregion.h b/gtk2_ardour/ghostregion.h index 152d34a64b..cf3146be44 100644 --- a/gtk2_ardour/ghostregion.h +++ b/gtk2_ardour/ghostregion.h @@ -109,7 +109,8 @@ public: void update_range(); void add_note(NoteBase*); - void update_note (NoteBase*); + void update_note (Note*); + void update_hit (Hit*); void remove_note (NoteBase*); void clear_events(); diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 60a6630451..7ed7244435 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -1704,8 +1704,10 @@ MidiRegionView::update_sustained (Note* ev, bool update_ghost_regions) TempoMap& map (trackview.session()->tempo_map()); const boost::shared_ptr mr = midi_region(); boost::shared_ptr note = ev->note(); - const double qn_note_time = note->time().to_double() + ((_region->pulse() * 4.0) - mr->start_beats()); - const framepos_t note_start_frames = map.frame_at_quarter_note (qn_note_time) - _region->position(); + + const double session_source_start = (_region->pulse() * 4.0) - mr->start_beats(); + const framepos_t note_start_frames = map.frame_at_quarter_note (note->time().to_double() + session_source_start) - _region->position(); + const double x0 = trackview.editor().sample_to_pixel (note_start_frames); double x1; const double y0 = 1 + floor(midi_stream_view()->note_to_y(note->note())); @@ -1715,13 +1717,12 @@ MidiRegionView::update_sustained (Note* ev, bool update_ghost_regions) if (note->length() > 0) { double note_end_time = note->end_time().to_double(); - if (note->end_time() > mr->start_beats() + mr->length_beats()) { + if (note_end_time > mr->start_beats() + mr->length_beats()) { note_end_time = mr->start_beats() + mr->length_beats(); } - const double session_qn_start = (_region->pulse() * 4.0) - mr->start_beats(); - const double quarter_note_end_time = session_qn_start + note_end_time; - const framepos_t note_end_frames = map.frame_at_quarter_note (quarter_note_end_time) - _region->position(); + const framepos_t note_end_frames = map.frame_at_quarter_note (session_source_start + note_end_time) - _region->position(); + x1 = std::max(1., trackview.editor().sample_to_pixel (note_end_frames)) - 1; } else { x1 = std::max(1., trackview.editor().sample_to_pixel (_region->length())) - 1; @@ -1729,8 +1730,7 @@ MidiRegionView::update_sustained (Note* ev, bool update_ghost_regions) y1 = y0 + std::max(1., floor(midi_stream_view()->note_height()) - 1); - ArdourCanvas::Rect rect (x0, y0, x1, y1); - ev->set (rect); + ev->set (ArdourCanvas::Rect (x0, y0, x1, y1)); if (!note->length()) { if (_active_notes && note->note() < 128) { @@ -1791,14 +1791,15 @@ MidiRegionView::update_hit (Hit* ev, bool update_ghost_regions) 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())); + const uint32_t base_col = ev->base_color(); + ev->set_fill_color(base_col); + ev->set_outline_color(ev->calculate_outline(base_col, ev->selected())); if (update_ghost_regions) { for (std::vector::iterator i = ghosts.begin(); i != ghosts.end(); ++i) { MidiGhostRegion* gr = dynamic_cast (*i); if (gr) { - gr->update_note (ev); + gr->update_hit (ev); } } } @@ -2914,9 +2915,9 @@ MidiRegionView::commit_resizing (NoteBase* primary, bool at_front, double delta_ } /* and then to beats */ - const double e_baf = tmap.exact_beat_at_frame (current_fr + midi_region()->position(), divisions); - const double quarter_note_start_beat = tmap.quarter_note_at_beat (_region->beat() - midi_region()->start_beats()); - const Evoral::Beats x_beats = Evoral::Beats (tmap.quarter_note_at_beat (e_baf) - quarter_note_start_beat); + const double e_qaf = tmap.exact_qn_at_frame (current_fr + midi_region()->position(), divisions); + const double quarter_note_start = (_region->pulse() * 4.0) - midi_region()->start_beats(); + const Evoral::Beats x_beats = Evoral::Beats (e_qaf - quarter_note_start); if (at_front && x_beats < canvas_note->note()->end_time()) { note_diff_add_change (canvas_note, MidiModel::NoteDiffCommand::StartTime, x_beats - (sign * snap_delta_beats)); -- cgit v1.2.3