Drop references held by any GUI Lua script after execution
[ardour.git] / gtk2_ardour / video_monitor.cc
index 1fe8f97f0918fcfbe1c19d248d87a20db579ac28..38a5a08177bfb82b5bf6145e2aeb26596b435613 100644 (file)
@@ -1,29 +1,32 @@
 /*
-    Copyright (C) 2010 Paul Davis
-    Author: Robin Gareus <robin@gareus.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Copyright (C) 2013-2016 Tim Mayberry <mojofunk@gmail.com>
+ * Copyright (C) 2013-2018 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include <cstdio>
 
-*/
 #include "pbd/file_utils.h"
 #include "pbd/convert.h"
+#include "ardour/filesystem_paths.h"
+
 #include "gui_thread.h"
 #include "timers.h"
 #include "utils.h"
-
-#include <stdio.h>
 #include "public_editor.h"
 #include "editor.h"
 #include "video_monitor.h"
@@ -76,7 +79,7 @@ VideoMonitor::start ()
        sync_by_manual_seek = false;
        if (clock_connection.connected()) { clock_connection.disconnect(); }
 
-       if (process->start(debug_enable?2:1)) {
+       if (process->start (debug_enable ? SystemExec::MergeWithStdin : SystemExec::IgnoreAndClose)) {
                return false;
        }
        return true;
@@ -129,7 +132,14 @@ VideoMonitor::open (std::string filename)
        manually_seeked_frame = 0;
        osdmode = 10; // 1: frameno, 2: timecode, 8: box
        starting = 15;
+
+       std::string ardour_mono_file;
+       if (find_file (ARDOUR::ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
+               process->write_to_stdin("osd font "+ ardour_mono_file  +"\n");
+       }
+
        process->write_to_stdin("load " + filename + "\n");
+
        process->write_to_stdin("set fps -1\n");
        process->write_to_stdin("window resize 100%\n");
        process->write_to_stdin("window ontop on\n");
@@ -150,6 +160,7 @@ VideoMonitor::open (std::string filename)
        process->write_to_stdin("notify settings\n");
        process->write_to_stdin("window letterbox on\n");
        process->write_to_stdin("osd mode 10\n");
+
        for(XJSettings::const_iterator it = xjadeo_settings.begin(); it != xjadeo_settings.end(); ++it) {
                if (skip_setting(it->first)) { continue; }
                process->write_to_stdin(it->first + " " + it->second + "\n");
@@ -381,7 +392,7 @@ VideoMonitor::parse_output (std::string d, size_t /*s*/)
                                                xjadeo_settings["window letterbox"] = value;
                                        } else if(key ==  "osdmode") {
                                                knownstate |= 1;
-                                               osdmode = atoi(value);
+                                               osdmode = atoi(value) & ~0x40;
                                                if (starting || atoi(xjadeo_settings["osd mode"]) != osdmode) {
                                                        if (!starting && _session) _session->set_dirty ();
                                                        if ((osdmode & 1) == 1) { UiState("xjadeo-window-osd-frame-on"); }
@@ -430,8 +441,8 @@ VideoMonitor::save_session ()
 
        for(XJSettings::const_iterator it = xjadeo_settings.begin(); it != xjadeo_settings.end(); ++it) {
          XMLNode* child = node->add_child (X_("XJSetting"));
-               child->add_property (X_("k"), it->first);
-               child->add_property (X_("v"), it->second);
+               child->set_property (X_("k"), it->first);
+               child->set_property (X_("v"), it->second);
        }
 }
 
@@ -441,6 +452,7 @@ VideoMonitor::set_session (ARDOUR::Session *s)
 {
        SessionHandlePtr::set_session (s);
        if (!_session) { return; }
+       ARDOUR::Config->ParameterChanged.connect (*this, invalidator (*this), ui_bind (&VideoMonitor::parameter_changed, this, _1), gui_context());
        _session->config.ParameterChanged.connect (*this, invalidator (*this), ui_bind (&VideoMonitor::parameter_changed, this, _1), gui_context());
        XMLNode* node = _session->extra_xml (X_("XJSettings"));
        if (!node) { return;}
@@ -466,31 +478,33 @@ VideoMonitor::get_custom_setting (const std::string k)
        return (xjadeo_settings[k]);
 }
 
-#define NO_OFFSET (ARDOUR::max_framepos) //< skip setting or modifying offset
+#define NO_OFFSET (Temporal::max_samplepos) //< skip setting or modifying offset
 void
 VideoMonitor::srsupdate ()
 {
        if (!_session) { return; }
-       if (editor->dragging_playhead()) { return ;}
-       manual_seek(_session->audible_frame(), false, NO_OFFSET);
+       if (editor->dragging_playhead() || editor->preview_video_drag_active()) {
+               return;
+       }
+       manual_seek(_session->audible_sample(), false, NO_OFFSET);
 }
 
 void
-VideoMonitor::set_offset (ARDOUR::frameoffset_t offset)
+VideoMonitor::set_offset (ARDOUR::sampleoffset_t offset)
 {
        if (!is_started()) { return; }
        if (!_session) { return; }
        if (offset == NO_OFFSET ) { return; }
 
-       framecnt_t video_frame_offset;
-       framecnt_t audio_sample_rate;
+       samplecnt_t video_frame_offset;
+       samplecnt_t audio_sample_rate;
        if (_session->config.get_videotimeline_pullup()) {
-               audio_sample_rate = _session->frame_rate();
+               audio_sample_rate = _session->sample_rate();
        } else {
-               audio_sample_rate = _session->nominal_frame_rate();
+               audio_sample_rate = _session->nominal_sample_rate();
        }
 
-       /* Note: pull-up/down are applied here: frame_rate() vs. nominal_frame_rate() */
+       /* Note: pull-up/down are applied here: sample_rate() vs. nominal_sample_rate() */
        if (_session->config.get_use_video_file_fps()) {
                video_frame_offset = floor(offset * fps / audio_sample_rate);
        } else {
@@ -505,19 +519,19 @@ VideoMonitor::set_offset (ARDOUR::frameoffset_t offset)
 }
 
 void
-VideoMonitor::manual_seek (framepos_t when, bool /*force*/, ARDOUR::frameoffset_t offset)
+VideoMonitor::manual_seek (samplepos_t when, bool /*force*/, ARDOUR::sampleoffset_t offset)
 {
        if (!is_started()) { return; }
        if (!_session) { return; }
-       framecnt_t video_frame;
-       framecnt_t audio_sample_rate;
+       samplecnt_t video_frame;
+       samplecnt_t audio_sample_rate;
        if (_session->config.get_videotimeline_pullup()) {
-               audio_sample_rate = _session->frame_rate();
+               audio_sample_rate = _session->sample_rate();
        } else {
-               audio_sample_rate = _session->nominal_frame_rate();
+               audio_sample_rate = _session->nominal_sample_rate();
        }
 
-       /* Note: pull-up/down are applied here: frame_rate() vs. nominal_frame_rate() */
+       /* Note: pull-up/down are applied here: sample_rate() vs. nominal_sample_rate() */
        if (_session->config.get_use_video_file_fps()) {
                video_frame = floor(when * fps / audio_sample_rate);
        } else {
@@ -555,9 +569,8 @@ VideoMonitor::xjadeo_sync_setup ()
        if (!_session) { return; }
 
        bool my_manual_seek = true;
-       if (_session->config.get_external_sync()) {
-               if (ARDOUR::Config->get_sync_source() == ARDOUR::Engine)
-                       my_manual_seek = false;
+       if (_session->synced_to_engine ()) {
+               my_manual_seek = false;
        }
 
        if (my_manual_seek != sync_by_manual_seek) {