Fixed incomplete merge for audioengine.cc
[ardour.git] / libs / ardour / audioengine.cc
index a92e7d45249ef5aff1ae600369e734bd2a27379a..16283d92320a145ae360dbc1a548f12790c86709 100644 (file)
@@ -210,7 +210,7 @@ AudioEngine::process_callback (pframes_t nframes)
                 * before the process_callback. it may even be 
                 * jack/alsa only). but better safe than sorry.
                 */
-               PortManager::silence_physical (nframes);
+               PortManager::silence_outputs (nframes);
                return 0;
        }
 
@@ -455,7 +455,7 @@ AudioEngine::backend_reset_requested()
 void
 AudioEngine::do_reset_backend()
 {
-       SessionEvent::create_per_thread_pool (X_("Backend reset processing thread"), 512);
+       SessionEvent::create_per_thread_pool (X_("Backend reset processing thread"), 1024);
     
        Glib::Threads::Mutex::Lock guard (_reset_request_lock);
     
@@ -468,25 +468,28 @@ AudioEngine::do_reset_backend()
                        Glib::Threads::RecMutex::Lock pl (_state_lock);
                        g_atomic_int_dec_and_test (&_hw_reset_request_count);
                
-                       std::cout << "AudioEngine::RESET::Reset request processing. Requests left: " << _hw_reset_request_count << std::endl;
-                       DeviceResetStarted(); // notify about device reset to be started
-               
-                       // backup the device name
-                       std::string name = _backend->device_name ();
-               
-                       std::cout << "AudioEngine::RESET::Stoping engine..." << std::endl;
-                       stop();
-               
-                       std::cout << "AudioEngine::RESET::Reseting device..." << std::endl;
-                       if ( 0 == _backend->reset_device () ) {
-                       
-                               std::cout << "AudioEngine::RESET::Starting engine..." << std::endl;
-                               start ();
-                       
+            std::cout << "AudioEngine::RESET::Reset request processing. Requests left: " << _hw_reset_request_count << std::endl;
+                        DeviceResetStarted(); // notify about device reset to be started
+            
+                        // backup the device name
+                        std::string name = _backend->device_name ();
+
+            std::cout << "AudioEngine::RESET::Reseting device..." << std::endl;
+                       if ( ( 0 == stop () ) &&
+                 ( 0 == _backend->reset_device () ) &&
+                 ( 0 == start () ) ) {
+                               
+                               std::cout << "AudioEngine::RESET::Engine started..." << std::endl;
+                               
                                // inform about possible changes
                                BufferSizeChanged (_backend->buffer_size() );
-                       } else {
-                               DeviceError();
+                DeviceResetFinished(); // notify about device reset finish
+            
+            } else {
+            
+                DeviceResetFinished(); // notify about device reset finish
+                               // we've got an error
+                DeviceError();
                        }
                        
                        std::cout << "AudioEngine::RESET::Done." << std::endl;
@@ -522,6 +525,8 @@ AudioEngine::do_devicelist_update()
 
             _devicelist_update_lock.unlock();
             
+            Glib::Threads::RecMutex::Lock pl (_state_lock);
+            
             g_atomic_int_dec_and_test (&_hw_devicelist_update_count);
             DeviceListChanged (); /* EMIT SIGNAL */
         
@@ -623,9 +628,11 @@ AudioEngine::remove_session ()
 void
 AudioEngine::reconnect_session_routes (bool reconnect_inputs, bool reconnect_outputs)
 {
-    if (_session) {
-        _session->reconnect_existing_routes(true, true, reconnect_inputs, reconnect_outputs);
-    }
+#ifdef USE_TRACKS_CODE_FEATURES
+       if (_session) {
+               _session->reconnect_existing_routes(true, true, reconnect_inputs, reconnect_outputs);
+       }
+#endif 
 }
 
 
@@ -768,7 +775,7 @@ void
 AudioEngine::drop_backend ()
 {
        if (_backend) {
-               stop(false);
+               _backend->stop ();
                _backend->drop_device ();
                _backend.reset ();
                _running = false;
@@ -856,18 +863,18 @@ AudioEngine::stop (bool for_latency)
                return 0;
        }
 
-       if (_session && _running) {
+       if (_backend->stop ()) {
+               return -1;
+       }
+       
+       if (_session && _running &&
+           (_session->state_of_the_state() & Session::Loading) == 0 &&
+           (_session->state_of_the_state() & Session::Deletion) == 0) {
                // it's not a halt, but should be handled the same way:
                // disable record, stop transport and I/O processign but save the data.
                _session->engine_halted ();
        }
 
-       Glib::Threads::Mutex::Lock lm (_process_lock);
-
-       if (_backend->stop ()) {
-               return -1;
-       }
-       
        _running = false;
        _processed_frames = 0;
        _measuring_latency = MeasureNone;
@@ -1151,6 +1158,12 @@ AudioEngine::set_systemic_output_latency (uint32_t ol)
        return _backend->set_systemic_output_latency  (ol);
 }
 
+bool
+AudioEngine::thread_initialised_for_audio_processing ()
+{
+    return SessionEvent::has_per_thread_pool () && AsyncMIDIPort::is_process_thread();
+}
+
 /* END OF BACKEND PROXY API */
 
 void