13
0

temporal: add round_up_to_bar() methods to Meter, Metric and TempoMap

This commit is contained in:
Paul Davis 2024-10-28 14:01:43 -06:00
parent 428437ed72
commit 364598e94f
2 changed files with 17 additions and 1 deletions

View File

@ -359,6 +359,17 @@ Meter::round_to_bar (Temporal::BBT_Time const & bbt) const
return BBT_Time (bbt.bars, 1, 0);
}
Temporal::BBT_Time
Meter::round_up_to_bar (Temporal::BBT_Time const & bbt) const
{
if (bbt.beats == 1 && bbt.ticks == 0) {
/* on bar, do not round up */
return bbt;
}
return BBT_Time (bbt.bars+1, 1, 0);
}
Temporal::BBT_Time
Meter::round_up_to_beat_div (Temporal::BBT_Time const & bbt, int beat_div) const
{

View File

@ -304,6 +304,7 @@ class LIBTEMPORAL_API Meter {
BBT_Time bbt_add (BBT_Time const & bbt, BBT_Offset const & add) const;
BBT_Time bbt_subtract (BBT_Time const & bbt, BBT_Offset const & sub) const;
BBT_Time round_to_bar (BBT_Time const &) const;
BBT_Time round_up_to_bar (BBT_Time const &) const;
BBT_Time round_up_to_beat_div (BBT_Time const &, int beat_div) const;
BBT_Time round_up_to_beat (BBT_Time const & bbt) const { return round_up_to_beat_div (bbt, 1); }
BBT_Time round_to_beat (BBT_Time const &) const;
@ -470,6 +471,7 @@ class LIBTEMPORAL_API TempoMetric
BBT_Argument bbt_add (BBT_Time const & bbt, BBT_Offset const & add) const { return BBT_Argument (reftime(), _meter->bbt_add (bbt, add)); }
BBT_Argument bbt_subtract (BBT_Time const & bbt, BBT_Offset const & sub) const { return BBT_Argument (reftime(), _meter->bbt_subtract (bbt, sub)); }
BBT_Argument round_to_bar (BBT_Time const & bbt) const { return BBT_Argument (reftime(), _meter->round_to_bar (bbt)); }
BBT_Argument round_up_to_bar (BBT_Time const & bbt) const { return BBT_Argument (reftime(), _meter->round_up_to_bar (bbt)); }
Beats to_quarters (BBT_Offset const & bbo) const { return _meter->to_quarters (bbo); }
/* combination methods that require both tempo and meter information */
@ -929,10 +931,13 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
*/
LIBTEMPORAL_API double quarters_per_minute_at (timepos_t const & pos) const;
/* convenience function */
/* convenience functions */
LIBTEMPORAL_API BBT_Argument round_to_bar (BBT_Argument const & bbt) const {
return metric_at (bbt).round_to_bar (bbt);
}
LIBTEMPORAL_API BBT_Argument round_up_to_bar (BBT_Argument const & bbt) const {
return metric_at (bbt).round_up_to_bar (bbt);
}
LIBTEMPORAL_API BBT_Argument bbt_at (timepos_t const &) const;
LIBTEMPORAL_API BBT_Argument bbt_at (Beats const &) const;