From dceca00a694e4514937a425c3619dbabaa9b5d5f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 3 Oct 2019 17:23:57 -0600 Subject: [PATCH] factor out NSM startup code --- gtk2_ardour/ardour_ui.h | 1 + gtk2_ardour/ardour_ui_startup.cc | 159 +++++++++++++++++-------------- 2 files changed, 86 insertions(+), 74 deletions(-) diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index 8efcb787e7..890572c2c7 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -439,6 +439,7 @@ private: SessionDialog *_session_dialog; int starting (); + int nsm_init (); int ask_about_saving_session (const std::vector& actions); diff --git a/gtk2_ardour/ardour_ui_startup.cc b/gtk2_ardour/ardour_ui_startup.cc index 8e97cd5a98..ac7f69d0b4 100644 --- a/gtk2_ardour/ardour_ui_startup.cc +++ b/gtk2_ardour/ardour_ui_startup.cc @@ -398,11 +398,93 @@ ARDOUR_UI::check_announcements () #endif } +int +ARDOUR_UI::nsm_init () +{ + const char *nsm_url; + + if ((nsm_url = g_getenv ("NSM_URL")) == 0) { + return 0; + } + + nsm = new NSM_Client; + + if (nsm->init (nsm_url)) { + delete nsm; + nsm = 0; + error << _("NSM: initialization failed") << endmsg; + return -1; + } + + /* the ardour executable may have different names: + * + * waf's obj.target for distro versions: eg ardour4, ardourvst4 + * Ardour4, Mixbus3 for bundled versions + full path on OSX & windows + * argv[0] does not apply since we need the wrapper-script (not the binary itself) + * + * The wrapper startup script should set the environment variable 'ARDOUR_SELF' + */ + const char *process_name = g_getenv ("ARDOUR_SELF"); + nsm->announce (PROGRAM_NAME, ":dirty:", process_name ? process_name : "ardour6"); + + unsigned int i = 0; + // wait for announce reply from nsm server + for ( i = 0; i < 5000; ++i) { + nsm->check (); + + Glib::usleep (i); + if (nsm->is_active()) { + break; + } + } + if (i == 5000) { + error << _("NSM server did not announce itself") << endmsg; + return -1; + } + // wait for open command from nsm server + for ( i = 0; i < 5000; ++i) { + nsm->check (); + Glib::usleep (1000); + if (nsm->client_id ()) { + break; + } + } + + if (i == 5000) { + error << _("NSM: no client ID provided") << endmsg; + return -1; + } + + if (_session && nsm) { + _session->set_nsm_state( nsm->is_active() ); + } else { + error << _("NSM: no session created") << endmsg; + return -1; + } + + // nsm requires these actions disabled + vector action_names; + action_names.push_back("SaveAs"); + action_names.push_back("Rename"); + action_names.push_back("New"); + action_names.push_back("Open"); + action_names.push_back("Recent"); + action_names.push_back("Close"); + + for (vector::const_iterator n = action_names.begin(); n != action_names.end(); ++n) { + Glib::RefPtr act = ActionManager::get_action (X_("Main"), (*n).c_str()); + if (act) { + act->set_sensitive (false); + } + } + + return 0; +} + int ARDOUR_UI::starting () { Application* app = Application::instance (); - const char *nsm_url; bool brand_new_user = ArdourStartup::required (); app->ShouldQuit.connect (sigc::mem_fun (*this, &ARDOUR_UI::queue_finish)); @@ -425,78 +507,8 @@ ARDOUR_UI::starting () return -1; } - if ((nsm_url = g_getenv ("NSM_URL")) != 0) { - nsm = new NSM_Client; - if (!nsm->init (nsm_url)) { - /* the ardour executable may have different names: - * - * waf's obj.target for distro versions: eg ardour4, ardourvst4 - * Ardour4, Mixbus3 for bundled versions + full path on OSX & windows - * argv[0] does not apply since we need the wrapper-script (not the binary itself) - * - * The wrapper startup script should set the environment variable 'ARDOUR_SELF' - */ - const char *process_name = g_getenv ("ARDOUR_SELF"); - nsm->announce (PROGRAM_NAME, ":dirty:", process_name ? process_name : "ardour6"); - - unsigned int i = 0; - // wait for announce reply from nsm server - for ( i = 0; i < 5000; ++i) { - nsm->check (); - - Glib::usleep (i); - if (nsm->is_active()) { - break; - } - } - if (i == 5000) { - error << _("NSM server did not announce itself") << endmsg; - return -1; - } - // wait for open command from nsm server - for ( i = 0; i < 5000; ++i) { - nsm->check (); - Glib::usleep (1000); - if (nsm->client_id ()) { - break; - } - } - - if (i == 5000) { - error << _("NSM: no client ID provided") << endmsg; - return -1; - } - - if (_session && nsm) { - _session->set_nsm_state( nsm->is_active() ); - } else { - error << _("NSM: no session created") << endmsg; - return -1; - } - - // nsm requires these actions disabled - vector action_names; - action_names.push_back("SaveAs"); - action_names.push_back("Rename"); - action_names.push_back("New"); - action_names.push_back("Open"); - action_names.push_back("Recent"); - action_names.push_back("Close"); - - for (vector::const_iterator n = action_names.begin(); n != action_names.end(); ++n) { - Glib::RefPtr act = ActionManager::get_action (X_("Main"), (*n).c_str()); - if (act) { - act->set_sensitive (false); - } - } - - } else { - delete nsm; - nsm = 0; - error << _("NSM: initialization failed") << endmsg; - return -1; - } - + if (nsm_init ()) { + return -1; } else { if (brand_new_user) { @@ -661,4 +673,3 @@ ARDOUR_UI::check_memory_locking () } #endif // !__APPLE__ } -