rename Timecode::BBT_Time::ticks_per_beat to Timecode::BBT_Time::ticks_per_bar_division which is a more accurate and informative name. The number doesn't describe the smallest division of a "beat" (which is only defined contextually anyway), but rather the smallest division of the the divisions of a bar. If using a meter of 4/8, there are 4 divisions per bar, and we can divide each one into ticks_per_bar_division pieces; in a separate meter (section) of 3/8, there are 3 divisions per bar, each of which can be divided into ticks_per_bar_division_pieces.

git-svn-id: svn://localhost/ardour2/branches/3.0@11022 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2011-12-19 19:44:43 +00:00
parent ca9a444aa9
commit e9b4f14668
12 changed files with 60 additions and 47 deletions

View file

@ -1779,7 +1779,7 @@ AudioClock::bbt_validate_edit (const string& str)
return false; return false;
} }
if (any.bbt.ticks > Timecode::BBT_Time::ticks_per_beat) { if (any.bbt.ticks > Timecode::BBT_Time::ticks_per_bar_division) {
return false; return false;
} }

View file

@ -1262,7 +1262,7 @@ Editor::compute_bbt_ruler_scale (framepos_t lower, framepos_t upper)
bbt_ruler_scale = bbt_show_ticks_detail; bbt_ruler_scale = bbt_show_ticks_detail;
} }
if ((bbt_ruler_scale == bbt_show_ticks_detail) && (lower_beat.beats == upper_beat.beats) && (upper_beat.ticks - lower_beat.ticks <= Timecode::BBT_Time::ticks_per_beat / 4)) { if ((bbt_ruler_scale == bbt_show_ticks_detail) && (lower_beat.beats == upper_beat.beats) && (upper_beat.ticks - lower_beat.ticks <= Timecode::BBT_Time::ticks_per_bar_division / 4)) {
bbt_ruler_scale = bbt_show_ticks_super_detail; bbt_ruler_scale = bbt_show_ticks_super_detail;
} }
} }
@ -1391,14 +1391,14 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute())); frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
frame_skip_error -= frame_skip; frame_skip_error -= frame_skip;
skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision); skip = (uint32_t) (Timecode::BBT_Time::ticks_per_bar_division / bbt_beat_subdivision);
pos = (*i).frame + frame_skip; pos = (*i).frame + frame_skip;
accumulated_error = frame_skip_error; accumulated_error = frame_skip_error;
tick = skip; tick = skip;
for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) { for (t = 0; (tick < Timecode::BBT_Time::ticks_per_bar_division) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) { if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
i_am_accented = true; i_am_accented = true;
@ -1483,14 +1483,14 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute())); frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
frame_skip_error -= frame_skip; frame_skip_error -= frame_skip;
skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision); skip = (uint32_t) (Timecode::BBT_Time::ticks_per_bar_division / bbt_beat_subdivision);
pos = (*i).frame + frame_skip; pos = (*i).frame + frame_skip;
accumulated_error = frame_skip_error; accumulated_error = frame_skip_error;
tick = skip; tick = skip;
for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) { for (t = 0; (tick < Timecode::BBT_Time::ticks_per_bar_division) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) { if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
i_am_accented = true; i_am_accented = true;
@ -1580,14 +1580,14 @@ Editor::metric_get_bbt (GtkCustomRulerMark **marks, gdouble lower, gdouble /*upp
frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute())); frame_skip = (framepos_t) floor (frame_skip_error = (_session->frame_rate() * 60) / (bbt_beat_subdivision * (*i).tempo->beats_per_minute()));
frame_skip_error -= frame_skip; frame_skip_error -= frame_skip;
skip = (uint32_t) (Timecode::BBT_Time::ticks_per_beat / bbt_beat_subdivision); skip = (uint32_t) (Timecode::BBT_Time::ticks_per_bar_division / bbt_beat_subdivision);
pos = (*i).frame + frame_skip; pos = (*i).frame + frame_skip;
accumulated_error = frame_skip_error; accumulated_error = frame_skip_error;
tick = skip; tick = skip;
for (t = 0; (tick < Timecode::BBT_Time::ticks_per_beat) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) { for (t = 0; (tick < Timecode::BBT_Time::ticks_per_bar_division) && (n < bbt_nmarks) && (pos < next_beat_pos) ; pos += frame_skip, tick += skip, ++t) {
if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) { if (t % bbt_accent_modulo == (bbt_accent_modulo - 1)) {
i_am_accented = true; i_am_accented = true;

View file

@ -221,7 +221,7 @@ MidiListEditor::redisplay_model ()
bbt.bars = 0; bbt.bars = 0;
dur = (*i)->end_time() - (*i)->time(); dur = (*i)->end_time() - (*i)->time();
bbt.beats = floor (dur); bbt.beats = floor (dur);
bbt.ticks = (uint32_t) lrint (fmod (dur, 1.0) * Timecode::BBT_Time::ticks_per_beat); bbt.ticks = (uint32_t) lrint (fmod (dur, 1.0) * Timecode::BBT_Time::ticks_per_bar_division);
_session->tempo_map().bbt_duration_at (region->position(), bbt, 0); _session->tempo_map().bbt_duration_at (region->position(), bbt, 0);

View file

@ -812,7 +812,7 @@ MidiRegionView::create_note_at (framepos_t t, double y, double length, bool sh,
length = region_frames_to_region_beats (region_beats_to_region_frames (length) - 1); length = region_frames_to_region_beats (region_beats_to_region_frames (length) - 1);
*/ */
length -= 1.0/Timecode::BBT_Time::ticks_per_beat; length -= 1.0/Timecode::BBT_Time::ticks_per_bar_division;
} }
const boost::shared_ptr<NoteType> new_note (new NoteType (mtv->get_channel_for_add (), const boost::shared_ptr<NoteType> new_note (new NoteType (mtv->get_channel_for_add (),

View file

@ -272,8 +272,8 @@ StepEditor::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Evo
up by 1 tick from where the last note ended up by 1 tick from where the last note ended
*/ */
at += 1.0/Timecode::BBT_Time::ticks_per_beat; at += 1.0/Timecode::BBT_Time::ticks_per_bar_division;
len -= 1.0/Timecode::BBT_Time::ticks_per_beat; len -= 1.0/Timecode::BBT_Time::ticks_per_bar_division;
} }
step_edit_region_view->step_add_note (channel, pitch, velocity, at, len); step_edit_region_view->step_add_note (channel, pitch, velocity, at, len);
@ -293,7 +293,7 @@ StepEditor::step_add_note (uint8_t channel, uint8_t pitch, uint8_t velocity, Evo
step_edit_beat_pos += beat_duration; step_edit_beat_pos += beat_duration;
step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos); step_edit_region_view->move_step_edit_cursor (step_edit_beat_pos);
} else { } else {
step_edit_beat_pos += 1.0/Timecode::BBT_Time::ticks_per_beat; // tiny, but no longer overlapping step_edit_beat_pos += 1.0/Timecode::BBT_Time::ticks_per_bar_division; // tiny, but no longer overlapping
_step_edit_chord_duration = max (_step_edit_chord_duration, beat_duration); _step_edit_chord_duration = max (_step_edit_chord_duration, beat_duration);
} }

View file

@ -209,7 +209,7 @@ VerboseCursor::set_duration (framepos_t start, framepos_t end, double x, double
ticks -= sbbt.ticks; ticks -= sbbt.ticks;
if (ticks < 0) { if (ticks < 0) {
ticks += int (Timecode::BBT_Time::ticks_per_beat); ticks += int (Timecode::BBT_Time::ticks_per_bar_division);
--beats; --beats;
} }

View file

@ -1420,7 +1420,7 @@ AUPlugin::get_beat_and_tempo_callback (Float64* outCurrentBeat,
float beat; float beat;
beat = metric.meter().beats_per_bar() * bbt.bars; beat = metric.meter().beats_per_bar() * bbt.bars;
beat += bbt.beats; beat += bbt.beats;
beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat; beat += bbt.ticks / Timecode::BBT_Time::ticks_per_bar_division;
*outCurrentBeat = beat; *outCurrentBeat = beat;
} }
@ -1461,7 +1461,7 @@ AUPlugin::get_musical_time_location_callback (UInt32* outDeltaSampleOffsetToNe
*outDeltaSampleOffsetToNextBeat = 0; *outDeltaSampleOffsetToNextBeat = 0;
} else { } else {
*outDeltaSampleOffsetToNextBeat = (UInt32) *outDeltaSampleOffsetToNextBeat = (UInt32)
floor (((Timecode::BBT_Time::ticks_per_beat - bbt.ticks)/Timecode::BBT_Time::ticks_per_beat) * // fraction of a beat to next beat floor (((Timecode::BBT_Time::ticks_per_bar_division - bbt.ticks)/Timecode::BBT_Time::ticks_per_bar_division) * // fraction of a beat to next beat
metric.tempo().frames_per_beat(_session.frame_rate(), metric.meter())); // frames per beat metric.tempo().frames_per_beat(_session.frame_rate(), metric.meter())); // frames per beat
} }
} }
@ -1553,7 +1553,7 @@ AUPlugin::get_transport_state_callback (Boolean* outIsPlaying,
float beat; float beat;
beat = metric.meter().beats_per_bar() * bbt.bars; beat = metric.meter().beats_per_bar() * bbt.bars;
beat += bbt.beats; beat += bbt.beats;
beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat; beat += bbt.ticks / Timecode::BBT_Time::ticks_per_bar_division;
*outCycleStartBeat = beat; *outCycleStartBeat = beat;
} }
@ -1565,7 +1565,7 @@ AUPlugin::get_transport_state_callback (Boolean* outIsPlaying,
float beat; float beat;
beat = metric.meter().beats_per_bar() * bbt.bars; beat = metric.meter().beats_per_bar() * bbt.bars;
beat += bbt.beats; beat += bbt.beats;
beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat; beat += bbt.ticks / Timecode::BBT_Time::ticks_per_bar_division;
*outCycleEndBeat = beat; *outCycleEndBeat = beat;
} }

