Use PBD::copy_file in Session::create() to copy the template file.
[ardour.git] / libs / ardour / audioengine.cc
index 273829fa7565d6cf56d95dc2c6071ee55bfce878..cbdd1fda1ce8fc088c66161295cd3775a356dd66 100644 (file)
@@ -255,6 +255,11 @@ AudioEngine::_graph_order_callback (void *arg)
        return 0;
 }
 
+/** Wrapped which is called by JACK as its process callback.  It is just
+ * here to get us back into C++ land by calling AudioEngine::process_callback()
+ * @param nframes Number of frames passed by JACK.
+ * @param arg User argument passed by JACK, which will be the AudioEngine*.
+ */
 int
 AudioEngine::_process_callback (nframes_t nframes, void *arg)
 {
@@ -267,11 +272,17 @@ AudioEngine::_freewheel_callback (int onoff, void *arg)
        static_cast<AudioEngine*>(arg)->_freewheeling = onoff;
 }
 
+/** Method called by JACK (via _process_callback) which says that there
+ * is work to be done.
+ * @param nframes Number of frames to process.
+ */
 int
 AudioEngine::process_callback (nframes_t nframes)
 {
        // CycleTimer ct ("AudioEngine::process");
        Glib::Mutex::Lock tm (_process_lock, Glib::TRY_LOCK);
+
+       /// The number of frames that will have been processed when we've finished
        nframes_t next_processed_frames;
        
        /* handle wrap around of total frames counter */
@@ -281,13 +292,15 @@ AudioEngine::process_callback (nframes_t nframes)
        } else {
                next_processed_frames = _processed_frames + nframes;
        }
-       
+
        if (!tm.locked() || session == 0) {
+               /* return having done nothing */
                _processed_frames = next_processed_frames;
                return 0;
        }
 
        if (session_remove_pending) {
+               /* perform the actual session removal */
                session = 0;
                session_remove_pending = false;
                session_removed.signal();
@@ -296,6 +309,7 @@ AudioEngine::process_callback (nframes_t nframes)
        }
 
        if (_freewheeling) {
+               /* emit the Freewheel signal and stop freewheeling in the event of trouble */
                if (Freewheel (nframes)) {
                        cerr << "Freewheeling returned non-zero!\n";
                        _freewheeling = false;
@@ -304,13 +318,26 @@ AudioEngine::process_callback (nframes_t nframes)
                return 0;
        }
 
-       if (run_process_cycle (session, nframes)) {
-               /* we were zombified, maybe because a ladspa plugin took
-                  too long, or jackd exited, or something like that.
-               */
+       boost::shared_ptr<Ports> p = ports.reader();
+
+       // Prepare ports (ie read data if necessary)
+       for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
+               (*i)->cycle_start (nframes);
+       }
+       
+       if (session) {
+               session->process (nframes);
+       }
+
+       if (!_running) {
                _processed_frames = next_processed_frames;
                return 0;
        }
+       
+       // Finalize ports (ie write data if necessary)
+       for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
+               (*i)->cycle_end ();
+       }
 
        if (last_monitor_check + monitor_check_interval < next_processed_frames) {
 
@@ -336,28 +363,6 @@ AudioEngine::process_callback (nframes_t nframes)
        return 0;
 }
 
-int
-AudioEngine::run_process_cycle (Session* s, jack_nframes_t nframes)
-{
-       boost::shared_ptr<Ports> p = ports.reader();
-
-       // Prepare ports (ie read data if necessary)
-       for (Ports::iterator i = p->begin(); i != p->end(); ++i)
-               (*i)->cycle_start (nframes);
-       
-       s->process (nframes);
-
-       if (!_running) {
-               return -1;
-       }
-       
-       // Finalize ports (ie write data if necessary)
-       for (Ports::iterator i = p->begin(); i != p->end(); ++i)
-               (*i)->cycle_end ();
-
-       return 0;
-}
-
 int
 AudioEngine::_sample_rate_callback (nframes_t nframes, void *arg)
 {
@@ -456,14 +461,23 @@ AudioEngine::set_session (Session *s)
                   can before we really start running.
                */
                
-               run_process_cycle (session, blocksize);
-               run_process_cycle (session, blocksize);
-               run_process_cycle (session, blocksize);
-               run_process_cycle (session, blocksize);
-               run_process_cycle (session, blocksize);
-               run_process_cycle (session, blocksize);
-               run_process_cycle (session, blocksize);
-               run_process_cycle (session, blocksize);
+               boost::shared_ptr<Ports> p = ports.reader();
+
+               for (Ports::iterator i = p->begin(); i != p->end(); ++i)
+                       (*i)->cycle_start (blocksize);
+
+               s->process (blocksize);
+               s->process (blocksize);
+               s->process (blocksize);
+               s->process (blocksize);
+               s->process (blocksize);
+               s->process (blocksize);
+               s->process (blocksize);
+               s->process (blocksize);
+
+               for (Ports::iterator i = p->begin(); i != p->end(); ++i)
+                       (*i)->cycle_end ();
+
        }
 }