Fix editor sizing issue introduced in 4dc65e66
[ardour.git] / gtk2_ardour / ardour_ui.cc
index 979ab3504aeb0e6277d57948e2956e10267167e3..6dd659420c84eff9c5ff9039dfb0ddbcec4c558b 100644 (file)
@@ -79,6 +79,7 @@
 
 #include "widgets/fastmeter.h"
 #include "widgets/prompter.h"
+#include "widgets/tooltips.h"
 
 #include "ardour/ardour.h"
 #include "ardour/audio_backend.h"
 #include "ardour/session_state_utils.h"
 #include "ardour/session_utils.h"
 #include "ardour/source_factory.h"
-#include "ardour/slave.h"
+#include "ardour/transport_master.h"
+#include "ardour/transport_master_manager.h"
 #include "ardour/system_exec.h"
 #include "ardour/track.h"
 #include "ardour/vca_manager.h"
@@ -165,6 +167,7 @@ typedef uint64_t microseconds_t;
 #include "nsm.h"
 #include "opts.h"
 #include "pingback.h"
+#include "plugin_dspload_window.h"
 #include "processor_box.h"
 #include "public_editor.h"
 #include "rc_option_editor.h"
@@ -184,6 +187,7 @@ typedef uint64_t microseconds_t;
 #include "time_axis_view_item.h"
 #include "time_info_box.h"
 #include "timers.h"
+#include "transport_masters_dialog.h"
 #include "utils.h"
 #include "utils_videotl.h"
 #include "video_server_dialog.h"
@@ -268,7 +272,6 @@ libxml_structured_error_func (void* /* parsing_context*/,
 
 ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
        : Gtkmm2ext::UI (PROGRAM_NAME, X_("gui"), argcp, argvp)
-       , session_loaded (false)
        , session_load_in_progress (false)
        , gui_object_state (new GUIObjectState)
        , primary_clock   (new MainClock (X_("primary"),   X_("transport"), true ))
@@ -313,6 +316,8 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
        , export_video_dialog (X_("video-export"), _("Video Export Dialog"))
        , lua_script_window (X_("script-manager"), _("Script Manager"))
        , idleometer (X_("idle-o-meter"), _("Idle'o'Meter"))
+       , plugin_dsp_load_window (X_("plugin-dsp-load"), _("Plugin DSP Load"))
+       , transport_masters_window (X_("transport-masters"), _("Transport Masters"))
        , session_option_editor (X_("session-options-editor"), _("Properties"), boost::bind (&ARDOUR_UI::create_session_option_editor, this))
        , add_video_dialog (X_("add-video"), _("Add Video"), boost::bind (&ARDOUR_UI::create_add_video_dialog, this))
        , bundle_manager (X_("bundle-manager"), _("Bundle Manager"), boost::bind (&ARDOUR_UI::create_bundle_manager, this))
@@ -472,6 +477,8 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
                export_video_dialog.set_state (*ui_xml, 0);
                lua_script_window.set_state (*ui_xml, 0);
                idleometer.set_state (*ui_xml, 0);
+               plugin_dsp_load_window.set_state (*ui_xml, 0);
+               transport_masters_window.set_state (*ui_xml, 0);
        }
 
        /* Separate windows */
@@ -493,6 +500,8 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
        WM::Manager::instance().register_window (&audio_port_matrix);
        WM::Manager::instance().register_window (&midi_port_matrix);
        WM::Manager::instance().register_window (&idleometer);
+       WM::Manager::instance().register_window (&plugin_dsp_load_window);
+       WM::Manager::instance().register_window (&transport_masters_window);
 
        /* do not retain position for add route dialog */
        add_route_dialog.set_state_mask (WindowProxy::Size);
@@ -583,7 +592,6 @@ ARDOUR_UI::engine_running ()
        }
        update_disk_space ();
        update_cpu_load ();
