Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

playtransport.C

Go to the documentation of this file.
00001 #include "edl.h"
00002 #include "keys.h"
00003 #include "language.h"
00004 #include "localsession.h"
00005 #include "mwindow.h"
00006 #include "playbackengine.h"
00007 #include "playtransport.h"
00008 #include "preferences.h"
00009 #include "theme.h"
00010 #include "transportque.h"
00011 #include "vframe.h"
00012 #include "localsession.h"
00013 
00014 
00015 
00016 PlayTransport::PlayTransport(MWindow *mwindow, 
00017         BC_WindowBase *subwindow, 
00018         int x, 
00019         int y)
00020 {
00021         this->subwindow = subwindow;
00022         this->mwindow = mwindow;
00023         this->x = x;
00024         this->y = y;
00025         this->slider = 0;
00026         this->engine = 0;
00027 }
00028 
00029 
00030 PlayTransport::~PlayTransport()
00031 {
00032         delete forward_play;
00033         delete frame_forward_play;
00034         delete reverse_play;
00035         delete frame_reverse_play;
00036         delete fast_reverse;
00037         delete fast_play;
00038         delete rewind_button;
00039         delete stop_button;
00040         delete end_button;
00041 }
00042 
00043 void PlayTransport::set_engine(PlaybackEngine *engine)
00044 {
00045         this->engine = engine;
00046 }
00047 
00048 void PlayTransport::set_slider(BC_Slider *slider)
00049 {
00050         this->slider = slider;
00051 }
00052 
00053 int PlayTransport::get_transport_width(MWindow *mwindow)
00054 {
00055         return mwindow->theme->get_image_set("stop")[0]->get_w() * 7 +
00056                 mwindow->theme->get_image_set("rewind")[0]->get_w() * 2;
00057 }
00058 
00059 int PlayTransport::create_objects()
00060 {
00061         int x = this->x, y = this->y;
00062         subwindow->add_subwindow(rewind_button = new RewindButton(mwindow, this, x, y));
00063         x += rewind_button->get_w();
00064         subwindow->add_subwindow(fast_reverse = new FastReverseButton(mwindow, this, x, y)); 
00065         x += fast_reverse->get_w();
00066         subwindow->add_subwindow(reverse_play = new ReverseButton(mwindow, this, x, y)); 
00067         x += reverse_play->get_w();
00068         subwindow->add_subwindow(frame_reverse_play = new FrameReverseButton(mwindow, this, x, y)); 
00069         x += frame_reverse_play->get_w();
00070         subwindow->add_subwindow(stop_button = new StopButton(mwindow, this, x, y)); 
00071         x += stop_button->get_w();
00072         subwindow->add_subwindow(frame_forward_play = new FramePlayButton(mwindow, this, x, y)); 
00073         x += frame_forward_play->get_w();
00074         subwindow->add_subwindow(forward_play = new PlayButton(mwindow, this, x, y)); 
00075         x += forward_play->get_w();
00076         subwindow->add_subwindow(fast_play = new FastPlayButton(mwindow, this, x, y)); 
00077         x += fast_play->get_w();
00078         subwindow->add_subwindow(end_button = new EndButton(mwindow, this, x, y)); 
00079         x += end_button->get_w();
00080 
00081         reverse = 0;
00082         speed = 0;
00083 
00084         return 0;
00085 }
00086 
00087 void PlayTransport::reposition_buttons(int x, int y)
00088 {
00089         this->x = x;
00090         this->y = y;
00091         rewind_button->reposition_window(x, y);
00092         x += rewind_button->get_w();
00093         fast_reverse->reposition_window(x, y);
00094         x += fast_reverse->get_w();
00095         reverse_play->reposition_window(x, y);
00096         x += reverse_play->get_w();
00097         frame_reverse_play->reposition_window(x, y);
00098         x += frame_reverse_play->get_w();
00099         stop_button->reposition_window(x, y);
00100         x += stop_button->get_w();
00101         frame_forward_play->reposition_window(x, y);
00102         x += frame_forward_play->get_w();
00103         forward_play->reposition_window(x, y);
00104         x += forward_play->get_w();
00105         fast_play->reposition_window(x, y);
00106         x += fast_play->get_w();
00107         end_button->reposition_window(x, y);
00108         x += end_button->get_w();
00109 }
00110 
00111 int PlayTransport::get_w()
00112 {
00113         return end_button->get_x() + end_button->get_w() - rewind_button->get_x();
00114 }
00115 
00116 int PlayTransport::flip_vertical(int vertical, int &x, int &y)
00117 {
00118         if(vertical)
00119         {
00120                 rewind_button->reposition_window(x, y); 
00121                 y += rewind_button->get_h();
00122                 fast_reverse->reposition_window(x, y); 
00123                 y += fast_reverse->get_h();
00124                 reverse_play->reposition_window(x, y); 
00125                 y += reverse_play->get_h();
00126                 frame_reverse_play->reposition_window(x, y); 
00127                 y += frame_reverse_play->get_h();
00128                 stop_button->reposition_window(x, y); 
00129                 y += stop_button->get_h();
00130                 frame_forward_play->reposition_window(x, y); 
00131                 y += frame_forward_play->get_h();
00132                 forward_play->reposition_window(x, y); 
00133                 y += forward_play->get_h();
00134                 fast_play->reposition_window(x, y); 
00135                 y += fast_play->get_h();
00136                 end_button->reposition_window(x, y); 
00137                 y += end_button->get_h();
00138         }
00139         else
00140         {
00141                 rewind_button->reposition_window(x, y - 2); 
00142                 x += rewind_button->get_w();
00143                 fast_reverse->reposition_window(x, y - 2); 
00144                 x += fast_reverse->get_w();
00145                 reverse_play->reposition_window(x, y - 2); 
00146                 x += reverse_play->get_w();
00147                 frame_reverse_play->reposition_window(x, y - 2); 
00148                 x += frame_reverse_play->get_w();
00149                 stop_button->reposition_window(x, y - 2); 
00150                 x += stop_button->get_w();
00151                 frame_forward_play->reposition_window(x, y - 2); 
00152                 x += frame_forward_play->get_w();
00153                 forward_play->reposition_window(x, y - 2); 
00154                 x += forward_play->get_w();
00155                 fast_play->reposition_window(x, y - 2); 
00156                 x += fast_play->get_w();
00157                 end_button->reposition_window(x, y - 2); 
00158                 x += end_button->get_w();
00159         }
00160 
00161         return 0;
00162 }
00163 
00164 int PlayTransport::keypress_event()
00165 {
00166         int result = 0;
00167         if(subwindow->shift_down())
00168         {
00169                 switch(subwindow->get_keypress())
00170                 {
00171                         case END:
00172                                 subwindow->lock_window("PlayTransport::keypress_event 1");
00173                                 goto_end();                                   
00174                                 result = 1; 
00175                                 subwindow->unlock_window();
00176                                 break;
00177                         case HOME:
00178                                 subwindow->lock_window("PlayTransport::keypress_event 2");
00179                         goto_start();                                 
00180                                 result = 1; 
00181                                 subwindow->unlock_window();
00182                                 break;
00183                 }
00184                 return result;
00185         }
00186 
00187 // Set playback range to in/out points if CTRL is down
00188         int use_inout = 0;
00189         if(subwindow->ctrl_down())
00190         {
00191                 use_inout = 1;
00192         }
00193         subwindow->unlock_window();
00194 
00195 
00196         switch(subwindow->get_keypress())
00197         {
00198                 case KPPLUS:        handle_transport(FAST_REWIND, 0, use_inout);                result = 1; break;
00199                 case KP6:           handle_transport(NORMAL_REWIND, 0, use_inout);              result = 1; break;
00200                 case KP5:           handle_transport(SLOW_REWIND, 0, use_inout);                result = 1; break;
00201                 case KP4:           handle_transport(SINGLE_FRAME_REWIND, 0, use_inout);        result = 1; break;
00202                 case KP1:           handle_transport(SINGLE_FRAME_FWD, 0, use_inout);                     result = 1; break;
00203                 case KP2:           handle_transport(SLOW_FWD, 0, use_inout);                             result = 1; break;
00204                 case KP3:           handle_transport(NORMAL_FWD, 0, use_inout);                           result = 1; break;
00205                 case KPENTER:       handle_transport(FAST_FWD, 0, use_inout);                             result = 1; break;
00206                 case KPINS:         handle_transport(STOP, 0, use_inout);                       result = 1; break;
00207                 case ' ':           handle_transport(NORMAL_FWD, 0, use_inout);                 result = 1; break;
00208                 case 'k':           handle_transport(STOP, 0, use_inout);                                         result = 1; break;
00209                 case END:
00210                         subwindow->lock_window("PlayTransport::keypress_event 3");
00211                         goto_end();                                   
00212                         result = 1; 
00213                         subwindow->unlock_window();
00214                         break;
00215                 case HOME:
00216                         subwindow->lock_window("PlayTransport::keypress_event 4");
00217                     goto_start();                                 
00218                         result = 1; 
00219                         subwindow->unlock_window();
00220                         break;
00221         }
00222 
00223         subwindow->lock_window("PlayTransport::keypress_event 5");
00224 
00225         return result;
00226 }
00227 
00228 
00229 void PlayTransport::goto_start()
00230 {
00231         handle_transport(REWIND, 1, 0);
00232 }
00233 
00234 void PlayTransport::goto_end()
00235 {
00236         handle_transport(GOTO_END, 1, 0);
00237 }
00238 
00239 
00240 
00241 void PlayTransport::handle_transport(int command, 
00242         int wait_tracking,
00243         int use_inout)
00244 {
00245         if(!get_edl()) return;
00246 
00247 
00248 
00249 // Dispatch command
00250         switch(command)
00251         {
00252 // Commands that play back
00253                 case FAST_REWIND:
00254                 case NORMAL_REWIND:
00255                 case SLOW_REWIND:
00256                 case SINGLE_FRAME_REWIND:
00257                 case SINGLE_FRAME_FWD:
00258                 case SLOW_FWD:
00259                 case NORMAL_FWD:
00260                 case FAST_FWD:
00261 // Stop
00262                         if(engine->command->command == command && 
00263                                 !engine->command->single_frame())
00264                         {
00265                                 engine->que->send_command(STOP,
00266                                         CHANGE_NONE, 
00267                                         0,
00268                                         0,
00269                                         0,
00270                                         0);
00271                                 engine->interrupt_playback(wait_tracking);
00272                         }
00273                         else
00274 // Resume or change direction
00275                         if(engine->command->command != STOP &&
00276                                 engine->command->command != COMMAND_NONE &&
00277                                 engine->command->command != SINGLE_FRAME_FWD &&
00278                                 engine->command->command != SINGLE_FRAME_REWIND)
00279                         {
00280                                 engine->que->send_command(STOP,
00281                                         CHANGE_NONE, 
00282                                         0,
00283                                         0,
00284                                         0,
00285                                         0);
00286                                 engine->interrupt_playback(wait_tracking);
00287                                 engine->que->send_command(command,
00288                                         CHANGE_NONE, 
00289                                         get_edl(),
00290                                         1,
00291                                         1,
00292                                         use_inout);
00293                         }
00294                         else
00295 // Start from scratch
00296                         {
00297                                 engine->que->send_command(command,
00298                                         CHANGE_NONE, 
00299                                         get_edl(),
00300                                         1,
00301                                         0,
00302                                         use_inout);
00303                         }
00304                         break;
00305 
00306 // Commands that stop
00307                 case STOP:
00308                 case REWIND:
00309                 case GOTO_END:
00310                         engine->que->send_command(STOP,
00311                                 CHANGE_NONE, 
00312                                 0,
00313                                 0,
00314                                 0,
00315                                 0);
00316                         engine->interrupt_playback(wait_tracking);
00317                         break;
00318         }
00319 }
00320 
00321 EDL* PlayTransport::get_edl()
00322 {
00323         return mwindow->edl;
00324 }
00325 
00326 int PlayTransport::pause_transport()
00327 {
00328         if(active_button) active_button->set_mode(PLAY_MODE);
00329         return 0;
00330 }
00331 
00332 
00333 int PlayTransport::reset_transport()
00334 {
00335         fast_reverse->set_mode(PLAY_MODE);
00336         reverse_play->set_mode(PLAY_MODE);
00337         forward_play->set_mode(PLAY_MODE);
00338         frame_reverse_play->set_mode(PLAY_MODE);
00339         frame_forward_play->set_mode(PLAY_MODE);
00340         fast_play->set_mode(PLAY_MODE);
00341         return 0;
00342 }
00343 
00344 PTransportButton::PTransportButton(MWindow *mwindow, PlayTransport *transport, int x, int y, VFrame **data)
00345  : BC_Button(x, y, data)
00346 {
00347         this->mwindow = mwindow;
00348         this->transport = transport;
00349         mode = PLAY_MODE;
00350 }
00351 PTransportButton::~PTransportButton()
00352 {
00353 }
00354 
00355 int PTransportButton::set_mode(int mode)
00356 {
00357         this->mode = mode;
00358         return 0;
00359 }
00360 
00361 
00362 RewindButton::RewindButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
00363  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("rewind"))
00364 {
00365         set_tooltip(_("Rewind ( Home )"));
00366 }
00367 int RewindButton::handle_event()
00368 {
00369 //      unlock_window();
00370         transport->goto_start();
00371 //      lock_window();
00372         return 1;
00373 }
00374 
00375 FastReverseButton::FastReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
00376  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("fastrev")) 
00377 {
00378         set_tooltip(_("Fast reverse ( + )"));
00379 }
00380 int FastReverseButton::handle_event() 
00381 {
00382         unlock_window();
00383         transport->handle_transport(FAST_REWIND, 0, ctrl_down());
00384         lock_window("FastReverseButton::handle_event");
00385         return 1;
00386 }
00387 
00388 // Reverse playback normal speed
00389 
00390 ReverseButton::ReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
00391  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("reverse")) 
00392 {
00393         set_tooltip(_("Normal reverse ( 6 )"));
00394 }
00395 int ReverseButton::handle_event()
00396 {
00397         unlock_window();
00398         transport->handle_transport(NORMAL_REWIND, 0, ctrl_down());
00399         lock_window("ReverseButton::handle_event");
00400         return 1;
00401 }
00402 
00403 // Reverse playback one frame
00404 
00405 FrameReverseButton::FrameReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
00406  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("framerev"))
00407 {
00408         set_tooltip(_("Frame reverse ( 4 )"));
00409 }
00410 int FrameReverseButton::handle_event()
00411 {
00412         unlock_window();
00413         transport->handle_transport(SINGLE_FRAME_REWIND, 0, ctrl_down());
00414         lock_window("FrameReverseButton::handle_event");
00415         return 1;
00416 }
00417 
00418 // forward playback normal speed
00419 
00420 PlayButton::PlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
00421  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("play")) 
00422 {
00423         set_tooltip(_("Normal forward ( 3 )"));
00424 }
00425 int PlayButton::handle_event()
00426 {
00427         unlock_window();
00428         transport->handle_transport(NORMAL_FWD, 0, ctrl_down());
00429         lock_window("PlayButton::handle_event");
00430         return 1;
00431 }
00432 
00433 
00434 
00435 // forward playback one frame
00436 
00437 FramePlayButton::FramePlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
00438  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("framefwd")) 
00439 {
00440         set_tooltip(_("Frame forward ( 1 )"));
00441 }
00442 int FramePlayButton::handle_event()
00443 {
00444         unlock_window();
00445         transport->handle_transport(SINGLE_FRAME_FWD, 0, ctrl_down());
00446         lock_window("FramePlayButton::handle_event");
00447         return 1;
00448 }
00449 
00450 
00451 
00452 FastPlayButton::FastPlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
00453  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("fastfwd")) 
00454 {
00455         set_tooltip(_("Fast forward ( Enter )"));
00456 }
00457 int FastPlayButton::handle_event() 
00458 {
00459         unlock_window();
00460         transport->handle_transport(FAST_FWD, 0, ctrl_down());
00461         lock_window("FastPlayButton::handle_event");
00462         return 1;
00463 }
00464 
00465 EndButton::EndButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
00466  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("end")) 
00467 {
00468         set_tooltip(_("Jump to end ( End )"));
00469 }
00470 int EndButton::handle_event()
00471 {       
00472 //      unlock_window();
00473         transport->goto_end();
00474 //      lock_window();
00475         return 1;
00476 }
00477 
00478 StopButton::StopButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
00479  : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("stop")) 
00480 {
00481         set_tooltip(_("Stop ( 0 )"));
00482 }
00483 int StopButton::handle_event()
00484 {
00485         unlock_window();
00486         transport->handle_transport(STOP, 0, 0);
00487         lock_window("StopButton::handle_event");
00488         return 1;
00489 }

Generated on Sun Jan 8 13:38:58 2006 for Cinelerra-svn by  doxygen 1.4.4