diff options
author | David Robillard <d@drobilla.net> | 2015-01-07 19:05:21 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2015-01-07 19:05:41 -0500 |
commit | 84412e1367b2432aadb6ce996b6c15d2846aadca (patch) | |
tree | 922194bb5005d24569b506974a4a0313fd43e2c7 /gtk2_ardour/tempo_lines.cc | |
parent | 04bbe402b030017476bc774af0e940bcd99f35b0 (diff) |
Draw beat sudivisions according to snap setting.
Diffstat (limited to 'gtk2_ardour/tempo_lines.cc')
-rw-r--r-- | gtk2_ardour/tempo_lines.cc | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/gtk2_ardour/tempo_lines.cc b/gtk2_ardour/tempo_lines.cc index cb3eebbaa8..354814604c 100644 --- a/gtk2_ardour/tempo_lines.cc +++ b/gtk2_ardour/tempo_lines.cc @@ -53,39 +53,14 @@ TempoLines::hide () lines.hide (); } -static uint8_t -tick_alpha(uint8_t base_alpha, unsigned divisions) -{ - if (divisions == 32) { - return std::max(0, base_alpha / 5); - } else if (divisions == 16) { - return std::max(0, base_alpha / 4); - } else if (divisions == 8) { - return std::max(0, base_alpha / 3); - } else if (divisions == 4) { - return std::max(0, base_alpha / 2); - } - return 0; -} - void TempoLines::draw_ticks (const ARDOUR::TempoMap::BBTPointList::const_iterator& b, - double beat_density, + unsigned divisions, framecnt_t leftmost_frame, framecnt_t frame_rate) { - const double fpb = b->tempo->frames_per_beat(frame_rate); - const uint32_t base = ARDOUR_UI::config()->color_mod("measure line beat", "measure line beat"); - unsigned divisions = 4; - if (beat_density < 0.01) { - divisions = 32; - } else if (beat_density < 0.025) { - divisions = 16; - } else if (beat_density < 0.05) { - divisions = 8; - } else if (beat_density < 0.1) { - divisions = 4; - } + const double fpb = b->tempo->frames_per_beat(frame_rate); + const uint32_t base = ARDOUR_UI::config()->color_mod("measure line beat", "measure line beat"); for (unsigned l = 1; l < divisions; ++l) { /* find the coarsest division level this tick falls on */ @@ -97,7 +72,8 @@ TempoLines::draw_ticks (const ARDOUR::TempoMap::BBTPointList::const_iterator& b, } /* draw line with alpha corresponding to coarsest level */ - const uint32_t c = UINT_RGBA_CHANGE_A(base, tick_alpha(UINT_RGBA_A(base), level)); + const uint8_t a = max(0, (int)rint(UINT_RGBA_A(base) / log2(level))); + const uint32_t c = UINT_RGBA_CHANGE_A(base, a); const framepos_t f = b->frame + (l * (fpb / (double)divisions)); if (f > leftmost_frame) { lines.add (PublicEditor::instance().sample_to_pixel_unrounded (f), 1.0, c); @@ -108,6 +84,7 @@ TempoLines::draw_ticks (const ARDOUR::TempoMap::BBTPointList::const_iterator& b, void TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin, const ARDOUR::TempoMap::BBTPointList::const_iterator& end, + unsigned divisions, framecnt_t leftmost_frame, framecnt_t frame_rate) { @@ -133,13 +110,18 @@ TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin, return; } + /* constrain divisions to a log2 factor to cap line density */ + while (divisions > 3 && beat_density * divisions > 0.4) { + divisions /= 2; + } + lines.clear (); if (beat_density < 0.1 && begin != end && begin->frame > 0) { /* draw subdivisions of the beat before the first visible beat line */ ARDOUR::TempoMap::BBTPointList::const_iterator prev = begin; --prev; - draw_ticks(prev, beat_density, leftmost_frame, frame_rate); + draw_ticks(prev, divisions, leftmost_frame, frame_rate); } for (i = begin; i != end; ++i) { @@ -159,7 +141,7 @@ TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin, if (beat_density < 0.1) { /* draw subdivisions of this beat */ - draw_ticks(i, beat_density, leftmost_frame, frame_rate); + draw_ticks(i, divisions, leftmost_frame, frame_rate); } } } |