Merge branch 'master' into windows+cc
[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
21 #include <jack/types.h>
22
23 #include <glib/gstdio.h>
24
25 #include "ardour/profile.h"
26 #include "ardour/rc_configuration.h"
27 #include "ardour/audio_track.h"
28 #include "ardour/audioregion.h"
29
30 #include "ardour_ui.h"
31 #include "editor.h"
32 #include "canvas/rectangle.h"
33 #include "editing.h"
34 #include "audio_time_axis.h"
35 #include "video_image_frame.h"
36 #include "export_video_dialog.h"
37 #include "export_video_infobox.h"
38 #include "interthread_progress_window.h"
39
40 #include "pbd/openuri.h"
41 #include "i18n.h"
42
43 using namespace std;
44
45 void
46 Editor::set_video_timeline_height (const int h)
47 {
48         if (videotl_bar_height == h) { return; }
49         if (h < 2 || h > 8) { return; }
50   videotl_bar_height = h;
51         videotl_label.set_size_request (-1, (int)timebar_height * videotl_bar_height);
52         ARDOUR_UI::instance()->video_timeline->set_height(videotl_bar_height * timebar_height);
53         update_ruler_visibility();
54 }
55
56 void
57 Editor::update_video_timeline (bool flush)
58 {
59         if (flush) {
60                 ARDOUR_UI::instance()->video_timeline->flush_local_cache();
61         }
62         if (!ruler_video_action->get_active()) return;
63         ARDOUR_UI::instance()->video_timeline->update_video_timeline();
64 }
65
66 bool
67 Editor::is_video_timeline_locked ()
68 {
69         return ARDOUR_UI::instance()->video_timeline->is_offset_locked();
70 }
71
72 void
73 Editor::set_video_timeline_locked (const bool l)
74 {
75         ARDOUR_UI::instance()->video_timeline->set_offset_locked(l);
76 }
77
78 void
79 Editor::toggle_video_timeline_locked ()
80 {
81         ARDOUR_UI::instance()->video_timeline->toggle_offset_locked();
82 }
83
84 void
85 Editor::embed_audio_from_video (std::string path, framepos_t n)
86 {
87         vector<std::string> paths;
88         paths.push_back(path);
89 #if 0
90         do_import (paths, Editing::ImportDistinctFiles, Editing::ImportAsTrack, ARDOUR::SrcBest, n);
91 #else
92         current_interthread_info = &import_status;
93         import_status.current = 1;
94         import_status.total = paths.size ();
95         import_status.all_done = false;
96
97         ImportProgressWindow ipw (&import_status, _("Import"), _("Cancel Import"));
98         ipw.show ();
99
100         boost::shared_ptr<ARDOUR::Track> track;
101         bool ok = (import_sndfiles (paths, Editing::ImportDistinctFiles, Editing::ImportAsTrack, ARDOUR::SrcBest, n, 1, 1, track, false) == 0);
102         if (ok && track) {
103                 boost::shared_ptr<ARDOUR::Playlist> pl = track->playlist();
104                 pl->find_next_region(n, ARDOUR::End, 0)->set_video_locked(true);
105                 _session->save_state ("");
106         }
107
108         import_status.all_done = true;
109 #endif
110         ::g_unlink(path.c_str());
111 }
112
113 void
114 Editor::export_video (bool range)
115 {
116         if (ARDOUR::Config->get_show_video_export_info()) {
117                 ExportVideoInfobox infobox (_session);
118                 Gtk::ResponseType rv = (Gtk::ResponseType) infobox.run();
119                 if (infobox.show_again()) {
120                         ARDOUR::Config->set_show_video_export_info(false);
121                 }
122                 switch (rv) {
123                         case GTK_RESPONSE_YES:
124                                 PBD::open_uri (ARDOUR::Config->get_reference_manual_url() + "/video-timeline/operations/#export");
125                                 break;
126                         default:
127                                 break;
128                 }
129         }
130         ExportVideoDialog dialog (_session, get_selection().time, range);
131         Gtk::ResponseType r = (Gtk::ResponseType) dialog.run();
132         (void) r; // keep gcc quiet
133         dialog.hide();
134 }