expand bbox for Canvas::Line to get rid of artifacts caused when moving them around...
[ardour.git] / gtk2_ardour / ardour_ui.cc
index c520018a96c8a5aad98dfff497a82b10293970fe..eebd35aefbc041c1449979c5670b0e3f30cafe78 100644 (file)
@@ -116,12 +116,10 @@ typedef uint64_t microseconds_t;
 #include "time_axis_view_item.h"
 #include "utils.h"
 #include "window_proxy.h"
-#ifdef WITH_VIDEOTIMELINE
 #include "video_server_dialog.h"
 #include "add_video_dialog.h"
 #include "transcode_video_dialog.h"
-#include "system_exec.h" /* to launch video-server */
-#endif
+#include "system_exec.h"
 
 #include "i18n.h"
 
@@ -201,10 +199,8 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
        session_selector_window = 0;
        last_key_press_time = 0;
        add_route_dialog = 0;
-#ifdef WITH_VIDEOTIMELINE
        add_video_dialog = 0;
        video_server_process = 0;
-#endif
        route_params = 0;
        bundle_manager = 0;
        rc_option_editor = 0;
@@ -471,10 +467,10 @@ ARDOUR_UI::~ARDOUR_UI ()
        delete editor;
        delete mixer;
        delete add_route_dialog;
-#ifdef WITH_VIDEOTIMELINE
-       if (add_video_dialog) delete add_video_dialog;
+       if (add_video_dialog) {
+               delete add_video_dialog;
+       }
        stop_video_server();
-#endif
 }
 
 void
@@ -660,16 +656,48 @@ ARDOUR_UI::startup ()
        app->ready ();
 
        nsm_url = getenv ("NSM_URL");
+       nsm = 0;
 
        if (nsm_url) {
                nsm = new NSM_Client;
                if (!nsm->init (nsm_url)) {
                        nsm->announce (PROGRAM_NAME, ":dirty:", "ardour3");
 
-                       do {
+                       unsigned int i = 0;
+                       // wait for announce reply from nsm server
+                       for ( i = 0; i < 5000; ++i) {
                                nsm->check ();
-                               usleep (10);
-                       } while (!nsm->client_id ());
+                               usleep (i);
+                               if (nsm->is_active())
+                                       break;
+                       }
+                       // wait for open command from nsm server
+                       for ( i = 0; i < 5000; ++i) {
+                               nsm->check ();
+                               usleep (1000);
+                               if (nsm->client_id ())
+                                       break;
+                       }
+
+                       if (_session && nsm) {
+                               _session->set_nsm_state( nsm->is_active() );
+                       }
+
+                       // 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 {
@@ -678,7 +706,7 @@ ARDOUR_UI::startup ()
                }
        }
 
