Merge branch 'patches' of https://github.com/jdekozak/ardour
[ardour.git] / gtk2_ardour / open_video_monitor_dialog.cc
1 /*
2     Copyright (C) 2010 Paul Davis
3     Author: Robin Gareus <robin@gareus.org>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20 #ifdef WITH_VIDEOTIMELINE
21
22 #include <cstdio>
23 #include <cmath>
24
25 #include <sigc++/bind.h>
26
27 #include "pbd/file_utils.h"
28 #include "pbd/error.h"
29 #include "pbd/convert.h"
30 #include "gtkmm2ext/utils.h"
31 #include "ardour/profile.h"
32 #include "ardour/template_utils.h"
33 #include "ardour/session.h"
34 #include "ardour_ui.h"
35
36 #include "utils.h"
37 #include "add_video_dialog.h"
38 #include "video_monitor.h"
39 #include "i18n.h"
40
41 using namespace Gtk;
42 using namespace std;
43 using namespace PBD;
44 using namespace ARDOUR;
45
46 OpenVideoMonitorDialog::OpenVideoMonitorDialog (Session* s)
47         : ArdourDialog (_("Open Video Monitor"))
48         , filename_label ()
49         , showagain_checkbox (_("Don't show this dialog again. (Reset in Edit->Preferences)."))
50         , win_checkbox (_("Restore last window size and position."))
51         , att_checkbox (_("Restore Window Attributes (fullscreen, on-top)."))
52         , osd_checkbox (_("Restore On-Screen-Display settings."))
53         , off_checkbox (_("Restore Time Offset."))
54         , label_winsize ()
55         , label_winpos ()
56         , label_letterbox ()
57         , label_ontop ()
58         , label_fullscreen ()
59         , label_osd ()
60         , label_offset ()
61 #if 1
62         , debug_checkbox (_("Enable Debug Mode: Dump Communication to stdout."))
63 #endif
64 {
65         set_session (s);
66
67         set_name ("OpenVideoMonitorDialog");
68         set_position (Gtk::WIN_POS_MOUSE);
69         set_modal (true);
70         set_skip_taskbar_hint (true);
71         set_resizable (false);
72
73         Gtk::Label* l;
74         VBox* vbox = manage (new VBox);
75         VBox* options_box = manage (new VBox);
76
77         l = manage (new Label (_("<b>Video Monitor Window</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
78         l->set_use_markup ();
79         vbox->pack_start (*l, false, true);
80         l = manage (new Label (_("The video monitor state can restored to the last known settings for this session. To modify the settings, interact with the monitor itself: Move its window or focus it and use keyboard shortcuts (or the OSX menu bar). Consult the xjadeo documentation for available keyboard shortcuts."), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
81         l->set_size_request(550,-1);
82         l->set_line_wrap();
83         vbox->pack_start (*l, false, true,4);
84
85         l = manage (new Label (_("<b>Open Video file:</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
86         l->set_use_markup ();
87         vbox->pack_start (*l, false, true, 4);
88         vbox->pack_start (filename_label, false, false);
89
90         l = manage (new Label (_("<b>Session Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
91         l->set_use_markup ();
92         options_box->pack_start (*l, false, true, 4);
93
94         options_box->pack_start (win_checkbox, false, true, 2);
95         options_box->pack_start (label_winpos, false, false, 2);
96         options_box->pack_start (label_winsize, false, false, 2);
97         options_box->pack_start (label_letterbox, false, false, 2);
98
99         options_box->pack_start (att_checkbox, false, true, 2);
100         options_box->pack_start (label_fullscreen, false, false, 2);
101         options_box->pack_start (label_ontop, false, false, 2);
102
103         options_box->pack_start (osd_checkbox, false, true, 2);
104         options_box->pack_start (label_osd, false, false, 2);
105
106         options_box->pack_start (off_checkbox, false, true, 2);
107         options_box->pack_start (label_offset, false, false, 2);
108
109         options_box->pack_start (*(manage (new  HSeparator())), true, true, 2);
110         options_box->pack_start (showagain_checkbox, false, true, 2);
111
112 #if 1
113         options_box->pack_start (debug_checkbox, false, true, 2);
114         debug_checkbox.set_active(false);
115 #endif
116
117         vbox->pack_start (*options_box, false, true);
118
119         get_vbox()->set_spacing (4);
120         get_vbox()->pack_start (*vbox, false, false);
121
122         showagain_checkbox.set_active(false);
123         show_all_children ();
124         add_button (Stock::CANCEL, RESPONSE_CANCEL);
125         add_button (Stock::OPEN, RESPONSE_ACCEPT);
126 }
127
128 OpenVideoMonitorDialog::~OpenVideoMonitorDialog ()
129 {
130 }
131
132 void
133 OpenVideoMonitorDialog::on_show ()
134 {
135         label_offset.set_text(string_compose(_("Offset: %1 Video frame(s)"), "-"));
136         label_osd.set_text(string_compose(_("On-Screen-Display: %1"), "-"));
137         label_letterbox.set_text(string_compose(_("Letterbox: %1"), "-"));
138         label_winsize.set_text(string_compose(_("Size: %1"), "-"));
139         label_winpos.set_text(string_compose(_("Position: %1"), "-"));
140         label_fullscreen.set_text(string_compose(_("Fullscreen: %1"), "-"));
141         label_ontop.set_text(string_compose(_("Window on Top: %1"), "-"));
142
143 #define L_YESNO(v) (atoi(v)?_("Yes"):_("No"))
144 #define L_OSDMODE(i) ( std::string((i)? "":_("(Off)")) \
145                                   +std::string((i&1)?_("Frame Number "):"") \
146                       +std::string((i&2)?_("SMPTE "):"") \
147                       +std::string((i&4)?_("Text "):"") \
148                       +std::string((i&8)?_("Box "):"") )
149
150         XMLNode* node = _session->extra_xml (X_("XJSettings"));
151         if (node) {
152                 XMLNodeList nlist = node->children();
153                 XMLNodeConstIterator niter;
154                 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
155                         std::string k = (*niter)->property(X_("k"))->value();
156                         std::string v = (*niter)->property(X_("v"))->value();
157                         if (k == "osd mode") { label_osd.set_text(string_compose(_("On-Screen-Display: %1"), L_OSDMODE(atoi(v)))); }
158                         if (k == "window letterbox") { label_letterbox.set_text(string_compose(_("Letterbox: %1"), L_YESNO(v))); }
159                         if (k == "window xy") { label_winpos.set_text(string_compose(_("Position: %1"), v)); }
160                         if (k == "window ontop") { label_ontop.set_text(string_compose(_("Window On Top: %1"), L_YESNO(v))); }
161                         if (k == "window zoom") { label_fullscreen.set_text(string_compose(_("Fullscreen: %1"), L_YESNO(v))); }
162                         if (k == "window size") { label_winsize.set_text(string_compose(_("Size: %1"), v)); }
163                         if (k == "set offset") { label_offset.set_text(string_compose(_("Offset: %1 video-frame(s)"), v)); }
164                 }
165         }
166
167         Dialog::on_show ();
168 }
169
170 int
171 OpenVideoMonitorDialog::xj_settings_mask ()
172 {
173         int rv =0;
174         if (!win_checkbox.get_active()) { rv |= XJ_WINDOW_SIZE | XJ_WINDOW_POS | XJ_LETTERBOX; }
175         if (!att_checkbox.get_active()) { rv |= XJ_WINDOW_ONTOP | XJ_FULLSCREEN; }
176         if (!osd_checkbox.get_active()) { rv |= XJ_OSD; }
177         if (!off_checkbox.get_active()) { rv |= XJ_OFFSET; }
178         return rv;
179 }
180
181 void
182 OpenVideoMonitorDialog::set_filename (const std::string fn)
183 {
184   filename_label.set_text(fn);
185 }
186
187 void
188 OpenVideoMonitorDialog::setup_settings_mask (const int f)
189 {
190         win_checkbox.set_active((f&XJ_WINDOW_SIZE) == 0);
191         att_checkbox.set_active((f&XJ_WINDOW_ONTOP) == 0);
192         osd_checkbox.set_active((f&XJ_OSD) == 0);
193         off_checkbox.set_active((f&XJ_OFFSET) == 0);
194 }
195
196 #endif /* WITH_VIDEOTIMELINE */