factor out NSM startup code
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 3 Oct 2019 23:23:57 +0000 (17:23 -0600)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 3 Oct 2019 23:23:57 +0000 (17:23 -0600)
gtk2_ardour/ardour_ui.h
gtk2_ardour/ardour_ui_startup.cc

index 8efcb787e7b41c0f458508d4079e48e2a0ae0576..890572c2c7f664b53b5113ef07b571b4d4b2a5e8 100644 (file)
@@ -439,6 +439,7 @@ private:
        SessionDialog *_session_dialog;
 
        int starting ();
+       int nsm_init ();
 
        int  ask_about_saving_session (const std::vector<std::string>& actions);
 
index 8e97cd5a98820218110305035f64efa2fd26aecd..ac7f69d0b4d1d7d5feb3cf0941e87ba5103c43bf 100644 (file)
@@ -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<string> 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<string>::const_iterator n = action_names.begin(); n != action_names.end(); ++n) {
+               Glib::RefPtr<Action> 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<string> 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<string>::const_iterator n = action_names.begin(); n != action_names.end(); ++n) {
-                               Glib::RefPtr<Action> 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__
 }
-