tracks build ... backends are hard-coded
[ardour.git] / gtk2_ardour / ardour_ui.cc
index a1bd4646317d7bef3851e5639ebda33c74164ad7..0d646c8add46e24811c95fec8035b2d42e948632 100644 (file)
@@ -181,30 +181,23 @@ 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)
+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 ))
        , secondary_clock (new MainClock (X_("secondary"), X_("secondary"), false))
-         
-         /* big clock */
-
        , big_clock (new AudioClock (X_("bigclock"), false, "big", true, true, false, false))
        , video_timeline(0)
-
-         /* start of private members */
+       , ignore_dual_punch (false)
        , editor (0)
        , mixer (0)
        , nsm (0)
        , _was_dirty (false)
        , _mixer_on_top (false)
        , first_time_engine_run (true)
-
-         /* transport */
-
        , roll_controllable (new TransportControllable ("transport roll", *this, TransportControllable::Roll))
        , stop_controllable (new TransportControllable ("transport stop", *this, TransportControllable::Stop))
        , goto_start_controllable (new TransportControllable ("transport goto start", *this, TransportControllable::GotoStart))
@@ -212,19 +205,22 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
        , auto_loop_controllable (new TransportControllable ("transport auto loop", *this, TransportControllable::AutoLoop))
        , play_selection_controllable (new TransportControllable ("transport play selection", *this, TransportControllable::PlaySelection))
        , rec_controllable (new TransportControllable ("transport rec-enable", *this, TransportControllable::RecordEnable))
-
        , auto_return_button (ArdourButton::led_default_elements)
        , follow_edits_button (ArdourButton::led_default_elements)
        , auto_input_button (ArdourButton::led_default_elements)
-
        , auditioning_alert_button (_("Audition"))
        , solo_alert_button (_("Solo"))
        , feedback_alert_button (_("Feedback"))
        , 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)
+       , last_key_press_time (0)
+       , save_as_dialog (0)
+       , meterbridge (0)
        , speaker_config_window (X_("speaker-config"), _("Speaker Configuration"))
        , key_editor (X_("key-editor"), _("Key Bindings"))
        , rc_option_editor (X_("rc-options-editor"), _("Preferences"))
@@ -240,12 +236,17 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
        , big_clock_window (X_("big-clock"), _("Big Clock"), boost::bind (&ARDOUR_UI::create_big_clock_window, this))
        , audio_port_matrix (X_("audio-connection-manager"), _("Audio Connections"), boost::bind (&ARDOUR_UI::create_global_port_matrix, this, ARDOUR::DataType::AUDIO))
        , midi_port_matrix (X_("midi-connection-manager"), _("MIDI Connections"), boost::bind (&ARDOUR_UI::create_global_port_matrix, this, ARDOUR::DataType::MIDI))
-
+       , video_server_process (0)
+       , splash (0)
+       , have_configure_timeout (false)
+       , last_configure_time (0)
+       , last_peak_grab (0)
+       , have_disk_speed_dialog_displayed (false)
        , _status_bar_visibility (X_("status-bar"))
        , _feedback_exists (false)
        , _log_not_acknowledged (LogLevelNone)
 {
-       Gtkmm2ext::init(localedir);
+       Gtkmm2ext::init (localedir);
 
        if (ARDOUR::handle_old_configuration_files (boost::bind (ask_about_configuration_copy, _1, _2, _3))) {
                MessageDialog msg (string_compose (_("Your configuration files were copied. You can now restart %1."), PROGRAM_NAME), true);
@@ -253,12 +254,7 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
                /* configuration was modified, exit immediately */
                _exit (0);
        }
-
        
-       splash = 0;
-
-       _numpad_locate_happening = false;
-
        if (theArdourUI == 0) {
                theArdourUI = this;
        }
@@ -267,20 +263,6 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
        boost::function<void (string)> pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1));
        ui_config->map_parameters (pc);
 
