From 62a4df52c75ec56219027a14935ab6e5e6a3c5c0 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 10 Oct 2024 13:30:52 -0600 Subject: [PATCH] tentative steps in infrastructure for displaying clip data during capture --- libs/ardour/ardour/triggerbox.h | 2 ++ libs/ardour/triggerbox.cc | 63 +++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index fe4fd69793..623e5e9454 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -966,6 +966,8 @@ class LIBARDOUR_API TriggerBox : public Processor, public std::enable_shared_fro void maybe_capture (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes); void finish_recording (BufferSet& bufs); void set_armed (SlotArmInfo*); + SlotArmInfo* capture_info() const { return _arm_info; } + PBD::Signal0 Captured; /* These four are accessed (read/write) only from process() context */ diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 2b424e69ff..19cc94c81d 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -3633,7 +3633,7 @@ TriggerBox::maybe_capture (BufferSet& bufs, samplepos_t start_sample, samplepos_ /* Audio */ - const size_t n_buffers = bufs.count().n_audio(); + size_t n_buffers = bufs.count().n_audio(); if (n_buffers) { @@ -3646,38 +3646,49 @@ TriggerBox::maybe_capture (BufferSet& bufs, samplepos_t start_sample, samplepos_ } } - /* MIDI */ + n_buffers = bufs.count().n_midi(); + bool send_signal = false; - MidiBuffer& buf = bufs.get_midi (0); - Track* trk = static_cast (_owner); - MidiTrack* mt = dynamic_cast(trk); - MidiChannelFilter* filter = mt ? &mt->capture_filter() : 0; - TempoMap::SharedPtr tmap (TempoMap::use()); + if (n_buffers) { - for (MidiBuffer::iterator i = buf.begin(); i != buf.end(); ++i) { - Evoral::Event ev (*i, false); - if (ev.time() > nframes) { - break; - } + /* MIDI */ - bool skip_event = false; + MidiBuffer& buf = bufs.get_midi (0); + Track* trk = static_cast (_owner); + MidiTrack* mt = dynamic_cast(trk); + MidiChannelFilter* filter = mt ? &mt->capture_filter() : 0; + TempoMap::SharedPtr tmap (TempoMap::use()); - if (mt) { - /* skip injected immediate/out-of-band events */ - MidiBuffer const& ieb (mt->immediate_event_buffer()); - for (MidiBuffer::const_iterator j = ieb.begin(); j != ieb.end(); ++j) { - if (*j == ev) { - skip_event = true; + for (MidiBuffer::iterator i = buf.begin(); i != buf.end(); ++i) { + Evoral::Event ev (*i, false); + if (ev.time() > nframes) { + break; + } + + bool skip_event = false; + + if (mt) { + /* skip injected immediate/out-of-band events */ + MidiBuffer const& ieb (mt->immediate_event_buffer()); + for (MidiBuffer::const_iterator j = ieb.begin(); j != ieb.end(); ++j) { + if (*j == ev) { + skip_event = true; + } + } + } + + if (!skip_event && (!filter || !filter->filter(ev.buffer(), ev.size()))) { + const samplepos_t event_time (start_sample + ev.time() - ai->start.samples()); + if (!ai->end || (event_time < ai->end.samples())) { + ai->midi_buf->write (tmap->quarters_at_sample (event_time), ev.event_type(), ev.size(), ev.buffer()); + send_signal = true; } } } + } - if (!skip_event && (!filter || !filter->filter(ev.buffer(), ev.size()))) { - const samplepos_t event_time (start_sample + ev.time() - ai->start.samples()); - if (!ai->end || (event_time < ai->end.samples())) { - ai->midi_buf->write (tmap->quarters_at_sample (event_time), ev.event_type(), ev.size(), ev.buffer()); - } - } + if (send_signal) { + Captured(); /* EMIT SIGNAL */ } if (reached_end) { @@ -5632,7 +5643,7 @@ TriggerBoxThread::build_audio_source (AudioTrigger* t) plist2.add (ARDOUR::Properties::whole_file, false); std::shared_ptr copy (RegionFactory::create (whole, plist2)); - t->set_region_in_worker_thread_from_capture (copy); + t->set_region_in_worker_thread_from_capture (copy); /* make it loop */ t->set_follow_action0 (FollowAction::Again); }