2013-03-12 17:00:09 -04:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#include "pbd/file_utils.h"
|
2013-06-08 03:03:26 -04:00
|
|
|
#include "pbd/convert.h"
|
2013-03-12 17:00:09 -04:00
|
|
|
#include "gui_thread.h"
|
2014-12-25 10:02:00 -05:00
|
|
|
#include "timers.h"
|
2013-06-09 18:52:24 -04:00
|
|
|
#include "utils.h"
|
2013-03-12 17:00:09 -04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "public_editor.h"
|
2013-06-09 18:52:24 -04:00
|
|
|
#include "editor.h"
|
2013-03-12 17:00:09 -04:00
|
|
|
#include "video_monitor.h"
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2013-03-12 17:00:09 -04:00
|
|
|
|
|
|
|
using namespace std;
|
2013-06-08 03:03:26 -04:00
|
|
|
using namespace PBD;
|
2014-06-25 15:27:37 -04:00
|
|
|
using namespace ARDOUR_UI_UTILS;
|
2013-03-12 17:00:09 -04:00
|
|
|
|
|
|
|
VideoMonitor::VideoMonitor (PublicEditor *ed, std::string xjadeo_bin_path)
|
|
|
|
: editor (ed)
|
|
|
|
{
|
|
|
|
manually_seeked_frame = 0;
|
|
|
|
fps =0.0; // = _session->timecode_frames_per_second();
|
2014-06-06 16:23:43 -04:00
|
|
|
sync_by_manual_seek = true;
|
2013-03-12 17:00:09 -04:00
|
|
|
_restore_settings_mask = 0;
|
|
|
|
clock_connection = sigc::connection();
|
2013-04-03 16:29:04 -04:00
|
|
|
state_connection = sigc::connection();
|
2013-03-12 17:00:09 -04:00
|
|
|
debug_enable = false;
|
2013-04-03 16:29:04 -04:00
|
|
|
state_clk_divide = 0;
|
|
|
|
starting = 0;
|
|
|
|
osdmode = 10; // 1: frameno, 2: timecode, 8: box
|
2013-03-12 17:00:09 -04:00
|
|
|
|
2014-06-06 16:23:43 -04:00
|
|
|
process = new ARDOUR::SystemExec(xjadeo_bin_path, X_("-R -J"));
|
2013-04-03 16:29:04 -04:00
|
|
|
process->ReadStdout.connect_same_thread (*this, boost::bind (&VideoMonitor::parse_output, this, _1 ,_2));
|
2013-03-12 17:00:09 -04:00
|
|
|
process->Terminated.connect (*this, invalidator (*this), boost::bind (&VideoMonitor::terminated, this), gui_context());
|
2013-06-09 16:56:03 -04:00
|
|
|
XJKeyEvent.connect (*this, invalidator (*this), boost::bind (&VideoMonitor::forward_keyevent, this, _1), gui_context());
|
2013-03-12 17:00:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
VideoMonitor::~VideoMonitor ()
|
|
|
|
{
|
|
|
|
if (clock_connection.connected()) {
|
|
|
|
clock_connection.disconnect();
|
|
|
|
}
|
2013-04-03 16:29:04 -04:00
|
|
|
if (state_connection.connected()) {
|
|
|
|
state_connection.disconnect();
|
|
|
|
}
|
2013-03-12 17:00:09 -04:00
|
|
|
delete process;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VideoMonitor::start ()
|
|
|
|
{
|
|
|
|
if (is_started()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
manually_seeked_frame = 0;
|
|
|
|
sync_by_manual_seek = false;
|
|
|
|
if (clock_connection.connected()) { clock_connection.disconnect(); }
|
|
|
|
|
|
|
|
if (process->start(debug_enable?2:1)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-04-08 22:05:07 -04:00
|
|
|
VideoMonitor::query_full_state (bool wait)
|
2013-03-12 17:00:09 -04:00
|
|
|
{
|
2013-04-08 22:05:07 -04:00
|
|
|
knownstate = 0;
|
2013-03-12 17:00:09 -04:00
|
|
|
process->write_to_stdin("get windowsize\n");
|
|
|
|
process->write_to_stdin("get windowpos\n");
|
|
|
|
process->write_to_stdin("get letterbox\n");
|
|
|
|
process->write_to_stdin("get fullscreen\n");
|
|
|
|
process->write_to_stdin("get ontop\n");
|
|
|
|
process->write_to_stdin("get offset\n");
|
|
|
|
process->write_to_stdin("get osdcfg\n");
|
2013-04-08 22:05:07 -04:00
|
|
|
int timeout = 40;
|
|
|
|
if (wait && knownstate !=127 && --timeout) {
|
2013-07-19 20:26:30 -04:00
|
|
|
Glib::usleep(50000);
|
2013-04-08 22:05:07 -04:00
|
|
|
sched_yield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VideoMonitor::quit ()
|
|
|
|
{
|
|
|
|
if (!is_started()) return;
|
|
|
|
if (state_connection.connected()) { state_connection.disconnect(); }
|
|
|
|
if (clock_connection.connected()) { clock_connection.disconnect(); }
|
2013-06-09 13:39:25 -04:00
|
|
|
query_full_state(true);
|
2013-03-12 17:00:09 -04:00
|
|
|
process->write_to_stdin("quit\n");
|
2013-04-08 22:05:07 -04:00
|
|
|
/* the 'quit' command should result in process termination
|
2013-03-12 17:00:09 -04:00
|
|
|
* but in case it fails (communication failure, SIGSTOP, ??)
|
|
|
|
* here's a timeout..
|
|
|
|
*/
|
|
|
|
int timeout = 40;
|
|
|
|
while (is_started() && --timeout) {
|
2013-07-19 20:26:30 -04:00
|
|
|
Glib::usleep(50000);
|
2013-04-03 16:29:04 -04:00
|
|
|
sched_yield();
|
2013-03-12 17:00:09 -04:00
|
|
|
}
|
2013-04-03 16:29:04 -04:00
|
|
|
if (timeout <= 0) {
|
|
|
|
process->terminate();
|
2013-03-12 17:00:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VideoMonitor::open (std::string filename)
|
|
|
|
{
|
|
|
|
if (!is_started()) return;
|
|
|
|
manually_seeked_frame = 0;
|
2013-04-03 16:29:04 -04:00
|
|
|
osdmode = 10; // 1: frameno, 2: timecode, 8: box
|
2013-04-03 18:51:03 -04:00
|
|
|
starting = 15;
|
2013-03-12 17:00:09 -04:00
|
|
|
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");
|
|
|
|
process->write_to_stdin("set seekmode 1\n");
|
2013-06-09 16:56:03 -04:00
|
|
|
/* override bitwise flags -- see xjadeo.h
|
2014-07-21 18:39:58 -04:00
|
|
|
* 0x0001 : ignore 'q', ESC / quit
|
|
|
|
* 0x0002 : ignore "window closed by WM" / quit
|
|
|
|
* 0x0004 : (osx only) menu-exit / quit
|
|
|
|
* 0x0008 : ignore mouse-button 1 -- resize
|
|
|
|
* 0x0010 : no A/V offset control with keyboard
|
|
|
|
* 0x0020 : don't use jack-session
|
|
|
|
* 0x0040 : disable jack transport control
|
|
|
|
* 0x0080 : disallow sync source change (OSX menu)
|
|
|
|
* 0x0100 : disallow file open (OSX menu, X11 DnD)
|
2013-06-09 16:56:03 -04:00
|
|
|
*/
|
2014-07-21 18:39:58 -04:00
|
|
|
process->write_to_stdin("set override 504\n");
|
2013-06-09 16:56:03 -04:00
|
|
|
process->write_to_stdin("notify keyboard\n");
|
|
|
|
process->write_to_stdin("notify settings\n");
|
2013-03-12 17:00:09 -04:00
|
|
|
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");
|
|
|
|
}
|
2013-04-03 16:29:04 -04:00
|
|
|
if (!state_connection.connected()) {
|
2013-04-03 18:51:03 -04:00
|
|
|
starting = 15;
|
2013-04-03 16:29:04 -04:00
|
|
|
querystate();
|
|
|
|
state_clk_divide = 0;
|
|
|
|
/* TODO once every two second or so -- state_clk_divide hack below */
|
2014-12-25 10:02:00 -05:00
|
|
|
state_connection = Timers::rapid_connect (sigc::mem_fun (*this, &VideoMonitor::querystate));
|
2013-04-03 16:29:04 -04:00
|
|
|
}
|
2014-07-24 12:25:15 -04:00
|
|
|
sync_by_manual_seek = true;
|
2014-12-25 10:02:00 -05:00
|
|
|
clock_connection = Timers::fps_connect (sigc::mem_fun (*this, &VideoMonitor::srsupdate));
|
2013-03-12 17:00:09 -04:00
|
|
|
xjadeo_sync_setup();
|
|
|
|
}
|
|
|
|
|
2013-04-03 16:29:04 -04:00
|
|
|
void
|
|
|
|
VideoMonitor::querystate ()
|
|
|
|
{
|
|
|
|
/* clock-divider hack -- RapidScreenUpdate == every_point_one_seconds */
|
2013-04-08 22:05:07 -04:00
|
|
|
state_clk_divide = (state_clk_divide + 1) % 300; // 30 secs
|
|
|
|
if (state_clk_divide == 0) {
|
|
|
|
// every 30 seconds
|
|
|
|
query_full_state(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (state_clk_divide%25 != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// every 2.5 seconds:
|
2013-04-03 16:29:04 -04:00
|
|
|
process->write_to_stdin("get fullscreen\n");
|
|
|
|
process->write_to_stdin("get ontop\n");
|
|
|
|
process->write_to_stdin("get osdcfg\n");
|
|
|
|
process->write_to_stdin("get letterbox\n");
|
|
|
|
}
|
|
|
|
|
2013-03-12 17:00:09 -04:00
|
|
|
bool
|
|
|
|
VideoMonitor::skip_setting (std::string which)
|
|
|
|
{
|
|
|
|
if (_restore_settings_mask & XJ_OSD && which == "osd mode") { return true; }
|
|
|
|
if (_restore_settings_mask & XJ_LETTERBOX && which == "window letterbox") { return true; }
|
|
|
|
if (_restore_settings_mask & XJ_WINDOW_SIZE && which == "window size") { return true; }
|
|
|
|
if (_restore_settings_mask & XJ_WINDOW_POS && which == "window xy") { return true; }
|
|
|
|
if (_restore_settings_mask & XJ_WINDOW_ONTOP && which == "window ontop") { return true; }
|
|
|
|
if (_restore_settings_mask & XJ_LETTERBOX && which == "window letterbox") { return true; }
|
|
|
|
if (_restore_settings_mask & XJ_OFFSET && which == "set offset") { return true; }
|
|
|
|
if (_restore_settings_mask & XJ_FULLSCREEN && which == "window zoom") { return true; }
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-03 16:29:04 -04:00
|
|
|
void
|
|
|
|
VideoMonitor::send_cmd (int what, int param)
|
|
|
|
{
|
|
|
|
bool osd_update = false;
|
2013-06-10 11:22:28 -04:00
|
|
|
int prev_osdmode = osdmode;
|
2013-04-03 16:29:04 -04:00
|
|
|
if (!is_started()) return;
|
|
|
|
switch (what) {
|
|
|
|
case 1:
|
|
|
|
if (param) process->write_to_stdin("window ontop on\n");
|
|
|
|
else process->write_to_stdin("window ontop off\n");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (param) osdmode |= 2;
|
|
|
|
else osdmode &= ~2;
|
2013-06-10 11:22:28 -04:00
|
|
|
osd_update = (prev_osdmode != osdmode);
|
2013-04-03 16:29:04 -04:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (param) osdmode |= 1;
|
|
|
|
else osdmode &= ~1;
|
2013-06-10 11:22:28 -04:00
|
|
|
osd_update = (prev_osdmode != osdmode);
|
2013-04-03 16:29:04 -04:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (param) osdmode |= 8;
|
|
|
|
else osdmode &= ~8;
|
2013-06-10 11:22:28 -04:00
|
|
|
osd_update = (prev_osdmode != osdmode);
|
2013-04-03 16:29:04 -04:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
if (param) process->write_to_stdin("window zoom on\n");
|
|
|
|
else process->write_to_stdin("window zoom off\n");
|
|
|
|
break;
|
2013-04-03 18:51:03 -04:00
|
|
|
case 6:
|
|
|
|
if (param) process->write_to_stdin("window letterbox on\n");
|
|
|
|
else process->write_to_stdin("window letterbox off\n");
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
process->write_to_stdin("window resize 100%");
|
|
|
|
break;
|
2013-04-03 16:29:04 -04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-06-10 11:22:28 -04:00
|
|
|
if (osd_update) {
|
2013-04-03 16:29:04 -04:00
|
|
|
std::ostringstream osstream; osstream << "osd mode " << osdmode << "\n";
|
|
|
|
process->write_to_stdin(osstream.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 17:00:09 -04:00
|
|
|
bool
|
|
|
|
VideoMonitor::is_started ()
|
|
|
|
{
|
|
|
|
return process->is_running();
|
|
|
|
}
|
|
|
|
|
2013-06-09 16:56:03 -04:00
|
|
|
void
|
|
|
|
VideoMonitor::forward_keyevent (unsigned int keyval)
|
|
|
|
{
|
2015-07-07 22:12:21 -04:00
|
|
|
emulate_key_event (keyval);
|
2013-06-09 16:56:03 -04:00
|
|
|
}
|
|
|
|
|
2013-03-12 17:00:09 -04:00
|
|
|
void
|
2013-05-04 22:02:05 -04:00
|
|
|
VideoMonitor::parse_output (std::string d, size_t /*s*/)
|
2013-03-12 17:00:09 -04:00
|
|
|
{
|
|
|
|
std::string line = d;
|
|
|
|
std::string::size_type start = 0;
|
|
|
|
std::string::size_type end = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
end = d.find('\n', start);
|
|
|
|
if (end == std::string::npos) break;
|
|
|
|
line = d.substr(start,end-start);
|
|
|
|
start=end+1;
|
|
|
|
if (line.length() <4 || line.at(0)!='@') continue;
|
|
|
|
#if 1 /* DEBUG */
|
|
|
|
if (debug_enable) {
|
|
|
|
printf("xjadeo: '%s'\n", line.c_str());
|
|
|
|
}
|
|
|
|
#endif
|
2013-06-08 03:03:26 -04:00
|
|
|
int status = atoi(line.substr(1,3));
|
2013-03-12 17:00:09 -04:00
|
|
|
switch(status / 100) {
|
|
|
|
case 4: /* errors */
|
|
|
|
if (status == 403) {
|
|
|
|
PBD::warning << _("Video Monitor: File Not Found.") << endmsg;
|
|
|
|
/* check: we should only write from the main thread.
|
|
|
|
* However it should not matter for 'quit'.
|
|
|
|
*/
|
|
|
|
process->write_to_stdin("quit\n");
|
|
|
|
}
|
2013-06-09 16:56:03 -04:00
|
|
|
#ifdef DEBUG_XJCOM
|
|
|
|
else
|
|
|
|
printf("xjadeo: error '%s'\n", line.c_str());
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 3: /* async notifications */
|
|
|
|
{
|
|
|
|
std::string::size_type equalsign = line.find('=');
|
|
|
|
std::string::size_type comment = line.find('#');
|
|
|
|
if (comment != std::string::npos) { line = line.substr(0,comment); }
|
|
|
|
if (equalsign != std::string::npos) {
|
|
|
|
std::string key = line.substr(5, equalsign - 5);
|
|
|
|
std::string value = line.substr(equalsign + 1);
|
|
|
|
|
|
|
|
if (status == 310 && key=="keypress") {
|
|
|
|
/* keyboard event */
|
|
|
|
XJKeyEvent((unsigned int)atoi(value));
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_XJCOM
|
|
|
|
else {
|
|
|
|
std::string msg = line.substr(5);
|
|
|
|
printf("xjadeo: async '%s' -> '%s'\n", key, value);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_XJCOM
|
|
|
|
else {
|
|
|
|
std::string msg = line.substr(5);
|
|
|
|
printf("xjadeo: async '%s'\n", msg.c_str());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} break;
|
|
|
|
case 1: /* text messages - command reply */
|
|
|
|
break;
|
|
|
|
case 8: /* comments / info for humans */
|
2013-03-12 17:00:09 -04:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* replies:
|
|
|
|
* 201: var=<int>
|
|
|
|
* 202: var=<double>
|
|
|
|
* 210: var=<int>x<int>
|
|
|
|
* 220: var=<string>
|
|
|
|
* 228: var=<smpte-string>
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
std::string::size_type equalsign = line.find('=');
|
|
|
|
std::string::size_type comment = line.find('#');
|
|
|
|
if (comment != std::string::npos) { line = line.substr(0,comment); }
|
|
|
|
if (equalsign != std::string::npos) {
|
|
|
|
std::string key = line.substr(5, equalsign - 5);
|
|
|
|
std::string value = line.substr(equalsign + 1);
|
|
|
|
#if 0 /* DEBUG */
|
|
|
|
std::cout << "parsed: " << key << " => " << value << std::endl;
|
|
|
|
#endif
|
2013-04-08 22:05:07 -04:00
|
|
|
if (key == "windowpos") {
|
|
|
|
knownstate |= 16;
|
|
|
|
if (xjadeo_settings["window xy"] != value) {
|
|
|
|
if (!starting && _session) _session->set_dirty ();
|
|
|
|
}
|
2013-03-12 17:00:09 -04:00
|
|
|
xjadeo_settings["window xy"] = value;
|
|
|
|
} else if(key == "windowsize") {
|
2013-04-08 22:05:07 -04:00
|
|
|
knownstate |= 32;
|
|
|
|
if (xjadeo_settings["window size"] != value) {
|
|
|
|
if (!starting && _session) _session->set_dirty ();
|
|
|
|
}
|
2013-03-12 17:00:09 -04:00
|
|
|
xjadeo_settings["window size"] = value;
|
|
|
|
} else if(key == "windowontop") {
|
2013-04-08 22:05:07 -04:00
|
|
|
knownstate |= 2;
|
2013-04-03 16:29:04 -04:00
|
|
|
if (starting || xjadeo_settings["window ontop"] != value) {
|
2013-04-08 22:05:07 -04:00
|
|
|
if (!starting && _session) _session->set_dirty ();
|
2013-06-08 03:03:26 -04:00
|
|
|
if (atoi(value)) { UiState("xjadeo-window-ontop-on"); }
|
2013-04-03 16:29:04 -04:00
|
|
|
else { UiState("xjadeo-window-ontop-off"); }
|
2013-04-08 22:05:07 -04:00
|
|
|
starting &= ~2;
|
2013-04-03 16:29:04 -04:00
|
|
|
}
|
2013-03-12 17:00:09 -04:00
|
|
|
xjadeo_settings["window ontop"] = value;
|
|
|
|
} else if(key == "fullscreen") {
|
2013-04-08 22:05:07 -04:00
|
|
|
knownstate |= 4;
|
2013-04-03 16:29:04 -04:00
|
|
|
if (starting || xjadeo_settings["window zoom"] != value) {
|
2013-04-08 22:05:07 -04:00
|
|
|
if (!starting && _session) _session->set_dirty ();
|
2013-06-08 03:03:26 -04:00
|
|
|
if (atoi(value)) { UiState("xjadeo-window-fullscreen-on"); }
|
2013-04-03 16:29:04 -04:00
|
|
|
else { UiState("xjadeo-window-fullscreen-off"); }
|
2013-04-08 22:05:07 -04:00
|
|
|
starting &= ~4;
|
2013-04-03 16:29:04 -04:00
|
|
|
}
|
2013-03-12 17:00:09 -04:00
|
|
|
xjadeo_settings["window zoom"] = value;
|
|
|
|
} else if(key == "letterbox") {
|
2013-04-08 22:05:07 -04:00
|
|
|
knownstate |= 8;
|
2013-04-03 18:51:03 -04:00
|
|
|
if (starting || xjadeo_settings["window letterbox"] != value) {
|
2013-04-08 22:05:07 -04:00
|
|
|
if (!starting && _session) _session->set_dirty ();
|
2013-06-08 03:03:26 -04:00
|
|
|
if (atoi(value)) { UiState("xjadeo-window-letterbox-on"); }
|
2013-04-03 18:51:03 -04:00
|
|
|
else { UiState("xjadeo-window-letterbox-off"); }
|
2013-04-08 22:05:07 -04:00
|
|
|
starting &= ~8;
|
2013-04-03 18:51:03 -04:00
|
|
|
}
|
2013-03-12 17:00:09 -04:00
|
|
|
xjadeo_settings["window letterbox"] = value;
|
|
|
|
} else if(key == "osdmode") {
|
2013-04-08 22:05:07 -04:00
|
|
|
knownstate |= 1;
|
2013-06-08 03:03:26 -04:00
|
|
|
osdmode = atoi(value);
|
|
|
|
if (starting || atoi(xjadeo_settings["osd mode"]) != osdmode) {
|
2013-04-08 22:05:07 -04:00
|
|
|
if (!starting && _session) _session->set_dirty ();
|
2013-04-03 16:29:04 -04:00
|
|
|
if ((osdmode & 1) == 1) { UiState("xjadeo-window-osd-frame-on"); }
|
|
|
|
if ((osdmode & 1) == 0) { UiState("xjadeo-window-osd-frame-off"); }
|
|
|
|
if ((osdmode & 2) == 2) { UiState("xjadeo-window-osd-timecode-on"); }
|
|
|
|
if ((osdmode & 2) == 0) { UiState("xjadeo-window-osd-timecode-off"); }
|
|
|
|
if ((osdmode & 8) == 8) { UiState("xjadeo-window-osd-box-on"); }
|
|
|
|
if ((osdmode & 8) == 0) { UiState("xjadeo-window-osd-box-off"); }
|
|
|
|
}
|
2013-04-08 22:05:07 -04:00
|
|
|
starting &= ~1;
|
2013-03-12 17:00:09 -04:00
|
|
|
xjadeo_settings["osd mode"] = value;
|
|
|
|
} else if(key == "offset") {
|
2013-04-08 22:05:07 -04:00
|
|
|
knownstate |= 64;
|
|
|
|
if (xjadeo_settings["set offset"] != value) {
|
|
|
|
if (!starting && _session) _session->set_dirty ();
|
|
|
|
}
|
2013-03-12 17:00:09 -04:00
|
|
|
xjadeo_settings["set offset"] = value;
|
2013-06-09 16:56:03 -04:00
|
|
|
#ifdef DEBUG_XJCOM
|
|
|
|
} else {
|
|
|
|
printf("xjadeo: '%s' -> '%s'\n", key.c_str(), value.c_str());
|
|
|
|
#endif
|
2013-03-12 17:00:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VideoMonitor::terminated ()
|
|
|
|
{
|
2013-04-03 16:29:04 -04:00
|
|
|
process->terminate(); // from gui-context clean up
|
2013-03-12 17:00:09 -04:00
|
|
|
Terminated();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VideoMonitor::save_session ()
|
|
|
|
{
|
|
|
|
if (!_session) { return; }
|
2013-06-10 13:04:55 -04:00
|
|
|
XMLNode* node = _session->extra_xml (X_("XJSettings"), true);
|
2013-04-08 22:05:07 -04:00
|
|
|
if (!node) return;
|
2013-06-10 11:01:24 -04:00
|
|
|
node->remove_nodes_and_delete("XJSetting");
|
2013-03-12 17:00:09 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
VideoMonitor::set_session (ARDOUR::Session *s)
|
|
|
|
{
|
|
|
|
SessionHandlePtr::set_session (s);
|
|
|
|
if (!_session) { return; }
|
2016-12-09 17:43:37 -05:00
|
|
|
ARDOUR::Config->ParameterChanged.connect (*this, invalidator (*this), ui_bind (&VideoMonitor::parameter_changed, this, _1), gui_context());
|
2013-03-12 17:00:09 -04:00
|
|
|
_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;}
|
|
|
|
xjadeo_settings.clear();
|
|
|
|
|
|
|
|
XMLNodeList nlist = node->children();
|
|
|
|
XMLNodeConstIterator niter;
|
|
|
|
for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
|
|
|
|
xjadeo_settings[(*niter)->property(X_("k"))->value()] = (*niter)->property(X_("v"))->value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VideoMonitor::set_custom_setting (const std::string k, const std::string v)
|
|
|
|
{
|
|
|
|
xjadeo_settings[k] = v;
|
|
|
|
return true; /* TODO: check if key is valid */
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string
|
|
|
|
VideoMonitor::get_custom_setting (const std::string k)
|
|
|
|
{
|
|
|
|
return (xjadeo_settings[k]);
|
|
|
|
}
|
2013-04-03 16:29:04 -04:00
|
|
|
|
2014-10-22 23:11:10 -04:00
|
|
|
#define NO_OFFSET (ARDOUR::max_framepos) //< skip setting or modifying offset
|
2013-03-12 17:00:09 -04:00
|
|
|
void
|
|
|
|
VideoMonitor::srsupdate ()
|
|
|
|
{
|
|
|
|
if (!_session) { return; }
|
|
|
|
if (editor->dragging_playhead()) { return ;}
|
|
|
|
manual_seek(_session->audible_frame(), false, NO_OFFSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VideoMonitor::set_offset (ARDOUR::frameoffset_t offset)
|
|
|
|
{
|
|
|
|
if (!is_started()) { return; }
|
|
|
|
if (!_session) { return; }
|
|
|
|
if (offset == NO_OFFSET ) { return; }
|
|
|
|
|
|
|
|
framecnt_t video_frame_offset;
|
2013-04-17 03:09:56 -04:00
|
|
|
framecnt_t audio_sample_rate;
|
2013-03-12 17:00:09 -04:00
|
|
|
if (_session->config.get_videotimeline_pullup()) {
|
2013-04-17 03:09:56 -04:00
|
|
|
audio_sample_rate = _session->frame_rate();
|
2013-03-12 17:00:09 -04:00
|
|
|
} else {
|
2013-04-17 03:09:56 -04:00
|
|
|
audio_sample_rate = _session->nominal_frame_rate();
|
2013-03-12 17:00:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: pull-up/down are applied here: frame_rate() vs. nominal_frame_rate() */
|
|
|
|
if (_session->config.get_use_video_file_fps()) {
|
2013-04-17 03:09:56 -04:00
|
|
|
video_frame_offset = floor(offset * fps / audio_sample_rate);
|
2013-03-12 17:00:09 -04:00
|
|
|
} else {
|
2013-04-17 03:09:56 -04:00
|
|
|
video_frame_offset = floor(offset * _session->timecode_frames_per_second() / audio_sample_rate);
|
2013-03-12 17:00:09 -04:00
|
|
|
}
|
|
|
|
|
2013-06-10 13:43:23 -04:00
|
|
|
if (video_offset == video_frame_offset) { return; }
|
|
|
|
video_offset = video_frame_offset;
|
|
|
|
|
2013-03-12 17:00:09 -04:00
|
|
|
std::ostringstream osstream1; osstream1 << -1 * video_frame_offset;
|
|
|
|
process->write_to_stdin("set offset " + osstream1.str() + "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-04 22:02:05 -04:00
|
|
|
VideoMonitor::manual_seek (framepos_t when, bool /*force*/, ARDOUR::frameoffset_t offset)
|
2013-03-12 17:00:09 -04:00
|
|
|
{
|
|
|
|
if (!is_started()) { return; }
|
|
|
|
if (!_session) { return; }
|
|
|
|
framecnt_t video_frame;
|
2013-04-17 03:09:56 -04:00
|
|
|
framecnt_t audio_sample_rate;
|
2013-03-12 17:00:09 -04:00
|
|
|
if (_session->config.get_videotimeline_pullup()) {
|
2013-04-17 03:09:56 -04:00
|
|
|
audio_sample_rate = _session->frame_rate();
|
2013-03-12 17:00:09 -04:00
|
|
|
} else {
|
2013-04-17 03:09:56 -04:00
|
|
|
audio_sample_rate = _session->nominal_frame_rate();
|
2013-03-12 17:00:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: pull-up/down are applied here: frame_rate() vs. nominal_frame_rate() */
|
|
|
|
if (_session->config.get_use_video_file_fps()) {
|
2013-04-17 03:09:56 -04:00
|
|
|
video_frame = floor(when * fps / audio_sample_rate);
|
2013-03-12 17:00:09 -04:00
|
|
|
} else {
|
2013-04-17 03:09:56 -04:00
|
|
|
video_frame = floor(when * _session->timecode_frames_per_second() / audio_sample_rate);
|
2013-03-12 17:00:09 -04:00
|
|
|
}
|
|
|
|
if (video_frame < 0 ) video_frame = 0;
|
|
|
|
|
|
|
|
if (video_frame == manually_seeked_frame) { return; }
|
|
|
|
manually_seeked_frame = video_frame;
|
|
|
|
|
|
|
|
#if 0 /* DEBUG */
|
|
|
|
std::cout <<"seek: " << video_frame << std::endl;
|
|
|
|
#endif
|
|
|
|
std::ostringstream osstream; osstream << video_frame;
|
|
|
|
process->write_to_stdin("seek " + osstream.str() + "\n");
|
|
|
|
|
|
|
|
set_offset(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VideoMonitor::parameter_changed (std::string const & p)
|
|
|
|
{
|
|
|
|
if (!is_started()) { return; }
|
|
|
|
if (!_session) { return; }
|
|
|
|
if (p != "external-sync" && p != "sync-source") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
xjadeo_sync_setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VideoMonitor::xjadeo_sync_setup ()
|
|
|
|
{
|
|
|
|
if (!is_started()) { return; }
|
|
|
|
if (!_session) { return; }
|
|
|
|
|
|
|
|
bool my_manual_seek = true;
|
|
|
|
if (_session->config.get_external_sync()) {
|
2013-09-19 17:34:23 -04:00
|
|
|
if (ARDOUR::Config->get_sync_source() == ARDOUR::Engine)
|
2013-03-12 17:00:09 -04:00
|
|
|
my_manual_seek = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (my_manual_seek != sync_by_manual_seek) {
|
|
|
|
if (sync_by_manual_seek) {
|
|
|
|
if (clock_connection.connected()) {
|
|
|
|
clock_connection.disconnect();
|
|
|
|
}
|
|
|
|
process->write_to_stdin("jack connect\n");
|
|
|
|
} else {
|
|
|
|
process->write_to_stdin("jack disconnect\n");
|
2014-12-25 10:02:00 -05:00
|
|
|
clock_connection = Timers::fps_connect (sigc::mem_fun (*this, &VideoMonitor::srsupdate));
|
2013-03-12 17:00:09 -04:00
|
|
|
}
|
|
|
|
sync_by_manual_seek = my_manual_seek;
|
|
|
|
}
|
|
|
|
}
|