summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2019-11-04 12:57:19 -0700
committerPaul Davis <paul@linuxaudiosystems.com>2019-11-04 12:57:19 -0700
commit62c4e88a9d8f4a7b019243fe9a10830b1da0150c (patch)
tree59f4809ddcc999d09898348cea9ca79e2fd20a54
parent47672fceec568949d8dcf3f2be516a644ff4ccbd (diff)
avoid use of Port::port_offset() everywhere except Port::flush_buffers() and Port::get_buffer()
Split cycles are run as if they are an entire self-contained cycle, starting at zero and running for "nframes". We adjust the timing and position of data only when retrieving and writing it to Port buffers.
-rw-r--r--libs/ardour/delivery.cc6
-rw-r--r--libs/ardour/disk_reader.cc4
-rw-r--r--libs/ardour/midi_buffer.cc21
-rw-r--r--libs/ardour/midi_port.cc16
-rw-r--r--libs/ardour/midi_track.cc12
-rw-r--r--libs/ardour/rt_midibuffer.cc2
-rw-r--r--libs/ardour/session_midi.cc11
-rw-r--r--libs/ardour/ticker.cc13
8 files changed, 37 insertions, 48 deletions
diff --git a/libs/ardour/delivery.cc b/libs/ardour/delivery.cc
index 463bfce88b..b27aded421 100644
--- a/libs/ardour/delivery.cc
+++ b/libs/ardour/delivery.cc
@@ -309,7 +309,7 @@ Delivery::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample
for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
if (*t != DataType::AUDIO && bufs.count().get(*t) > 0) {
- _output->copy_to_outputs (bufs, *t, nframes, Port::port_offset());
+ _output->copy_to_outputs (bufs, *t, nframes, 0);
}
}
@@ -328,7 +328,7 @@ Delivery::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample
for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
if (*t != DataType::AUDIO && bufs.count().get(*t) > 0) {
- _output->copy_to_outputs (bufs, *t, nframes, Port::port_offset());
+ _output->copy_to_outputs (bufs, *t, nframes, 0);
}
}
}
@@ -349,7 +349,7 @@ Delivery::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample
if (outs.count ().get (*t) <= n) {
continue;
}
- b->read_from (outs.get_available (*t, n++), nframes, (*t == DataType::AUDIO ? 0 : -Port::port_offset()));
+ b->read_from (outs.get_available (*t, n++), nframes, 0);
}
}
}
diff --git a/libs/ardour/disk_reader.cc b/libs/ardour/disk_reader.cc
index bb1717c8d7..c5e2256aa6 100644
--- a/libs/ardour/disk_reader.cc
+++ b/libs/ardour/disk_reader.cc
@@ -1100,8 +1100,8 @@ DiskReader::get_midi_playback (MidiBuffer& dst, samplepos_t start_sample, sample
* loop end.
*/
- DEBUG_TRACE (DEBUG::MidiDiskIO, string_compose ("playback buffer read, from %1 to %2 (%3)", start_sample, end_sample, nframes));
- size_t events_read = rtmb->read (*target, start_sample, end_sample, _tracker, Port::port_offset ());
+ DEBUG_TRACE (DEBUG::MidiDiskIO, string_compose ("playback buffer read, from %1 to %2 (%3)\n", start_sample, end_sample, nframes));
+ size_t events_read = rtmb->read (*target, start_sample, end_sample, _tracker);
DEBUG_TRACE (DEBUG::MidiDiskIO, string_compose ("%1 MDS events read %2 range %3 .. %4\n", _name, events_read, playback_sample, playback_sample + nframes));
}
diff --git a/libs/ardour/midi_buffer.cc b/libs/ardour/midi_buffer.cc
index 0a36c84e49..f447ef59f8 100644
--- a/libs/ardour/midi_buffer.cc
+++ b/libs/ardour/midi_buffer.cc
@@ -96,11 +96,6 @@ MidiBuffer::copy(MidiBuffer const * const copy)
}
-/** Read events from @a src starting at time @a offset into the START of this buffer, for
- * time duration @a nframes. Relative time, where 0 = start of buffer.
- *
- * Note that offset and nframes refer to sample time, NOT buffer offsets or event counts.
- */
void
MidiBuffer::read_from (const Buffer& src, samplecnt_t nframes, sampleoffset_t dst_offset, sampleoffset_t /* src_offset*/)
{
@@ -110,11 +105,10 @@ MidiBuffer::read_from (const Buffer& src, samplecnt_t nframes, sampleoffset_t ds
const MidiBuffer& msrc = (const MidiBuffer&) src;
assert (_capacity >= msrc.size());
+ assert (dst_offset == 0); /* there is no known scenario in Nov 2019 where this should be false */
- if (dst_offset == 0) {
- clear ();
- assert (_size == 0);
- }
+ clear ();
+ assert (_size == 0);
for (MidiBuffer::const_iterator i = msrc.begin(); i != msrc.end(); ++i) {
const Evoral::Event<TimeType> ev(*i, false);
@@ -129,9 +123,10 @@ MidiBuffer::read_from (const Buffer& src, samplecnt_t nframes, sampleoffset_t ds
Check it is within range of this (split) cycle, then shift.
*/
if (ev.time() >= 0 && ev.time() < nframes) {
- push_back (ev.time() + dst_offset, ev.size(), ev.buffer());
+ push_back (ev.time(), ev.size(), ev.buffer());
} else {
- cerr << "\t!!!! MIDI event @ " << ev.time() << " skipped, not within range 0 .. " << nframes << ": ";
+ cerr << "\t!!!! MIDI event @ " << ev.time() << " skipped, not within range 0 .. " << nframes << endl;
+ PBD::stacktrace (cerr, 30);
}
} else {
/* Negative offset: shifting events from global/port
@@ -143,12 +138,12 @@ MidiBuffer::read_from (const Buffer& src, samplecnt_t nframes, sampleoffset_t ds
Shift first, then check it is within range of this
(split) cycle.
*/
- const samplepos_t evtime = ev.time() + dst_offset;
+ const samplepos_t evtime = ev.time();
if (evtime >= 0 && evtime < nframes) {
push_back (evtime, ev.size(), ev.buffer());
} else {
- cerr << "\t!!!! MIDI event @ " << evtime << " (based on " << ev.time() << " + " << dst_offset << ") skipped, not within range 0 .. " << nframes << ": ";
+ cerr << "\t!!!! MIDI event @ " << evtime << " (based on " << ev.time() << ") skipped, not within range 0 .. " << nframes << ": ";
}
}
}
diff --git a/libs/ardour/midi_port.cc b/libs/ardour/midi_port.cc
index 7eed2ef468..2e0d8c2e44 100644
--- a/libs/ardour/midi_port.cc
+++ b/libs/ardour/midi_port.cc
@@ -273,12 +273,13 @@ MidiPort::flush_buffers (pframes_t nframes)
const Evoral::Event<MidiBuffer::TimeType> ev (*i, false);
+ const samplepos_t adjusted_time = ev.time() + _global_port_buffer_offset;
if (sends_output() && _trace_parser) {
uint8_t const * const buf = ev.buffer();
const samplepos_t now = AudioEngine::instance()->sample_time_at_cycle_start();
- _trace_parser->set_timestamp (now + ev.time());
+ _trace_parser->set_timestamp (now + adjusted_time);
uint32_t limit = ev.size();
@@ -295,8 +296,8 @@ MidiPort::flush_buffers (pframes_t nframes)
const Session* s = AudioEngine::instance()->session();
const samplepos_t now = (s ? s->transport_sample() : 0);
DEBUG_STR_DECL(a);
- DEBUG_STR_APPEND(a, string_compose ("MidiPort %7 %1 pop event @ %2 (global %4, within %5 gpbo %6 sz %3 ", _buffer, ev.time(), ev.size(),
- now + ev.time(), nframes, _global_port_buffer_offset, name()));
+ DEBUG_STR_APPEND(a, string_compose ("MidiPort %7 %1 pop event @ %2[%7] (global %4, within %5 gpbo %6 sz %3 ", _buffer, adjusted_time, ev.size(),
+ now + adjusted_time, nframes, _global_port_buffer_offset, name(), ev.time()));
for (size_t i=0; i < ev.size(); ++i) {
DEBUG_STR_APPEND(a,hex);
DEBUG_STR_APPEND(a,"0x");
@@ -311,14 +312,13 @@ MidiPort::flush_buffers (pframes_t nframes)
// XXX consider removing this check for optimized builds
// and just send 'em all, at cycle_end
// see AudioEngine::split_cycle (), PortManager::cycle_end()
- if ( ev.time() >= _global_port_buffer_offset
- && ev.time() < _global_port_buffer_offset + nframes) {
- pframes_t tme = floor (ev.time() / _speed_ratio);
+ if ((adjusted_time >= _global_port_buffer_offset) && (adjusted_time < _global_port_buffer_offset + nframes)) {
+ pframes_t tme = floor (adjusted_time / _speed_ratio);
if (port_engine.midi_event_put (port_buffer, tme, ev.buffer(), ev.size()) != 0) {
- cerr << "write failed, dropped event, time " << ev.time() << endl;
+ cerr << "write failed, dropped event, time " << adjusted_time << '/' << ev.time() << endl;
}
} else {
- cerr << "Dropped outgoing MIDI event. time " << ev.time()
+ cerr << "Dropped outgoing MIDI event. time " << adjusted_time << '/' << ev.time()
<< " out of range [" << _global_port_buffer_offset
<< " .. " << _global_port_buffer_offset + nframes
<< "]";
diff --git a/libs/ardour/midi_track.cc b/libs/ardour/midi_track.cc
index 575ccdc3a5..2711f2e864 100644
--- a/libs/ardour/midi_track.cc
+++ b/libs/ardour/midi_track.cc
@@ -462,12 +462,12 @@ MidiTrack::snapshot_out_of_band_data (samplecnt_t nframes)
* the last argument ("stop on overflow in destination") so that we'll
* ship the rest out next time.
*
- * the Port::port_offset() + (nframes-1) argument puts all these events at the last
+ * the (nframes-1) argument puts all these events at the last
* possible position of the output buffer, so that we do not
- * violate monotonicity when writing. Port::port_offset() will
- * be non-zero if we're in a split process cycle.
+ * violate monotonicity when writing.
*/
- _immediate_events.read (_immediate_event_buffer, 0, 1, Port::port_offset() + nframes - 1, true);
+
+ _immediate_events.read (_immediate_event_buffer, 0, 1, nframes - 1, true);
}
void
@@ -821,7 +821,7 @@ MidiTrack::act_on_mute ()
}
/* Resolve active notes. */
- _disk_reader->resolve_tracker(_immediate_events, Port::port_offset());
+ _disk_reader->resolve_tracker (_immediate_events, 0);
}
}
@@ -873,7 +873,7 @@ void
MidiTrack::realtime_handle_transport_stopped ()
{
Route::realtime_handle_transport_stopped ();
- _disk_reader->resolve_tracker (_immediate_events, Port::port_offset());
+ _disk_reader->resolve_tracker (_immediate_events, 0);
}
void
diff --git a/libs/ardour/rt_midibuffer.cc b/libs/ardour/rt_midibuffer.cc
index ec8a2852bd..3a60c9e93f 100644
--- a/libs/ardour/rt_midibuffer.cc
+++ b/libs/ardour/rt_midibuffer.cc
@@ -223,7 +223,7 @@ RTMidiBuffer::read (MidiBuffer& dst, samplepos_t start, samplepos_t end, MidiSta
break;
}
- DEBUG_TRACE (DEBUG::MidiRingBuffer, string_compose ("read event sz %1 @ %2\n", size, unadjusted_time));
+ DEBUG_TRACE (DEBUG::MidiRingBuffer, string_compose ("read event sz %1 @ %2 (=> %3 via -%4 +%5\n", size, unadjusted_time, evtime, start, offset));
tracker.track (addr);
++item;
diff --git a/libs/ardour/session_midi.cc b/libs/ardour/session_midi.cc
index 2e77aa6ef2..6967a1cdf5 100644
--- a/libs/ardour/session_midi.cc
+++ b/libs/ardour/session_midi.cc
@@ -456,7 +456,7 @@ Session::send_full_time_code (samplepos_t const t, MIDI::pframes_t nframes)
// Send message at offset 0, sent time is for the start of this cycle
MidiBuffer& mb (_midi_ports->mtc_output_port()->get_midi_buffer (nframes));
- mb.push_back (Port::port_offset(), sizeof (msg), msg);
+ mb.push_back (0, sizeof (msg), msg);
_pframes_since_last_mtc = 0;
return 0;
@@ -558,7 +558,7 @@ Session::send_midi_time_code_for_cycle (samplepos_t start_sample, samplepos_t en
assert (out_stamp < nframes);
MidiBuffer& mb (_midi_ports->mtc_output_port()->get_midi_buffer(nframes));
- if (!mb.push_back (Port::port_offset () + out_stamp, 2, mtc_msg)) {
+ if (!mb.push_back (out_stamp, 2, mtc_msg)) {
error << string_compose(_("Session: cannot send quarter-frame MTC message (%1)"), strerror (errno))
<< endmsg;
return -1;
@@ -598,12 +598,7 @@ Session::send_midi_time_code_for_cycle (samplepos_t start_sample, samplepos_t en
void
Session::send_immediate_mmc (MachineControlCommand c)
{
- if (AudioEngine::instance()->in_process_thread()) {
- _mmc->send (c, Port::port_offset());
- } else {
- _mmc->send (c, 0);
- }
-
+ _mmc->send (c, 0);
}
bool
diff --git a/libs/ardour/ticker.cc b/libs/ardour/ticker.cc
index 7e36978177..7d378d72ae 100644
--- a/libs/ardour/ticker.cc
+++ b/libs/ardour/ticker.cc
@@ -329,7 +329,7 @@ MidiClockTicker::send_midi_clock_event (pframes_t offset, pframes_t nframes)
static uint8_t msg = MIDI_CMD_COMMON_CLOCK;
MidiBuffer& mb (_midi_port->get_midi_buffer (nframes));
- mb.push_back (offset + Port::port_offset(), 1, &msg);
+ mb.push_back (offset, 1, &msg);
DEBUG_TRACE (DEBUG::MidiClock, string_compose ("Tick with offset %1\n", offset));
}
@@ -343,7 +343,7 @@ MidiClockTicker::send_start_event (pframes_t offset, pframes_t nframes)
static uint8_t msg = { MIDI_CMD_COMMON_START };
MidiBuffer& mb (_midi_port->get_midi_buffer (nframes));
- mb.push_back (offset + Port::port_offset(), 1, &msg);
+ mb.push_back (offset, 1, &msg);
DEBUG_TRACE (DEBUG::MidiClock, string_compose ("Start %1\n", _last_tick));
}
@@ -357,7 +357,7 @@ MidiClockTicker::send_continue_event (pframes_t offset, pframes_t nframes)
static uint8_t msg = { MIDI_CMD_COMMON_CONTINUE };
MidiBuffer& mb (_midi_port->get_midi_buffer (nframes));
- mb.push_back (offset + Port::port_offset(), 1, &msg);
+ mb.push_back (offset, 1, &msg);
DEBUG_TRACE (DEBUG::MidiClock, string_compose ("Continue %1\n", _last_tick));
}
@@ -371,7 +371,7 @@ MidiClockTicker::send_stop_event (pframes_t offset, pframes_t nframes)
static uint8_t msg = MIDI_CMD_COMMON_STOP;
MidiBuffer& mb (_midi_port->get_midi_buffer (nframes));
- mb.push_back (offset + Port::port_offset(), 1, &msg);
+ mb.push_back (offset, 1, &msg);
DEBUG_TRACE (DEBUG::MidiClock, string_compose ("Stop %1\n", _last_tick));
}
@@ -395,9 +395,8 @@ MidiClockTicker::send_position_event (uint32_t midi_beats, pframes_t offset, pfr
msg[2] = midi_beats >> 7;
MidiBuffer& mb (_midi_port->get_midi_buffer (nframes));
- mb.push_back (offset + Port::port_offset(), 3, &msg[0]);
+ mb.push_back (offset, 3, &msg[0]);
- DEBUG_TRACE (DEBUG::MidiClock, string_compose ("Song Position Sent: %1 to %2 (events now %3, buf = %4)\n", midi_beats, _midi_port->name(),
- mb.size(), &mb));
+ DEBUG_TRACE (DEBUG::MidiClock, string_compose ("Song Position Sent: %1 to %2 (events now %3, buf = %4)\n", midi_beats, _midi_port->name(), mb.size(), &mb));
}