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"
29 #include "preferences.h"
31 #include "transportque.h"
34 TransportCommand::TransportCommand(Preferences *preferences)
36 // In rendering we want a master EDL so settings don't get clobbered
37 // in the middle of a job.
39 edl->create_objects();
42 this->preferences = preferences;
46 TransportCommand::~TransportCommand()
48 edl->Garbage::remove_user();
51 void TransportCommand::reset()
53 command = COMMAND_NONE;
68 EDL* TransportCommand::get_edl()
73 void TransportCommand::delete_edl()
75 edl->Garbage::remove_user();
79 void TransportCommand::new_edl()
82 edl->create_objects();
86 void TransportCommand::copy_from(TransportCommand *command)
88 this->command = command->command;
89 this->change_type = command->change_type;
90 this->edl->copy_all(command->edl);
91 this->start_position = command->start_position;
92 this->end_position = command->end_position;
93 this->playbackstart = command->playbackstart;
94 this->realtime = command->realtime;
95 this->resume = command->resume;
96 this->locked = command->locked;
97 this->toggle_audio = command->toggle_audio;
98 this->loop_play = command->loop_play;
99 this->displacement = command->displacement;
100 this->speed = command->speed;
103 TransportCommand& TransportCommand::operator=(TransportCommand &command)
109 int TransportCommand::single_frame(int command)
111 return (command == SINGLE_FRAME_FWD || command == SINGLE_FRAME_REWIND ||
112 command == CURRENT_FRAME || command == LAST_FRAME);
115 int TransportCommand::get_direction(int command)
118 case SINGLE_FRAME_FWD:
125 case SINGLE_FRAME_REWIND:
138 float TransportCommand::get_speed(int command, float speed)
140 // fast = 2.0, slow = 0.5
141 // float my_fast_speed = 2.0;
142 // float my_slow_speed = 0.5;
143 float my_fast_speed = preferences->fast_speed;
144 float my_slow_speed = preferences->slow_speed;
149 return speed ? speed : my_slow_speed;
153 case SINGLE_FRAME_FWD:
154 case SINGLE_FRAME_REWIND:
161 return speed ? speed : my_fast_speed;
167 // Assume starting without pause
168 void TransportCommand::set_playback_range(EDL *edl, int use_inout, int do_displacement)
170 if( !edl ) edl = this->edl;
171 double length = edl->tracks->total_playable_length();
172 double frame_period = 1.0 / edl->session->frame_rate;
175 start_position = use_inout && edl->local_session->inpoint_valid() ?
176 edl->local_session->get_inpoint() :
177 !loop_play ? edl->local_session->get_selectionstart(1) : 0;
178 end_position = use_inout && edl->local_session->outpoint_valid() ?
179 edl->local_session->get_outpoint() :
180 !loop_play ? edl->local_session->get_selectionend(1) : length;
181 if( start_position >= length )
182 length = edl->tracks->total_length();
184 if( command == REWIND ) {
185 start_position = end_position = 0;
186 command = CURRENT_FRAME;
188 else if( command == GOTO_END ) {
189 start_position = end_position = length;
190 command = LAST_FRAME;
192 else if( !use_inout && EQUIV(start_position, end_position) ) {
193 // starting play at or past end_position, play to end_position of media (for mixers)
198 end_position = length;
199 // this prevents a crash if start_position position is after the loop when playing forwards
200 if( edl->local_session->loop_playback &&
201 start_position > edl->local_session->loop_end ) {
202 start_position = edl->local_session->loop_start;
204 displacement = realtime && do_displacement ? frame_period : 0;
211 // this prevents a crash if start_position position is before the loop when playing backwards
212 if( edl->local_session->loop_playback &&
213 end_position <= edl->local_session->loop_start ) {
214 end_position = edl->local_session->loop_end;
218 case SINGLE_FRAME_FWD:
219 displacement = realtime && do_displacement ? frame_period : 0;
222 end_position = start_position + frame_period;
225 case SINGLE_FRAME_REWIND:
226 start_position = end_position - frame_period;
229 start_position += displacement;
230 end_position += displacement;
232 // if( start_position < 0 )
233 // start_position = 0;
234 // if( end_position > length )
235 // end_position = length;
236 if( end_position < start_position )
237 end_position = start_position;
239 playbackstart = get_direction() == PLAY_FORWARD ?
240 start_position : end_position;
243 void TransportCommand::playback_range_adjust_inout()
245 if(edl->local_session->inpoint_valid() ||
246 edl->local_session->outpoint_valid())
248 playback_range_inout();
252 void TransportCommand::playback_range_inout()
254 if(edl->local_session->inpoint_valid())
255 start_position = edl->local_session->get_inpoint();
259 if(edl->local_session->outpoint_valid())
260 end_position = edl->local_session->get_outpoint();
262 end_position = edl->tracks->total_playable_length();
263 if( start_position >= end_position )
264 end_position = edl->tracks->total_length();
268 void TransportCommand::playback_range_project()
271 end_position = edl->tracks->total_playable_length();
274 void TransportCommand::playback_range_1frame()
276 start_position = end_position = edl->local_session->get_selectionstart(1);
277 if( edl->session->frame_rate > 0 ) end_position += 1./edl->session->frame_rate;