use Canvas::LineSet for tempolines rather than N different Canvas::Line items plus a cache
This commit is contained in:
parent
7a3a66db72
commit
c8ab1aaf7d
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
#include "canvas/canvas.h"
|
#include "canvas/canvas.h"
|
||||||
#include "canvas/item.h"
|
#include "canvas/item.h"
|
||||||
|
#include "canvas/line_set.h"
|
||||||
|
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
#include "marker.h"
|
#include "marker.h"
|
||||||
|
@ -176,7 +177,7 @@ Editor::draw_measures (ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tempo_lines == 0) {
|
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);
|
tempo_lines->draw (begin, end);
|
||||||
|
|
|
@ -74,8 +74,8 @@ MidiStreamView::MidiStreamView (MidiTimeAxisView& tv)
|
||||||
/* put the note lines in the timeaxisview's group, so it
|
/* put the note lines in the timeaxisview's group, so it
|
||||||
can be put below ghost regions from MIDI underlays
|
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(
|
_note_lines->Event.connect(
|
||||||
sigc::bind(sigc::mem_fun(_trackview.editor(),
|
sigc::bind(sigc::mem_fun(_trackview.editor(),
|
||||||
&PublicEditor::canvas_stream_view_event),
|
&PublicEditor::canvas_stream_view_event),
|
||||||
|
@ -273,7 +273,8 @@ void
|
||||||
MidiStreamView::update_contents_height ()
|
MidiStreamView::update_contents_height ()
|
||||||
{
|
{
|
||||||
StreamView::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);
|
apply_note_range (lowest_note(), highest_note(), true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
#include "pbd/compose.h"
|
#include "pbd/compose.h"
|
||||||
|
|
||||||
#include "canvas/line.h"
|
|
||||||
#include "canvas/canvas.h"
|
#include "canvas/canvas.h"
|
||||||
#include "canvas/debug.h"
|
#include "canvas/debug.h"
|
||||||
|
|
||||||
|
@ -29,35 +28,28 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
TempoLines::TempoLines (ArdourCanvas::Canvas& canvas, ArdourCanvas::Group* group, double h)
|
TempoLines::TempoLines (ArdourCanvas::Group* group, double)
|
||||||
: _canvas (canvas)
|
: lines (group, ArdourCanvas::LineSet::Vertical)
|
||||||
, _group (group)
|
|
||||||
, _height (h)
|
|
||||||
{
|
{
|
||||||
|
lines.set_extent (ArdourCanvas::COORD_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TempoLines::tempo_map_changed()
|
TempoLines::tempo_map_changed()
|
||||||
{
|
{
|
||||||
/* remove all lines from the group, put them in the cache (to avoid
|
lines.clear ();
|
||||||
* unnecessary object destruction+construction later), and clear _lines
|
|
||||||
*/
|
|
||||||
|
|
||||||
_group->clear ();
|
|
||||||
_cache.insert (_cache.end(), _lines.begin(), _lines.end());
|
|
||||||
_lines.clear ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TempoLines::show ()
|
TempoLines::show ()
|
||||||
{
|
{
|
||||||
_group->show ();
|
lines.show ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TempoLines::hide ()
|
TempoLines::hide ()
|
||||||
{
|
{
|
||||||
_group->hide ();
|
lines.hide ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -65,7 +57,6 @@ TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
|
||||||
const ARDOUR::TempoMap::BBTPointList::const_iterator& end)
|
const ARDOUR::TempoMap::BBTPointList::const_iterator& end)
|
||||||
{
|
{
|
||||||
ARDOUR::TempoMap::BBTPointList::const_iterator i;
|
ARDOUR::TempoMap::BBTPointList::const_iterator i;
|
||||||
ArdourCanvas::Rect const visible = _group->window_to_item (_canvas.visible_area ());
|
|
||||||
double beat_density;
|
double beat_density;
|
||||||
|
|
||||||
uint32_t beats = 0;
|
uint32_t beats = 0;
|
||||||
|
@ -79,15 +70,15 @@ TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
|
||||||
bars = (*i).bar - (*begin).bar;
|
bars = (*i).bar - (*begin).bar;
|
||||||
beats = distance (begin, end) - bars;
|
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 (beat_density > 4.0f) {
|
||||||
/* if the lines are too close together, they become useless */
|
/* if the lines are too close together, they become useless */
|
||||||
tempo_map_changed();
|
lines.clear ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tempo_map_changed ();
|
lines.clear ();
|
||||||
|
|
||||||
for (i = begin; i != end; ++i) {
|
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::Coord xpos = PublicEditor::instance().sample_to_pixel_unrounded ((*i).frame);
|
||||||
|
|
||||||
ArdourCanvas::Line* line;
|
lines.add (xpos, 1.0, color);
|
||||||
|
|
||||||
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 ();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,12 +19,13 @@
|
||||||
#ifndef __ardour_tempo_lines_h__
|
#ifndef __ardour_tempo_lines_h__
|
||||||
#define __ardour_tempo_lines_h__
|
#define __ardour_tempo_lines_h__
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include "ardour/tempo.h"
|
#include "ardour/tempo.h"
|
||||||
|
|
||||||
|
#include "canvas/line_set.h"
|
||||||
|
|
||||||
class TempoLines {
|
class TempoLines {
|
||||||
public:
|
public:
|
||||||
TempoLines(ArdourCanvas::Canvas& canvas, ArdourCanvas::Group* group, double screen_height);
|
TempoLines (ArdourCanvas::Group* group, double screen_height);
|
||||||
|
|
||||||
void tempo_map_changed();
|
void tempo_map_changed();
|
||||||
|
|
||||||
|
@ -35,12 +36,7 @@ public:
|
||||||
void hide();
|
void hide();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::list<ArdourCanvas::Line*> Lines;
|
ArdourCanvas::LineSet lines;
|
||||||
Lines _lines;
|
|
||||||
Lines _cache;
|
|
||||||
|
|
||||||
ArdourCanvas::Canvas& _canvas;
|
|
||||||
ArdourCanvas::Group* _group;
|
|
||||||
double _height;
|
double _height;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user