leftmost_position => leftmost_sample, current_page_frames => current_page_samples
[ardour.git] / gtk2_ardour / ardour_ui.cc
index 4ab24dcd18d7695c4f50e2ee7f9388c47e2ef734..6801222e8b9b872a5b005c6176d0166fd909572e 100644 (file)
@@ -116,13 +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 "video_copy_dialog.h"
-#include "system_exec.h" /* to launch video-server */
-#endif
+#include "system_exec.h"
 
 #include "i18n.h"
 
@@ -202,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;
@@ -472,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
@@ -650,7 +645,7 @@ void
 ARDOUR_UI::startup ()
 {
        Application* app = Application::instance ();
-
+       char *nsm_url;
        app->ShouldQuit.connect (sigc::mem_fun (*this, &ARDOUR_UI::queue_finish));
        app->ShouldLoad.connect (sigc::mem_fun (*this, &ARDOUR_UI::idle_load));
 
@@ -660,7 +655,58 @@ ARDOUR_UI::startup ()
 
        app->ready ();
 
-       if (get_session_parameters (true, ARDOUR_COMMAND_LINE::new_session, ARDOUR_COMMAND_LINE::load_template)) {
+       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");
+
+                       unsigned int i = 0;
+                       // wait for announce reply from nsm server
+                       for ( i = 0; i < 5000; ++i) {
+                               nsm->check ();
+                               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 {
+                       delete nsm;
+                       nsm = 0;
+               }
+       }
+
+       else if (get_session_parameters (true, ARDOUR_COMMAND_LINE::new_session, ARDOUR_COMMAND_LINE::load_template)) {
                exit (1);
        }
 
@@ -784,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;
@@ -826,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
@@ -929,6 +968,19 @@ ARDOUR_UI::every_second ()
        update_buffer_load ();
        update_disk_space ();
        update_timecode_format ();
+
+       if (nsm && nsm->is_active ()) {
+               nsm->check ();
+
+               if (!_was_dirty && _session->dirty ()) {
+                       nsm->is_dirty ();
+                       _was_dirty = true;
+               }
+               else if (_was_dirty && !_session->dirty ()){
+                       nsm->is_clean ();
+                       _was_dirty = false;
+               }
+       }
        return TRUE;
 }
 
@@ -2283,6 +2335,7 @@ ARDOUR_UI::save_state_canfail (string name, bool switch_to_it)
        }
 
        save_ardour_state (); /* XXX cannot fail? yeah, right ... */
+       editor->save_canvas_state ();
        return 0;
 }
 
@@ -2416,7 +2469,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;
@@ -2492,11 +2545,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 */
@@ -2560,6 +2613,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) {
@@ -2611,7 +2668,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);
 
@@ -2677,9 +2734,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;
        }
@@ -3229,7 +3283,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;
        }
 
@@ -3267,7 +3325,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)
 {
@@ -3420,43 +3477,38 @@ ARDOUR_UI::add_video (Gtk::Window* float_window)
        }
 
        switch (add_video_dialog->import_option()) {
-               case VTL_IMPORT_COPY:
-               {
-                       VideoCopyDialog *video_copy_dialog;
-                       video_copy_dialog = new VideoCopyDialog(_session, path);
-                       //video_copy_dialog->setup_non_interactive_copy();
-                       ResponseType r = (ResponseType) video_copy_dialog->run ();
-                       video_copy_dialog->hide();
-                       if (r != RESPONSE_ACCEPT) { return; }
-                       path = video_copy_dialog->get_filename();
-                       delete video_copy_dialog;
-               }
-                       break;
                case VTL_IMPORT_TRANSCODE:
-               {
-                       TranscodeVideoDialog *transcode_video_dialog;
-                       transcode_video_dialog = new TranscodeVideoDialog (_session, path);
-                       ResponseType r = (ResponseType) transcode_video_dialog->run ();
-                       transcode_video_dialog->hide();
-                       if (r != RESPONSE_ACCEPT) { return; }
-                       path = transcode_video_dialog->get_filename();
-                       if (!transcode_video_dialog->get_audiofile().empty()) {
-                               editor->embed_audio_from_video(transcode_video_dialog->get_audiofile());
+                       {
+                               TranscodeVideoDialog *transcode_video_dialog;
+                               transcode_video_dialog = new TranscodeVideoDialog (_session, path);
+                               ResponseType r = (ResponseType) transcode_video_dialog->run ();
+                               transcode_video_dialog->hide();
+                               if (r != RESPONSE_ACCEPT) {
+                                       delete transcode_video_dialog;
+                                       return;
+                               }
+                               if (!transcode_video_dialog->get_audiofile().empty()) {
+                                       editor->embed_audio_from_video(transcode_video_dialog->get_audiofile());
+                               }
+                               switch (transcode_video_dialog->import_option()) {
+                                       case VTL_IMPORT_TRANSCODED:
+                                               path = transcode_video_dialog->get_filename();
+                                               local_file = true;
+                                               break;
+                                       case VTL_IMPORT_REFERENCE:
+                                               break;
+                                       default:
+                                               delete transcode_video_dialog;
+                                               return;
+                               }
+                               delete transcode_video_dialog;
                        }
-                       delete transcode_video_dialog;
-               }
                        break;
                default:
                case VTL_IMPORT_NONE:
                        break;
        }
 
-       if (path.empty()) {
-               /* may have been overriden by 'audio only import'
-                * in transcode_video_dialog */
-               path = add_video_dialog->file_name(local_file);;
-       }
-
        /* strip _session->session_directory().video_path() from video file if possible */
        if (local_file && !path.compare(0, _session->session_directory().video_path().size(), _session->session_directory().video_path())) {
                 path=path.substr(_session->session_directory().video_path().size());
@@ -3474,6 +3526,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);
@@ -3495,6 +3552,7 @@ ARDOUR_UI::remove_video ()
        _session->add_extra_xml(*node);
        node = new XMLNode(X_("Videomonitor"));
        _session->add_extra_xml(*node);
+       stop_video_server();
 }
 
 void
@@ -3507,7 +3565,6 @@ ARDOUR_UI::flush_videotimeline_cache (bool localcacheonly)
        }
        editor->queue_visual_videotimeline_update();
 }
-#endif
 
 XMLNode*
 ARDOUR_UI::mixer_settings () const
@@ -3777,9 +3834,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
 }