diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2011-05-30 21:37:58 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2011-05-30 21:37:58 +0000 |
commit | de9e216cb5fcc08b6c39071d7cef031673aa67da (patch) | |
tree | 696922c23551b5609277be3dbbc4b1d378ad6fc2 /libs | |
parent | 14a80c091d850045bd35c56d5d378bfdd2fbe4f9 (diff) |
(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
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/delivery.h | 1 | ||||
-rw-r--r-- | libs/ardour/ardour/midi_port.h | 5 | ||||
-rw-r--r-- | libs/ardour/ardour/midi_track.h | 1 | ||||
-rw-r--r-- | libs/ardour/ardour/port.h | 1 | ||||
-rw-r--r-- | libs/ardour/ardour/processor.h | 1 | ||||
-rw-r--r-- | libs/ardour/ardour/route.h | 1 | ||||
-rw-r--r-- | libs/ardour/ardour/session.h | 1 | ||||
-rw-r--r-- | libs/ardour/delivery.cc | 12 | ||||
-rw-r--r-- | libs/ardour/midi_diskstream.cc | 2 | ||||
-rw-r--r-- | libs/ardour/midi_port.cc | 61 | ||||
-rw-r--r-- | libs/ardour/midi_source.cc | 3 | ||||
-rw-r--r-- | libs/ardour/midi_track.cc | 13 | ||||
-rw-r--r-- | libs/ardour/session_transport.cc | 21 |
13 files changed, 107 insertions, 16 deletions
diff --git a/libs/ardour/ardour/delivery.h b/libs/ardour/ardour/delivery.h index 309eff8511..70016ade05 100644 --- a/libs/ardour/ardour/delivery.h +++ b/libs/ardour/ardour/delivery.h @@ -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; } diff --git a/libs/ardour/ardour/midi_port.h b/libs/ardour/ardour/midi_port.h index 9a685be4e4..69e17ca08e 100644 --- a/libs/ardour/ardour/midi_port.h +++ b/libs/ardour/ardour/midi_port.h @@ -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 diff --git a/libs/ardour/ardour/midi_track.h b/libs/ardour/ardour/midi_track.h index 35f1ab58e3..af02585529 100644 --- a/libs/ardour/ardour/midi_track.h +++ b/libs/ardour/ardour/midi_track.h @@ -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>); diff --git a/libs/ardour/ardour/port.h b/libs/ardour/ardour/port.h index 15085ec47b..5eceac5ebc 100644 --- a/libs/ardour/ardour/port.h +++ b/libs/ardour/ardour/port.h @@ -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; diff --git a/libs/ardour/ardour/processor.h b/libs/ardour/ardour/processor.h index 05f7dd4fb1..d6d023d8d1 100644 --- a/libs/ardour/ardour/processor.h +++ b/libs/ardour/ardour/processor.h @@ -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 diff --git a/libs/ardour/ardour/route.h b/libs/ardour/ardour/route.h index 8f2baa18f9..5dc9c9358b 100644 --- a/libs/ardour/ardour/route.h +++ b/libs/ardour/ardour/route.h @@ -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 */ diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index c1bd84ae46..3bda654a8e 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -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 (); diff --git a/libs/ardour/delivery.cc b/libs/ardour/delivery.cc index efdb4d9ad0..31337e7e83 100644 --- a/libs/ardour/delivery.cc +++ b/libs/ardour/delivery.cc @@ -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 () { diff --git a/libs/ardour/midi_diskstream.cc b/libs/ardour/midi_diskstream.cc index 6c51958caa..a99feec465 100644 --- a/libs/ardour/midi_diskstream.cc +++ b/libs/ardour/midi_diskstream.cc @@ -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); } diff --git a/libs/ardour/midi_port.cc b/libs/ardour/midi_port.cc index 39f43eeef9..77fe712c5c 100644 --- a/libs/ardour/midi_port.cc +++ b/libs/ardour/midi_port.cc @@ -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)); } @@ -119,31 +119,60 @@ MidiPort::cycle_split () } 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) { if (sends_output ()) { 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 diff --git a/libs/ardour/midi_source.cc b/libs/ardour/midi_source.cc index 6f8e0184df..fe7a7821db 100644 --- a/libs/ardour/midi_source.cc +++ b/libs/ardour/midi_source.cc @@ -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; diff --git a/libs/ardour/midi_track.cc b/libs/ardour/midi_track.cc index 07b6d2ac6d..8ff9c3e0c5 100644 --- a/libs/ardour/midi_track.cc +++ b/libs/ardour/midi_track.cc @@ -399,6 +399,19 @@ MidiTrack::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_fr } 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 () { Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK); diff --git a/libs/ardour/session_transport.cc b/libs/ardour/session_transport.cc index a030d3afc2..48b84c492c 100644 --- a/libs/ardour/session_transport.cc +++ b/libs/ardour/session_transport.cc @@ -271,6 +271,15 @@ Session::realtime_stop (bool abort, bool clear_state) } 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 () { restart: @@ -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) { |