(1) push a locate all the way through the processing heirarchy so that MIDI output...
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 30 May 2011 21:37:58 +0000 (21:37 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 30 May 2011 21:37:58 +0000 (21:37 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@9635 d708f5d6-7413-0410-9779-e7cbd77b26cf

13 files changed:
libs/ardour/ardour/delivery.h
libs/ardour/ardour/midi_port.h
libs/ardour/ardour/midi_track.h
libs/ardour/ardour/port.h
libs/ardour/ardour/processor.h
libs/ardour/ardour/route.h
libs/ardour/ardour/session.h
libs/ardour/delivery.cc
libs/ardour/midi_diskstream.cc
libs/ardour/midi_port.cc
libs/ardour/midi_source.cc
libs/ardour/midi_track.cc
libs/ardour/session_transport.cc

index 309eff85111aad987d6e66c5cdb9a3eae24d51ed..70016ade0517070a28b96e9d5f3028ec21d89547 100644 (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; }
 
index 9a685be4e44b6810c566c765028a7d267b5fb0b8..69e17ca08e07c4db81bf913ef28766f0fbf82303 100644 (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
index 35f1ab58e3434d20f36967e5d6e2ac99acd4f96c..af0258552939b3f507bae8c1dbfbf12f9dcd985f 100644 (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>);
index 15085ec47ba970c2caad3586a4fc882910f57ea4..5eceac5ebcc0555baaabdf1bb934811ad00dcb4c 100644 (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;
 
index 05f7dd4fb1281b8726782ed7afbf8a48d28422ae..d6d023d8d1b67d2ba03e56da694193a4b54c7db6 100644 (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
index 8f2baa18f94dba3302a698fbb41a995d013c4c28..5dc9c9358b83ceeaf1554f8605d87f412732d6c7 100644 (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 */
index c1bd84ae4658a21ea4b26f86ce70de28b7812a50..3bda654a8ebd959147a892b410e8bc92494fdb92 100644 (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 ();
index efdb4d9ad0a354f4540a7c539727aacc916999dc..31337e7e83c18e22bc7874a95cdfe6338f486d13 100644 (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 ()
 {
index 6c51958caa859200ac6c41e40a64ccb392fb5c94..a99feec465f704baccad8daa91bfbc8fd4bc9e6e 100644 (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);
 }
 
 
index 39f43eeef90b6195604dab8eefe552af6a76d9c0..77fe712c5caeb28b84fc273bb74077fc68338803 100644 (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
index 6f8e0184df7d2701ac35c818500fc5200096cbdb..fe7a7821db8312bb1522871bb5b25af74fe800e4 100644 (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;
 
index 07b6d2ac6d127cb2c178bbc36700d526b3b05db6..8ff9c3e0c5f7988faf233be43ea03a0b7e329333 100644 (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 ()
 {
index a030d3afc2d6486d065fae41ee17304bd16a50ff..48b84c492c84ff50ffc1ecc65f3d8538a58cfdc5 100644 (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) {