(1) push a locate all the way through the processing heirarchy so that MIDI output ports can resolve any notes currently playing (2) remove MidiStateTracker from MidiPort and use a fixed set of MIDI messages (sustain-off and all-notes-off, per channel) to do note resolution (3) move note resolution caused by a LoopEvent psuedo-event to within the main MidiPort::flush_output() loop, so that we resolve (turn off) Notes that come before the loop point, rather than send them out after the note resolution messages

git-svn-id: svn://localhost/ardour2/branches/3.0@9635 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2011-05-30 21:37:58 +00:00
parent 14a80c091d
commit de9e216cb5
13 changed files with 107 additions and 16 deletions

View File

@ -76,6 +76,7 @@ public:
void no_outs_cuz_we_no_monitor(bool);
void cycle_start (pframes_t);
void transport_stopped (framepos_t frame);
void realtime_locate ();
BufferSet& output_buffers() { return *_output_buffers; }

View File

@ -43,6 +43,7 @@ class MidiPort : public Port {
void flush_buffers (pframes_t nframes, framepos_t time);
void transport_stopped ();
void realtime_locate ();
void reset ();
Buffer& get_buffer (pframes_t nframes) {
@ -59,9 +60,9 @@ class MidiPort : public Port {
private:
MidiBuffer* _buffer;
bool _has_been_mixed_down;
bool _resolve_in_process;
bool _resolve_required;
MidiStateTracker _midi_state_tracker;
void resolve_notes (void* jack_buffer, MidiBuffer::TimeType when);
};
} // namespace ARDOUR

View File

@ -43,6 +43,7 @@ public:
int declick, bool can_record, bool rec_monitors_input, bool& need_butler);
void realtime_handle_transport_stopped ();
void realtime_locate ();
void use_new_diskstream ();
void set_diskstream (boost::shared_ptr<Diskstream>);

View File

@ -118,6 +118,7 @@ public:
virtual Buffer& get_buffer (pframes_t nframes) = 0;
virtual void flush_buffers (pframes_t /*nframes*/, framepos_t /*time*/) {}
virtual void transport_stopped () {}
virtual void realtime_locate () {}
bool physically_connected () const;

View File

@ -85,6 +85,7 @@ class Processor : public SessionObject, public Automatable, public Latent
virtual ChanCount output_streams() const { return _configured_output; }
virtual void realtime_handle_transport_stopped () {}
virtual void realtime_locate () {}
/* note: derived classes should implement state(), NOT get_state(), to allow
us to merge C++ inheritance and XML lack-of-inheritance reasonably

View File

@ -124,6 +124,7 @@ class Route : public SessionObject, public Automatable, public RouteGroupMember,
virtual bool record_enabled() const { return false; }
virtual void nonrealtime_handle_transport_stopped (bool abort, bool did_locate, bool flush_processors);
virtual void realtime_handle_transport_stopped () {}
virtual void realtime_locate () {}
virtual void set_pending_declick (int);
/* end of vfunc-based API */

View File

@ -1195,6 +1195,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
void stop_transport (bool abort = false, bool clear_state = false);
void start_transport ();
void realtime_stop (bool abort, bool clear_state);
void realtime_locate ();
void non_realtime_start_scrub ();
void non_realtime_set_speed ();
void non_realtime_locate ();

View File

@ -479,6 +479,18 @@ Delivery::transport_stopped (framepos_t now)
}
}
void
Delivery::realtime_locate ()
{
if (_output) {
PortSet& ports (_output->ports());
for (PortSet::iterator i = ports.begin(); i != ports.end(); ++i) {
(*i).realtime_locate ();
}
}
}
gain_t
Delivery::target_gain ()
{

View File

@ -146,7 +146,7 @@ MidiDiskstream::non_realtime_locate (framepos_t position)
if (_write_source) {
_write_source->set_timeline_position (position);
}
seek(position, false);
seek (position, false);
}

View File

