Initial commit
[fillmore] / src / lombard / video_project.vala
1 /* Copyright 2009-2010 Yorba Foundation
2  *
3  * This software is licensed under the GNU Lesser General Public License
4  * (version 2.1 or later).  See the COPYING file in this distribution. 
5  */
6
7 using Logging;
8
9 namespace Model {
10
11 class VideoProject : Project {
12     public TimecodeTimeSystem time_provider;
13
14     public override void load_complete() {
15         if (find_video_track() == null) {
16             add_track(new VideoTrack(this));
17         }
18     }
19
20     public VideoProject(string? filename) throws Error {
21         base(filename, true);
22         // TODO: When vala supports throwing from base constructor remove this check
23         if (this != null) {
24             time_provider = new TimecodeTimeSystem();
25         }
26     }
27
28     public override string get_app_name() {
29         return App.NAME;
30     }
31
32     public override TimeCode get_clip_time(ClipFile f) {
33         TimeCode t = {};
34
35         if (f.is_of_type(MediaType.VIDEO)) {
36             Fraction rate;
37             if (!get_framerate_fraction(out rate)) {
38                 rate.numerator = 2997;
39                 rate.denominator = 100;
40             }
41             t = frame_to_time(time_to_frame_with_rate(f.length, rate), rate);
42         } else
43             t.get_from_length(f.length);
44             
45         return t;
46     }
47
48     public void go_previous_frame() {
49         VideoTrack? video_track = find_video_track();
50         if (video_track != null) {
51             media_engine.go(video_track.previous_frame(transport_get_position()));
52         }
53     }
54
55     public void go_next_frame() {
56         VideoTrack? video_track = find_video_track();
57         if (video_track != null) {
58             media_engine.go(video_track.next_frame(transport_get_position()));
59         }
60     }
61
62     public bool get_framerate_fraction(out Fraction rate) {
63         foreach (Track track in tracks) {
64             VideoTrack video_track = track as VideoTrack;
65             if (video_track != null && video_track.get_framerate(out rate))
66                 return true;
67         }
68         return false;
69     }
70 }
71 }