From c8ab1aaf7da5671d6040c042a173233c3b1905a4 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 9 Jun 2014 15:39:57 -0400 Subject: use Canvas::LineSet for tempolines rather than N different Canvas::Line items plus a cache --- gtk2_ardour/editor_tempodisplay.cc | 3 ++- gtk2_ardour/midi_streamview.cc | 7 +++--- gtk2_ardour/tempo_lines.cc | 46 +++++++++----------------------------- gtk2_ardour/tempo_lines.h | 12 ++++------ 4 files changed, 20 insertions(+), 48 deletions(-) diff --git a/gtk2_ardour/editor_tempodisplay.cc b/gtk2_ardour/editor_tempodisplay.cc index 10333f1eec..fab99fc0b2 100644 --- a/gtk2_ardour/editor_tempodisplay.cc +++ b/gtk2_ardour/editor_tempodisplay.cc @@ -40,6 +40,7 @@ #include "canvas/canvas.h" #include "canvas/item.h" +#include "canvas/line_set.h" #include "editor.h" #include "marker.h" @@ -176,7 +177,7 @@ Editor::draw_measures (ARDOUR::TempoMap::BBTPointList::const_iterator& begin, } if (tempo_lines == 0) { - tempo_lines = new TempoLines (*_track_canvas, time_line_group, ArdourCanvas::COORD_MAX); + tempo_lines = new TempoLines (time_line_group, ArdourCanvas::LineSet::Vertical); } tempo_lines->draw (begin, end); diff --git a/gtk2_ardour/midi_streamview.cc b/gtk2_ardour/midi_streamview.cc index a1e1269468..04cbf8301d 100644 --- a/gtk2_ardour/midi_streamview.cc +++ b/gtk2_ardour/midi_streamview.cc @@ -74,8 +74,8 @@ MidiStreamView::MidiStreamView (MidiTimeAxisView& tv) /* put the note lines in the timeaxisview's group, so it can be put below ghost regions from MIDI underlays */ - _note_lines = new ArdourCanvas::LineSet (_canvas_group); - + _note_lines = new ArdourCanvas::LineSet (_canvas_group, ArdourCanvas::LineSet::Horizontal); + _note_lines->Event.connect( sigc::bind(sigc::mem_fun(_trackview.editor(), &PublicEditor::canvas_stream_view_event), @@ -273,7 +273,8 @@ void MidiStreamView::update_contents_height () { StreamView::update_contents_height(); - _note_lines->set_height (child_height ()); + + _note_lines->set_extent (ArdourCanvas::COORD_MAX); apply_note_range (lowest_note(), highest_note(), true); } diff --git a/gtk2_ardour/tempo_lines.cc b/gtk2_ardour/tempo_lines.cc index 917e141313..ee01da9672 100644 --- a/gtk2_ardour/tempo_lines.cc +++ b/gtk2_ardour/tempo_lines.cc @@ -19,7 +19,6 @@ #include "pbd/compose.h" -#include "canvas/line.h" #include "canvas/canvas.h" #include "canvas/debug.h" @@ -29,35 +28,28 @@ using namespace std; -TempoLines::TempoLines (ArdourCanvas::Canvas& canvas, ArdourCanvas::Group* group, double h) - : _canvas (canvas) - , _group (group) - , _height (h) +TempoLines::TempoLines (ArdourCanvas::Group* group, double) + : lines (group, ArdourCanvas::LineSet::Vertical) { + lines.set_extent (ArdourCanvas::COORD_MAX); } void TempoLines::tempo_map_changed() { - /* remove all lines from the group, put them in the cache (to avoid - * unnecessary object destruction+construction later), and clear _lines - */ - - _group->clear (); - _cache.insert (_cache.end(), _lines.begin(), _lines.end()); - _lines.clear (); + lines.clear (); } void TempoLines::show () { - _group->show (); + lines.show (); } void TempoLines::hide () { - _group->hide (); + lines.hide (); } void @@ -65,7 +57,6 @@ TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin, const ARDOUR::TempoMap::BBTPointList::const_iterator& end) { ARDOUR::TempoMap::BBTPointList::const_iterator i; - ArdourCanvas::Rect const visible = _group->window_to_item (_canvas.visible_area ()); double beat_density; uint32_t beats = 0; @@ -79,15 +70,15 @@ TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin, bars = (*i).bar - (*begin).bar; beats = distance (begin, end) - bars; - beat_density = (beats * 10.0f) / visible.width (); + beat_density = (beats * 10.0f) / lines.canvas()->width(); if (beat_density > 4.0f) { /* if the lines are too close together, they become useless */ - tempo_map_changed(); + lines.clear (); return; } - tempo_map_changed (); + lines.clear (); for (i = begin; i != end; ++i) { @@ -102,24 +93,7 @@ TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin, ArdourCanvas::Coord xpos = PublicEditor::instance().sample_to_pixel_unrounded ((*i).frame); - ArdourCanvas::Line* line; - - if (!_cache.empty()) { - line = _cache.back (); - _cache.pop_back (); - line->reparent (_group); - } else { - line = new ArdourCanvas::Line (_group); - CANVAS_DEBUG_NAME (line, string_compose ("tempo measure line @ %1", (*i).frame)); - line->set_ignore_events (true); - } - - line->set_x0 (xpos); - line->set_x1 (xpos); - line->set_y0 (0.0); - line->set_y1 (_height); - line->set_outline_color (color); - line->show (); + lines.add (xpos, 1.0, color); } } diff --git a/gtk2_ardour/tempo_lines.h b/gtk2_ardour/tempo_lines.h index 912a77aea2..e096df54af 100644 --- a/gtk2_ardour/tempo_lines.h +++ b/gtk2_ardour/tempo_lines.h @@ -19,12 +19,13 @@ #ifndef __ardour_tempo_lines_h__ #define __ardour_tempo_lines_h__ -#include #include "ardour/tempo.h" +#include "canvas/line_set.h" + class TempoLines { public: - TempoLines(ArdourCanvas::Canvas& canvas, ArdourCanvas::Group* group, double screen_height); + TempoLines (ArdourCanvas::Group* group, double screen_height); void tempo_map_changed(); @@ -35,12 +36,7 @@ public: void hide(); private: - typedef std::list Lines; - Lines _lines; - Lines _cache; - - ArdourCanvas::Canvas& _canvas; - ArdourCanvas::Group* _group; + ArdourCanvas::LineSet lines; double _height; }; -- cgit v1.2.3