#include <cmath>
-#include <sigc++/bind.h>
#include <glibmm/thread.h>
#include "pbd/xml++.h"
/* "true" rounding */
- /* round to nearest beat */
- if (bbt.ticks >= (Meter::ticks_per_beat/2)) {
- try {
- bbt = bbt_add (bbt, one_beat, metric);
- }
- catch (...) {
- return frame;
- }
- }
+ float midbar_beats;
+ float midbar_ticks;
- /* round to nearest bar */
- if (bbt.beats >= metric.meter().beats_per_bar()/2) {
- try {
- bbt = bbt_add (bbt, one_bar, metric);
- }
- catch (...) {
- return frame;
- }
- }
+ midbar_beats = metric.meter().beats_per_bar() / 2;
+ midbar_ticks = Meter::ticks_per_beat * fmod (midbar_beats, 1.0f);
+ midbar_beats = floor (midbar_beats);
+
+ BBT_Time midbar (bbt.bars, lrintf (midbar_beats), lrintf (midbar_ticks));
+
+ if (bbt < midbar) {
+ /* round down */
+ bbt.beats = 1;
+ bbt.ticks = 0;
+ } else {
+ /* round up */
+ bbt.bars++;
+ bbt.beats = 1;
+ bbt.ticks = 0;
+ }
}
/* force beats & ticks to their values at the start of a bar */
bbt.beats = 1;
return bbt_add (start, other, metric);
}
+/**
+ * add the BBT interval @param increment to @param start and return the result
+ */
BBT_Time
-TempoMap::bbt_add (const BBT_Time& start, const BBT_Time& other, const TempoMetric& metric) const
+TempoMap::bbt_add (const BBT_Time& start, const BBT_Time& increment, const TempoMetric& /*metric*/) const
{
BBT_Time result = start;
- BBT_Time op = other;
+ BBT_Time op = increment; /* argument is const, but we need to modify it */
uint32_t ticks = result.ticks + op.ticks;
if (ticks >= Meter::ticks_per_beat) {
return result;
}
+/**
+ * subtract the BBT interval @param decrement from @param start and return the result
+ */
BBT_Time
-TempoMap::bbt_subtract (const BBT_Time& start, const BBT_Time& other) const
+TempoMap::bbt_subtract (const BBT_Time& start, const BBT_Time& decrement) const
{
BBT_Time result = start;
- BBT_Time op = other;
+ BBT_Time op = decrement; /* argument is const, but we need to modify it */
if (op.ticks > result.ticks) {
/* subtract an extra beat later; meanwhile set ticks to the right "carry" value */
*/
const MeterSection* meter = 0;
- list<const MeterSection*>::const_reverse_iterator next_meter;
+ list<const MeterSection*>::reverse_iterator next_meter; // older versions of GCC don't
+ // support const_reverse_iterator::operator!=()
for (next_meter = meter_sections.rbegin(); next_meter != meter_sections.rend(); ++next_meter) {