-       update_xrun_count ();
        update_sample_rate (AudioEngine::instance()->sample_rate());
        update_timecode_format ();
        update_peak_thread_work ();
@@ -1508,8 +1516,6 @@ void
 ARDOUR_UI::every_second ()
 {
        update_cpu_load ();
-       update_xrun_count ();
-       update_buffer_load ();
        update_disk_space ();
        update_timecode_format ();
        update_peak_thread_work ();
@@ -1531,8 +1537,7 @@ ARDOUR_UI::every_second ()
 void
 ARDOUR_UI::every_point_one_seconds ()
 {
-       // TODO get rid of this..
-       // ShuttleControl is updated directly via TransportStateChange signal
+       if (editor) editor->build_region_boundary_cache();
 }
 
 void
@@ -1589,7 +1594,7 @@ ARDOUR_UI::update_sample_rate (samplecnt_t)
 
        ENSURE_GUI_THREAD (*this, &ARDOUR_UI::update_sample_rate, ignored)
 
-       if (!AudioEngine::instance()->connected()) {
+       if (!AudioEngine::instance()->running()) {
 
                snprintf (buf, sizeof (buf), "%s", _("Audio: <span foreground=\"red\">none</span>"));
 
@@ -1655,6 +1660,9 @@ ARDOUR_UI::update_format ()
        case MBWF:
                s << _("MBWF");
                break;
+       case FLAC:
+               s << _("FLAC");
+               break;
        }
 
        s << " ";
@@ -1677,43 +1685,33 @@ ARDOUR_UI::update_format ()
 }
 
 void
-ARDOUR_UI::update_xrun_count ()
+ARDOUR_UI::update_cpu_load ()
 {
-       char buf[64];
+       const unsigned int x = _session ? _session->get_xrun_count () : 0;
+       double const c = AudioEngine::instance()->get_dsp_load ();
 
-       /* If this text is changed, the set_size_request_to_display_given_text call in ARDOUR_UI::resize_text_widgets
-          should also be changed.
-       */
+       const char* const bg = c > 90 ? " background=\"red\"" : "";
 
-       if (_session) {
-               const unsigned int x = _session->get_xrun_count ();
-               dsp_load_indicator.set_xrun_count (x);
-               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);
-               }
+       char buf[64];
+       if (x > 9999) {
+               snprintf (buf, sizeof (buf), "DSP: <span%s>%.0f%%</span> (>10k)", bg, c);
+       } else if (x > 0) {
+               snprintf (buf, sizeof (buf), "DSP: <span%s>%.0f%%</span> (%d)", bg, c, x);
        } else {
-               snprintf (buf, sizeof (buf), _("X: <span foreground=\"%s\">?</span>"), X_("yellow"));
-               dsp_load_indicator.set_xrun_count (UINT_MAX);
+               snprintf (buf, sizeof (buf), "DSP: <span%s>%.0f%%</span>", bg, c);
        }
-       xrun_label.set_markup (buf);
-       set_tip (xrun_label, _("Audio dropouts. Shift+click to reset"));
-}
 