-       editor = 0;
-       mixer = 0;
-       meterbridge = 0;
-       editor = 0;
-       _session_is_new = false;
-       session_selector_window = 0;
-       last_key_press_time = 0;
-       video_server_process = 0;
-       open_session_selector = 0;
-       have_configure_timeout = false;
-       have_disk_speed_dialog_displayed = false;
-       session_loaded = false;
-       ignore_dual_punch = false;
-
        roll_button.set_controllable (roll_controllable);
        stop_button.set_controllable (stop_controllable);
        goto_start_button.set_controllable (goto_start_controllable);
@@ -298,9 +280,6 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
        rec_button.set_name ("transport recenable button");
        midi_panic_button.set_name ("transport button");
 
-       last_configure_time= 0;
-       last_peak_grab = 0;
-
        ARDOUR::Diskstream::DiskOverrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_overrun_handler, this), gui_context());
        ARDOUR::Diskstream::DiskUnderrun.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::disk_underrun_handler, this), gui_context());
 
@@ -456,8 +435,12 @@ ARDOUR_UI::engine_running ()
                first_time_engine_run = false;
        } 
        
+       if (_session) {
+               _session->reset_xrun_count ();
+       }
        update_disk_space ();
        update_cpu_load ();
+       update_xrun_count ();
        update_sample_rate (AudioEngine::instance()->sample_rate());
        update_timecode_format ();
 }
@@ -821,13 +804,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
@@ -1201,6 +1187,7 @@ void
 ARDOUR_UI::every_second ()
 {
        update_cpu_load ();
+       update_xrun_count ();
        update_buffer_load ();
        update_disk_space ();
        update_timecode_format ();
@@ -1361,6 +1348,29 @@ ARDOUR_UI::update_format ()
        format_label.set_markup (s.str ());
 }
 
+void
+ARDOUR_UI::update_xrun_count ()
+{
+       char buf[64];
+
+       /* If this text is changed, the set_size_request_to_display_given_text call in ARDOUR_UI::resize_text_widgets
+          should also be changed.
+       */
+
+       if (_session) {
+               const unsigned int x = _session->get_xrun_count ();
+               if (x > 9999) {
+                       snprintf (buf, sizeof (buf), _("X: <span foreground=\"%s\">&gt;10K</span>"), X_("red"));
+               } else {
+                       snprintf (buf, sizeof (buf), _("X: <span foreground=\"%s\">%u</span>"), x > 0 ? X_("red") : X_("green"), x);
+               }
+       } else {
+               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_cpu_load ()
 {
@@ -2094,7 +2104,6 @@ ARDOUR_UI::get_smart_mode() const
 void
 ARDOUR_UI::toggle_roll (bool with_abort, bool roll_out_of_bounded_mode)
 {
-
        if (!_session) {
                return;
        }
@@ -2403,50 +2412,75 @@ ARDOUR_UI::save_session_as ()
                return;
        }
 
-       SaveAsDialog sad;
+       if (!save_as_dialog) {
+               save_as_dialog = new SaveAsDialog;
+       } else {
+               save_as_dialog->clear_name ();
+       }
 
-       switch (sad.run()) {
+       int response = save_as_dialog->run ();
+
+       save_as_dialog->hide ();
+       
+       switch (response) {
        case Gtk::RESPONSE_OK:
                break;
        default:
                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;
-
-       sa.new_parent_folder = sad.new_parent_folder ();
-       sa.new_name = sad.new_name ();
-       sa.switch_to = sad.switch_to();
-       sa.copy_media = sad.copy_media();
-       sa.copy_external = sad.copy_external();
-
-       /* 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));
+       Session::SaveAs sa;
+
+       sa.new_parent_folder = save_as_dialog->new_parent_folder ();
+       sa.new_name = save_as_dialog->new_name ();
+       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 ();
+
+       /* 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.
@@ -4831,3 +4865,9 @@ ARDOUR_UI::audioengine_became_silent ()
                break;
        }
 }
+       
+void
+ARDOUR_UI::hide_application ()
+{
+    Application::instance ()-> hide ();
+}