#include "editor_cursors.h"
#include "ui_config.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
using namespace ARDOUR;
using namespace PBD;
}
void
-Editor::update_tempo_based_rulers (std::vector<TempoMap::BBTPoint>& grid)
+Editor::update_tempo_based_rulers ()
{
if (_session == 0) {
return;
}
- compute_bbt_ruler_scale (grid, leftmost_frame, leftmost_frame+current_page_samples());
-
_bbt_metric->units_per_pixel = samples_per_pixel;
if (ruler_bbt_action->get_active()) {
mark.position = pos;
marks.push_back (mark);
++n;
- }
- /* can't use Timecode::increment_hours() here because we may be traversing thousands of hours
- and doing it 1 hour at a time is just stupid (and slow).
- */
- timecode.hours += timecode_mark_modulo;
+ }
+ /* can't use Timecode::increment_hours() here because we may be traversing thousands of hours
+ * and doing it 1 hour at a time is just stupid (and slow).
+ */
+ timecode.hours += timecode_mark_modulo - (timecode.hours % timecode_mark_modulo);
}
break;
}
}
void
-Editor::compute_bbt_ruler_scale (std::vector<ARDOUR::TempoMap::BBTPoint>& grid, framepos_t lower, framepos_t upper)
+Editor::compute_bbt_ruler_scale (framepos_t lower, framepos_t upper)
{
if (_session == 0) {
return;
std::vector<TempoMap::BBTPoint>::const_iterator i;
Timecode::BBT_Time lower_beat, upper_beat; // the beats at each end of the ruler
- framecnt_t beat_before_lower_pos = _session->tempo_map().frame_at_beat (floor(_session->tempo_map().beat_at_frame (lower)));
- framecnt_t beat_after_upper_pos = _session->tempo_map().frame_at_beat (floor (_session->tempo_map().beat_at_frame (upper)) + 1.0);
+ double floor_lower_beat = floor(max (0.0, _session->tempo_map().beat_at_frame (lower)));
+
+ if (floor_lower_beat < 0.0) {
+ floor_lower_beat = 0.0;
+ }
+
+ const framecnt_t beat_before_lower_pos = _session->tempo_map().frame_at_beat (floor_lower_beat);
+ const framecnt_t beat_after_upper_pos = _session->tempo_map().frame_at_beat (floor (max (0.0, _session->tempo_map().beat_at_frame (upper))) + 1.0);
_session->bbt_time (beat_before_lower_pos, lower_beat);
_session->bbt_time (beat_after_upper_pos, upper_beat);
bbt_beat_subdivision = 4;
break;
}
- if (distance (grid.begin(), grid.end()) == 0) {
+
+ const double ceil_upper_beat = floor (max (0.0, _session->tempo_map().beat_at_frame (upper))) + 1.0;
+ if (ceil_upper_beat == floor_lower_beat) {
return;
}
- i = grid.end();
- i--;
-
- /* XX ?? */
- /*
- if ((*i).beat >= (*grid.begin()).beat) {
- bbt_bars = (*i).bar - (*grid.begin()).bar;
- } else {
- bbt_bars = (*i).bar - (*grid.begin()).bar;
- }
- */
- /*XXX totally wrong */
- bbt_bars = (floor (_session->tempo_map().beat_at_frame (upper)) - floor (_session->tempo_map().beat_at_frame (lower))) / 4;
+ bbt_bars = _session->tempo_map().bbt_at_beat (ceil_upper_beat).bars - _session->tempo_map().bbt_at_beat (floor_lower_beat).bars;
- beats = distance (grid.begin(), grid.end()) - bbt_bars;
+ beats = (ceil_upper_beat - floor_lower_beat) - bbt_bars;
+ double beat_density = ((beats + 1) * ((double) (upper - lower) / (double) (1 + beat_after_upper_pos - beat_before_lower_pos))) / 5.0;
/* Only show the bar helper if there aren't many bars on the screen */
if ((bbt_bars < 2) || (beats < 5)) {
bbt_bar_helper_on = true;
}
- if (bbt_bars > 8192) {
+ if (beat_density > 8192) {
bbt_ruler_scale = bbt_show_many;
- } else if (bbt_bars > 1024) {
+ } else if (beat_density > 1024) {
bbt_ruler_scale = bbt_show_64;
- } else if (bbt_bars > 256) {
+ } else if (beat_density > 512) {
bbt_ruler_scale = bbt_show_16;
- } else if (bbt_bars > 64) {
+ } else if (beat_density > 128) {
bbt_ruler_scale = bbt_show_4;
- } else if (bbt_bars > 10) {
+ } else if (beat_density > 16) {
bbt_ruler_scale = bbt_show_1;
- } else if (bbt_bars > 2) {
+ } else if (beat_density > 2) {
bbt_ruler_scale = bbt_show_beats;
- } else if (bbt_bars > 0) {
+ } else if (beat_density > 0.5) {
bbt_ruler_scale = bbt_show_ticks;
} else {
bbt_ruler_scale = bbt_show_ticks_detail;
next_beat.beats = (*i).beat;
next_beat.bars = (*i).bar;
next_beat.ticks = tick;
- pos = _session->tempo_map().frame_time (next_beat);
+ pos = _session->tempo_map().frame_at_bbt (next_beat);
if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
i_am_accented = true;
next_beat.beats = (*i).beat;
next_beat.bars = (*i).bar;
next_beat.ticks = tick;
- pos = _session->tempo_map().frame_time (next_beat);
+ pos = _session->tempo_map().frame_at_bbt (next_beat);
if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
i_am_accented = true;
while (tick < Timecode::BBT_Time::ticks_per_beat && (n < bbt_nmarks)) {
next_beat.ticks = tick;
- pos = _session->tempo_map().frame_time (next_beat);
+ pos = _session->tempo_map().frame_at_bbt (next_beat);
if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
i_am_accented = true;
}