r370: Heroine Virutal's official release 1.2.1
[cinelerra_cv/mob.git] / hvirtual / cinelerra / playtransport.C
blob33b128f5a447a8e8d9fe175b9618255632181c95
1 #include "edl.h"
2 #include "keys.h"
3 #include "language.h"
4 #include "mwindow.h"
5 #include "playbackengine.h"
6 #include "playtransport.h"
7 #include "preferences.h"
8 #include "theme.h"
9 #include "transportque.h"
10 #include "vframe.h"
14 PlayTransport::PlayTransport(MWindow *mwindow, 
15         BC_WindowBase *subwindow, 
16         int x, 
17         int y)
19         this->subwindow = subwindow;
20         this->mwindow = mwindow;
21         this->x = x;
22         this->y = y;
23         this->slider = 0;
24         this->engine = 0;
28 PlayTransport::~PlayTransport()
30         delete forward_play;
31         delete frame_forward_play;
32         delete reverse_play;
33         delete frame_reverse_play;
34         delete fast_reverse;
35         delete fast_play;
36         delete rewind_button;
37         delete stop_button;
38         delete end_button;
41 void PlayTransport::set_engine(PlaybackEngine *engine)
43         this->engine = engine;
46 void PlayTransport::set_slider(BC_Slider *slider)
48         this->slider = slider;
51 int PlayTransport::get_transport_width(MWindow *mwindow)
53 //printf("PlayTransport::get_transport_width %p\n", mwindow->theme->rewind_data);
54         return mwindow->theme->stop_data[0]->get_w() * 7 +
55                 mwindow->theme->rewind_data[0]->get_w() * 2;
58 int PlayTransport::create_objects()
60         int x = this->x, y = this->y;
61         subwindow->add_subwindow(rewind_button = new RewindButton(mwindow, this, x, y));
62         x += rewind_button->get_w();
63         subwindow->add_subwindow(fast_reverse = new FastReverseButton(mwindow, this, x, y)); 
64         x += fast_reverse->get_w();
65         subwindow->add_subwindow(reverse_play = new ReverseButton(mwindow, this, x, y)); 
66         x += reverse_play->get_w();
67         subwindow->add_subwindow(frame_reverse_play = new FrameReverseButton(mwindow, this, x, y)); 
68         x += frame_reverse_play->get_w();
69         subwindow->add_subwindow(stop_button = new StopButton(mwindow, this, x, y)); 
70         x += stop_button->get_w();
71         subwindow->add_subwindow(frame_forward_play = new FramePlayButton(mwindow, this, x, y)); 
72         x += frame_forward_play->get_w();
73         subwindow->add_subwindow(forward_play = new PlayButton(mwindow, this, x, y)); 
74         x += forward_play->get_w();
75         subwindow->add_subwindow(fast_play = new FastPlayButton(mwindow, this, x, y)); 
76         x += fast_play->get_w();
77         subwindow->add_subwindow(end_button = new EndButton(mwindow, this, x, y)); 
78         x += end_button->get_w();
80         reverse = 0;
81         speed = 0;
83         return 0;
86 void PlayTransport::reposition_buttons(int x, int y)
88         this->x = x;
89         this->y = y;
90         rewind_button->reposition_window(x, y);
91         x += rewind_button->get_w();
92         fast_reverse->reposition_window(x, y);
93         x += fast_reverse->get_w();
94         reverse_play->reposition_window(x, y);
95         x += reverse_play->get_w();
96         frame_reverse_play->reposition_window(x, y);
97         x += frame_reverse_play->get_w();
98         stop_button->reposition_window(x, y);
99         x += stop_button->get_w();
100         frame_forward_play->reposition_window(x, y);
101         x += frame_forward_play->get_w();
102         forward_play->reposition_window(x, y);
103         x += forward_play->get_w();
104         fast_play->reposition_window(x, y);
105         x += fast_play->get_w();
106         end_button->reposition_window(x, y);
107         x += end_button->get_w();
110 int PlayTransport::get_w()
112         return end_button->get_x() + end_button->get_w() - rewind_button->get_x();
115 int PlayTransport::flip_vertical(int vertical, int &x, int &y)
117         if(vertical)
118         {
119                 rewind_button->reposition_window(x, y); 
120                 y += rewind_button->get_h();
121                 fast_reverse->reposition_window(x, y); 
122                 y += fast_reverse->get_h();
123                 reverse_play->reposition_window(x, y); 
124                 y += reverse_play->get_h();
125                 frame_reverse_play->reposition_window(x, y); 
126                 y += frame_reverse_play->get_h();
127                 stop_button->reposition_window(x, y); 
128                 y += stop_button->get_h();
129                 frame_forward_play->reposition_window(x, y); 
130                 y += frame_forward_play->get_h();
131                 forward_play->reposition_window(x, y); 
132                 y += forward_play->get_h();
133                 fast_play->reposition_window(x, y); 
134                 y += fast_play->get_h();
135                 end_button->reposition_window(x, y); 
136                 y += end_button->get_h();
137         }
138         else
139         {
140                 rewind_button->reposition_window(x, y - 2); 
141                 x += rewind_button->get_w();
142                 fast_reverse->reposition_window(x, y - 2); 
143                 x += fast_reverse->get_w();
144                 reverse_play->reposition_window(x, y - 2); 
145                 x += reverse_play->get_w();
146                 frame_reverse_play->reposition_window(x, y - 2); 
147                 x += frame_reverse_play->get_w();
148                 stop_button->reposition_window(x, y - 2); 
149                 x += stop_button->get_w();
150                 frame_forward_play->reposition_window(x, y - 2); 
151                 x += frame_forward_play->get_w();
152                 forward_play->reposition_window(x, y - 2); 
153                 x += forward_play->get_w();
154                 fast_play->reposition_window(x, y - 2); 
155                 x += fast_play->get_w();
156                 end_button->reposition_window(x, y - 2); 
157                 x += end_button->get_w();
158         }
160         return 0;
163 int PlayTransport::keypress_event()
165         int result = 0;
166         if(subwindow->shift_down())
167         {
168                 switch(subwindow->get_keypress())
169                 {
170                         case END:
171                                 subwindow->lock_window("PlayTransport::keypress_event 1");
172                                 goto_end();                                   
173                                 result = 1; 
174                                 subwindow->unlock_window();
175                                 break;
176                         case HOME:
177                                 subwindow->lock_window("PlayTransport::keypress_event 2");
178                         goto_start();                                 
179                                 result = 1; 
180                                 subwindow->unlock_window();
181                                 break;
182                 }
183                 return result;
184         }
186         subwindow->unlock_window();
187         switch(subwindow->get_keypress())
188         {
189                 case KPPLUS:        handle_transport(FAST_REWIND);                result = 1; break;
190                 case KP6:           handle_transport(NORMAL_REWIND);              result = 1; break;
191                 case KP5:           handle_transport(SLOW_REWIND);                result = 1; break;
192                 case KP4:           handle_transport(SINGLE_FRAME_REWIND);        result = 1; break;
193                 case KP1:           handle_transport(SINGLE_FRAME_FWD);                   result = 1; break;
194                 case KP2:           handle_transport(SLOW_FWD);                           result = 1; break;
195                 case KP3:           handle_transport(NORMAL_FWD);                         result = 1; break;
196                 case KPENTER:       handle_transport(FAST_FWD);                           result = 1; break;
197                 case KPINS:         handle_transport(STOP);                       result = 1; break;
198                 case ' ':           handle_transport(NORMAL_FWD);                 result = 1; break;
199                 case 'k':           handle_transport(STOP);                                       result = 1; break;
200                 case END:
201                         subwindow->lock_window("PlayTransport::keypress_event 3");
202                         goto_end();                                   
203                         result = 1; 
204                         subwindow->unlock_window();
205                         break;
206                 case HOME:
207                         subwindow->lock_window("PlayTransport::keypress_event 4");
208                     goto_start();                                 
209                         result = 1; 
210                         subwindow->unlock_window();
211                         break;
212         }
214         subwindow->lock_window("PlayTransport::keypress_event 5");
216         return result;
220 void PlayTransport::goto_start()
222         handle_transport(REWIND, 1);
225 void PlayTransport::goto_end()
227         handle_transport(GOTO_END, 1);
232 void PlayTransport::handle_transport(int command, int wait_tracking)
234 //printf("PlayTransport::handle_transport 1\n");
235         if(!get_edl()) return;
236 //printf("PlayTransport::handle_transport 2 %d\n", command);
238 // Dispatch command
239         switch(command)
240         {
241                 case FAST_REWIND:
242                 case NORMAL_REWIND:
243                 case SLOW_REWIND:
244                 case SINGLE_FRAME_REWIND:
245                 case SINGLE_FRAME_FWD:
246                 case SLOW_FWD:
247                 case NORMAL_FWD:
248                 case FAST_FWD:
249 // Stop
250 //printf("PlayTransport::handle_transport 3 %d %d\n", engine->command->command, command);
251                         if(engine->command->command == command && 
252                                 !engine->command->single_frame())
253                         {
254 //printf("PlayTransport::handle_transport 4 %d\n", command);
255                                 engine->que->send_command(STOP,
256                                         CHANGE_NONE, 
257                                         0,
258                                         0);
259                                 engine->interrupt_playback(wait_tracking);
260                         }
261                         else
262 // Resume or change direction
263                         if(engine->command->command != STOP &&
264                                 engine->command->command != COMMAND_NONE &&
265                                 engine->command->command != SINGLE_FRAME_FWD &&
266                                 engine->command->command != SINGLE_FRAME_REWIND)
267                         {
268 //printf("PlayTransport::handle_transport 5 %d\n", command);
269                                 engine->que->send_command(STOP,
270                                         CHANGE_NONE, 
271                                         0,
272                                         0);
273 //printf("PlayTransport::handle_transport 3\n");
274                                 engine->interrupt_playback(wait_tracking);
275 //printf("PlayTransport::handle_transport 4\n");
276                                 engine->que->send_command(command,
277                                         CHANGE_NONE, 
278                                         get_edl(),
279                                         1,
280                                         1);
281 //printf("PlayTransport::handle_transport 5\n");
282                         }
283                         else
284 // Start from scratch
285                         {
286 //printf("PlayTransport::handle_transport 6 %d\n", command);
287                                 engine->que->send_command(command,
288                                         CHANGE_NONE, 
289                                         get_edl(),
290                                         1,
291                                         0);
292                         }
293                         break;
295                 case STOP:
296                 case REWIND:
297                 case GOTO_END:
298 //printf("PlayTransport 1\n");
299                         engine->que->send_command(STOP,
300                                 CHANGE_NONE, 
301                                 0,
302                                 0);
303 //printf("PlayTransport 1\n");
304                         engine->interrupt_playback(wait_tracking);
305                         break;
306         }
307 //printf("PlayTransport::handle_transport 2\n");
310 EDL* PlayTransport::get_edl()
312         return mwindow->edl;
315 int PlayTransport::pause_transport()
317         if(active_button) active_button->set_mode(PLAY_MODE);
318         return 0;
322 int PlayTransport::reset_transport()
324         fast_reverse->set_mode(PLAY_MODE);
325         reverse_play->set_mode(PLAY_MODE);
326         forward_play->set_mode(PLAY_MODE);
327         frame_reverse_play->set_mode(PLAY_MODE);
328         frame_forward_play->set_mode(PLAY_MODE);
329         fast_play->set_mode(PLAY_MODE);
330         return 0;
333 PTransportButton::PTransportButton(MWindow *mwindow, PlayTransport *transport, int x, int y, VFrame **data)
334  : BC_Button(x, y, data)
336         this->mwindow = mwindow;
337         this->transport = transport;
338         mode = PLAY_MODE;
340 PTransportButton::~PTransportButton()
344 int PTransportButton::set_mode(int mode)
346         this->mode = mode;
347         return 0;
351 RewindButton::RewindButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
352  : PTransportButton(mwindow, transport, x, y, mwindow->theme->rewind_data)
354         set_tooltip(_("Rewind ( Home )"));
356 int RewindButton::handle_event()
358 //      unlock_window();
359         transport->goto_start();
360 //      lock_window();
361         return 1;
364 FastReverseButton::FastReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
365  : PTransportButton(mwindow, transport, x, y, mwindow->theme->fastrev_data) 
367         set_tooltip(_("Fast reverse ( + )"));
369 int FastReverseButton::handle_event() 
371         unlock_window();
372         transport->handle_transport(FAST_REWIND);
373         lock_window("FastReverseButton::handle_event");
374         return 1;
377 // Reverse playback normal speed
379 ReverseButton::ReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
380  : PTransportButton(mwindow, transport, x, y, mwindow->theme->reverse_data) 
382         set_tooltip(_("Normal reverse ( 6 )"));
384 int ReverseButton::handle_event()
386         unlock_window();
387         transport->handle_transport(NORMAL_REWIND);
388         lock_window("ReverseButton::handle_event");
389         return 1;
392 // Reverse playback one frame
394 FrameReverseButton::FrameReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
395  : PTransportButton(mwindow, transport, x, y, mwindow->theme->framerev_data)
397         set_tooltip(_("Frame reverse ( 4 )"));
399 int FrameReverseButton::handle_event()
401         unlock_window();
402         transport->handle_transport(SINGLE_FRAME_REWIND);
403         lock_window("FrameReverseButton::handle_event");
404         return 1;
407 // forward playback normal speed
409 PlayButton::PlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
410  : PTransportButton(mwindow, transport, x, y, mwindow->theme->forward_data) 
412         set_tooltip(_("Normal forward ( 3 )"));
414 int PlayButton::handle_event()
416 //printf("PlayButton::handle_event 1\n");
417         unlock_window();
418         transport->handle_transport(NORMAL_FWD);        
419         lock_window("PlayButton::handle_event");
420 //printf("PlayButton::handle_event 2\n");
421         return 1;
426 // forward playback one frame
428 FramePlayButton::FramePlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
429  : PTransportButton(mwindow, transport, x, y, mwindow->theme->framefwd_data) 
431         set_tooltip(_("Frame forward ( 1 )"));
433 int FramePlayButton::handle_event()
435         unlock_window();
436         transport->handle_transport(SINGLE_FRAME_FWD);
437         lock_window("FramePlayButton::handle_event");
438         return 1;
443 FastPlayButton::FastPlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
444  : PTransportButton(mwindow, transport, x, y, mwindow->theme->fastfwd_data) 
446         set_tooltip(_("Fast forward ( Enter )"));
448 int FastPlayButton::handle_event() 
450         unlock_window();
451         transport->handle_transport(FAST_FWD);
452         lock_window("FastPlayButton::handle_event");
453         return 1;
456 EndButton::EndButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
457  : PTransportButton(mwindow, transport, x, y, mwindow->theme->end_data) 
459         set_tooltip(_("Jump to end ( End )"));
461 int EndButton::handle_event()
462 {       
463 //      unlock_window();
464         transport->goto_end();
465 //      lock_window();
466         return 1;
469 StopButton::StopButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
470  : PTransportButton(mwindow, transport, x, y, mwindow->theme->stop_data) 
472         set_tooltip(_("Stop ( 0 )"));
474 int StopButton::handle_event()
476         unlock_window();
477         transport->handle_transport(STOP);
478         lock_window("StopButton::handle_event");
479         return 1;