4 * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "bcsignals.h"
26 #include "edlsession.h"
31 #include "playabletracks.h"
32 #include "preferences.h"
33 #include "mainsession.h"
34 #include "trackcanvas.h"
36 #include "transportque.h"
43 VEdit::VEdit(EDL *edl, Edits *edits)
51 int VEdit::load_properties_derived(FileXML *xml)
53 channel = xml->tag.get_property("CHANNEL", (int64_t)0);
61 Asset* VEdit::get_nested_asset(int64_t *source_position,
67 // Make position relative to edit
68 *source_position = position - startproject + startsource;
70 if(debug) printf("VEdit::get_nested_asset %d " _LD " " _LD " " _LD " " _LD "\n",
71 __LINE__, *source_position, position, startproject, startsource);
73 // Descend into nested EDLs
76 // Convert position to nested EDL rate
77 if(debug) printf("VEdit::get_nested_asset %d\n",
79 int64_t pos = *source_position;
80 if(direction == PLAY_REVERSE && pos > 0) --pos;
81 *source_position = Units::to_int64((double)pos *
82 nested_edl->session->frame_rate /
83 edl->session->frame_rate);
84 PlayableTracks *playable_tracks = new PlayableTracks(
90 if(playable_tracks->size())
92 VTrack *nested_track = (VTrack*)playable_tracks->get(0);
93 VEdit* nested_edit = (VEdit*)nested_track->edits->editof(
99 result = nested_edit->get_nested_asset(
106 delete playable_tracks;
107 if(debug) printf("VEdit::get_nested_asset %d\n",
113 // Convert position to asset rate
114 if(debug) printf("VEdit::get_nested_asset %d " _LD " %f %f\n",
118 edl->session->frame_rate);
119 int64_t pos = *source_position;
120 if(direction == PLAY_REVERSE && pos > 0) --pos;
121 *source_position = Units::to_int64((double)pos *
123 edl->session->frame_rate);
130 int VEdit::read_frame(VFrame *video_out,
131 int64_t input_position,
136 int use_asynchronous)
138 int64_t source_position = 0;
141 if(use_nudge) input_position += track->nudge;
142 if(debug) printf("VEdit::read_frame %d source_position=" _LD " input_position=" _LD "\n",
143 __LINE__, source_position, input_position);
145 Asset *asset = get_nested_asset(&source_position,
149 if(debug) printf("VEdit::read_frame %d source_position=" _LD " input_position=" _LD "\n",
150 __LINE__, source_position, input_position);
152 File *file = cache->check_out(asset,
156 if(debug) printf("VEdit::read_frame %d path=%s source_position=" _LD "\n",
157 __LINE__, asset->path, source_position);
162 if(debug) printf("VEdit::read_frame %d\n", __LINE__);
163 source_position = (direction == PLAY_FORWARD) ?
165 (source_position - 1);
166 if(debug) printf("VEdit::read_frame %d " _LD " " _LD "\n",
167 __LINE__, input_position, source_position);
170 file->start_video_decode_thread();
172 file->stop_video_thread();
173 if(debug) printf("VEdit::read_frame %d\n", __LINE__);
175 file->set_layer(channel);
176 //printf("VEdit::read_frame %d %lld\n", __LINE__, source_position);
177 file->set_video_position(source_position, 0);
179 if(use_cache) file->set_cache_frames(use_cache);
180 result = file->read_frame(video_out);
182 if(debug) printf("VEdit::read_frame %d\n", __LINE__);
183 if(use_cache) file->set_cache_frames(0);
185 if(debug) printf("VEdit::read_frame %d\n", __LINE__);
186 cache->check_in(asset);
187 if(debug) printf("VEdit::read_frame %d\n", __LINE__);
195 int VEdit::copy_properties_derived(FileXML *xml, int64_t length_in_selection)
200 int VEdit::dump_derived()
202 printf(" VEdit::dump_derived\n");
203 printf(" startproject " _LD "\n", startproject);
204 printf(" length " _LD "\n", length);
208 int64_t VEdit::get_source_end(int64_t default_)
210 if(!nested_edl && !asset) return default_; // Infinity
214 return (int64_t)(nested_edl->tracks->total_playable_length() *
215 edl->session->frame_rate + 0.5);
218 return (int64_t)((double)asset->video_length /
220 edl->session->frame_rate + 0.5);