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"
29 #include "transportque.h"
31 TransportCommand::TransportCommand()
33 // In rendering we want a master EDL so settings don't get clobbered
34 // in the middle of a job.
36 edl->create_objects();
42 TransportCommand::~TransportCommand()
44 edl->Garbage::remove_user();
47 void TransportCommand::reset()
57 // Don't reset the change type for commands which don't perform the change
58 if(command != STOP) change_type = 0;
59 command = COMMAND_NONE;
62 EDL* TransportCommand::get_edl()
67 void TransportCommand::delete_edl()
69 edl->Garbage::remove_user();
73 void TransportCommand::new_edl()
76 edl->create_objects();
80 void TransportCommand::copy_from(TransportCommand *command)
82 this->command = command->command;
83 this->change_type = command->change_type;
84 this->edl->copy_all(command->edl);
85 this->start_position = command->start_position;
86 this->end_position = command->end_position;
87 this->playbackstart = command->playbackstart;
88 this->realtime = command->realtime;
89 this->resume = command->resume;
90 this->audio_toggle = command->audio_toggle;
91 this->displacement = command->displacement;
94 TransportCommand& TransportCommand::operator=(TransportCommand &command)
100 int TransportCommand::single_frame(int command)
102 return (command == SINGLE_FRAME_FWD ||
103 command == SINGLE_FRAME_REWIND ||
104 command == CURRENT_FRAME);
106 int TransportCommand::single_frame()
108 return single_frame(command);
112 int TransportCommand::get_direction(int command)
115 case SINGLE_FRAME_FWD:
122 case SINGLE_FRAME_REWIND:
133 int TransportCommand::get_direction()
135 return get_direction(command);
138 float TransportCommand::get_speed(int command)
147 case SINGLE_FRAME_FWD:
148 case SINGLE_FRAME_REWIND:
159 float TransportCommand::get_speed()
161 return get_speed(command);
164 // Assume starting without pause
165 void TransportCommand::set_playback_range(EDL *edl,
166 int use_inout, int toggle_audio, int use_displacement)
168 if(!edl) edl = this->edl;
170 double length = edl->tracks->total_playable_length();
171 double frame_period = 1.0 / edl->session->frame_rate;
172 double start = edl->local_session->get_selectionstart(1);
173 double end = edl->local_session->get_selectionend(1);
177 if( edl->local_session->inpoint_valid() )
178 start_position = edl->local_session->get_inpoint();
179 if( edl->local_session->outpoint_valid() )
180 end_position = edl->local_session->get_outpoint();
182 else if( !EQUIV(start, end) ) {
183 start_position = start;
187 // starting play at or past end, play to end of media (for mixers)
188 if( start >= length )
189 length = edl->tracks->total_length();
194 start_position = start;
195 end_position = length;
196 // this prevents a crash if start position is after the loop when playing forwards
197 if( edl->local_session->loop_playback &&
198 start_position > edl->local_session->loop_end ) {
199 start_position = edl->local_session->loop_start;
208 // this prevents a crash if start position is before the loop when playing backwards
209 if( edl->local_session->loop_playback &&
210 end_position <= edl->local_session->loop_start ) {
211 end_position = edl->local_session->loop_end;
216 case SINGLE_FRAME_FWD:
217 start_position = start;
218 end_position = start_position + frame_period;
221 case SINGLE_FRAME_REWIND:
223 start_position = end_position - frame_period;
227 if( use_displacement && command != CURRENT_FRAME &&
228 get_direction() == PLAY_FORWARD ) {
229 start_position += frame_period;
230 end_position += frame_period;
235 playbackstart = get_direction() == PLAY_FORWARD ? start_position : end_position;
236 audio_toggle = toggle_audio;
239 void TransportCommand::playback_range_adjust_inout()
241 if(edl->local_session->inpoint_valid() ||
242 edl->local_session->outpoint_valid())
244 playback_range_inout();
248 void TransportCommand::playback_range_inout()
250 if(edl->local_session->inpoint_valid())
251 start_position = edl->local_session->get_inpoint();
255 if(edl->local_session->outpoint_valid())
256 end_position = edl->local_session->get_outpoint();
258 end_position = edl->tracks->total_playable_length();
259 if( start_position >= end_position )
260 end_position = edl->tracks->total_length();
264 void TransportCommand::playback_range_project()
267 end_position = edl->tracks->total_playable_length();
270 void TransportCommand::playback_range_1frame()
272 start_position = end_position = edl->local_session->get_selectionstart(1);
273 if( edl->session->frame_rate > 0 ) end_position += 1./edl->session->frame_rate;
277 TransportQue::TransportQue()
279 input_lock = new Condition(1, "TransportQue::input_lock");
280 output_lock = new Condition(0, "TransportQue::output_lock", 1);
283 TransportQue::~TransportQue()
289 int TransportQue::send_command(int command, int change_type,
290 EDL *new_edl, int realtime, int resume,
291 int use_inout, int toggle_audio, int use_displacement)
293 input_lock->lock("TransportQue::send_command 1");
294 this->command.command = command;
295 // Mutually exclusive operation
296 this->command.change_type |= change_type;
297 this->command.realtime = realtime;
298 this->command.resume = resume;
302 // Just change the EDL if the change requires it because renderengine
303 // structures won't point to the new EDL otherwise and because copying the
304 // EDL for every cursor movement is slow.
305 if(change_type == CHANGE_EDL ||
306 (uint32_t)change_type == CHANGE_ALL)
309 this->command.get_edl()->copy_all(new_edl);
312 if(change_type == CHANGE_PARAMS)
314 this->command.get_edl()->synchronize_params(new_edl);
317 // Set playback range
318 this->command.set_playback_range(new_edl,
319 use_inout, toggle_audio, use_displacement);
322 input_lock->unlock();
324 output_lock->unlock();
328 void TransportQue::update_change_type(int change_type)
330 input_lock->lock("TransportQue::update_change_type");
331 this->command.change_type |= change_type;
332 input_lock->unlock();