Merge branch 'master' of git.ardour.org:ardour/ardour
[ardour.git] / gtk2_ardour / video_timeline.h
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 #ifndef __ardour_video_timeline_h__
23 #define __ardour_video_timeline_h__
24
25 #include <string>
26
27 #include <sigc++/signal.h>
28 #include "ardour/ardour.h"
29 #include "ardour/session.h"
30 #include "ardour/session_handle.h"
31 #include "video_image_frame.h"
32 #include "video_monitor.h"
33 #include "pbd/signals.h"
34 #include "canvas.h"
35
36 namespace ARDOUR {
37         class Session;
38 }
39
40 class PublicEditor;
41
42 /** @class VideoTimeLine
43  *  @brief video-timline controller and display
44  *
45  *  The video-timeline can be displayed in a canvas-group. Given a filename
46  *  it queries the video-server about file-information and
47  *  creates \ref VideoImageFrame as neccesary (which
48  *  query the server for image-data).
49  *
50  *  This class contains the algorithm to position the single frames
51  *  on the timeline according to current-zoom level and video-file
52  *  attributes. see \ref update_video_timeline()
53  *
54  *  The VideoTimeLine class includes functionality to launch a video-monitor
55  *  corresponding to its currently diplayed file.
56  */
57 class VideoTimeLine : public sigc::trackable, public ARDOUR::SessionHandlePtr, public PBD::ScopedConnectionList, public PBD::StatefulDestructible
58 {
59         public:
60         VideoTimeLine (PublicEditor*, ArdourCanvas::Group*, int);
61         virtual ~VideoTimeLine ();
62
63         void set_session (ARDOUR::Session *s);
64         void update_video_timeline ();
65         void set_height (int);
66
67         void save_undo (void);
68         XMLNode& get_state ();
69         int set_state (const XMLNode&, int version);
70
71         bool video_file_info (std::string, bool);
72         double get_video_file_fps () { return video_file_fps; }
73         void set_update_session_fps (bool v=true) { auto_set_session_fps = v; }
74
75         void set_offset_locked (bool v);
76         void toggle_offset_locked ();
77         bool is_offset_locked () { return video_offset_lock; }
78
79         void open_video_monitor ();
80         void close_video_monitor ();
81         void control_video_monitor (int, int);
82         void terminated_video_monitor ();
83         void manual_seek_video_monitor (framepos_t pos);
84
85         void parameter_changed (std::string const & p);
86         void set_video_server_url (std::string);
87         void set_video_server_docroot (std::string);
88
89         bool found_xjadeo () { return ((_xjadeo_bin.empty())?false:true); }
90         bool check_server ();
91         void flush_local_cache ();
92         void vmon_update ();
93         void flush_cache ();
94         void save_session ();
95         void close_session ();
96         void sync_session_state (); /* video-monitor does not actively report window/pos changes, query it */
97         float get_apv(); /* audio frames per video frame; */
98         ARDOUR::framecnt_t get_duration () { return video_duration;}
99         ARDOUR::frameoffset_t get_offset () { return video_offset;}
100         ARDOUR::frameoffset_t quantify_frames_to_apv (ARDOUR::frameoffset_t offset) { return floor(offset/get_apv())*get_apv(); }
101         void set_offset (ARDOUR::frameoffset_t offset) { video_offset = quantify_frames_to_apv(offset); } // this function does not update video_offset_p, call save_undo() to finalize changes to this! - this fn is currently only used from editor_drag.cc
102
103         protected:
104
105         PublicEditor *editor;
106         ArdourCanvas::Group *videotl_bar_group;
107         int bar_height;
108
109         std::string _xjadeo_bin;
110         void find_xjadeo ();
111
112
113         ARDOUR::frameoffset_t video_start_offset; /**< unit: audio-frames - video-file */
114         ARDOUR::frameoffset_t video_offset; /**< unit: audio-frames - session */
115         ARDOUR::frameoffset_t video_offset_p; /**< used for undo from editor_drag.cc */
116         framepos_t video_duration;     /**< unit: audio-frames */
117         std::string video_filename;
118         bool        local_file;
119         double      video_aspect_ratio;
120         double      video_file_fps;
121         bool        auto_set_session_fps;
122         bool        video_offset_lock;
123
124         std::string video_server_url;
125         std::string server_docroot;
126
127         typedef std::list<VideoImageFrame*> VideoFrames;
128         VideoFrames video_frames;
129         VideoImageFrame *get_video_frame (framepos_t vfn, int cut=0, int rightend = -1);
130         bool        flush_frames;
131         void        remove_frames ();
132
133         std::string translated_filename ();
134
135         VideoMonitor *vmonitor;
136         bool reopen_vmonitor;
137
138         PBD::Signal0<void> VtlUpdate;
139         PBD::Signal1<void,std::string> GuiUpdate;
140         void gui_update (const std::string &);
141
142         PBD::ScopedConnection sessionsave;
143 };
144
145 #endif /* __ardour_video_timeline_h__ */
146
147 #endif /* WITH_VIDEOTIMELINE */