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/canvas.h"
23 #include "canvas/debug.h"
25 #include "tempo_lines.h"
26 #include "public_editor.h"
27 #include "rgb_macros.h"
28 #include "ui_config.h"
32 TempoLines::TempoLines (ArdourCanvas::Container* group, double, ARDOUR::BeatsFramesConverter* bfc)
33 : lines (group, ArdourCanvas::LineSet::Vertical)
36 lines.set_extent (ArdourCanvas::COORD_MAX);
39 TempoLines::~TempoLines ()
46 TempoLines::tempo_map_changed()
64 TempoLines::draw_ticks (std::vector<ARDOUR::TempoMap::BBTPoint>& grid,
66 framecnt_t leftmost_frame,
67 framecnt_t frame_rate)
69 const uint32_t base = UIConfiguration::instance().color_mod("measure line beat", "measure line beat");
71 for (unsigned l = 1; l < divisions; ++l) {
72 /* find the coarsest division level this tick falls on */
73 unsigned level = divisions;
74 for (unsigned d = divisions; d >= 4; d /= 2) {
75 if (l % (divisions / d) == 0) {
79 /* draw line with alpha corresponding to coarsest level */
80 const uint8_t a = max(8, (int)rint(UINT_RGBA_A(base) / (0.8 * log2(level))));
81 const uint32_t c = UINT_RGBA_CHANGE_A(base, a);
82 const framepos_t f = _bfc->to (Evoral::Beats (grid.begin()->qn + (l / (double) divisions)));
84 if (f > leftmost_frame) {
85 lines.add (PublicEditor::instance().sample_to_pixel_unrounded (f), 1.0, c);
91 TempoLines::draw (std::vector<ARDOUR::TempoMap::BBTPoint>& grid,
93 framecnt_t leftmost_frame,
94 framecnt_t frame_rate)
96 std::vector<ARDOUR::TempoMap::BBTPoint>::const_iterator i;
101 const uint32_t bar_color = UIConfiguration::instance().color ("measure line bar");
102 const uint32_t beat_color = UIConfiguration::instance().color_mod ("measure line beat", "measure line beat");
105 bool all_bars = false;
106 /* get the first bar spacing */
110 bars = (*i).bar - (*grid.begin()).bar;
114 if (bars < distance (grid.begin(), grid.end()) - 1) {
115 /* grid contains beats and bars */
116 beats = distance (grid.begin(), grid.end()) - bars;
118 /* grid contains only bars */
119 beats = distance (grid.begin(), grid.end());
121 if (i != grid.begin()) {
122 const int32_t last_bar = (*i).bar;
124 bar_mod = (last_bar - (*i).bar) * 4;
130 double canvas_width_used = 1.0;
131 if (leftmost_frame < grid.front().frame) {
132 const framecnt_t frame_distance = max ((framecnt_t) 1, grid.back().frame - grid.front().frame);
133 canvas_width_used = 1.0 - ((grid.front().frame - leftmost_frame) / (double) (frame_distance + grid.front().frame));
136 beat_density = (beats * 10.0f) / (lines.canvas()->width() * canvas_width_used);
138 if (beat_density > 2.0f) {
139 /* if the lines are too close together, they become useless */
144 /* constrain divisions to a log2 factor to cap line density */
145 while (divisions > 3 && beat_density * divisions > 0.4) {
150 if (beat_density <= 0.12 && grid.begin() != grid.end() && grid.begin()->frame > 0 && !all_bars) {
151 /* draw subdivisions of the beat before the first visible beat line XX this shouldn't happen now */
152 std::vector<ARDOUR::TempoMap::BBTPoint> vec;
154 draw_ticks (vec, divisions, leftmost_frame, frame_rate);
157 for (i = grid.begin(); i != grid.end(); ++i) {
160 /* keep all_bar beat density down */
161 if (all_bars && beat_density > 0.3 && ((*i).bar % bar_mod) != 1) {
167 if (beat_density > 0.3) {
168 continue; /* only draw beat lines if the gaps between beats are large. */
173 ArdourCanvas::Coord xpos = PublicEditor::instance().sample_to_pixel_unrounded ((*i).frame);
175 lines.add (xpos, 1.0, color);
177 if (beat_density <= 0.12 && !all_bars) {
178 /* draw subdivisions of this beat */
179 std::vector<ARDOUR::TempoMap::BBTPoint> vec;
181 draw_ticks (vec, divisions, leftmost_frame, frame_rate);