13
0

working segment descriptor save/restore/set/fetch and use by triggerbox

This commit is contained in:
Paul Davis 2022-01-14 09:57:16 -07:00
parent 6d2a124f5e
commit 9ccaab5deb
2 changed files with 35 additions and 8 deletions

View File

@ -147,8 +147,10 @@ Source::get_state ()
for (auto const & sd : segment_descriptors) {
sd_node->add_child_nocopy (sd.get_state());
}
node->add_child_nocopy (*sd_node);
}
return *node;
}
@ -540,11 +542,34 @@ Source::empty () const
bool
Source::get_segment_descriptor (TimelineRange const & range, SegmentDescriptor& segment)
{
/* Note: since we disallow overlapping segments, any overlap between
the @param range and an existing segment counts as a match.
*/
for (auto const & sd : segment_descriptors) {
if (coverage_exclusive_ends (sd.position(), sd.position() + sd.extent(),
segment.position(), segment.position() + segment.extent()) != Temporal::OverlapNone) {
segment = sd;
return true;
}
}
return false;
}
int
Source::set_segment_descriptor (SegmentDescriptor const & sr)
{
/* We disallow any overlap between segments. They must describe non-overlapping ranges */
for (auto const & sd : segment_descriptors) {
if (coverage_exclusive_ends (sd.position(), sd.position() + sd.extent(),
sr.position(), sr.position() + sr.extent()) != Temporal::OverlapNone) {
return -1;
}
}
segment_descriptors.push_back (sr);
return 0;
}

View File

@ -1100,6 +1100,7 @@ AudioTrigger::estimate_tempo ()
_estimated_tempo = segment.tempo().quarter_notes_per_minute ();
_meter = segment.meter();
DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1: tempo and meter from segment descriptor\n", index()));
} else {
/* not a great guess, but what else can we do? */
@ -1170,17 +1171,18 @@ AudioTrigger::estimate_tempo ()
return;
}
if (!have_segment) {
segment.set_extent (_region->start_sample(), _region->length_samples());
}
cerr << name() << " Estimated bpm " << _apparent_tempo << " from " << (double) data.length / _box.session().sample_rate() << " seconds\n";
}
segment.set_tempo (Temporal::Tempo (_estimated_tempo, 4));
if (!have_segment) {
segment.set_extent (_region->start_sample(), _region->length_samples());
}
for (auto & src : _region->sources()) {
src->set_segment_descriptor (segment);
}
cerr << name() << " Estimated bpm " << _estimated_tempo << " from " << (double) data.length / _box.session().sample_rate() << " seconds\n";
segment.set_tempo (Temporal::Tempo (_estimated_tempo, 4));
cerr << name() << " Estimated bpm " << _estimated_tempo << " from " << (double) data.length / _box.session().sample_rate() << " seconds\n";
for (auto & src : _region->sources()) {
src->set_segment_descriptor (segment);
}
}