r668: Configure.in and autogen.sh cleanup based on ideas by giskard.
[cinelerra_cv.git] / cinelerra / playtransport.C
blob6b278b2d40a24c222ac4bbbf812567be1e394a93
1 #include "edl.h"
2 #include "keys.h"
3 #include "language.h"
4 #include "localsession.h"
5 #include "mwindow.h"
6 #include "playbackengine.h"
7 #include "playtransport.h"
8 #include "preferences.h"
9 #include "theme.h"
10 #include "transportque.h"
11 #include "vframe.h"
12 #include "localsession.h"
16 PlayTransport::PlayTransport(MWindow *mwindow, 
17         BC_WindowBase *subwindow, 
18         int x, 
19         int y)
21         this->subwindow = subwindow;
22         this->mwindow = mwindow;
23         this->x = x;
24         this->y = y;
25         this->slider = 0;
26         this->engine = 0;
30 PlayTransport::~PlayTransport()
32         delete forward_play;
33         delete frame_forward_play;
34         delete reverse_play;
35         delete frame_reverse_play;
36         delete fast_reverse;
37         delete fast_play;
38         delete rewind_button;
39         delete stop_button;
40         delete end_button;
43 void PlayTransport::set_engine(PlaybackEngine *engine)
45         this->engine = engine;
48 void PlayTransport::set_slider(BC_Slider *slider)
50         this->slider = slider;
53 int PlayTransport::get_transport_width(MWindow *mwindow)
55         return mwindow->theme->get_image_set("stop")[0]->get_w() * 7 +
56                 mwindow->theme->get_image_set("rewind")[0]->get_w() * 2;
59 int PlayTransport::create_objects()
61         int x = this->x, y = this->y;
62         subwindow->add_subwindow(rewind_button = new RewindButton(mwindow, this, x, y));
63         x += rewind_button->get_w();
64         subwindow->add_subwindow(fast_reverse = new FastReverseButton(mwindow, this, x, y)); 
65         x += fast_reverse->get_w();
66         subwindow->add_subwindow(reverse_play = new ReverseButton(mwindow, this, x, y)); 
67         x += reverse_play->get_w();
68         subwindow->add_subwindow(frame_reverse_play = new FrameReverseButton(mwindow, this, x, y)); 
69         x += frame_reverse_play->get_w();
70         subwindow->add_subwindow(stop_button = new StopButton(mwindow, this, x, y)); 
71         x += stop_button->get_w();
72         subwindow->add_subwindow(frame_forward_play = new FramePlayButton(mwindow, this, x, y)); 
73         x += frame_forward_play->get_w();
74         subwindow->add_subwindow(forward_play = new PlayButton(mwindow, this, x, y)); 
75         x += forward_play->get_w();
76         subwindow->add_subwindow(fast_play = new FastPlayButton(mwindow, this, x, y)); 
77         x += fast_play->get_w();
78         subwindow->add_subwindow(end_button = new EndButton(mwindow, this, x, y)); 
79         x += end_button->get_w();
81         reverse = 0;
82         speed = 0;
84         return 0;
87 void PlayTransport::reposition_buttons(int x, int y)
89         this->x = x;
90         this->y = y;
91         rewind_button->reposition_window(x, y);
92         x += rewind_button->get_w();
93         fast_reverse->reposition_window(x, y);
94         x += fast_reverse->get_w();
95         reverse_play->reposition_window(x, y);
96         x += reverse_play->get_w();
97         frame_reverse_play->reposition_window(x, y);
98         x += frame_reverse_play->get_w();
99         stop_button->reposition_window(x, y);
100         x += stop_button->get_w();
101         frame_forward_play->reposition_window(x, y);
102         x += frame_forward_play->get_w();
103         forward_play->reposition_window(x, y);
104         x += forward_play->get_w();
105         fast_play->reposition_window(x, y);
106         x += fast_play->get_w();
107         end_button->reposition_window(x, y);
108         x += end_button->get_w();
111 int PlayTransport::get_w()
113         return end_button->get_x() + end_button->get_w() - rewind_button->get_x();
116 int PlayTransport::flip_vertical(int vertical, int &x, int &y)
118         if(vertical)
119         {
120                 rewind_button->reposition_window(x, y); 
121                 y += rewind_button->get_h();
122                 fast_reverse->reposition_window(x, y); 
123                 y += fast_reverse->get_h();
124                 reverse_play->reposition_window(x, y); 
125                 y += reverse_play->get_h();
126                 frame_reverse_play->reposition_window(x, y); 
127                 y += frame_reverse_play->get_h();
128                 stop_button->reposition_window(x, y); 
129                 y += stop_button->get_h();
130                 frame_forward_play->reposition_window(x, y); 
131                 y += frame_forward_play->get_h();
132                 forward_play->reposition_window(x, y); 
133                 y += forward_play->get_h();
134                 fast_play->reposition_window(x, y); 
135                 y += fast_play->get_h();
136                 end_button->reposition_window(x, y); 
137                 y += end_button->get_h();
138         }
139         else
140         {
141                 rewind_button->reposition_window(x, y - 2); 
142                 x += rewind_button->get_w();
143                 fast_reverse->reposition_window(x, y - 2); 
144                 x += fast_reverse->get_w();
145                 reverse_play->reposition_window(x, y - 2); 
146                 x += reverse_play->get_w();
147                 frame_reverse_play->reposition_window(x, y - 2); 
148                 x += frame_reverse_play->get_w();
149                 stop_button->reposition_window(x, y - 2); 
150                 x += stop_button->get_w();
151                 frame_forward_play->reposition_window(x, y - 2); 
152                 x += frame_forward_play->get_w();
153                 forward_play->reposition_window(x, y - 2); 
154                 x += forward_play->get_w();
155                 fast_play->reposition_window(x, y - 2); 
156                 x += fast_play->get_w();
157                 end_button->reposition_window(x, y - 2); 
158                 x += end_button->get_w();
159         }
161         return 0;
164 int PlayTransport::keypress_event()
166         int result = 0;
167         if(subwindow->shift_down())
168         {
169                 switch(subwindow->get_keypress())
170                 {
171                         case END:
172                                 subwindow->lock_window("PlayTransport::keypress_event 1");
173                                 goto_end();                                   
174                                 result = 1; 
175                                 subwindow->unlock_window();
176                                 break;
177                         case HOME:
178                                 subwindow->lock_window("PlayTransport::keypress_event 2");
179                         goto_start();                                 
180                                 result = 1; 
181                                 subwindow->unlock_window();
182                                 break;
183                 }
184                 return result;
185         }
187 // Set playback range to in/out points if CTRL is down
188         int use_inout = 0;
189         if(subwindow->ctrl_down())
190         {
191                 use_inout = 1;
192         }
193         subwindow->unlock_window();
196         switch(subwindow->get_keypress())
197         {
198                 case KPPLUS:        handle_transport(FAST_REWIND, 0, use_inout);                result = 1; break;
199                 case KP6:           handle_transport(NORMAL_REWIND, 0, use_inout);              result = 1; break;
200                 case KP5:           handle_transport(SLOW_REWIND, 0, use_inout);                result = 1; break;
201                 case KP4:           handle_transport(SINGLE_FRAME_REWIND, 0, use_inout);        result = 1; break;
202                 case KP1:           handle_transport(SINGLE_FRAME_FWD, 0, use_inout);                     result = 1; break;
203                 case KP2:           handle_transport(SLOW_FWD, 0, use_inout);                             result = 1; break;
204                 case KP3:           handle_transport(NORMAL_FWD, 0, use_inout);                           result = 1; break;
205                 case KPENTER:       handle_transport(FAST_FWD, 0, use_inout);                             result = 1; break;
206                 case KPINS:         handle_transport(STOP, 0, use_inout);                       result = 1; break;
207                 case ' ':           handle_transport(NORMAL_FWD, 0, use_inout);                 result = 1; break;
208                 case 'k':           handle_transport(STOP, 0, use_inout);                                         result = 1; break;
209                 case END:
210                         subwindow->lock_window("PlayTransport::keypress_event 3");
211                         goto_end();                                   
212                         result = 1; 
213                         subwindow->unlock_window();
214                         break;
215                 case HOME:
216                         subwindow->lock_window("PlayTransport::keypress_event 4");
217                     goto_start();                                 
218                         result = 1; 
219                         subwindow->unlock_window();
220                         break;
221         }
223         subwindow->lock_window("PlayTransport::keypress_event 5");
225         return result;
229 void PlayTransport::goto_start()
231         handle_transport(REWIND, 1, 0);
234 void PlayTransport::goto_end()
236         handle_transport(GOTO_END, 1, 0);
241 void PlayTransport::handle_transport(int command, 
242         int wait_tracking,
243         int use_inout)
245         if(!get_edl()) return;
249 // Dispatch command
250         switch(command)
251         {
252 // Commands that play back
253                 case FAST_REWIND:
254                 case NORMAL_REWIND:
255                 case SLOW_REWIND:
256                 case SINGLE_FRAME_REWIND:
257                 case SINGLE_FRAME_FWD:
258                 case SLOW_FWD:
259                 case NORMAL_FWD:
260                 case FAST_FWD:
261 // Stop
262                         if(engine->command->command == command && 
263                                 !engine->command->single_frame())
264                         {
265                                 engine->que->send_command(STOP,
266                                         CHANGE_NONE, 
267                                         0,
268                                         0,
269                                         0,
270                                         0);
271                                 engine->interrupt_playback(wait_tracking);
272                         }
273                         else
274 // Resume or change direction
275                         if(engine->command->command != STOP &&
276                                 engine->command->command != COMMAND_NONE &&
277                                 engine->command->command != SINGLE_FRAME_FWD &&
278                                 engine->command->command != SINGLE_FRAME_REWIND)
279                         {
280                                 engine->que->send_command(STOP,
281                                         CHANGE_NONE, 
282                                         0,
283                                         0,
284                                         0,
285                                         0);
286                                 engine->interrupt_playback(wait_tracking);
287                                 engine->que->send_command(command,
288                                         CHANGE_NONE, 
289                                         get_edl(),
290                                         1,
291                                         1,
292                                         use_inout);
293                         }
294                         else
295 // Start from scratch
296                         {
297                                 engine->que->send_command(command,
298                                         CHANGE_NONE, 
299                                         get_edl(),
300                                         1,
301                                         0,
302                                         use_inout);
303                         }
304                         break;
306 // Commands that stop
307                 case STOP:
308                 case REWIND:
309                 case GOTO_END:
310                         engine->que->send_command(STOP,
311                                 CHANGE_NONE, 
312                                 0,
313                                 0,
314                                 0,
315                                 0);
316                         engine->interrupt_playback(wait_tracking);
317                         break;
318         }
321 EDL* PlayTransport::get_edl()
323         return mwindow->edl;
326 int PlayTransport::pause_transport()
328         if(active_button) active_button->set_mode(PLAY_MODE);
329         return 0;
333 int PlayTransport::reset_transport()
335         fast_reverse->set_mode(PLAY_MODE);
336         reverse_play->set_mode(PLAY_MODE);
337         forward_play->set_mode(PLAY_MODE);
338         frame_reverse_play->set_mode(PLAY_MODE);
339         frame_forward_play->set_mode(PLAY_MODE);
340         fast_play->set_mode(PLAY_MODE);
341         return 0;
344 PTransportButton::PTransportButton(MWindow *mwindow, PlayTransport *transport, int x, int y, VFrame **data)
345  : BC_Button(x, y, data)
347         this->mwindow = mwindow;
348         this->transport = transport;
349         mode = PLAY_MODE;
351 PTransportButton::~PTransportButton()
355 int PTransportButton::set_mode(int mode)
357         this->mode = mode;
358         return 0;
362 RewindButton::RewindButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
363  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("rewind"))
365         set_tooltip(_("Rewind ( Home )"));
367 int RewindButton::handle_event()
369 //      unlock_window();
370         transport->goto_start();
371 //      lock_window();
372         return 1;
375 FastReverseButton::FastReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
376  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("fastrev")) 
378         set_tooltip(_("Fast reverse ( + )"));
380 int FastReverseButton::handle_event() 
382         unlock_window();
383         transport->handle_transport(FAST_REWIND, 0, ctrl_down());
384         lock_window("FastReverseButton::handle_event");
385         return 1;
388 // Reverse playback normal speed
390 ReverseButton::ReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
391  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("reverse")) 
393         set_tooltip(_("Normal reverse ( 6 )"));
395 int ReverseButton::handle_event()
397         unlock_window();
398         transport->handle_transport(NORMAL_REWIND, 0, ctrl_down());
399         lock_window("ReverseButton::handle_event");
400         return 1;
403 // Reverse playback one frame
405 FrameReverseButton::FrameReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
406  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("framerev"))
408         set_tooltip(_("Frame reverse ( 4 )"));
410 int FrameReverseButton::handle_event()
412         unlock_window();
413         transport->handle_transport(SINGLE_FRAME_REWIND, 0, ctrl_down());
414         lock_window("FrameReverseButton::handle_event");
415         return 1;
418 // forward playback normal speed
420 PlayButton::PlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
421  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("play")) 
423         set_tooltip(_("Normal forward ( 3 )"));
425 int PlayButton::handle_event()
427         unlock_window();
428         transport->handle_transport(NORMAL_FWD, 0, ctrl_down());
429         lock_window("PlayButton::handle_event");
430         return 1;
435 // forward playback one frame
437 FramePlayButton::FramePlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
438  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("framefwd")) 
440         set_tooltip(_("Frame forward ( 1 )"));
442 int FramePlayButton::handle_event()
444         unlock_window();
445         transport->handle_transport(SINGLE_FRAME_FWD, 0, ctrl_down());
446         lock_window("FramePlayButton::handle_event");
447         return 1;
452 FastPlayButton::FastPlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
453  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("fastfwd")) 
455         set_tooltip(_("Fast forward ( Enter )"));
457 int FastPlayButton::handle_event() 
459         unlock_window();
460         transport->handle_transport(FAST_FWD, 0, ctrl_down());
461         lock_window("FastPlayButton::handle_event");
462         return 1;
465 EndButton::EndButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
466  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("end")) 
468         set_tooltip(_("Jump to end ( End )"));
470 int EndButton::handle_event()
471 {       
472 //      unlock_window();
473         transport->goto_end();
474 //      lock_window();
475         return 1;
478 StopButton::StopButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
479  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("stop")) 
481         set_tooltip(_("Stop ( 0 )"));
483 int StopButton::handle_event()
485         unlock_window();
486         transport->handle_transport(STOP, 0, 0);
487         lock_window("StopButton::handle_event");
488         return 1;