-void
-ARDOUR_UI::update_cpu_load ()
-{
-       char buf[64];
+       dsp_load_label.set_markup (buf);
 
-       /* 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 (x > 9999) {
+               snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: >10k\n%s"), c, _("Shift+Click to clear xruns."));
+       } else if (x > 0) {
+               snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: %u\n%s"), c, x, _("Shift+Click to clear xruns."));
+       } else {
+               snprintf (buf, sizeof (buf), _("DSP: %.1f%%"), c);
+       }
 
-       double const c = AudioEngine::instance()->get_dsp_load ();
-       dsp_load_indicator.set_dsp_load (c);
-       snprintf (buf, sizeof (buf), _("DSP: <span foreground=\"%s\">%5.1f%%</span>"), c >= 90 ? X_("red") : X_("green"), c);
-       cpu_load_label.set_markup (buf);
+       ArdourWidgets::set_tooltip (dsp_load_label, buf);
 }
 
 void
@@ -1730,64 +1728,68 @@ ARDOUR_UI::update_peak_thread_work ()
 }
 
 void
-ARDOUR_UI::update_buffer_load ()
+ARDOUR_UI::count_recenabled_streams (Route& route)
 {
-       char buf[256];
-
-       uint32_t const playback = _session ? _session->playback_load () : 100;
-       uint32_t const capture = _session ? _session->capture_load () : 100;
-
-       /* 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) {
-               snprintf (
-                       buf, sizeof (buf),
-                       _("Buffers: <span foreground=\"green\">p:</span><span foreground=\"%s\">%" PRIu32 "%%</span> "
-                                  "<span foreground=\"green\">c:</span><span foreground=\"%s\">%" PRIu32 "%%</span>"),
-                       playback <= 5 ? X_("red") : X_("green"),
-                       playback,
-                       capture <= 5 ? X_("red") : X_("green"),
-                       capture
-                       );
-
-               buffer_load_label.set_markup (buf);
-       } else {
-               buffer_load_label.set_text ("");
+       Track* track = dynamic_cast<Track*>(&route);
+       if (track && track->rec_enable_control()->get_value()) {
+               rec_enabled_streams += track->n_inputs().n_total();
        }
 }
 
 void
-ARDOUR_UI::count_recenabled_streams (Route& route)
+ARDOUR_UI::format_disk_space_label (float remain_sec)
 {
-       Track* track = dynamic_cast<Track*>(&route);
-       if (track && track->rec_enable_control()->get_value()) {
-               rec_enabled_streams += track->n_inputs().n_total();
+       if (remain_sec < 0) {
+               disk_space_label.set_text (_("N/A"));
+               ArdourWidgets::set_tooltip (disk_space_label, _("Unknown"));
+               return;
        }
+
+       char buf[64];
+
+       int sec = floor (remain_sec);
+       int hrs  = sec / 3600;
+       int mins = (sec / 60) % 60;
+       int secs = sec % 60;
+       snprintf (buf, sizeof(buf), _("%02dh:%02dm:%02ds"), hrs, mins, secs);
+       ArdourWidgets::set_tooltip (disk_space_label, buf);
+
+       if (remain_sec > 86400) {
+               disk_space_label.set_text (_("Rec: >24h"));
+               return;
+       } else if (remain_sec > 32400 /* 9 hours */) {
+               snprintf (buf, sizeof (buf), "Rec: %.0fh", remain_sec / 3600.f);
+       } else if (remain_sec > 5940 /* 99 mins */) {
+               snprintf (buf, sizeof (buf), "Rec: %.1fh", remain_sec / 3600.f);
+       } else {
+               snprintf (buf, sizeof (buf), "Rec: %.0fm", remain_sec / 60.f);
+       }
+       disk_space_label.set_text (buf);
+
 }
 
 void
 ARDOUR_UI::update_disk_space()
 {
        if (_session == 0) {
+               format_disk_space_label (-1);
                return;
        }
 
        boost::optional<samplecnt_t> opt_samples = _session->available_capture_duration();
-       char buf[64];
        samplecnt_t fr = _session->sample_rate();
 
        if (fr == 0) {
                /* skip update - no SR available */
+               format_disk_space_label (-1);
                return;
        }
 
        if (!opt_samples) {
                /* Available space is unknown */
-               snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">Unknown</span>"));
+               format_disk_space_label (-1);
        } else if (opt_samples.get_value_or (0) == max_samplecnt) {
-               snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">24hrs+</span>"));
+               format_disk_space_label (max_samplecnt);
        } else {
                rec_enabled_streams = 0;
                _session->foreach_route (this, &ARDOUR_UI::count_recenabled_streams, false);
@@ -1798,32 +1800,9 @@ ARDOUR_UI::update_disk_space()
                        samples /= rec_enabled_streams;
                }
 
