remove method and inline its contents. Nothing gained by wrapping this up
[ardour.git] / gtk2_ardour / ardour_ui.cc
index 9ce9ca355c27c537e16899d7251ef3cc9e5fe2eb..a52233484053ed8d7707bc891d0a35604f921c39 100644 (file)
@@ -92,6 +92,7 @@
 #include "ardour/filename_extensions.h"
 #include "ardour/filesystem_paths.h"
 #include "ardour/ltc_file_reader.h"
+#include "ardour/monitor_control.h"
 #include "ardour/midi_track.h"
 #include "ardour/port.h"
 #include "ardour/plugin_manager.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"
@@ -166,6 +168,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"
@@ -185,6 +188,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"
@@ -269,14 +273,12 @@ 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 ))
        , secondary_clock (new MainClock (X_("secondary"), X_("secondary"), false))
        , big_clock (new AudioClock (X_("bigclock"), false, "big", true, true, false, false))
        , video_timeline(0)
-       , global_actions (X_("global"))
        , ignore_dual_punch (false)
        , main_window_visibility (0)
        , editor (0)
@@ -314,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))
@@ -473,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 */
@@ -494,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);
@@ -748,7 +756,7 @@ ARDOUR_UI::post_engine ()
                output << "      <tr><th>Action Name</th><th>Menu Name</th></tr>" << endl;
                output << "  </thead>\n  <tbody>" << endl;
 
-               Gtkmm2ext::ActionMap::get_all_actions (paths, labels, tooltips, keys, actions);
+               ActionManager::get_all_actions (paths, labels, tooltips, keys, actions);
 
                vector<string>::iterator p;
                vector<string>::iterator l;
@@ -1586,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>"));
 
@@ -1652,6 +1660,9 @@ ARDOUR_UI::update_format ()
        case MBWF:
                s << _("MBWF");
                break;
+       case FLAC:
+               s << _("FLAC");
+               break;
        }
 
        s << " ";
@@ -1679,16 +1690,18 @@ ARDOUR_UI::update_cpu_load ()
        const unsigned int x = _session ? _session->get_xrun_count () : 0;
        double const c = AudioEngine::instance()->get_dsp_load ();
 
+       const char* const bg = c > 90 ? " background=\"red\"" : "";
+
        char buf[64];
        if (x > 9999) {
-               snprintf (buf, sizeof (buf), "DSP: %.0f%% (>10k)", c);
+               snprintf (buf, sizeof (buf), "DSP: <span%s>%.0f%%</span> (>10k)", bg, c);
        } else if (x > 0) {
-               snprintf (buf, sizeof (buf), "DSP: %.0f%% (%d)", c, x);
+               snprintf (buf, sizeof (buf), "DSP: <span%s>%.0f%%</span> (%d)", bg, c, x);
        } else {
-               snprintf (buf, sizeof (buf), "DSP: %.0f%%", c);
+               snprintf (buf, sizeof (buf), "DSP: <span%s>%.0f%%</span>", bg, c);
        }
 
-       dsp_load_label.set_text (buf);
+       dsp_load_label.set_markup (buf);
 
        if (x > 9999) {
                snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: >10k\n%s"), c, _("Shift+Click to clear xruns."));
@@ -1799,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;
                }
@@ -1884,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"),
@@ -2108,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 ()
 {
@@ -2293,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:
@@ -2303,7 +2341,6 @@ ARDOUR_UI::transport_roll ()
                        return;
                }
        }
-#endif
 
        bool rolling = _session->transport_rolling();
 
@@ -2357,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:
@@ -2669,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;
@@ -2865,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;
@@ -3509,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 {
@@ -3620,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 ();
        }
@@ -3665,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) {
@@ -3730,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;
@@ -3882,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;
@@ -4321,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) {
@@ -4395,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;
        }
 }
 
@@ -5878,14 +5918,6 @@ ARDOUR_UI::key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey
        return true;
 }
 
-void
-ARDOUR_UI::load_bindings ()
-{
-       if ((global_bindings = Bindings::get_bindings (X_("Global"), global_actions)) == 0) {
-               error << _("Global keybindings are missing") << endmsg;
-       }
-}
-
 void
 ARDOUR_UI::cancel_solo ()
 {
@@ -5945,3 +5977,45 @@ ARDOUR_UI::reset_focus (Gtk::Widget* w)
        gtk_window_set_focus (GTK_WINDOW(top->gobj()), 0);
 
 }
+
+void
+ARDOUR_UI::monitor_dim_all ()
+{
+       boost::shared_ptr<Route> mon = _session->monitor_out ();
+       if (!mon) {
+               return;
+       }
+       boost::shared_ptr<ARDOUR::MonitorProcessor> _monitor = mon->monitor_control ();
+
+       Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-dim-all");
+       assert (act);  Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
+       assert (tact); _monitor->set_dim_all (tact->get_active());
+}
+
+void
+ARDOUR_UI::monitor_cut_all ()
+{
+       boost::shared_ptr<Route> mon = _session->monitor_out ();
+       if (!mon) {
+               return;
+       }
+       boost::shared_ptr<ARDOUR::MonitorProcessor> _monitor = mon->monitor_control ();
+
+       Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-cut-all");
+       assert (act);  Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
+       assert (tact); _monitor->set_cut_all (tact->get_active());
+}
+
+void
+ARDOUR_UI::monitor_mono ()
+{
+       boost::shared_ptr<Route> mon = _session->monitor_out ();
+       if (!mon) {
+               return;
+       }
+       boost::shared_ptr<ARDOUR::MonitorProcessor> _monitor = mon->monitor_control ();
+
+       Glib::RefPtr<Action> act = ActionManager::get_action (X_("Monitor"), "monitor-mono");
+       assert (act);  Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
+       assert (tact);_monitor->set_mono (tact->get_active());
+}