part one of hiding Diskstreams and making them a private object of a Track
[ardour.git] / libs / ardour / session_process.cc
index 329bb62174f30592be99ca6fe3b0537e73a52d58..483a8f071a6164d13ef6b125445bf325b0c35454 100644 (file)
@@ -51,10 +51,6 @@ using namespace std;
 void
 Session::process (nframes_t nframes)
 {
-       // This is no more the appropriate place to call cycle
-       // start. cycle_start needs to be called at the Route::roll()
-       // where the signals which we want to mixdown have been calculated.
-       //
        MIDI::Manager::instance()->cycle_start(nframes);
 
        _silent = false;
@@ -85,15 +81,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)
 {
@@ -132,7 +119,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();
@@ -159,18 +146,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;
                }
@@ -180,7 +156,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();
@@ -203,18 +179,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;
                }
@@ -224,7 +189,7 @@ Session::silent_process_routes (nframes_t nframes)
 }
 
 void
-Session::commit_diskstreams (nframes_t nframes, bool &needs_butler)
+Session::get_diskstream_statistics ()
 {
        int dret;
        float pworst = 1.0f;
@@ -237,21 +202,6 @@ Session::commit_diskstreams (nframes_t nframes, bool &needs_butler)
                        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;
-                       }
-
-               } else if (dret < 0) {
-                       (*i)->recover();
-               }
-
                pworst = min (pworst, (*i)->playback_buffer_load());
                cworst = min (cworst, (*i)->capture_buffer_load());
        }
@@ -398,16 +348,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) {
@@ -572,6 +517,7 @@ Session::follow_slave (nframes_t nframes)
                        
                        if (_slave->give_slave_full_control_over_transport_speed()) {
                                set_transport_speed (slave_speed, false, false);
+                               //std::cout << "set speed = " << slave_speed << "\n";
                        } else {
                                float adjusted_speed = slave_speed + (1.5 * (delta /  float(_current_frame_rate)));
                                request_transport_speed (adjusted_speed);
@@ -580,10 +526,12 @@ Session::follow_slave (nframes_t nframes)
                                                                           slave_speed));
                        }
                        
-                       if (abs(average_slave_delta) > _slave->resolution()) {
+#if 1
+                       if ((nframes_t) abs(average_slave_delta) > _slave->resolution()) {
                                cerr << "average slave delta greater than slave resolution (" << _slave->resolution() << "), going to silent motion\n";
                                goto silent_motion;
                        }
+#endif
                }
        }
 
@@ -747,9 +695,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 ();
@@ -827,8 +773,6 @@ Session::process_without_events (nframes_t nframes)
 
        click (_transport_frame, nframes);
 
-       prepare_diskstreams ();
-
        if (_transport_speed == 1.0) {
                frames_moved = (long) nframes;
        } else {
@@ -837,13 +781,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 {
@@ -879,6 +821,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) {
@@ -896,7 +844,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;
        }
@@ -983,18 +931,6 @@ Session::set_next_event ()
        }
 }
 
-void
-Session::cleanup_event (SessionEvent* ev, int status)
-{
-       switch (ev->type) {
-       case SessionEvent::SetRecordEnable:
-               delete ev->routes;
-               break;
-       default:
-               break;
-       }
-}
-
 void
 Session::process_event (SessionEvent* ev)
 {
@@ -1134,8 +1070,9 @@ Session::process_event (SessionEvent* ev)
                set_play_range (ev->audio_range, (ev->speed == 1.0f));
                break;
 
-       case SessionEvent::SetRecordEnable:
-               do_record_enable_change_all (ev->routes, ev->yes_or_no);
+       case SessionEvent::RealTimeOperation:
+               process_rtop (ev);
+               del = false; // other side of RT request needs to clean up
                break;
 
        default:
@@ -1148,9 +1085,8 @@ Session::process_event (SessionEvent* ev)
                del = del && !_remove_event (ev);
        }
 
-       ev->Complete (ev, 0); /* EMIT SIGNAL */
-
        if (del) {
                delete ev;
        }
 }
+