2 Copyright (C) 2002-2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "pbd/compose.h"
22 #include "canvas/line.h"
23 #include "canvas/canvas.h"
24 #include "canvas/debug.h"
26 #include "tempo_lines.h"
27 #include "ardour_ui.h"
28 #include "public_editor.h"
32 TempoLines::TempoLines (ArdourCanvas::Canvas& canvas, ArdourCanvas::Group* group, double h)
40 TempoLines::tempo_map_changed()
42 /* remove all lines from the group, put them in the cache (to avoid
43 * unnecessary object destruction+construction later), and clear _lines
47 _cache.insert (_cache.end(), _lines.begin(), _lines.end());
64 TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
65 const ARDOUR::TempoMap::BBTPointList::const_iterator& end)
67 ARDOUR::TempoMap::BBTPointList::const_iterator i;
68 ArdourCanvas::Rect const visible = _canvas.visible_area ();
75 /* get the first bar spacing */
79 bars = (*i).bar - (*begin).bar;
80 beats = distance (begin, end) - bars;
82 beat_density = (beats * 10.0f) / visible.width ();
84 if (beat_density > 4.0f) {
85 /* if the lines are too close together, they become useless */
92 for (i = begin; i != end; ++i) {
95 color = ARDOUR_UI::config()->get_canvasvar_MeasureLineBar();
97 if (beat_density > 2.0) {
98 continue; /* only draw beat lines if the gaps between beats are large. */
100 color = ARDOUR_UI::config()->get_canvasvar_MeasureLineBeat();
103 ArdourCanvas::Coord xpos = PublicEditor::instance().sample_to_pixel_unrounded ((*i).frame);
105 ArdourCanvas::Line* line;
107 if (!_cache.empty()) {
108 line = _cache.back ();
110 line->reparent (_group);
112 line = new ArdourCanvas::Line (_group);
113 CANVAS_DEBUG_NAME (line, string_compose ("tempo measure line @ %1", (*i).frame));
114 line->set_ignore_events (true);
120 line->set_y1 (_height);
121 line->set_outline_color (color);