Fix compile warning.
[ardour.git] / libs / ardour / session_process.cc
index 9baa0aea9e81dc6657bb08c8ed3e82b42f0426f9..e24b660fb69297521dc271983eabfb183a7c9d79 100644 (file)
 #include <glibmm/thread.h>
 
 #include "ardour/ardour.h"
-#include "ardour/audio_diskstream.h"
 #include "ardour/audioengine.h"
 #include "ardour/auditioner.h"
 #include "ardour/butler.h"
 #include "ardour/debug.h"
+#include "ardour/process_thread.h"
 #include "ardour/session.h"
 #include "ardour/slave.h"
 #include "ardour/timestamps.h"
+#include "ardour/port.h"
 
 #include "midi++/manager.h"
 
@@ -65,9 +66,13 @@ Session::process (nframes_t nframes)
                        post_transport ();
                }
        }
+        
+        _engine.main_thread()->get_buffers ();
 
        (this->*process_function) (nframes);
 
+        _engine.main_thread()->drop_buffers ();
+
        // the ticker is for sending time information like MidiClock
        nframes_t transport_frames = transport_frame();
        BBT_Time  transport_bbt;
@@ -81,15 +86,6 @@ Session::process (nframes_t nframes)
        MIDI::Manager::instance()->cycle_end();
 }
 
-void
-Session::prepare_diskstreams ()
-{
-       boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader();
-       for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
-               (*i)->prepare ();
-       }
-}
-
 int
 Session::fail_roll (nframes_t nframes)
 {
@@ -128,7 +124,7 @@ Session::no_roll (nframes_t nframes)
 }
 
 int