View file

@ -494,7 +494,7 @@ Session::jack_timebase_callback (jack_transport_state_t /*state*/,
pos->beats_per_bar = metric.meter().divisions_per_bar(); pos->beats_per_bar = metric.meter().divisions_per_bar();
pos->beat_type = metric.meter().note_divisor(); pos->beat_type = metric.meter().note_divisor();
pos->ticks_per_beat = Timecode::BBT_Time::ticks_per_beat; pos->ticks_per_beat = Timecode::BBT_Time::ticks_per_bar_division;
pos->beats_per_minute = metric.tempo().beats_per_minute(); pos->beats_per_minute = metric.tempo().beats_per_minute();
pos->valid = jack_position_bits_t (pos->valid | JackPositionBBT); pos->valid = jack_position_bits_t (pos->valid | JackPositionBBT);

View file

@ -735,7 +735,7 @@ TempoMap::timestamp_metrics (bool use_bbt)
first = false; first = false;
} else { } else {
if (bbt.ticks > BBT_Time::ticks_per_beat/2) { if (bbt.ticks > BBT_Time::ticks_per_bar_division/2) {
/* round up to next beat */ /* round up to next beat */
bbt.beats += 1; bbt.beats += 1;
} }
@ -863,7 +863,7 @@ void
TempoMap::bbt_time_with_metric (framepos_t frame, BBT_Time& bbt, const TempoMetric& metric) const TempoMap::bbt_time_with_metric (framepos_t frame, BBT_Time& bbt, const TempoMetric& metric) const
{ {
const double divisions_per_bar = metric.meter().divisions_per_bar(); const double divisions_per_bar = metric.meter().divisions_per_bar();
const double frames_per_tick = metric.meter().frames_per_division (metric.tempo(),_frame_rate) / BBT_Time::ticks_per_beat; const double frames_per_tick = metric.meter().frames_per_division (metric.tempo(),_frame_rate) / BBT_Time::ticks_per_bar_division;
/* now compute how far beyond the metric we actually are, and add the /* now compute how far beyond the metric we actually are, and add the
* relevant number of ticks to the metric's BBT time * relevant number of ticks to the metric's BBT time
@ -873,8 +873,8 @@ TempoMap::bbt_time_with_metric (framepos_t frame, BBT_Time& bbt, const TempoMetr
uint32_t tick_diff = (uint32_t) lrint ((double) frame_diff / frames_per_tick); uint32_t tick_diff = (uint32_t) lrint ((double) frame_diff / frames_per_tick);
bbt.ticks = metric.start().ticks + tick_diff; bbt.ticks = metric.start().ticks + tick_diff;
uint32_t beat_overflow = bbt.ticks / (uint32_t) BBT_Time::ticks_per_beat; uint32_t beat_overflow = bbt.ticks / (uint32_t) BBT_Time::ticks_per_bar_division;
bbt.ticks = bbt.ticks % (uint32_t) BBT_Time::ticks_per_beat; bbt.ticks = bbt.ticks % (uint32_t) BBT_Time::ticks_per_bar_division;
bbt.beats = metric.start().beats + beat_overflow; bbt.beats = metric.start().beats + beat_overflow;
/* bbt.beats uses 1-based counting, so adjust to get the right answer */ /* bbt.beats uses 1-based counting, so adjust to get the right answer */
uint32_t bar_overflow = (bbt.beats - 1) / (uint32_t) divisions_per_bar; uint32_t bar_overflow = (bbt.beats - 1) / (uint32_t) divisions_per_bar;
@ -929,7 +929,7 @@ TempoMap::count_frames_between (const BBT_Time& start, const BBT_Time& end) cons
uint32_t bar_offset = start.bars - m.start().bars; uint32_t bar_offset = start.bars - m.start().bars;
double beat_offset = bar_offset*m.meter().divisions_per_bar() - (m.start().beats-1) + (start.beats -1) double beat_offset = bar_offset*m.meter().divisions_per_bar() - (m.start().beats-1) + (start.beats -1)
+ start.ticks/BBT_Time::ticks_per_beat; + start.ticks/BBT_Time::ticks_per_bar_division;
start_frame = m.frame() + (framepos_t) rint(beat_offset * m.meter().frames_per_division(m.tempo(),_frame_rate)); start_frame = m.frame() + (framepos_t) rint(beat_offset * m.meter().frames_per_division(m.tempo(),_frame_rate));
@ -943,7 +943,7 @@ TempoMap::count_frames_between (const BBT_Time& start, const BBT_Time& end) cons
bar_offset = end.bars - m.start().bars; bar_offset = end.bars - m.start().bars;
beat_offset = bar_offset * m.meter().divisions_per_bar() - (m.start().beats -1) + (end.beats - 1) beat_offset = bar_offset * m.meter().divisions_per_bar() - (m.start().beats -1) + (end.beats - 1)
+ end.ticks/BBT_Time::ticks_per_beat; + end.ticks/BBT_Time::ticks_per_bar_division;
end_frame = m.frame() + (framepos_t) rint(beat_offset * m.meter().frames_per_division(m.tempo(),_frame_rate)); end_frame = m.frame() + (framepos_t) rint(beat_offset * m.meter().frames_per_division(m.tempo(),_frame_rate));
@ -1076,8 +1076,8 @@ TempoMap::bbt_duration_at_unlocked (const BBT_Time& when, const BBT_Time& bbt, i
*/ */
uint32_t ticks_at_beat = (uint32_t) (result.beats == ceil(divisions_per_bar) ? uint32_t ticks_at_beat = (uint32_t) (result.beats == ceil(divisions_per_bar) ?
(1 - (ceil(divisions_per_bar) - divisions_per_bar))* BBT_Time::ticks_per_beat (1 - (ceil(divisions_per_bar) - divisions_per_bar))* BBT_Time::ticks_per_bar_division
: BBT_Time::ticks_per_beat ); : BBT_Time::ticks_per_bar_division );
while (result.ticks >= ticks_at_beat) { while (result.ticks >= ticks_at_beat) {
result.beats++; result.beats++;
@ -1089,8 +1089,8 @@ TempoMap::bbt_duration_at_unlocked (const BBT_Time& when, const BBT_Time& bbt, i
divisions_per_bar = metric.meter().divisions_per_bar(); divisions_per_bar = metric.meter().divisions_per_bar();
} }
ticks_at_beat= (uint32_t) (result.beats == ceil(divisions_per_bar) ? ticks_at_beat= (uint32_t) (result.beats == ceil(divisions_per_bar) ?
(1 - (ceil(divisions_per_bar) - divisions_per_bar) ) * BBT_Time::ticks_per_beat (1 - (ceil(divisions_per_bar) - divisions_per_bar) ) * BBT_Time::ticks_per_bar_division
: BBT_Time::ticks_per_beat); : BBT_Time::ticks_per_bar_division);
} }
@ -1117,7 +1117,7 @@ TempoMap::bbt_duration_at_unlocked (const BBT_Time& when, const BBT_Time& bbt, i
result.ticks = when.ticks - bbt.ticks; result.ticks = when.ticks - bbt.ticks;
} else { } else {
uint32_t ticks_at_beat= (uint32_t) BBT_Time::ticks_per_beat; uint32_t ticks_at_beat= (uint32_t) BBT_Time::ticks_per_bar_division;
uint32_t t = bbt.ticks - when.ticks; uint32_t t = bbt.ticks - when.ticks;
do { do {
@ -1128,10 +1128,10 @@ TempoMap::bbt_duration_at_unlocked (const BBT_Time& when, const BBT_Time& bbt, i
metric = metric_at(result); // maybe there is a meter change metric = metric_at(result); // maybe there is a meter change
divisions_per_bar = metric.meter().divisions_per_bar(); divisions_per_bar = metric.meter().divisions_per_bar();
result.beats = (uint32_t) ceil(divisions_per_bar); result.beats = (uint32_t) ceil(divisions_per_bar);
ticks_at_beat = (uint32_t) ((1 - (ceil(divisions_per_bar) - divisions_per_bar)) * BBT_Time::ticks_per_beat) ; ticks_at_beat = (uint32_t) ((1 - (ceil(divisions_per_bar) - divisions_per_bar)) * BBT_Time::ticks_per_bar_division) ;
} else { } else {
--result.beats; --result.beats;
ticks_at_beat = (uint32_t) BBT_Time::ticks_per_beat; ticks_at_beat = (uint32_t) BBT_Time::ticks_per_bar_division;
} }
if (t <= ticks_at_beat) { if (t <= ticks_at_beat) {
@ -1186,7 +1186,7 @@ TempoMap::round_to_beat_subdivision (framepos_t fr, int sub_num, int dir)
bbt_time(fr, the_beat); bbt_time(fr, the_beat);
ticks_one_subdivisions_worth = (uint32_t)BBT_Time::ticks_per_beat / sub_num; ticks_one_subdivisions_worth = (uint32_t)BBT_Time::ticks_per_bar_division / sub_num;
ticks_one_half_subdivisions_worth = ticks_one_subdivisions_worth / 2; ticks_one_half_subdivisions_worth = ticks_one_subdivisions_worth / 2;
if (dir > 0) { if (dir > 0) {
@ -1293,7 +1293,7 @@ TempoMap::round_to_type (framepos_t frame, int dir, BBTPointType type)
float midbar_ticks; float midbar_ticks;
midbar_beats = metric.meter().divisions_per_bar() / 2 + 1; midbar_beats = metric.meter().divisions_per_bar() / 2 + 1;
midbar_ticks = BBT_Time::ticks_per_beat * fmod (midbar_beats, 1.0f); midbar_ticks = BBT_Time::ticks_per_bar_division * fmod (midbar_beats, 1.0f);
midbar_beats = floor (midbar_beats); midbar_beats = floor (midbar_beats);
BBT_Time midbar (bbt.bars, lrintf (midbar_beats), lrintf (midbar_ticks)); BBT_Time midbar (bbt.bars, lrintf (midbar_beats), lrintf (midbar_ticks));
@ -1346,7 +1346,7 @@ TempoMap::round_to_type (framepos_t frame, int dir, BBTPointType type)
/* "true" rounding */ /* "true" rounding */
/* round to nearest beat */ /* round to nearest beat */
if (bbt.ticks >= (BBT_Time::ticks_per_beat/2)) { if (bbt.ticks >= (BBT_Time::ticks_per_bar_division/2)) {
try { try {
bbt = bbt_add (bbt, one_beat, metric); bbt = bbt_add (bbt, one_beat, metric);
@ -1752,9 +1752,9 @@ TempoMap::bbt_add (const BBT_Time& start, const BBT_Time& increment, const Tempo
BBT_Time op = increment; /* argument is const, but we need to modify it */ BBT_Time op = increment; /* argument is const, but we need to modify it */
uint32_t ticks = result.ticks + op.ticks; uint32_t ticks = result.ticks + op.ticks;
if (ticks >= BBT_Time::ticks_per_beat) { if (ticks >= BBT_Time::ticks_per_bar_division) {
op.beats++; op.beats++;
result.ticks = ticks % (uint32_t) BBT_Time::ticks_per_beat; result.ticks = ticks % (uint32_t) BBT_Time::ticks_per_bar_division;
} else { } else {
result.ticks += op.ticks; result.ticks += op.ticks;
} }
@ -1855,7 +1855,7 @@ TempoMap::bbt_subtract (const BBT_Time& start, const BBT_Time& decrement) const
if (op.ticks > result.ticks) { if (op.ticks > result.ticks) {
/* subtract an extra beat later; meanwhile set ticks to the right "carry" value */ /* subtract an extra beat later; meanwhile set ticks to the right "carry" value */
op.beats++; op.beats++;
result.ticks = BBT_Time::ticks_per_beat - (op.ticks - result.ticks); result.ticks = BBT_Time::ticks_per_bar_division - (op.ticks - result.ticks);
} else { } else {
result.ticks -= op.ticks; result.ticks -= op.ticks;
} }
@ -2228,12 +2228,12 @@ TempoMap::framepos_plus_bbt (framepos_t pos, BBT_Time op) const
pos += llrint (beats * frames_per_beat); pos += llrint (beats * frames_per_beat);
if (op.ticks) { if (op.ticks) {
if (op.ticks >= BBT_Time::ticks_per_beat) { if (op.ticks >= BBT_Time::ticks_per_bar_division) {
pos += llrint (frames_per_beat + /* extra beat */ pos += llrint (frames_per_beat + /* extra beat */
(frames_per_beat * ((op.ticks % (uint32_t) BBT_Time::ticks_per_beat) / (frames_per_beat * ((op.ticks % (uint32_t) BBT_Time::ticks_per_bar_division) /
(double) BBT_Time::ticks_per_beat))); (double) BBT_Time::ticks_per_bar_division)));
} else { } else {
pos += llrint (frames_per_beat * (op.ticks / (double) BBT_Time::ticks_per_beat)); pos += llrint (frames_per_beat * (op.ticks / (double) BBT_Time::ticks_per_bar_division));
} }
} }

View file

@ -1025,8 +1025,8 @@ MackieControlProtocol::format_bbt_timecode (framepos_t now_frame)
subdiv = 3; subdiv = 3;
} }
uint32_t subdivisions = bbt_time.ticks / uint32_t (Timecode::BBT_Time::ticks_per_beat / subdiv); uint32_t subdivisions = bbt_time.ticks / uint32_t (Timecode::BBT_Time::ticks_per_bar_division / subdiv);
uint32_t ticks = bbt_time.ticks % uint32_t (Timecode::BBT_Time::ticks_per_beat / subdiv); uint32_t ticks = bbt_time.ticks % uint32_t (Timecode::BBT_Time::ticks_per_bar_division / subdiv);
os << setw(2) << setfill('0') << subdivisions + 1; os << setw(2) << setfill('0') << subdivisions + 1;
os << setw(3) << setfill('0') << ticks; os << setw(3) << setfill('0') << ticks;

View file

@ -23,7 +23,20 @@
using namespace Timecode; using namespace Timecode;
const double BBT_Time::ticks_per_beat = 1920.0; /* This number doesn't describe the smallest division of a "beat" (which is
only defined contextually anyway), but rather the smallest division of the the
divisions of a bar. If using a meter of 4/8, there are 4 divisions per bar, and
we can divide each one into ticks_per_bar_division pieces; in a separate meter
(section) of 3/8, there are 3 divisions per bar, each of which can be divided
into ticks_per_bar_division pieces.
The number is intended to have as many integer factors as possible so that
1/Nth divisions are integer numbers of ticks.
1920 is the largest legal value that be used inside an SMF file, and has many factors.
*/
const double BBT_Time::ticks_per_bar_division = 1920.0;
BBT_Time::BBT_Time (double dbeats) BBT_Time::BBT_Time (double dbeats)
{ {
@ -36,5 +49,5 @@ BBT_Time::BBT_Time (double dbeats)
bars = 0; bars = 0;
beats = rint (floor (dbeats)); beats = rint (floor (dbeats));
ticks = rint (floor (BBT_Time::ticks_per_beat * fmod (dbeats, 1.0))); ticks = rint (floor (BBT_Time::ticks_per_bar_division * fmod (dbeats, 1.0)));
} }

View file

@ -27,7 +27,7 @@ namespace Timecode {
/** Bar, Beat, Tick Time (i.e. Tempo-Based Time) */ /** Bar, Beat, Tick Time (i.e. Tempo-Based Time) */
struct BBT_Time { struct BBT_Time {
static const double ticks_per_beat; static const double ticks_per_bar_division;
uint32_t bars; uint32_t bars;
uint32_t beats; uint32_t beats;