fix verbose plugin scan
[ardour.git] / gtk2_ardour / ardour_ui.cc
index 2f38aec72f1b317ced33c7040d27ea37d9782e3a..524d16e017c002e8191ba0ec0959a74028b54f28 100644 (file)
@@ -28,6 +28,8 @@
 #include <cerrno>
 #include <fstream>
 
+#include <stdarg.h>
+
 #ifndef PLATFORM_WINDOWS
 #include <sys/resource.h>
 #endif
@@ -55,6 +57,8 @@
 #include "pbd/file_utils.h"
 #include "pbd/localtime_r.h"
 #include "pbd/pthread_utils.h"
+#include "pbd/replace_all.h"
+#include "pbd/xml++.h"
 
 #include "gtkmm2ext/application.h"
 #include "gtkmm2ext/bindings.h"
@@ -181,10 +185,40 @@ ask_about_configuration_copy (string const & old_dir, string const & new_dir, in
        return (msg.run() == Gtk::RESPONSE_YES);
 }
 
-ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
+static void
+libxml_generic_error_func (void* /* parsing_context*/,
+                   const char* msg,
+                   ...)
+{
+       va_list ap;
+       char buf[2048];
+
+       va_start (ap, msg);
+       vsnprintf (buf, sizeof (buf), msg, ap);
+       error << buf << endmsg;
+       va_end (ap);
+}
+
+static void
+libxml_structured_error_func (void* /* parsing_context*/,
+                              xmlErrorPtr err)
+{
+       string msg = err->message;
+
+       replace_all (msg, "\n", "");
+
+       error << X_("XML error: ") << msg << " in " << err->file << " at line " << err->line;
+       if (err->int2) {
+               error << ':' << err->int2;
+       }
+       error << endmsg;
+}
+
+
+ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir, UIConfiguration* uic)
 
        : Gtkmm2ext::UI (PROGRAM_NAME, argcp, argvp)
-       , ui_config (new UIConfiguration)
+       , ui_config (uic->post_gui_init ())
        , session_loaded (false)
        , gui_object_state (new GUIObjectState)
        , primary_clock   (new MainClock (X_("primary"),   X_("transport"), true ))
@@ -214,6 +248,7 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
        , error_alert_button ( ArdourButton::just_led_default_elements )
        , editor_meter(0)
        , editor_meter_peak_display()
+       , session_selector_window (0)
        , open_session_selector (0)
        , _numpad_locate_happening (false)
        , _session_is_new (false)
@@ -258,6 +293,11 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
                theArdourUI = this;
        }
 
+       /* stop libxml from spewing to stdout/stderr */
+
+       xmlSetGenericErrorFunc (this, libxml_generic_error_func);
+       xmlSetStructuredErrorFunc (this, libxml_structured_error_func);
+       
        ui_config->ParameterChanged.connect (sigc::mem_fun (*this, &ARDOUR_UI::parameter_changed));
        boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
        ui_config->map_parameters (pc);
@@ -803,13 +843,16 @@ ARDOUR_UI::starting ()
        if ((nsm_url = g_getenv ("NSM_URL")) != 0) {
                nsm = new NSM_Client;
                if (!nsm->init (nsm_url)) {
-                       /* TODO this needs fixing!
+                       /* 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)
-                        * No idea how to address all these.
+                        *
+                        * The wrapper startup script should set the environment variable 'ARDOUR_SELF'
                         */
-                       nsm->announce (PROGRAM_NAME, ":dirty:", "ardour4");
+                       const char *process_name = g_getenv ("ARDOUR_SELF");
+                       nsm->announce (PROGRAM_NAME, ":dirty:", process_name ? process_name : "ardour4");
 
                        unsigned int i = 0;
                        // wait for announce reply from nsm server
@@ -1345,7 +1388,7 @@ ARDOUR_UI::update_format ()
 }
 
 void
-ARDOUR_UI::update_cpu_load ()
+ARDOUR_UI::update_xrun_count ()
 {
        char buf[64];
 
@@ -1364,10 +1407,11 @@ ARDOUR_UI::update_cpu_load ()
                snprintf (buf, sizeof (buf), _("X: <span foreground=\"%s\">?</span>"), X_("yellow"));
        }
        xrun_label.set_markup (buf);
+       set_tip (xrun_label, _("Audio dropouts. Shift+click to reset"));
 }
 
 void