-Session::process_routes (nframes_t nframes)
+Session::process_routes (nframes_t nframes, bool& need_butler)
 {
        bool record_active;
        int  declick = get_transport_declick_required();
@@ -155,18 +151,7 @@ Session::process_routes (nframes_t nframes)
 
                (*i)->set_pending_declick (declick);
 
-               if ((ret = (*i)->roll (nframes, start_frame, end_frame, declick, record_active, rec_monitors)) < 0) {
-
-                       /* we have to do this here. Route::roll() for an AudioTrack will have called AudioDiskstream::process(),
-                          and the DS will expect AudioDiskstream::commit() to be called. but we're aborting from that
-                          call path, so make sure we release any outstanding locks here before we return failure.
-                       */
-
-                       boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader();
-                       for (DiskstreamList::iterator ids = dsl->begin(); ids != dsl->end(); ++ids) {
-                               (*ids)->recover ();
-                       }
-
+               if ((ret = (*i)->roll (nframes, start_frame, end_frame, declick, record_active, rec_monitors, need_butler)) < 0) {
                        stop_transport ();
                        return -1;
                }
@@ -176,7 +161,7 @@ Session::process_routes (nframes_t nframes)
 }
 
 int
-Session::silent_process_routes (nframes_t nframes)
+Session::silent_process_routes (nframes_t nframes, bool& need_butler)
 {
        bool record_active = actively_recording();
        int  declick = get_transport_declick_required();
@@ -199,18 +184,7 @@ Session::silent_process_routes (nframes_t nframes)
                        continue;
                }
 
-               if ((ret = (*i)->silent_roll (nframes, start_frame, end_frame, record_active, rec_monitors)) < 0) {
-
-                       /* we have to do this here. Route::roll() for an AudioTrack will have called AudioDiskstream::process(),
-                          and the DS will expect AudioDiskstream::commit() to be called. but we're aborting from that
-                          call path, so make sure we release any outstanding locks here before we return failure.
-                       */
-
-                       boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader();
-                       for (DiskstreamList::iterator ids = dsl->begin(); ids != dsl->end(); ++ids) {
-                               (*ids)->recover ();
-                       }
-
+               if ((ret = (*i)->silent_roll (nframes, start_frame, end_frame, record_active, rec_monitors, need_butler)) < 0) {
                        stop_transport ();
                        return -1;
                }
@@ -220,36 +194,22 @@ Session::silent_process_routes (nframes_t nframes)
 }
 
 void
-Session::commit_diskstreams (nframes_t nframes, bool &needs_butler)
+Session::get_track_statistics ()
 {
-       int dret;
        float pworst = 1.0f;
        float cworst = 1.0f;
 
-       boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader();
-       for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
+       boost::shared_ptr<RouteList> rl = routes.reader();
+       for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
 
-               if ((*i)->hidden()) {
-                       continue;
-               }
-
-               /* force all diskstreams not handled by a Route to call do their stuff.
-                  Note: the diskstreams that were handled by a route will just return zero
-                  from this call, because they know they were processed. So in fact, this
-                  also runs commit() for every diskstream.
-                */
-
-               if ((dret = (*i)->process (_transport_frame, nframes, actively_recording(), get_rec_monitors_input())) == 0) {
-                       if ((*i)->commit (nframes)) {
-                               needs_butler = true;
-                       }
+               boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
 
-               } else if (dret < 0) {
-                       (*i)->recover();
+               if (!tr || tr->hidden()) {
+                       continue;
                }
 
-               pworst = min (pworst, (*i)->playback_buffer_load());
-               cworst = min (cworst, (*i)->capture_buffer_load());
+               pworst = min (pworst, tr->playback_buffer_load());
+               cworst = min (cworst, tr->capture_buffer_load());
        }
 
        uint32_t pmin = g_atomic_int_get (&_playback_load);
@@ -394,16 +354,11 @@ Session::process_with_events (nframes_t nframes)
 
                                click (_transport_frame, this_nframes);
 
-                               /* now process frames between now and the first event in this block */
-                               prepare_diskstreams ();
-
-                               if (process_routes (this_nframes)) {
+                               if (process_routes (this_nframes, session_needs_butler)) {
                                        fail_roll (nframes);
                                        return;
                                }
 
-                               commit_diskstreams (this_nframes, session_needs_butler);
-
                                nframes -= this_nframes;
 
                                if (frames_moved < 0) {
@@ -686,18 +641,21 @@ Session::track_slave_state (float slave_speed, nframes_t slave_transport_frame,
                                bool ok = true;
                                nframes_t frame_delta = slave_transport_frame - _transport_frame;
 
-                               boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader();
-
-                               for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
-                                       if (!(*i)->can_internal_playback_seek (frame_delta)) {
+                               boost::shared_ptr<RouteList> rl = routes.reader();
+                               for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
+                                       boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
+                                       if (tr && !tr->can_internal_playback_seek (frame_delta)) {
                                                ok = false;
                                                break;
                                        }
                                }
 
                                if (ok) {
-                                       for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) {
-                                               (*i)->internal_playback_seek (frame_delta);
+                                       for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
+                                               boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
+                                               if (tr) {
+                                                       tr->internal_playback_seek (frame_delta);
+                                               }
                                        }
                                        _transport_frame += frame_delta;
 
@@ -746,9 +704,7 @@ Session::follow_slave_silently (nframes_t nframes, float slave_speed)
 
                bool need_butler;
 
-               prepare_diskstreams ();
-               silent_process_routes (nframes);
-               commit_diskstreams (nframes, need_butler);
+               silent_process_routes (nframes, need_butler);
 
                if (need_butler) {
                        _butler->summon ();
@@ -826,8 +782,6 @@ Session::process_without_events (nframes_t nframes)
 
        click (_transport_frame, nframes);
 
-       prepare_diskstreams ();
-
        if (_transport_speed == 1.0) {
                frames_moved = (long) nframes;
        } else {
@@ -836,13 +790,11 @@ Session::process_without_events (nframes_t nframes)
                frames_moved = (long) interpolation.interpolate (0, nframes, 0, 0);
        }
 
-       if (process_routes (nframes)) {
+       if (process_routes (nframes, session_needs_butler)) {
                fail_roll (nframes);
                return;
        }
 
-       commit_diskstreams (nframes, session_needs_butler);
-
        if (frames_moved < 0) {
                decrement_transport_position (-frames_moved);
        } else {
@@ -878,6 +830,12 @@ Session::process_audition (nframes_t nframes)
                _butler->summon ();
        }
 
+        /* if using a monitor section, run it because otherwise we don't hear anything */
+
+        if (auditioner->needs_monitor()) {
+                _monitor_out->passthru (_transport_frame, _transport_frame + nframes, nframes, false);
+        }
+        
        /* handle pending events */
 
        while (pending_events.read (&ev, 1) == 1) {
@@ -895,7 +853,7 @@ Session::process_audition (nframes_t nframes)
                process_event (ev);
        }
 
-       if (!auditioner->active()) {
+       if (!auditioner->auditioning()) {
                /* auditioner no longer active, so go back to the normal process callback */
                process_function = &Session::process_with_events;
        }
@@ -1095,11 +1053,11 @@ Session::process_event (SessionEvent* ev)
                break;
 
        case SessionEvent::Overwrite:
-               overwrite_some_buffers (static_cast<Diskstream*>(ev->ptr));
+               overwrite_some_buffers (static_cast<Track*>(ev->ptr));
                break;
 
-       case SessionEvent::SetDiskstreamSpeed:
-               set_diskstream_speed (static_cast<Diskstream*> (ev->ptr), ev->speed);
+       case SessionEvent::SetTrackSpeed:
+               set_track_speed (static_cast<Track*> (ev->ptr), ev->speed);
                break;
 
        case SessionEvent::SetSyncSource: