r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / playtransport.C
blobe02b78aad6f8121abb114210a3e4ff7e5e04eafb
1 #include "edl.h"
2 #include "keys.h"
3 #include "mwindow.h"
4 #include "playbackengine.h"
5 #include "playtransport.h"
6 #include "preferences.h"
7 #include "theme.h"
8 #include "transportque.h"
9 #include "vframe.h"
11 #include <libintl.h>
12 #define _(String) gettext(String)
13 #define gettext_noop(String) String
14 #define N_(String) gettext_noop (String)
17 PlayTransport::PlayTransport(MWindow *mwindow, 
18         BC_WindowBase *subwindow, 
19         int x, 
20         int y)
22         this->subwindow = subwindow;
23         this->mwindow = mwindow;
24         this->x = x;
25         this->y = y;
26         this->slider = 0;
27         this->engine = 0;
31 PlayTransport::~PlayTransport()
33         delete forward_play;
34         delete frame_forward_play;
35         delete reverse_play;
36         delete frame_reverse_play;
37         delete fast_reverse;
38         delete fast_play;
39         delete rewind_button;
40         delete stop_button;
41         delete end_button;
44 void PlayTransport::set_engine(PlaybackEngine *engine)
46         this->engine = engine;
49 void PlayTransport::set_slider(BC_Slider *slider)
51         this->slider = slider;
54 int PlayTransport::get_transport_width(MWindow *mwindow)
56 //printf("PlayTransport::get_transport_width %p\n", mwindow->theme->rewind_data);
57         return mwindow->theme->stop_data[0]->get_w() * 7 +
58                 mwindow->theme->rewind_data[0]->get_w() * 2;
61 int PlayTransport::create_objects()
63         int x = this->x, y = this->y;
64         subwindow->add_subwindow(rewind_button = new RewindButton(mwindow, this, x, y));
65         x += rewind_button->get_w();
66         subwindow->add_subwindow(fast_reverse = new FastReverseButton(mwindow, this, x, y)); 
67         x += fast_reverse->get_w();
68         subwindow->add_subwindow(reverse_play = new ReverseButton(mwindow, this, x, y)); 
69         x += reverse_play->get_w();
70         subwindow->add_subwindow(frame_reverse_play = new FrameReverseButton(mwindow, this, x, y)); 
71         x += frame_reverse_play->get_w();
72         subwindow->add_subwindow(stop_button = new StopButton(mwindow, this, x, y)); 
73         x += stop_button->get_w();
74         subwindow->add_subwindow(frame_forward_play = new FramePlayButton(mwindow, this, x, y)); 
75         x += frame_forward_play->get_w();
76         subwindow->add_subwindow(forward_play = new PlayButton(mwindow, this, x, y)); 
77         x += forward_play->get_w();
78         subwindow->add_subwindow(fast_play = new FastPlayButton(mwindow, this, x, y)); 
79         x += fast_play->get_w();
80         subwindow->add_subwindow(end_button = new EndButton(mwindow, this, x, y)); 
81         x += end_button->get_w();
83         reverse = 0;
84         speed = 0;
86         return 0;
89 void PlayTransport::reposition_buttons(int x, int y)
91         this->x = x;
92         this->y = y;
93         rewind_button->reposition_window(x, y);
94         x += rewind_button->get_w();
95         fast_reverse->reposition_window(x, y);
96         x += fast_reverse->get_w();
97         reverse_play->reposition_window(x, y);
98         x += reverse_play->get_w();
99         frame_reverse_play->reposition_window(x, y);
100         x += frame_reverse_play->get_w();
101         stop_button->reposition_window(x, y);
102         x += stop_button->get_w();
103         frame_forward_play->reposition_window(x, y);
104         x += frame_forward_play->get_w();
105         forward_play->reposition_window(x, y);
106         x += forward_play->get_w();
107         fast_play->reposition_window(x, y);
108         x += fast_play->get_w();
109         end_button->reposition_window(x, y);
110         x += end_button->get_w();
113 int PlayTransport::get_w()
115         return end_button->get_x() + end_button->get_w() - rewind_button->get_x();
118 int PlayTransport::flip_vertical(int vertical, int &x, int &y)
120         if(vertical)
121         {
122                 rewind_button->reposition_window(x, y); 
123                 y += rewind_button->get_h();
124                 fast_reverse->reposition_window(x, y); 
125                 y += fast_reverse->get_h();
126                 reverse_play->reposition_window(x, y); 
127                 y += reverse_play->get_h();
128                 frame_reverse_play->reposition_window(x, y); 
129                 y += frame_reverse_play->get_h();
130                 stop_button->reposition_window(x, y); 
131                 y += stop_button->get_h();
132                 frame_forward_play->reposition_window(x, y); 
133                 y += frame_forward_play->get_h();
134                 forward_play->reposition_window(x, y); 
135                 y += forward_play->get_h();
136                 fast_play->reposition_window(x, y); 
137                 y += fast_play->get_h();
138                 end_button->reposition_window(x, y); 
139                 y += end_button->get_h();
140         }
141         else
142         {
143                 rewind_button->reposition_window(x, y - 2); 
144                 x += rewind_button->get_w();
145                 fast_reverse->reposition_window(x, y - 2); 
146                 x += fast_reverse->get_w();
147                 reverse_play->reposition_window(x, y - 2); 
148                 x += reverse_play->get_w();
149                 frame_reverse_play->reposition_window(x, y - 2); 
150                 x += frame_reverse_play->get_w();
151                 stop_button->reposition_window(x, y - 2); 
152                 x += stop_button->get_w();
153                 frame_forward_play->reposition_window(x, y - 2); 
154                 x += frame_forward_play->get_w();
155                 forward_play->reposition_window(x, y - 2); 
156                 x += forward_play->get_w();
157                 fast_play->reposition_window(x, y - 2); 
158                 x += fast_play->get_w();
159                 end_button->reposition_window(x, y - 2); 
160                 x += end_button->get_w();
161         }
163         return 0;
166 int PlayTransport::keypress_event()
168 //printf("PlayTransport::keypress_event 1\n");
169         if(subwindow->shift_down()) return  0;
170         int result = 0;
172 //printf("PlayTransport::keypress_event %x\n", subwindow->get_keypress());
173         subwindow->unlock_window();
174         switch(subwindow->get_keypress())
175         {
176                 case KPPLUS:        handle_transport(FAST_REWIND);                result = 1; break;
177                 case KP6:           handle_transport(NORMAL_REWIND);              result = 1; break;
178                 case KP5:           handle_transport(SLOW_REWIND);                result = 1; break;
179                 case KP4:           handle_transport(SINGLE_FRAME_REWIND);        result = 1; break;
180                 case KP1:           handle_transport(SINGLE_FRAME_FWD);                   result = 1; break;
181                 case KP2:           handle_transport(SLOW_FWD);                           result = 1; break;
182                 case KP3:           handle_transport(NORMAL_FWD);                         result = 1; break;
183                 case KPENTER:       handle_transport(FAST_FWD);                           result = 1; break;
184                 case KPINS:         handle_transport(STOP);                       result = 1; break;
185                 case ' ':           handle_transport(NORMAL_FWD);                 result = 1; break;
186                 case 'k':           handle_transport(STOP);                                       result = 1; break;
187         }
189         subwindow->lock_window();
191         return result;
195 void PlayTransport::goto_start()
197         handle_transport(REWIND, 1);
200 void PlayTransport::goto_end()
202         handle_transport(END, 1);
207 void PlayTransport::handle_transport(int command, int wait_tracking)
209 //printf("PlayTransport::handle_transport 1\n");
210         if(!get_edl()) return;
211 //printf("PlayTransport::handle_transport 2 %d\n", command);
213 // Dispatch command
214         switch(command)
215         {
216                 case FAST_REWIND:
217                 case NORMAL_REWIND:
218                 case SLOW_REWIND:
219                 case SINGLE_FRAME_REWIND:
220                 case SINGLE_FRAME_FWD:
221                 case SLOW_FWD:
222                 case NORMAL_FWD:
223                 case FAST_FWD:
224 // Stop
225 //printf("PlayTransport::handle_transport 3 %d %d\n", engine->command->command, command);
226                         if(engine->command->command == command && 
227                                 !engine->command->single_frame())
228                         {
229 //printf("PlayTransport::handle_transport 4 %d\n", command);
230                                 engine->que->send_command(STOP,
231                                         CHANGE_NONE, 
232                                         0,
233                                         0);
234                                 engine->interrupt_playback(wait_tracking);
235                         }
236                         else
237 // Resume or change direction
238                         if(engine->command->command != STOP &&
239                                 engine->command->command != COMMAND_NONE &&
240                                 engine->command->command != SINGLE_FRAME_FWD &&
241                                 engine->command->command != SINGLE_FRAME_REWIND)
242                         {
243 //printf("PlayTransport::handle_transport 5 %d\n", command);
244                                 engine->que->send_command(STOP,
245                                         CHANGE_NONE, 
246                                         0,
247                                         0);
248 //printf("PlayTransport::handle_transport 3\n");
249                                 engine->interrupt_playback(wait_tracking);
250 //printf("PlayTransport::handle_transport 4\n");
251                                 engine->que->send_command(command,
252                                         CHANGE_NONE, 
253                                         get_edl(),
254                                         1,
255                                         1);
256 //printf("PlayTransport::handle_transport 5\n");
257                         }
258                         else
259 // Start from scratch
260                         {
261 //printf("PlayTransport::handle_transport 6 %d\n", command);
262                                 engine->que->send_command(command,
263                                         CHANGE_NONE, 
264                                         get_edl(),
265                                         1,
266                                         0);
267                         }
268                         break;
270                 case STOP:
271                 case REWIND:
272                 case GOTO_END:
273 //printf("PlayTransport 1\n");
274                         engine->que->send_command(STOP,
275                                 CHANGE_NONE, 
276                                 0,
277                                 0);
278 //printf("PlayTransport 1\n");
279                         engine->interrupt_playback(wait_tracking);
280 //printf("PlayTransport 2\n");
281                         break;
282         }
285 EDL* PlayTransport::get_edl()
287         return mwindow->edl;
290 int PlayTransport::pause_transport()
292         if(active_button) active_button->set_mode(PLAY_MODE);
293         return 0;
297 int PlayTransport::reset_transport()
299         fast_reverse->set_mode(PLAY_MODE);
300         reverse_play->set_mode(PLAY_MODE);
301         forward_play->set_mode(PLAY_MODE);
302         frame_reverse_play->set_mode(PLAY_MODE);
303         frame_forward_play->set_mode(PLAY_MODE);
304         fast_play->set_mode(PLAY_MODE);
305         return 0;
308 PTransportButton::PTransportButton(MWindow *mwindow, PlayTransport *transport, int x, int y, VFrame **data)
309  : BC_Button(x, y, data)
311         this->mwindow = mwindow;
312         this->transport = transport;
313         mode = PLAY_MODE;
315 PTransportButton::~PTransportButton()
319 int PTransportButton::set_mode(int mode)
321         this->mode = mode;
322         return 0;
326 RewindButton::RewindButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
327  : PTransportButton(mwindow, transport, x, y, mwindow->theme->rewind_data)
329         set_tooltip(_("Rewind"));
331 int RewindButton::handle_event()
333 //      unlock_window();
334         transport->goto_start();
335 //      lock_window();
336         return 1;
339 FastReverseButton::FastReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
340  : PTransportButton(mwindow, transport, x, y, mwindow->theme->fastrev_data) 
342         set_tooltip(_("Fast reverse ( + )"));
344 int FastReverseButton::handle_event() 
346         unlock_window();
347         transport->handle_transport(FAST_REWIND);
348         lock_window();
349         return 1;
352 // Reverse playback normal speed
354 ReverseButton::ReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
355  : PTransportButton(mwindow, transport, x, y, mwindow->theme->reverse_data) 
357         set_tooltip(_("Normal reverse ( 6 )"));
359 int ReverseButton::handle_event()
361         unlock_window();
362         transport->handle_transport(NORMAL_REWIND);
363         lock_window();
364         return 1;
367 // Reverse playback one frame
369 FrameReverseButton::FrameReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
370  : PTransportButton(mwindow, transport, x, y, mwindow->theme->framerev_data)
372         set_tooltip(_("Frame reverse ( 4 )"));
374 int FrameReverseButton::handle_event()
376         unlock_window();
377         transport->handle_transport(SINGLE_FRAME_REWIND);
378         lock_window();
379         return 1;
382 // forward playback normal speed
384 PlayButton::PlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
385  : PTransportButton(mwindow, transport, x, y, mwindow->theme->forward_data) 
387         set_tooltip(_("Normal forward ( 3 )"));
389 int PlayButton::handle_event()
391 //printf("PlayButton::handle_event 1\n");
392         unlock_window();
393         transport->handle_transport(NORMAL_FWD);        
394         lock_window();
395 //printf("PlayButton::handle_event 2\n");
396         return 1;
401 // forward playback one frame
403 FramePlayButton::FramePlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
404  : PTransportButton(mwindow, transport, x, y, mwindow->theme->framefwd_data) 
406         set_tooltip(_("Frame forward ( 1 )"));
408 int FramePlayButton::handle_event()
410         unlock_window();
411         transport->handle_transport(SINGLE_FRAME_FWD);
412         lock_window();
413         return 1;
418 FastPlayButton::FastPlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
419  : PTransportButton(mwindow, transport, x, y, mwindow->theme->fastfwd_data) 
421         set_tooltip(_("Fast forward ( Enter )"));
423 int FastPlayButton::handle_event() 
425         unlock_window();
426         transport->handle_transport(FAST_FWD);
427         lock_window();
428         return 1;
431 EndButton::EndButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
432  : PTransportButton(mwindow, transport, x, y, mwindow->theme->end_data) 
434         set_tooltip(_("Jump to end"));
436 int EndButton::handle_event()
437 {       
438 //      unlock_window();
439         transport->goto_end();
440 //      lock_window();
441         return 1;
444 StopButton::StopButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
445  : PTransportButton(mwindow, transport, x, y, mwindow->theme->stop_data) 
447         set_tooltip(_("Stop ( 0 )"));
449 int StopButton::handle_event()
451 //printf("StopButton::handle_event 1\n");
452         unlock_window();
453 //printf("StopButton::handle_event 1\n");
454         transport->handle_transport(STOP);
455 //printf("StopButton::handle_event 1\n");
456         lock_window();
457 //printf("StopButton::handle_event 2\n");
458         return 1;