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 "canvas/line.h"
21 #include "canvas/canvas.h"
22 #include "canvas/debug.h"
23 #include "tempo_lines.h"
24 #include "ardour_ui.h"
28 TempoLines::TempoLines (ArdourCanvas::Canvas& canvas, ArdourCanvas::Group* group, double screen_height)
31 , _height (screen_height)
36 TempoLines::tempo_map_changed()
38 /* remove all lines from the group, put them in the cache (to avoid
39 * unnecessary object destruction+construction later), and clear _lines
43 _cache.insert (_cache.end(), _lines.begin(), _lines.end());
50 for (Lines::iterator i = _lines.begin(); i != _lines.end(); ++i) {
58 for (Lines::iterator i = _lines.begin(); i != _lines.end(); ++i) {
64 TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
65 const ARDOUR::TempoMap::BBTPointList::const_iterator& end,
66 double samples_per_pixel)
68 ARDOUR::TempoMap::BBTPointList::const_iterator i;
69 ArdourCanvas::Rect const visible = _canvas.visible_area ();
76 /* get the first bar spacing */
80 bars = (*i).bar - (*begin).bar;
81 beats = distance (begin, end) - bars;
83 beat_density = (beats * 10.0f) / visible.width ();
85 if (beat_density > 4.0f) {
86 /* if the lines are too close together, they become useless */
93 for (i = begin; i != end; ++i) {
96 color = ARDOUR_UI::config()->get_canvasvar_MeasureLineBar();
98 if (beat_density > 2.0) {
99 continue; /* only draw beat lines if the gaps between beats are large. */
101 color = ARDOUR_UI::config()->get_canvasvar_MeasureLineBeat();
104 ArdourCanvas::Coord xpos = rint(((framepos_t)(*i).frame) / (double)samples_per_pixel);
106 ArdourCanvas::Line* line;
108 if (!_cache.empty()) {
109 line = _cache.back ();
111 line->reparent (_group);
113 line = new ArdourCanvas::Line (_group);
119 line->set_y1 (_height);
120 line->set_outline_color (color);