-       if (get_session_parameters (true, ARDOUR_COMMAND_LINE::new_session, ARDOUR_COMMAND_LINE::load_template)) {
+       else if (get_session_parameters (true, ARDOUR_COMMAND_LINE::new_session, ARDOUR_COMMAND_LINE::load_template)) {
                exit (1);
        }
 
@@ -802,13 +830,8 @@ ARDOUR_UI::idle_finish ()
 void
 ARDOUR_UI::finish()
 {
-#ifdef WITH_VIDEOTIMELINE
-       /* close video-monitor & pending requests
-        * would better be done in ~Editor() but that is not called..
-        */
-       ARDOUR_UI::instance()->video_timeline->close_session();
-#endif
        if (_session) {
+               ARDOUR_UI::instance()->video_timeline->sync_session_state();
 
                if (_session->dirty()) {
                        vector<string> actions;
@@ -844,10 +867,8 @@ If you still wish to quit, please use the\n\n\
                point_zero_one_second_connection.disconnect();
        }
 
-#ifdef WITH_VIDEOTIMELINE
        delete ARDOUR_UI::instance()->video_timeline;
        stop_video_server();
-#endif
 
        /* Save state before deleting the session, as that causes some
           windows to be destroyed before their visible state can be
@@ -948,7 +969,7 @@ ARDOUR_UI::every_second ()
        update_disk_space ();
        update_timecode_format ();
 
-       if (nsm) {
+       if (nsm && nsm->is_active ()) {
                nsm->check ();
 
                if (!_was_dirty && _session->dirty ()) {
@@ -2447,7 +2468,7 @@ ARDOUR_UI::build_session_from_nsd (const std::string& session_path, const std::s
 {
        BusProfile bus_profile;
 
-       if (Profile->get_sae()) {
+       if (nsm || Profile->get_sae()) {
 
                bus_profile.master_out_channels = 2;
                bus_profile.input_ac = AutoConnectPhysical;
@@ -2523,11 +2544,11 @@ ARDOUR_UI::get_session_parameters (bool quit_on_cancel, bool should_be_new, stri
         * treat a non-dirty session this way, so that it stays visible 
         * as we bring up the new session dialog.
         */
-#ifdef WITH_VIDEOTIMELINE
+
        if (_session && ARDOUR_UI::instance()->video_timeline) {
-               ARDOUR_UI::instance()->video_timeline->close_session();
+               ARDOUR_UI::instance()->video_timeline->sync_session_state();
        }
-#endif
+
        if (_session && _session->dirty()) {
                if (unload_session (false)) {
                        /* unload cancelled by user */
@@ -2591,6 +2612,10 @@ ARDOUR_UI::get_session_parameters (bool quit_on_cancel, bool should_be_new, stri
                
                session_name = _startup->session_name (likely_new);
                
+               if (nsm) {
+                       likely_new = true;
+               }
+
                string::size_type suffix = session_name.find (statefile_suffix);
                
                if (suffix != string::npos) {
@@ -2642,7 +2667,7 @@ ARDOUR_UI::get_session_parameters (bool quit_on_cancel, bool should_be_new, stri
 
                if (Glib::file_test (session_path, Glib::FileTest (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
 
-                       if (likely_new) {
+                       if (likely_new && !nsm) {
 
                                std::string existing = Glib::build_filename (session_path, session_name);
 
@@ -2708,9 +2733,6 @@ ARDOUR_UI::get_session_parameters (bool quit_on_cancel, bool should_be_new, stri
 void
 ARDOUR_UI::close_session()
 {
-#ifdef WITH_VIDEOTIMELINE
-       ARDOUR_UI::instance()->video_timeline->close_session();
-#endif
        if (!check_audioengine()) {
                return;
        }
@@ -3260,7 +3282,11 @@ ARDOUR_UI::add_route (Gtk::Window* float_window)
        string template_path = add_route_dialog->track_template();
 
        if (!template_path.empty()) {
-               _session->new_route_from_template (count, template_path);
+               if (add_route_dialog->name_template_is_default())  {
+                       _session->new_route_from_template (count, template_path, string());
+               } else {
+                       _session->new_route_from_template (count, template_path, add_route_dialog->name_template());
+               }
                return;
        }
 
@@ -3298,7 +3324,6 @@ ARDOUR_UI::add_route (Gtk::Window* float_window)
        /* idle connection will end at scope end */
 }
 
-#ifdef WITH_VIDEOTIMELINE
 void
 ARDOUR_UI::stop_video_server (bool ask_confirm)
 {
@@ -3500,6 +3525,11 @@ ARDOUR_UI::add_video (Gtk::Window* float_window)
                _session->add_extra_xml (*node);
                _session->set_dirty ();
 
+               _session->maybe_update_session_range(
+                       std::max(video_timeline->get_offset(), (ARDOUR::frameoffset_t) 0),
+                       std::max(video_timeline->get_offset() + video_timeline->get_duration(), (ARDOUR::frameoffset_t) 0));
+
+
                if (add_video_dialog->launch_xjadeo() && local_file) {
                        editor->set_xjadeo_sensitive(true);
                        editor->toggle_xjadeo_proc(1);
@@ -3521,6 +3551,7 @@ ARDOUR_UI::remove_video ()
        _session->add_extra_xml(*node);
        node = new XMLNode(X_("Videomonitor"));
        _session->add_extra_xml(*node);
+       stop_video_server();
 }
 
 void
@@ -3533,7 +3564,6 @@ ARDOUR_UI::flush_videotimeline_cache (bool localcacheonly)
        }
        editor->queue_visual_videotimeline_update();
 }
-#endif
 
 XMLNode*
 ARDOUR_UI::mixer_settings () const
@@ -3803,9 +3833,7 @@ ARDOUR_UI::update_transport_clocks (framepos_t pos)
        if (big_clock_window->get()) {
                big_clock->set (pos);
        }
-#ifdef WITH_VIDEOTIMELINE
        ARDOUR_UI::instance()->video_timeline->manual_seek_video_monitor(pos);
-#endif
 }