summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2011-12-19 19:44:43 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2011-12-19 19:44:43 +0000
commite9b4f14668a54e32e83005f0b09889372d1abe11 (patch)
tree1ce665f1cca65433ecafd9909908ecb7366e742b /libs
parentca9a444aa9a7e4c26aea2d31dedee3cbbc33ae78 (diff)
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
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/audio_unit.cc8
-rw-r--r--libs/ardour/session_time.cc2
-rw-r--r--libs/ardour/tempo.cc46
-rw-r--r--libs/surfaces/mackie/mackie_control_protocol.cc4
-rw-r--r--libs/timecode/src/bbt_time.cc17
-rw-r--r--libs/timecode/timecode/bbt_time.h2
6 files changed, 46 insertions, 33 deletions
diff --git a/libs/ardour/audio_unit.cc b/libs/ardour/audio_unit.cc
index ca171ddd97..dc8a6eabf4 100644
--- a/libs/ardour/audio_unit.cc
+++ b/libs/ardour/audio_unit.cc
@@ -1420,7 +1420,7 @@ AUPlugin::get_beat_and_tempo_callback (Float64* outCurrentBeat,
float beat;
beat = metric.meter().beats_per_bar() * bbt.bars;
beat += bbt.beats;
- beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat;
+ beat += bbt.ticks / Timecode::BBT_Time::ticks_per_bar_division;
*outCurrentBeat = beat;
}
@@ -1461,7 +1461,7 @@ AUPlugin::get_musical_time_location_callback (UInt32* outDeltaSampleOffsetToNe
*outDeltaSampleOffsetToNextBeat = 0;
} else {
*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
}
}
@@ -1553,7 +1553,7 @@ AUPlugin::get_transport_state_callback (Boolean* outIsPlaying,
float beat;
beat = metric.meter().beats_per_bar() * bbt.bars;
beat += bbt.beats;
- beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat;
+ beat += bbt.ticks / Timecode::BBT_Time::ticks_per_bar_division;
*outCycleStartBeat = beat;
}
@@ -1565,7 +1565,7 @@ AUPlugin::get_transport_state_callback (Boolean* outIsPlaying,
float beat;
beat = metric.meter().beats_per_bar() * bbt.bars;
beat += bbt.beats;
- beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat;
+ beat += bbt.ticks / Timecode::BBT_Time::ticks_per_bar_division;
*outCycleEndBeat = beat;
}
diff --git a/libs/ardour/session_time.cc b/libs/ardour/session_time.cc
index 0543fe2d02..cf8ef084b2 100644
--- a/libs/ardour/session_time.cc
+++ b/libs/ardour/session_time.cc
@@ -494,7 +494,7 @@ Session::jack_timebase_callback (jack_transport_state_t /*state*/,
pos->beats_per_bar = metric.meter().divisions_per_bar();
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->valid = jack_position_bits_t (pos->valid | JackPositionBBT);
diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc
index 3bb55f76f3..a8f5bdf7ae 100644
--- a/libs/ardour/tempo.cc
+++ b/libs/ardour/tempo.cc
@@ -735,7 +735,7 @@ TempoMap::timestamp_metrics (bool use_bbt)
first = false;
} 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 */
bbt.beats += 1;
}
@@ -863,7 +863,7 @@ void
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 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
* 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);
bbt.ticks = metric.start().ticks + tick_diff;
- uint32_t beat_overflow = bbt.ticks / (uint32_t) BBT_Time::ticks_per_beat;
- bbt.ticks = 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_bar_division;
bbt.beats = metric.start().beats + beat_overflow;
/* 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;
@@ -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;
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));
@@ -943,7 +943,7 @@ TempoMap::count_frames_between (const BBT_Time& start, const BBT_Time& end) cons
bar_offset = end.bars - m.start().bars;
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));
@@ -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) ?
- (1 - (ceil(divisions_per_bar) - divisions_per_bar))* BBT_Time::ticks_per_beat
- : BBT_Time::ticks_per_beat );
+ (1 - (ceil(divisions_per_bar) - divisions_per_bar))* BBT_Time::ticks_per_bar_division
+ : BBT_Time::ticks_per_bar_division );
while (result.ticks >= ticks_at_beat) {
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();
}
ticks_at_beat= (uint32_t) (result.beats == ceil(divisions_per_bar) ?
- (1 - (ceil(divisions_per_bar) - divisions_per_bar) ) * BBT_Time::ticks_per_beat
- : BBT_Time::ticks_per_beat);
+ (1 - (ceil(divisions_per_bar) - divisions_per_bar) ) * BBT_Time::ticks_per_bar_division
+ : 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;
} 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;
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
divisions_per_bar = metric.meter().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 {
--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) {
@@ -1186,7 +1186,7 @@ TempoMap::round_to_beat_subdivision (framepos_t fr, int sub_num, int dir)
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;
if (dir > 0) {
@@ -1293,7 +1293,7 @@ TempoMap::round_to_type (framepos_t frame, int dir, BBTPointType type)
float midbar_ticks;
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);
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 */
/* round to nearest beat */
- if (bbt.ticks >= (BBT_Time::ticks_per_beat/2)) {
+ if (bbt.ticks >= (BBT_Time::ticks_per_bar_division/2)) {
try {
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 */
uint32_t ticks = result.ticks + op.ticks;
- if (ticks >= BBT_Time::ticks_per_beat) {
+ if (ticks >= BBT_Time::ticks_per_bar_division) {
op.beats++;
- result.ticks = ticks % (uint32_t) BBT_Time::ticks_per_beat;
+ result.ticks = ticks % (uint32_t) BBT_Time::ticks_per_bar_division;
} else {
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) {
/* subtract an extra beat later; meanwhile set ticks to the right "carry" value */
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 {
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);
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 */
- (frames_per_beat * ((op.ticks % (uint32_t) BBT_Time::ticks_per_beat) /
- (double) BBT_Time::ticks_per_beat)));
+ (frames_per_beat * ((op.ticks % (uint32_t) BBT_Time::ticks_per_bar_division) /
+ (double) BBT_Time::ticks_per_bar_division)));
} 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));
}
}
diff --git a/libs/surfaces/mackie/mackie_control_protocol.cc b/libs/surfaces/mackie/mackie_control_protocol.cc
index 7e208686ba..6fda7d7404 100644
--- a/libs/surfaces/mackie/mackie_control_protocol.cc
+++ b/libs/surfaces/mackie/mackie_control_protocol.cc
@@ -1025,8 +1025,8 @@ MackieControlProtocol::format_bbt_timecode (framepos_t now_frame)
subdiv = 3;
}
- uint32_t subdivisions = 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_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_bar_division / subdiv);
os << setw(2) << setfill('0') << subdivisions + 1;
os << setw(3) << setfill('0') << ticks;
diff --git a/libs/timecode/src/bbt_time.cc b/libs/timecode/src/bbt_time.cc
index c48191abe8..6de822524d 100644
--- a/libs/timecode/src/bbt_time.cc
+++ b/libs/timecode/src/bbt_time.cc
@@ -23,7 +23,20 @@
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)
{
@@ -36,5 +49,5 @@ BBT_Time::BBT_Time (double dbeats)
bars = 0;
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)));
}
diff --git a/libs/timecode/timecode/bbt_time.h b/libs/timecode/timecode/bbt_time.h
index 226a2fc894..46307dbc04 100644
--- a/libs/timecode/timecode/bbt_time.h
+++ b/libs/timecode/timecode/bbt_time.h
@@ -27,7 +27,7 @@ namespace Timecode {
/** Bar, Beat, Tick Time (i.e. Tempo-Based Time) */
struct BBT_Time {
- static const double ticks_per_beat;
+ static const double ticks_per_bar_division;
uint32_t bars;
uint32_t beats;