temporal: rename Point::sample() to Point::sample_is_dangerous()

It is risky to take the sample value returned by this method and then convert it back
to either superclocks or beats, mostly because tempo & meter times are generally in
music time, and converting from superclocks to samples loses precision.

This rename is there to serve as a reminder to developers to be careful when using
this method
This commit is contained in:
Paul Davis 2025-12-29 09:13:41 -07:00
parent 22eee12f55
commit 8f815e21ea
5 changed files with 8 additions and 8 deletions

View file

@ -819,7 +819,7 @@ LuaBindings::common (lua_State* L)
.beginClass <Temporal::Point> ("Point")
.addFunction ("sclock", &Temporal::Point::sclock)
.addFunction ("beats", &Temporal::Point::beats)
.addFunction ("sample", &Temporal::Point::sample)
.addFunction ("sample", &Temporal::Point::sample_is_dangerous)
.addFunction ("bbt", &Temporal::Point::bbt)
.addFunction ("time", &Temporal::Point::time)
.endClass ()

View file

@ -3005,9 +3005,9 @@ LV2Plugin::connect_and_run(BufferSet& bufs,
}
}
while (m != m_end || ((tempo_map_point != tempo_map_points.end()) && ((*tempo_map_point).sample(TEMPORAL_SAMPLE_RATE) < tend))) {
while (m != m_end || ((tempo_map_point != tempo_map_points.end()) && ((*tempo_map_point).sample_is_dangerous (TEMPORAL_SAMPLE_RATE) < tend))) {
if (m != m_end && ((tempo_map_point == tempo_map_points.end()) || (*tempo_map_point).sample(TEMPORAL_SAMPLE_RATE) > (*m).time() + offset)) {
if (m != m_end && ((tempo_map_point == tempo_map_points.end()) || (*tempo_map_point).sample_is_dangerous (TEMPORAL_SAMPLE_RATE) > (*m).time() + offset)) {
const Evoral::Event<samplepos_t> ev (*m, false);
@ -3020,7 +3020,7 @@ LV2Plugin::connect_and_run(BufferSet& bufs,
} else {
assert (tempo_map_point != tempo_map_points.end());
const samplepos_t sample = tempo_map_point->sample (TEMPORAL_SAMPLE_RATE);
const samplepos_t sample = tempo_map_point->sample_is_dangerous (TEMPORAL_SAMPLE_RATE);
const Temporal::BBT_Time bbt = tempo_map_point->bbt();
double bpm = (superclock_ticks_per_second() * 60) / tempo_map_point->superclocks_per_note_type_at_superclock (tempo_map_point->sclock());

View file

@ -142,9 +142,9 @@ Session::click (samplepos_t cycle_start, samplecnt_t nframes)
assert (superclock_to_samples (p.sclock(), sample_rate()) < end);
if (p.bbt().is_bar() && (click_emphasis_data && Config->get_use_click_emphasis())) {
add_click (p.sample (sample_rate()), true);
add_click (p.sample_is_dangerous (sample_rate()), true);
} else {
add_click (p.sample (sample_rate()), false);
add_click (p.sample_is_dangerous (sample_rate()), false);
}
}

View file

@ -3325,7 +3325,7 @@ std::ostream&
std::operator<<(std::ostream& str, TempoMapPoint const & tmp)
{
str << '@' << std::setw (12) << tmp.sclock() << ' ' << tmp.sclock() / (double) superclock_ticks_per_second()
<< " secs " << tmp.sample (TEMPORAL_SAMPLE_RATE) << " samples"
<< " secs " << tmp.sample_is_dangerous (TEMPORAL_SAMPLE_RATE) << " samples"
<< (tmp.is_explicit_tempo() ? " EXP-T" : " imp-t")
<< (tmp.is_explicit_meter() ? " EXP-M" : " imp-m")
<< (tmp.is_explicit_position() ? " EXP-P" : " imp-p")

View file

@ -102,7 +102,7 @@ class /*LIBTEMPORAL_API*/ Point : public point_hook, public MapOwned {
LIBTEMPORAL_API superclock_t sclock() const { return _sclock; }
LIBTEMPORAL_API Beats const & beats() const { return _quarters; }
LIBTEMPORAL_API BBT_Time const & bbt() const { return _bbt; }
LIBTEMPORAL_API samplepos_t sample (int sr) const { return superclock_to_samples (sclock(), sr); }
LIBTEMPORAL_API samplepos_t sample_is_dangerous (int sr) const { return superclock_to_samples (sclock(), sr); }
LIBTEMPORAL_API virtual timepos_t time() const = 0;