r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / transportque.C
blob3cefca8b503d9de1e625bece19fb9510da7b4205
1 #include "bcsignals.h"
2 #include "clip.h"
3 #include "condition.h"
4 #include "edl.h"
5 #include "edlsession.h"
6 #include "localsession.h"
7 #include "tracks.h"
8 #include "transportque.h"
10 TransportCommand::TransportCommand()
12 // In rendering we want a master EDL so settings don't get clobbered
13 // in the middle of a job.
14         edl = new EDL;
15         edl->create_objects();
16         command = 0;
17         change_type = 0;
18         reset();
21 TransportCommand::~TransportCommand()
23         delete edl;
26 void TransportCommand::reset()
28         playbackstart = 0;
29         start_position = 0;
30         end_position = 0;
31         infinite = 0;
32         realtime = 0;
33         resume = 0;
34 // Don't reset the change type for commands which don't perform the change
35         if(command != STOP) change_type = 0;
36         command = COMMAND_NONE;
39 EDL* TransportCommand::get_edl()
41         return edl;
44 void TransportCommand::delete_edl()
46         delete edl;
47         edl = 0;
50 void TransportCommand::new_edl()
52         edl = new EDL;
53         edl->create_objects();
57 void TransportCommand::copy_from(TransportCommand *command)
59         this->command = command->command;
60         this->change_type = command->change_type;
61         this->edl->copy_all(command->edl);
62         this->start_position = command->start_position;
63         this->end_position = command->end_position;
64         this->playbackstart = command->playbackstart;
65         this->realtime = command->realtime;
66         this->resume = command->resume;
69 TransportCommand& TransportCommand::operator=(TransportCommand &command)
71         copy_from(&command);
72         return *this;
75 int TransportCommand::single_frame()
77         return (command == SINGLE_FRAME_FWD ||
78                 command == SINGLE_FRAME_REWIND ||
79                 command == CURRENT_FRAME);
83 int TransportCommand::get_direction()
85         switch(command)
86         {
87                 case SINGLE_FRAME_FWD:
88                 case NORMAL_FWD:
89                 case FAST_FWD:
90                 case SLOW_FWD:
91                 case CURRENT_FRAME:
92                         return PLAY_FORWARD;
93                         break;
95                 case SINGLE_FRAME_REWIND:
96                 case NORMAL_REWIND:
97                 case FAST_REWIND:
98                 case SLOW_REWIND:
99                         return PLAY_REVERSE;
100                         break;
102                 default:
103                         return PLAY_FORWARD;
104                         break;
105         }
108 float TransportCommand::get_speed()
110         switch(command)
111         {
112                 case SLOW_FWD:
113                 case SLOW_REWIND:
114                         return 0.5;
115                         break;
116                 
117                 case NORMAL_FWD:
118                 case NORMAL_REWIND:
119                 case SINGLE_FRAME_FWD:
120                 case SINGLE_FRAME_REWIND:
121                 case CURRENT_FRAME:
122                         return 1;
123                         break;
124                 
125                 case FAST_FWD:
126                 case FAST_REWIND:
127                         return 2;
128                         break;
129         }
132 // Assume starting without pause
133 void TransportCommand::set_playback_range(EDL *edl)
135         if(!edl) edl = this->edl;
136         switch(command)
137         {
138                 case SLOW_FWD:
139                 case FAST_FWD:
140                 case NORMAL_FWD:
141                         start_position = edl->local_session->selectionstart;
142                         if(EQUIV(edl->local_session->selectionend, edl->local_session->selectionstart))
143                                 end_position = edl->tracks->total_playable_length();
144                         else
145                                 end_position = edl->local_session->selectionend;
146 // this prevents a crash if start position is after the loop when playing forwards
147                     if (edl->local_session->loop_playback && start_position > edl->local_session->loop_end)  
148                         {
149                                     start_position = edl->local_session->loop_start;
150                         }
151                         break;
152                 
153                 case SLOW_REWIND:
154                 case FAST_REWIND:
155                 case NORMAL_REWIND:
156                         end_position = edl->local_session->selectionend;
157                         if(EQUIV(edl->local_session->selectionend, edl->local_session->selectionstart))
158                                 start_position = 0;
159                         else
160                                 start_position = edl->local_session->selectionstart;
161 // this prevents a crash if start position is before the loop when playing backwards
162                         if (edl->local_session->loop_playback && start_position <= edl->local_session->loop_start)
163                         {
164                                         start_position = edl->local_session->loop_end;
165                                         end_position = edl->local_session->loop_end;
166                         }
167                         break;
168                 
169                 case CURRENT_FRAME:
170                 case SINGLE_FRAME_FWD:
171                         start_position = edl->local_session->selectionstart;
172                         end_position = start_position + 
173                                 1.0 / 
174                                 edl->session->frame_rate;
175                         break;
176                 
177                 case SINGLE_FRAME_REWIND:
178                         start_position = edl->local_session->selectionend;
179                         end_position = start_position - 
180                                 1.0 / 
181                                 edl->session->frame_rate;
182                         break;
183         }
185         switch(get_direction())
186         {
187                 case PLAY_FORWARD:
188                         playbackstart = start_position;
189                         break;
191                 case PLAY_REVERSE:
192                         playbackstart = end_position;
193                         break;
194         }
195 // printf("TransportCommand::set_playback_range %f %f\n", 
196 // start_position * edl->session->frame_rate, 
197 // end_position * edl->session->frame_rate);
200 void TransportCommand::adjust_playback_range()
202         if(edl->local_session->in_point >= 0 ||
203                 edl->local_session->out_point >= 0)
204         {
205                 if(edl->local_session->in_point >= 0)
206                         start_position = edl->local_session->in_point;
207                 else
208                         start_position = 0;
210                 if(edl->local_session->out_point >= 0)
211                         end_position = edl->local_session->out_point;
212                 else
213                         end_position = edl->tracks->total_playable_length();
214         }
234 TransportQue::TransportQue()
236         input_lock = new Condition(1, "TransportQue::input_lock");
237         output_lock = new Condition(0, "TransportQue::output_lock");
240 TransportQue::~TransportQue()
242         delete input_lock;
243         delete output_lock;
246 int TransportQue::send_command(int command, 
247                 int change_type, 
248                 EDL *new_edl, 
249                 int realtime,
250                 int resume)
252         input_lock->lock("TransportQue::send_command 1");
253         this->command.command = command;
254 // Mutually exclusive operation
255         this->command.change_type |= change_type;
256         this->command.realtime = realtime;
257         this->command.resume = resume;
259         if(new_edl)
260         {
261 // Just change the EDL if the change requires it because renderengine
262 // structures won't point to the new EDL otherwise and because copying the
263 // EDL for every cursor movement is slow.
264                 if(change_type == CHANGE_EDL ||
265                         change_type == CHANGE_ALL)
266                 {
267 // Copy EDL
268                         this->command.get_edl()->copy_all(new_edl);
269                 }
270                 else
271                 if(change_type == CHANGE_PARAMS)
272                 {
273                         this->command.get_edl()->synchronize_params(new_edl);
274                 }
276 // Set playback range
277                 this->command.set_playback_range(new_edl);
278         }
280         input_lock->unlock();
282         output_lock->unlock();
283         return 0;
286 void TransportQue::update_change_type(int change_type)
288         input_lock->lock("TransportQue::update_change_type");
289         this->command.change_type |= change_type;
290         input_lock->unlock();