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