4 * Copyright (C) 2008 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
22 #include "bcsignals.h"
24 #include "condition.h"
26 #include "edlsession.h"
27 #include "localsession.h"
28 #include "playbackengine.h"
30 #include "transportque.h"
32 TransportCommand::TransportCommand()
34 // In rendering we want a master EDL so settings don't get clobbered
35 // in the middle of a job.
37 edl->create_objects();
43 TransportCommand::~TransportCommand()
45 edl->Garbage::remove_user();
48 void TransportCommand::reset()
50 command = COMMAND_NONE;
65 EDL* TransportCommand::get_edl()
70 void TransportCommand::delete_edl()
72 edl->Garbage::remove_user();
76 void TransportCommand::new_edl()
79 edl->create_objects();
83 void TransportCommand::copy_from(TransportCommand *command)
85 this->command = command->command;
86 this->change_type = command->change_type;
87 this->edl->copy_all(command->edl);
88 this->start_position = command->start_position;
89 this->end_position = command->end_position;
90 this->playbackstart = command->playbackstart;
91 this->realtime = command->realtime;
92 this->resume = command->resume;
93 this->locked = command->locked;
94 this->toggle_audio = command->toggle_audio;
95 this->loop_play = command->loop_play;
96 this->displacement = command->displacement;
97 this->speed = command->speed;
100 TransportCommand& TransportCommand::operator=(TransportCommand &command)
106 int TransportCommand::single_frame(int command)
108 return (command == SINGLE_FRAME_FWD || command == SINGLE_FRAME_REWIND ||
109 command == CURRENT_FRAME || command == LAST_FRAME);
112 int TransportCommand::get_direction(int command)
115 case SINGLE_FRAME_FWD:
122 case SINGLE_FRAME_REWIND:
135 float TransportCommand::get_speed(int command, float speed)
140 return speed ? speed : 0.5;
144 case SINGLE_FRAME_FWD:
145 case SINGLE_FRAME_REWIND:
152 return speed ? speed : 2.;
158 // Assume starting without pause
159 void TransportCommand::set_playback_range(EDL *edl, int use_inout, int do_displacement)
161 if( !edl ) edl = this->edl;
162 double length = edl->tracks->total_playable_length();
163 double frame_period = 1.0 / edl->session->frame_rate;
166 start_position = use_inout && edl->local_session->inpoint_valid() ?
167 edl->local_session->get_inpoint() :
168 !loop_play ? edl->local_session->get_selectionstart(1) : 0;
169 end_position = use_inout && edl->local_session->outpoint_valid() ?
170 edl->local_session->get_outpoint() :
171 !loop_play ? edl->local_session->get_selectionend(1) : length;
172 if( start_position >= length )
173 length = edl->tracks->total_length();
175 if( command == REWIND ) {
176 start_position = end_position = 0;
177 command = CURRENT_FRAME;
179 else if( command == GOTO_END ) {
180 start_position = end_position = length;
181 command = LAST_FRAME;
183 else if( !use_inout && EQUIV(start_position, end_position) ) {
184 // starting play at or past end_position, play to end_position of media (for mixers)
189 end_position = length;
190 // this prevents a crash if start_position position is after the loop when playing forwards
191 if( edl->local_session->loop_playback &&
192 start_position > edl->local_session->loop_end ) {
193 start_position = edl->local_session->loop_start;
195 displacement = realtime && do_displacement ? frame_period : 0;
202 // this prevents a crash if start_position position is before the loop when playing backwards
203 if( edl->local_session->loop_playback &&
204 end_position <= edl->local_session->loop_start ) {
205 end_position = edl->local_session->loop_end;
209 case SINGLE_FRAME_FWD:
210 displacement = realtime && do_displacement ? frame_period : 0;
213 end_position = start_position + frame_period;
216 case SINGLE_FRAME_REWIND:
217 start_position = end_position - frame_period;
220 start_position += displacement;
221 end_position += displacement;
223 // if( start_position < 0 )
224 // start_position = 0;
225 // if( end_position > length )
226 // end_position = length;
227 if( end_position < start_position )
228 end_position = start_position;
230 playbackstart = get_direction() == PLAY_FORWARD ?
231 start_position : end_position;
234 void TransportCommand::playback_range_adjust_inout()
236 if(edl->local_session->inpoint_valid() ||
237 edl->local_session->outpoint_valid())
239 playback_range_inout();
243 void TransportCommand::playback_range_inout()
245 if(edl->local_session->inpoint_valid())
246 start_position = edl->local_session->get_inpoint();
250 if(edl->local_session->outpoint_valid())
251 end_position = edl->local_session->get_outpoint();
253 end_position = edl->tracks->total_playable_length();
254 if( start_position >= end_position )
255 end_position = edl->tracks->total_length();
259 void TransportCommand::playback_range_project()
262 end_position = edl->tracks->total_playable_length();
265 void TransportCommand::playback_range_1frame()
267 start_position = end_position = edl->local_session->get_selectionstart(1);
268 if( edl->session->frame_rate > 0 ) end_position += 1./edl->session->frame_rate;