torben's port buffer reworking; torben's panner automation loading patch (allows...
[ardour.git] / libs / ardour / session_process.cc
index 44b63e08756bee087038e7777b382db7ddd2eb51..5a28fd5890c6b8d26f1efcb7abf7c1ada1fa022e 100644 (file)
@@ -50,13 +50,13 @@ using namespace std;
 void
 Session::process (nframes_t nframes)
 {
+       // This is no more the appriopriate 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);
 
-       if (synced_to_jack() && waiting_to_start) {
-               if ( _engine.transport_state() == AudioEngine::TransportRolling) {
-                       actually_start_transport ();
-               }
-       }
+       _silent = false;
 
        if (non_realtime_work_pending()) {
                if (!transport_work_requested ()) {
@@ -266,10 +266,10 @@ Session::process_with_events (nframes_t nframes)
        nframes_t this_nframes;
        nframes_t end_frame;
        nframes_t offset;
+       bool session_needs_butler = false;
        nframes_t stop_limit;
        long           frames_moved;
-       bool           session_needs_butler = false;
-
+       
        /* make sure the auditioner is silent */
 
        if (auditioner) {
@@ -302,7 +302,7 @@ Session::process_with_events (nframes_t nframes)
        }
 
        if (!process_can_proceed()) {
-               no_roll (nframes, 0);
+               _silent = true;
                return;
        }
 
@@ -317,8 +317,8 @@ Session::process_with_events (nframes_t nframes)
                Event* this_event;
                Events::iterator the_next_one;
                
-               if (post_transport_work & (PostTransportLocate|PostTransportStop)) {
-                       no_roll (nframes, 0);
+               if (!process_can_proceed()) {
+                       _silent = true;
                        return;
                }
                
@@ -333,7 +333,9 @@ Session::process_with_events (nframes_t nframes)
                        return;
                }
        
-               send_midi_time_code_for_cycle(nframes);
+               if (!_exporting) {
+                       send_midi_time_code_for_cycle (nframes);
+               }
 
                if (actively_recording()) {
                        stop_limit = max_frames;
@@ -494,7 +496,7 @@ Session::follow_slave (nframes_t nframes, nframes_t offset)
             << endl;
 #endif 
 
-       if (Config->get_timecode_source_is_synced()) {
+       if (_slave->is_always_synced() || Config->get_timecode_source_is_synced()) {
 
                /* if the TC source is synced, then we assume that its 
                   speed is binary: 0.0 or 1.0
@@ -642,7 +644,7 @@ Session::follow_slave (nframes_t nframes, nframes_t offset)
                slave_state = Stopped;
        }
 
-       if (slave_state == Running && !Config->get_timecode_source_is_synced()) {
+       if (slave_state == Running && !_slave->is_always_synced() && !Config->get_timecode_source_is_synced()) {
 
 
                if (_transport_speed != 0.0f) {
@@ -743,67 +745,66 @@ Session::process_without_events (nframes_t nframes)
        long frames_moved;
        nframes_t offset = 0;
 
-       {
-               if (post_transport_work & (PostTransportLocate|PostTransportStop)) {
-                       no_roll (nframes, 0);
-                       return;
-               }
-
-               if (!_exporting && _slave) {
-                       if (!follow_slave (nframes, 0)) {
-                               return;
-                       }
-               } 
+       if (!process_can_proceed()) {
+               _silent = true;
+               return;
+       }
 
-               if (_transport_speed == 0) {
-                       no_roll (nframes, 0);
+       if (!_exporting && _slave) {
+               if (!follow_slave (nframes, 0)) {
                        return;
                }
-       
-               send_midi_time_code_for_cycle(nframes);
+       } 
+
+       if (_transport_speed == 0) {
+               no_roll (nframes, 0);
+               return;
+       }
                
-               if (actively_recording()) {
-                       stop_limit = max_frames;
+       if (!_exporting) {
+               send_midi_time_code_for_cycle (nframes);
+       }
+
+       if (actively_recording()) {
+               stop_limit = max_frames;
+       } else {
+               if (Config->get_stop_at_session_end()) {
+                       stop_limit = current_end_frame();
                } else {
-                       if (Config->get_stop_at_session_end()) {
-                               stop_limit = current_end_frame();
-                       } else {
-                               stop_limit = max_frames;
-                       }
+                       stop_limit = max_frames;
                }
+       }
                
-               if (maybe_stop (stop_limit)) {
-                       no_roll (nframes, 0);
-                       return;
-               
+       if (maybe_stop (stop_limit)) {
+               no_roll (nframes, 0);
+               return;
+       } 
 
-               if (maybe_sync_start (nframes, offset)) {
-                       return;
-               }
+       if (maybe_sync_start (nframes, offset)) {
+               return;
+       }
 
-               click (_transport_frame, nframes, offset);
+       click (_transport_frame, nframes, offset);
 
-               prepare_diskstreams ();
+       prepare_diskstreams ();
        
-               frames_moved = (long) floor (_transport_speed * nframes);
+       frames_moved = (long) floor (_transport_speed * nframes);
 
-               if (process_routes (nframes, offset)) {
-                       no_roll (nframes, offset);
-                       return;
-               }
+       if (process_routes (nframes, offset)) {
+               no_roll (nframes, offset);
+               return;
+       }
 
-               commit_diskstreams (nframes, session_needs_butler);
+       commit_diskstreams (nframes, session_needs_butler);
 
-               if (frames_moved < 0) {
-                       decrement_transport_position (-frames_moved);
-               } else {
-                       increment_transport_position (frames_moved);
-               }
-
-               maybe_stop (stop_limit);
-               check_declick_out ();
+       if (frames_moved < 0) {
+               decrement_transport_position (-frames_moved);
+       } else {
+               increment_transport_position (frames_moved);
+       }
 
-       } /* implicit release of route lock */
+       maybe_stop (stop_limit);
+       check_declick_out ();
 
        if (session_needs_butler)
                summon_butler ();
@@ -864,18 +865,38 @@ Session::maybe_sync_start (nframes_t& nframes, nframes_t& offset)
 
        if (_engine.get_sync_offset (sync_offset) && sync_offset < nframes) {
 
+               /* generate silence up to the sync point, then
+                  adjust nframes + offset to reflect whatever
+                  is left to do.
+               */
+
                no_roll (sync_offset, 0);
                nframes -= sync_offset;
                offset += sync_offset;
                waiting_for_sync_offset = false;
                
                if (nframes == 0) {
-                       return true; // done
+                       return true; // done, nothing left to process
                }
                
        } else {
+
+               /* sync offset point is not within this process()
+                  cycle, so just generate silence. and don't bother 
+                  with any fancy stuff here, just the minimal silence.
+               */
+
+               g_atomic_int_inc (&processing_prohibited);
                no_roll (nframes, 0);
-               return true; // done
+               g_atomic_int_dec_and_test (&processing_prohibited);
+
+               if (Config->get_locate_while_waiting_for_sync()) {
+                       if (micro_locate (nframes)) {
+                               /* XXX ERROR !!! XXX */
+                       }
+               }
+
+               return true; // done, nothing left to process
        }
 
        return false;