18a49fc9b6479fa8144ca240a47ee697c10a9f51
[ardour.git] / gtk2_ardour / editor_videotimeline.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 <jack/types.h>
23
24 #include "ardour/profile.h"
25 #include "ardour/rc_configuration.h"
26
27 #include "ardour_ui.h"
28 #include "editor.h"
29 #include "simplerect.h"
30 #include "canvas_impl.h"
31 #include "editing.h"
32 #include "audio_time_axis.h"
33 #include "video_image_frame.h"
34 #include "export_video_dialog.h"
35 #include "export_video_infobox.h"
36
37 #include "i18n.h"
38
39 using namespace std;
40
41 void
42 Editor::set_video_timeline_height (const int h)
43 {
44         if (videotl_bar_height == h) { return; }
45         if (h < 2 || h > 8) { return; }
46   videotl_bar_height = h;
47         const double nh = (videotl_bar_height * timebar_height - ((ARDOUR::Profile->get_sae())?1.0:0.0));
48         videotl_label.set_size_request (-1, (int)timebar_height * videotl_bar_height);
49         videotl_bar->property_y2().set_value(nh);
50         ARDOUR_UI::instance()->video_timeline->set_height(videotl_bar_height * timebar_height);
51         update_ruler_visibility();
52 }
53
54 void
55 Editor::update_video_timeline (bool flush)
56 {
57 #if DEBUG
58         framepos_t rightmost_frame = leftmost_frame + current_page_frames();
59         std::cout << "VIDEO SCROLL: " << leftmost_frame << " -- " << rightmost_frame << std::endl;
60         std::cout << "SCROLL UNITS: " << frame_to_unit(leftmost_frame) << " -- " << frame_to_unit(rightmost_frame)
61                   << " = " << frame_to_unit(rightmost_frame) - frame_to_unit(leftmost_frame)
62                         << std::endl;
63 #endif
64
65         // TODO later: make this a list for mult. video tracks
66         // also modify  ardour_ui_dialogs.cc : set_session()
67         if (flush) {
68                 ARDOUR_UI::instance()->video_timeline->flush_local_cache();
69         }
70         if (!ruler_video_action->get_active()) return;
71         ARDOUR_UI::instance()->video_timeline->update_video_timeline();
72 }
73
74 bool
75 Editor::is_video_timeline_locked ()
76 {
77         return ARDOUR_UI::instance()->video_timeline->is_offset_locked();
78 }
79
80 void
81 Editor::set_video_timeline_locked (const bool l)
82 {
83         ARDOUR_UI::instance()->video_timeline->set_offset_locked(l);
84 }
85
86 void
87 Editor::toggle_video_timeline_locked ()
88 {
89         ARDOUR_UI::instance()->video_timeline->toggle_offset_locked();
90 }
91
92 void
93 Editor::embed_audio_from_video (std::string path)
94 {
95         vector<std::string> paths;
96         framepos_t n = 0; /* -1: use file's timestamp - but br0ken with ffmpeg wav extract */
97         paths.push_back(path);
98 #if 0
99         do_embed (paths, Editing::ImportDistinctFiles, Editing::ImportAsTrack, n);
100 #else
101         do_import (paths, Editing::ImportDistinctFiles, Editing::ImportAsTrack, ARDOUR::SrcBest, n);
102         unlink(path.c_str());
103 #endif
104 }
105
106 void
107 Editor::export_video ()
108 {
109         if (ARDOUR::Config->get_show_video_export_info()) {
110                 ExportVideoInfobox infobox (_session);
111                 infobox.run();
112                 if (infobox.show_again()) {
113                         ARDOUR::Config->set_show_video_export_info(false);
114                 }
115         }
116         ExportVideoDialog dialog (*this, _session);
117         Gtk::ResponseType r = (Gtk::ResponseType) dialog.run();
118         dialog.hide();
119 #if 0
120         if (r == Gtk::RESPONSE_ACCEPT) {
121                 ARDOUR_UI::instance()->popup_error(string_compose(_("Export Successful: %1"),dialog.get_exported_filename()));
122         }
123 #endif
124 }
125
126 #endif /* WITH_VIDEOTIMELINE */