Fix crash when X11 is not available for VST UIs
[ardour.git] / gtk2_ardour / engine_dialog.cc
index 82136ace0f10cf9f906581e76359ec99bf667e3e..a8209514c13bb685c5587d2ff04cc79a360eb9e4 100644 (file)
@@ -29,8 +29,6 @@
 
 #include <boost/scoped_ptr.hpp>
 
-#include <gtkmm/messagedialog.h>
-
 #include "pbd/error.h"
 #include "pbd/locale_guard.h"
 #include "pbd/xml++.h"
@@ -57,6 +55,7 @@
 
 #include "opts.h"
 #include "debug.h"
+#include "ardour_message.h"
 #include "ardour_ui.h"
 #include "engine_dialog.h"
 #include "gui_thread.h"
@@ -130,7 +129,7 @@ EngineControl::EngineControl ()
        vector<const ARDOUR::AudioBackendInfo*> backends = ARDOUR::AudioEngine::instance()->available_backends();
 
        if (backends.empty()) {
-               MessageDialog msg (string_compose (_("No audio/MIDI backends detected. %1 cannot run\n\n(This is a build/packaging/system error. It should never happen.)"), PROGRAM_NAME));
+               ArdourMessageDialog msg (string_compose (_("No audio/MIDI backends detected. %1 cannot run\n\n(This is a build/packaging/system error. It should never happen.)"), PROGRAM_NAME));
                msg.run ();
                throw failed_constructor ();
        }
@@ -470,23 +469,11 @@ EngineControl::config_parameter_changed (std::string const & p)
        }
 }
 
-bool
-EngineControl::try_autostart ()
-{
-       if (!start_stop_button.get_sensitive()) {
-               return false;
-       }
-       if (ARDOUR::AudioEngine::instance()->running()) {
-               return true;
-       }
-       return start_engine ();
-}
-
 bool
 EngineControl::start_engine ()
 {
        if (push_state_to_backend (true) != 0) {
-               MessageDialog msg (*this, ARDOUR::AudioEngine::instance()->get_last_backend_error());
+               ArdourMessageDialog msg (*this, ARDOUR::AudioEngine::instance()->get_last_backend_error());
                msg.run();
                return false;
        }
@@ -497,8 +484,7 @@ bool
 EngineControl::stop_engine (bool for_latency)
 {
        if (ARDOUR::AudioEngine::instance()->stop(for_latency)) {
-               MessageDialog msg(*this,
-                                 ARDOUR::AudioEngine::instance()->get_last_backend_error());
+               ArdourMessageDialog msg(*this, ARDOUR::AudioEngine::instance()->get_last_backend_error());
                msg.run();
                return false;
        }
@@ -771,13 +757,13 @@ EngineControl::enable_latency_tab ()
        ARDOUR::AudioEngine::instance()->get_physical_inputs (type, inputs);
 
        if (!ARDOUR::AudioEngine::instance()->running()) {
-               MessageDialog msg (_("Failed to start or connect to audio-engine.\n\nLatency calibration requires a working audio interface."));
+               ArdourMessageDialog msg (_("Failed to start or connect to audio-engine.\n\nLatency calibration requires a working audio interface."));
                notebook.set_current_page (0);
                msg.run ();
                return;
        }
        else if (inputs.empty() || outputs.empty()) {
-               MessageDialog msg (_("Your selected audio configuration is playback- or capture-only.\n\nLatency calibration requires playback and capture"));
+               ArdourMessageDialog msg (_("Your selected audio configuration is playback- or capture-only.\n\nLatency calibration requires playback and capture"));
                notebook.set_current_page (0);
                msg.run ();
                return;
@@ -1036,7 +1022,7 @@ EngineControl::refresh_midi_display (std::string focus)
 
                m = manage (new ArdourButton ((*p)->name, ArdourButton::led_default_elements));
                m->set_name ("midi device");
-               m->set_can_focus (Gtk::CAN_FOCUS);
+               m->set_can_focus (true);
                m->add_events (Gdk::BUTTON_RELEASE_MASK);
                m->set_active (enabled);
                m->signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &EngineControl::midi_device_enabled_toggled), m, *p));
@@ -2209,8 +2195,7 @@ EngineControl::set_current_state (const State& state)
 
        boost::shared_ptr<ARDOUR::AudioBackend> backend;
 
-       if (!(backend = ARDOUR::AudioEngine::instance ()->set_backend (
-                 state->backend, downcase (std::string(PROGRAM_NAME)), ""))) {
+       if (!(backend = ARDOUR::AudioEngine::instance ()->set_backend (state->backend, downcase (std::string (PROGRAM_NAME)), ""))) {
                DEBUG_ECONTROL (string_compose ("Unable to set backend to %1", state->backend));
                // this shouldn't happen as the invalid backend names should have been
                // removed from the list of states.
@@ -2756,11 +2741,16 @@ EngineControl::control_app_button_clicked ()
 }
 
 void
-EngineControl::on_response (int)
+EngineControl::on_response (int r)
 {
-       /* we do nothing when our response signal is emitted ... that's the
-        * responsibility of whoever displayed us.
+       /* Do not run ArdourDialog::on_response() which will hide us. Leave
+        * that to whoever invoked us, if they wish to hide us after "start".
+        *
+        * StartupFSM does hide us after response(); Window > Audio/MIDI Setup
+        * does not.
         */
+       pop_splash ();
+       Gtk::Dialog::on_response (r);
 }
 
 void
@@ -2841,10 +2831,11 @@ void
 EngineControl::set_desired_sample_rate (uint32_t sr)
 {
        _desired_sample_rate = sr;
-       if (ARDOUR::AudioEngine::instance ()->running ()
-                       && ARDOUR::AudioEngine::instance ()->sample_rate () != sr) {
+
+       if (ARDOUR::AudioEngine::instance ()->running () && ARDOUR::AudioEngine::instance ()->sample_rate () != sr) {
                stop_engine ();
        }
+
        device_changed ();
 }