Merge branch 'master' into cairocanvas
[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 "ardour/profile.h"
24 #include "ardour/rc_configuration.h"
25 #include "ardour/audio_track.h"
26 #include "ardour/audioregion.h"
27
28 #include "ardour_ui.h"
29 #include "editor.h"
30 #include "canvas/rectangle.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 #include "interthread_progress_window.h"
37
38 #include "i18n.h"
39
40 using namespace std;
41
42 void
43 Editor::set_video_timeline_height (const int h)
44 {
45         if (videotl_bar_height == h) { return; }
46         if (h < 2 || h > 8) { return; }
47   videotl_bar_height = h;
48         const double nh = (videotl_bar_height * timebar_height - ((ARDOUR::Profile->get_sae())?1.0:0.0));
49         videotl_label.set_size_request (-1, (int)timebar_height * videotl_bar_height);
50         videotl_bar->set_y1(nh);
51         ARDOUR_UI::instance()->video_timeline->set_height(videotl_bar_height * timebar_height);
52         update_ruler_visibility();
53 }
54
55 void
56 Editor::update_video_timeline (bool flush)
57 {
58 #if DEBUG
59         framepos_t rightmost_frame = leftmost_frame + current_page_frames();
60         std::cout << "VIDEO SCROLL: " << leftmost_frame << " -- " << rightmost_frame << std::endl;
61         std::cout << "SCROLL UNITS: " << frame_to_unit(leftmost_frame) << " -- " << frame_to_unit(rightmost_frame)
62                   << " = " << frame_to_unit(rightmost_frame) - frame_to_unit(leftmost_frame)
63                         << std::endl;
64 #endif
65
66         // TODO later: make this a list for mult. video tracks
67         // also modify  ardour_ui_dialogs.cc : set_session()
68         if (flush) {
69                 ARDOUR_UI::instance()->video_timeline->flush_local_cache();
70         }
71         if (!ruler_video_action->get_active()) return;
72         ARDOUR_UI::instance()->video_timeline->update_video_timeline();
73 }
74
75 bool
76 Editor::is_video_timeline_locked ()
77 {
78         return ARDOUR_UI::instance()->video_timeline->is_offset_locked();
79 }
80
81 void
82 Editor::set_video_timeline_locked (const bool l)
83 {
84         ARDOUR_UI::instance()->video_timeline->set_offset_locked(l);
85 }
86
87 void
88 Editor::toggle_video_timeline_locked ()
89 {
90         ARDOUR_UI::instance()->video_timeline->toggle_offset_locked();
91 }
92
93 void
94 Editor::embed_audio_from_video (std::string path, framepos_t n)
95 {
96         vector<std::string> paths;
97         paths.push_back(path);
98 #if 0
99         do_import (paths, Editing::ImportDistinctFiles, Editing::ImportAsTrack, ARDOUR::SrcBest, n);
100 #else
101         current_interthread_info = &import_status;
102         import_status.current = 1;
103         import_status.total = paths.size ();
104         import_status.all_done = false;
105
106         ImportProgressWindow ipw (&import_status, _("Import"), _("Cancel Import"));
107         ipw.show ();
108
109         boost::shared_ptr<ARDOUR::Track> track;
110         bool ok = (import_sndfiles (paths, Editing::ImportAsTrack, ARDOUR::SrcBest, n, 1, 1, track, false) == 0);
111         if (ok && track) {
112                 boost::shared_ptr<ARDOUR::Playlist> pl = track->playlist();
113                 pl->find_next_region(n, ARDOUR::End, 0)->set_video_locked(true);
114                 _session->save_state ("");
115         }
116
117         import_status.all_done = true;
118 #endif
119         unlink(path.c_str());
120 }
121
122 void
123 Editor::export_video ()
124 {
125         if (ARDOUR::Config->get_show_video_export_info()) {
126                 ExportVideoInfobox infobox (_session);
127                 infobox.run();
128                 if (infobox.show_again()) {
129                         ARDOUR::Config->set_show_video_export_info(false);
130                 }
131         }
132         ExportVideoDialog dialog (*this, _session);
133         Gtk::ResponseType r = (Gtk::ResponseType) dialog.run();
134         dialog.hide();
135 #if 0
136         if (r == Gtk::RESPONSE_ACCEPT) {
137                 ARDOUR_UI::instance()->popup_error(string_compose(_("Export Successful: %1"),dialog.get_exported_filename()));
138         }
139 #endif
140 }