-               int hrs;
-               int mins;
-               int secs;
-
-               hrs  = samples / (fr * 3600);
-
-               if (hrs > 24) {
-                       snprintf (buf, sizeof (buf), "%s", _("Disk: <span foreground=\"green\">&gt;24 hrs</span>"));
-               } else {
-                       samples -= hrs * fr * 3600;
-                       mins = samples / (fr * 60);
-                       samples -= mins * fr * 60;
-                       secs = samples / fr;
-
-                       bool const low = (hrs == 0 && mins <= 30);
-
-                       snprintf (
-                               buf, sizeof(buf),
-                               _("Disk: <span foreground=\"%s\">%02dh:%02dm:%02ds</span>"),
-                               low ? X_("red") : X_("green"),
-                               hrs, mins, secs
-                               );
-               }
+               format_disk_space_label (samples / (float)fr);
        }
 
-       disk_space_label.set_markup (buf);
 }
 
 void
@@ -1833,11 +1812,11 @@ ARDOUR_UI::update_timecode_format ()
 
        if (_session) {
                bool matching;
-               TimecodeSlave* tcslave;
-               SyncSource sync_src = Config->get_sync_source();
+               boost::shared_ptr<TimecodeTransportMaster> tcmaster;
+               boost::shared_ptr<TransportMaster> tm = TransportMasterManager::instance().current();
 
-               if ((sync_src == LTC || sync_src == MTC) && (tcslave = dynamic_cast<TimecodeSlave*>(_session->slave())) != 0) {
-                       matching = (tcslave->apparent_timecode_format() == _session->config.get_timecode_format());
+               if ((tm->type() == LTC || tm->type() == MTC) && (tcmaster = boost::dynamic_pointer_cast<TimecodeTransportMaster>(tm)) != 0) {
+                       matching = (tcmaster->apparent_timecode_format() == _session->config.get_timecode_format());
                } else {
                        matching = true;
                }
@@ -1918,7 +1897,7 @@ ARDOUR_UI::open_recent_session ()
 bool
 ARDOUR_UI::check_audioengine (Gtk::Window& parent)
 {
-       if (!AudioEngine::instance()->connected()) {
+       if (!AudioEngine::instance()->running()) {
                MessageDialog msg (parent, string_compose (
                                           _("%1 is not connected to any audio backend.\n"
                                           "You cannot open or close sessions in this condition"),
@@ -2142,6 +2121,32 @@ ARDOUR_UI::session_add_audio_route (
        }
 }
 
+void
+ARDOUR_UI::session_add_foldback_bus (uint32_t how_many, string const & name_template)
+{
+       RouteList routes;
+
+       assert (_session);
+
+       try {
+               routes = _session->new_audio_route (2, 2, 0, how_many, name_template, PresentationInfo::FoldbackBus, -1);
+
+               if (routes.size() != how_many) {
+                       error << string_compose (P_("could not create %1 new foldback bus", "could not create %1 new foldback busses", how_many), how_many)
+                             << endmsg;
+               }
+       }
+
+       catch (...) {
+               display_insufficient_ports_message ();
+               return;
+       }
+
+       for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
+               (*i)->set_strict_io (true);
+       }
+}
+
 void
 ARDOUR_UI::display_insufficient_ports_message ()
 {
@@ -2327,9 +2332,8 @@ ARDOUR_UI::transport_roll ()
                return;
        }
 
-#if 0
        if (_session->config.get_external_sync()) {
-               switch (Config->get_sync_source()) {
+               switch (TransportMasterManager::instance().current()->type()) {
                case Engine:
                        break;
                default:
@@ -2337,7 +2341,6 @@ ARDOUR_UI::transport_roll ()
                        return;
                }
        }
-#endif
 
        bool rolling = _session->transport_rolling();
 
@@ -2391,7 +2394,7 @@ ARDOUR_UI::toggle_roll (bool with_abort, bool roll_out_of_bounded_mode)
        }
 
        if (_session->config.get_external_sync()) {
-               switch (Config->get_sync_source()) {
+               switch (TransportMasterManager::instance().current()->type()) {
                case Engine:
                        break;
                default:
@@ -2703,13 +2706,13 @@ ARDOUR_UI::save_session_as ()
                                        MessageDialog msg (_main_window,
                                                        string_compose (_("\
 %1 was unable to save your session.\n\n\
-If you still wish to proceeed, please use the\n\n\
+If you still wish to proceed, please use the\n\n\
 \"Don't save now\" option."), PROGRAM_NAME));
                                        pop_back_splash(msg);
                                        msg.run ();
                                        return;
                                }
-                               // no break
+                               /* fall through */
                        case 0:
                                _session->remove_pending_capture_state ();
                                break;
@@ -2899,13 +2902,13 @@ ARDOUR_UI::snapshot_session (bool switch_to_it)
                                        MessageDialog msg (_main_window,
                                                        string_compose (_("\
 %1 was unable to save your session.\n\n\
-If you still wish to proceeed, please use the\n\n\
+If you still wish to proceed, please use the\n\n\
 \"Don't save now\" option."), PROGRAM_NAME));
                                        pop_back_splash(msg);
                                        msg.run ();
                                        return;
                                }
-                               // no break
+                               /* fall through */
                        case 0:
                                _session->remove_pending_capture_state ();
                                break;
@@ -3543,8 +3546,6 @@ ARDOUR_UI::load_session (const std::string& path, const std::string& snap_name,
                }
        }
 
-       session_loaded = false;
-
        loading_message (string_compose (_("Please wait while %1 loads your session"), PROGRAM_NAME));
 
        try {
@@ -3654,8 +3655,6 @@ ARDOUR_UI::load_session (const std::string& path, const std::string& snap_name,
 
        set_session (new_session);
 
-       session_loaded = true;
-
        if (_session) {
                _session->set_clean ();
        }
@@ -3699,7 +3698,6 @@ ARDOUR_UI::build_session (const std::string& path, const std::string& snap_name,
        Session *new_session;
        int x;
 
-       session_loaded = false;
        x = unload_session ();
 
        if (x < 0) {
@@ -3764,8 +3762,6 @@ ARDOUR_UI::build_session (const std::string& path, const std::string& snap_name,
 
        set_session (new_session);
 
-       session_loaded = true;
-
        new_session->save_state(new_session->name());
 
        return 0;
@@ -3916,13 +3912,7 @@ ARDOUR_UI::launch_chat ()
 
        switch (dialog.run()) {
        case RESPONSE_OK:
-#ifdef __APPLE__
-               open_uri("http://webchat.freenode.net/?channels=ardour-osx");
-#elif defined PLATFORM_WINDOWS
-               open_uri("http://webchat.freenode.net/?channels=ardour-windows");
-#else
                open_uri("http://webchat.freenode.net/?channels=ardour");
-#endif
                break;
        default:
                break;
@@ -4355,6 +4345,19 @@ ARDOUR_UI::add_route_dialog_response (int r)
                return;
        }
 
+       if (!AudioEngine::instance()->running ()) {
+               switch (r) {
+                       case AddRouteDialog::Add:
+                       case AddRouteDialog::AddAndClose:
+                               break;
+                       default:
+                               return;
+               }
+               add_route_dialog->ArdourDialog::on_response (r);
+               ARDOUR_UI_UTILS::engine_is_running ();
+               return;
+       }
+
        int count;
 
        switch (r) {
@@ -4429,6 +4432,9 @@ ARDOUR_UI::add_route_dialog_response (int r)
        case AddRouteDialog::VCAMaster:
                _session->vca_manager().create_vca (count, name_template);
                break;
+       case AddRouteDialog::FoldbackBus:
+               session_add_foldback_bus (count, name_template);
+               break;
        }
 }