use Canvas::LineSet for tempolines rather than N different Canvas::Line items plus a cache

This commit is contained in:
Paul Davis 2014-06-09 15:39:57 -04:00
parent 7a3a66db72
commit c8ab1aaf7d
4 changed files with 20 additions and 48 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -19,12 +19,13 @@
#ifndef __ardour_tempo_lines_h__
#define __ardour_tempo_lines_h__
#include <list>
#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<ArdourCanvas::Line*> Lines;
Lines _lines;
Lines _cache;
ArdourCanvas::Canvas& _canvas;
ArdourCanvas::Group* _group;
ArdourCanvas::LineSet lines;
double _height;
};