-ARDOUR_UI::update_xrun_count ()
+ARDOUR_UI::update_cpu_load ()
 {
        char buf[64];
 
@@ -2099,7 +2143,6 @@ ARDOUR_UI::get_smart_mode() const
 void
 ARDOUR_UI::toggle_roll (bool with_abort, bool roll_out_of_bounded_mode)
 {
-
        if (!_session) {
                return;
        }
@@ -2425,14 +2468,6 @@ ARDOUR_UI::save_session_as ()
                return;
        }
        
-       ArdourDialog progress_dialog(_("Save As"), true);
-       Gtk::Label label;
-       Gtk::ProgressBar progress_bar;
-
-       progress_dialog.get_vbox()->pack_start (label);
-       progress_dialog.get_vbox()->pack_start (progress_bar);
-       label.show ();
-       progress_bar.show ();
        
        Session::SaveAs sa;
 
@@ -2441,25 +2476,50 @@ ARDOUR_UI::save_session_as ()
        sa.switch_to = save_as_dialog->switch_to();
        sa.copy_media = save_as_dialog->copy_media();
        sa.copy_external = save_as_dialog->copy_external();
+       sa.include_media = save_as_dialog->include_media ();
 
-       /* this signal will be emitted from within this, the calling thread,
-        * after every file is copied. It provides information on percentage
-        * complete (in terms of total data to copy), the number of files
-        * copied so far, and the total number to copy.
-        */
-
-       ScopedConnection c;
-
-       sa.Progress.connect_same_thread (c, boost::bind (&ARDOUR_UI::save_as_progress_update, this, _1, _2, _3, &label, &progress_bar));
+       /* Only bother with a progress dialog if we're going to copy
+          media into the save-as target. Without that choice, this
+          will be very fast because we're only talking about a few kB's to
+          perhaps a couple of MB's of data.
+       */
        
-       progress_dialog.show_all ();
-       progress_dialog.present ();
+       ArdourDialog progress_dialog (_("Save As"), true);
+
+       if (sa.include_media && sa.copy_media) {
+               
+               Gtk::Label label;
+               Gtk::ProgressBar progress_bar;
+               
+               progress_dialog.get_vbox()->pack_start (label);
+               progress_dialog.get_vbox()->pack_start (progress_bar);
+               label.show ();
+               progress_bar.show ();
+
+               /* this signal will be emitted from within this, the calling thread,
+                * after every file is copied. It provides information on percentage
+                * complete (in terms of total data to copy), the number of files
+                * copied so far, and the total number to copy.
+                */
+               
+               ScopedConnection c;
+               
+               sa.Progress.connect_same_thread (c, boost::bind (&ARDOUR_UI::save_as_progress_update, this, _1, _2, _3, &label, &progress_bar));
+               
+               progress_dialog.show_all ();
+               progress_dialog.present ();
+       }
        
        if (_session->save_as (sa)) {
                /* ERROR MESSAGE */
                MessageDialog msg (string_compose (_("Save As failed: %1"), sa.failure_message));
                msg.run ();
        }
+
+       if (!sa.include_media) {
+               unload_session (false);
+               load_session (sa.final_session_folder_name, sa.new_name);
+       }
 }
 
 /** Ask the user for the name of a new snapshot and then take it.
@@ -3149,6 +3209,9 @@ ARDOUR_UI::load_session (const std::string& path, const std::string& snap_name,
                msg.set_position (Gtk::WIN_POS_CENTER);
                pop_back_splash (msg);
                msg.present ();
+
+               dump_errors (cerr);
+               
                (void) msg.run ();
                msg.hide ();
 
@@ -4844,3 +4907,9 @@ ARDOUR_UI::audioengine_became_silent ()
                break;
        }
 }
+       
+void
+ARDOUR_UI::hide_application ()
+{
+    Application::instance ()-> hide ();
+}