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()
55 // Don't reset the change type for commands which don't perform the change
56 if(command != STOP) change_type = 0;
57 command = COMMAND_NONE;
60 EDL* TransportCommand::get_edl()
65 void TransportCommand::delete_edl()
67 edl->Garbage::remove_user();
71 void TransportCommand::new_edl()
74 edl->create_objects();
78 void TransportCommand::copy_from(TransportCommand *command)
80 this->command = command->command;
81 this->change_type = command->change_type;
82 this->edl->copy_all(command->edl);
83 this->start_position = command->start_position;
84 this->end_position = command->end_position;
85 this->playbackstart = command->playbackstart;
86 this->realtime = command->realtime;
87 this->resume = command->resume;
90 TransportCommand& TransportCommand::operator=(TransportCommand &command)
96 int TransportCommand::single_frame()
98 return (command == SINGLE_FRAME_FWD ||
99 command == SINGLE_FRAME_REWIND ||
100 command == CURRENT_FRAME);
104 int TransportCommand::get_direction()
108 case SINGLE_FRAME_FWD:
115 case SINGLE_FRAME_REWIND:
127 float TransportCommand::get_speed()
137 case SINGLE_FRAME_FWD:
138 case SINGLE_FRAME_REWIND:
150 // Assume starting without pause
151 void TransportCommand::set_playback_range(EDL *edl, int use_inout)
153 if(!edl) edl = this->edl;
163 start_position = edl->local_session->get_selectionstart(1);
164 if(EQUIV(edl->local_session->get_selectionend(1), edl->local_session->get_selectionstart(1)))
165 end_position = edl->tracks->total_playable_length();
167 end_position = edl->local_session->get_selectionend(1);
168 // this prevents a crash if start position is after the loop when playing forwards
169 if (edl->local_session->loop_playback &&
170 start_position > edl->local_session->loop_end)
172 start_position = edl->local_session->loop_start;
179 end_position = edl->local_session->get_selectionend(1);
180 if(EQUIV(edl->local_session->get_selectionend(1), edl->local_session->get_selectionstart(1)))
183 start_position = edl->local_session->get_selectionstart(1);
185 // this prevents a crash if start position is before the loop when playing backwards
186 if (edl->local_session->loop_playback &&
187 end_position <= edl->local_session->loop_start)
189 end_position = edl->local_session->loop_end;
194 case SINGLE_FRAME_FWD:
195 start_position = edl->local_session->get_selectionstart(1);
196 end_position = start_position +
198 edl->session->frame_rate;
201 case SINGLE_FRAME_REWIND:
202 start_position = edl->local_session->get_selectionend(1);
203 end_position = start_position -
205 edl->session->frame_rate;
212 if(edl->local_session->inpoint_valid())
213 start_position = edl->local_session->get_inpoint();
214 if(edl->local_session->outpoint_valid())
215 end_position = edl->local_session->get_outpoint();
218 switch(get_direction())
221 playbackstart = start_position;
225 playbackstart = end_position;
231 void TransportCommand::playback_range_adjust_inout()
233 if(edl->local_session->inpoint_valid() ||
234 edl->local_session->outpoint_valid())
236 playback_range_inout();
240 void TransportCommand::playback_range_inout()
242 if(edl->local_session->inpoint_valid())
243 start_position = edl->local_session->get_inpoint();
247 if(edl->local_session->outpoint_valid())
248 end_position = edl->local_session->get_outpoint();
250 end_position = edl->tracks->total_playable_length();
253 void TransportCommand::playback_range_project()
256 end_position = edl->tracks->total_playable_length();
274 TransportQue::TransportQue()
276 input_lock = new Condition(1, "TransportQue::input_lock");
277 output_lock = new Condition(0, "TransportQue::output_lock", 1);
280 TransportQue::~TransportQue()
286 int TransportQue::send_command(int command,
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, use_inout);
321 input_lock->unlock();
323 output_lock->unlock();
327 void TransportQue::update_change_type(int change_type)
329 input_lock->lock("TransportQue::update_change_type");
330 this->command.change_type |= change_type;
331 input_lock->unlock();