@ -29,7 +29,7 @@ using namespace std;
MidiPort::MidiPort (const std::string& name, Flags flags)
: Port (name, DataType::MIDI, flags)
, _has_been_mixed_down (false)
, _resolve_in_process (false)
, _resolve_required (false)
{
_buffer = new MidiBuffer (AudioEngine::instance()->raw_buffer_size (DataType::MIDI));
}
@ -118,6 +118,35 @@ MidiPort::cycle_split ()
_has_been_mixed_down = false;
}
void
MidiPort::resolve_notes (void* jack_buffer, MidiBuffer::TimeType when)
{
uint8_t ev[3];
ev[2] = 0;
for (uint8_t channel = 0; channel <= 0xF; channel++) {
ev[0] = (MIDI_CMD_CONTROL | channel);
/* we need to send all notes off AND turn the
* sustain/damper pedal off to handle synths
* that prioritize sustain over AllNotesOff
*/
ev[1] = MIDI_CTL_SUSTAIN;
if (jack_midi_event_write (jack_buffer, when, ev, 3) != 0) {
cerr << "failed to deliver sustain-zero on channel " << channel << " on port " << name() << endl;
}
ev[1] = MIDI_CTL_ALL_NOTES_OFF;
if (jack_midi_event_write (jack_buffer, 0, ev, 3) != 0) {
cerr << "failed to deliver ALL NOTES OFF on channel " << channel << " on port " << name() << endl;
}
}
}
void
MidiPort::flush_buffers (pframes_t nframes, framepos_t time)
{
@ -125,25 +154,25 @@ MidiPort::flush_buffers (pframes_t nframes, framepos_t time)
void* jack_buffer = jack_port_get_buffer (_jack_port, nframes);
// Feed the data through the MidiStateTracker
bool did_loop;
_midi_state_tracker.track (_buffer->begin(), _buffer->end(), did_loop);
if (did_loop || _resolve_in_process) {
/* add necessary note offs */
_midi_state_tracker.resolve_notes (*_buffer, time);
if (_resolve_required) {
/* resolve all notes at the start of the buffer */
resolve_notes (jack_buffer, 0);
_resolve_required= false;
}
_resolve_in_process = false;
for (MidiBuffer::iterator i = _buffer->begin(); i != _buffer->end(); ++i) {
const Evoral::Event<framepos_t>& ev = *i;
const Evoral::MIDIEvent<MidiBuffer::TimeType> ev (*i, false);
// event times are in frames, relative to cycle start
assert (ev.time() < (nframes + _global_port_buffer_offset + _port_buffer_offset));
if (ev.event_type() == LoopEventType) {
resolve_notes (jack_buffer, ev.time());
continue;
}
if (ev.time() >= _global_port_buffer_offset + _port_buffer_offset) {
if (jack_midi_event_write (jack_buffer, (jack_nframes_t) ev.time(), ev.buffer(), ev.size()) != 0) {
cerr << "write failed, drop flushed note off on the floor, time "
@ -160,7 +189,13 @@ MidiPort::flush_buffers (pframes_t nframes, framepos_t time)
void
MidiPort::transport_stopped ()
{
_resolve_in_process = true;
_resolve_required = true;
}
void
MidiPort::realtime_locate ()
{
_resolve_required = true;
}
void

View File

@ -206,6 +206,9 @@ MidiSource::midi_read (Evoral::EventSink<framepos_t>& dst, framepos_t source_sta
BeatsFramesConverter converter(_session.tempo_map(), source_start);
DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("MidiSource::midi-read() sstart %1 start %2 cnt %3 tracker %4\n",
source_start, start, cnt, tracker));
if (_model) {
Evoral::Sequence<double>::const_iterator& i = _model_iter;

View File

@ -398,6 +398,19 @@ MidiTrack::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_fr
return ret;
}
void
MidiTrack::realtime_locate ()
{
Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
if (!lm.locked ()) {
return;
}
for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
(*i)->realtime_locate ();
}
}
void
MidiTrack::realtime_handle_transport_stopped ()
{

View File

@ -270,6 +270,15 @@ Session::realtime_stop (bool abort, bool clear_state)
transport_sub_state = 0;
}
void
Session::realtime_locate ()
{
boost::shared_ptr<RouteList> r = routes.reader ();
for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
(*i)->realtime_locate ();
}
}
void
Session::butler_transport_work ()
{
@ -843,8 +852,20 @@ Session::locate (framepos_t target_frame, bool with_roll, bool with_flush, bool
outbound_mtc_timecode_frame = _transport_frame;
next_quarter_frame_to_send = 0;
/* do "stopped" stuff if:
*
* we are rolling AND
* no autoplay in effect AND
* we're not going to keep rolling after the locate AND
* !(playing a loop with JACK sync)
*
*/
if (transport_rolling() && (!auto_play_legal || !config.get_auto_play()) && !with_roll && !(synced_to_jack() && play_loop)) {
realtime_stop (false, true); // XXX paul - check if the 2nd arg is really correct
} else {
/* otherwise tell the world that we located */
realtime_locate ();
}
if (force || !with_loop || loop_changing) {