4 #include "localsession.h"
6 #include "playbackengine.h"
7 #include "playtransport.h"
8 #include "preferences.h"
10 #include "transportque.h"
12 #include "localsession.h"
16 PlayTransport::PlayTransport(MWindow *mwindow,
17 BC_WindowBase *subwindow,
21 this->subwindow = subwindow;
22 this->mwindow = mwindow;
30 PlayTransport::~PlayTransport()
33 delete frame_forward_play;
35 delete frame_reverse_play;
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();
87 void PlayTransport::reposition_buttons(int x, int 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)
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();
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();
164 int PlayTransport::keypress_event()
167 if(subwindow->shift_down())
169 switch(subwindow->get_keypress())
172 subwindow->lock_window("PlayTransport::keypress_event 1");
175 subwindow->unlock_window();
178 subwindow->lock_window("PlayTransport::keypress_event 2");
181 subwindow->unlock_window();
187 // Set playback range to in/out points if CTRL is down
189 if(subwindow->ctrl_down())
193 subwindow->unlock_window();
196 switch(subwindow->get_keypress())
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;
210 subwindow->lock_window("PlayTransport::keypress_event 3");
213 subwindow->unlock_window();
216 subwindow->lock_window("PlayTransport::keypress_event 4");
219 subwindow->unlock_window();
223 subwindow->lock_window("PlayTransport::keypress_event 5");
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,
246 if(!get_edl()) return;
248 // Stop requires transferring the output buffer to a refresh buffer.
250 //printf("PlayTransport::handle_transport 1 %d\n", command);
251 int prev_command = engine->command->command;
252 int prev_direction = engine->command->get_direction();
253 int prev_single_frame = engine->command->single_frame();
258 // Commands that play back
262 case SINGLE_FRAME_REWIND:
263 case SINGLE_FRAME_FWD:
267 // Same direction pressed twice. Stop
268 if(prev_command == command &&
274 // Resume or change direction
275 if(prev_command != STOP &&
276 prev_command != COMMAND_NONE &&
277 prev_command != SINGLE_FRAME_FWD &&
278 prev_command != SINGLE_FRAME_REWIND)
280 engine->que->send_command(STOP,
286 engine->interrupt_playback(wait_tracking);
287 engine->que->send_command(command,
295 // Start from scratch
297 engine->que->send_command(command,
306 // Commands that stop
313 engine->que->send_command(STOP,
319 engine->interrupt_playback(wait_tracking);
325 engine->que->send_command(STOP,
331 engine->interrupt_playback(wait_tracking);
332 // This is necessary to get an OpenGL output buffer
333 // printf("PlayTransport::handle_transport 2 update_refresh=%d prev_command=%d prev_direction=%d\n",
334 // update_refresh, prev_command, prev_direction);
335 if(!prev_single_frame &&
337 prev_command != STOP &&
338 prev_command != COMMAND_NONE)
340 engine->que->send_command(
341 (prev_direction == PLAY_FORWARD) ? SINGLE_FRAME_REWIND : SINGLE_FRAME_FWD,
351 EDL* PlayTransport::get_edl()
356 int PlayTransport::pause_transport()
358 if(active_button) active_button->set_mode(PLAY_MODE);
363 int PlayTransport::reset_transport()
365 fast_reverse->set_mode(PLAY_MODE);
366 reverse_play->set_mode(PLAY_MODE);
367 forward_play->set_mode(PLAY_MODE);
368 frame_reverse_play->set_mode(PLAY_MODE);
369 frame_forward_play->set_mode(PLAY_MODE);
370 fast_play->set_mode(PLAY_MODE);
374 PTransportButton::PTransportButton(MWindow *mwindow, PlayTransport *transport, int x, int y, VFrame **data)
375 : BC_Button(x, y, data)
377 this->mwindow = mwindow;
378 this->transport = transport;
381 PTransportButton::~PTransportButton()
385 int PTransportButton::set_mode(int mode)
392 RewindButton::RewindButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
393 : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("rewind"))
395 set_tooltip(_("Rewind ( Home )"));
397 int RewindButton::handle_event()
400 transport->goto_start();
405 FastReverseButton::FastReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
406 : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("fastrev"))
408 set_tooltip(_("Fast reverse ( + )"));
410 int FastReverseButton::handle_event()
413 transport->handle_transport(FAST_REWIND, 0, ctrl_down());
414 lock_window("FastReverseButton::handle_event");
418 // Reverse playback normal speed
420 ReverseButton::ReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
421 : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("reverse"))
423 set_tooltip(_("Normal reverse ( 6 )"));
425 int ReverseButton::handle_event()
428 transport->handle_transport(NORMAL_REWIND, 0, ctrl_down());
429 lock_window("ReverseButton::handle_event");
433 // Reverse playback one frame
435 FrameReverseButton::FrameReverseButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
436 : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("framerev"))
438 set_tooltip(_("Frame reverse ( 4 )"));
440 int FrameReverseButton::handle_event()
443 transport->handle_transport(SINGLE_FRAME_REWIND, 0, ctrl_down());
444 lock_window("FrameReverseButton::handle_event");
448 // forward playback normal speed
450 PlayButton::PlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
451 : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("play"))
453 set_tooltip(_("Normal forward ( 3 )"));
455 int PlayButton::handle_event()
458 transport->handle_transport(NORMAL_FWD, 0, ctrl_down());
459 lock_window("PlayButton::handle_event");
465 // forward playback one frame
467 FramePlayButton::FramePlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
468 : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("framefwd"))
470 set_tooltip(_("Frame forward ( 1 )"));
472 int FramePlayButton::handle_event()
475 transport->handle_transport(SINGLE_FRAME_FWD, 0, ctrl_down());
476 lock_window("FramePlayButton::handle_event");
482 FastPlayButton::FastPlayButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
483 : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("fastfwd"))
485 set_tooltip(_("Fast forward ( Enter )"));
487 int FastPlayButton::handle_event()
490 transport->handle_transport(FAST_FWD, 0, ctrl_down());
491 lock_window("FastPlayButton::handle_event");
495 EndButton::EndButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
496 : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("end"))
498 set_tooltip(_("Jump to end ( End )"));
500 int EndButton::handle_event()
503 transport->goto_end();
508 StopButton::StopButton(MWindow *mwindow, PlayTransport *transport, int x, int y)
509 : PTransportButton(mwindow, transport, x, y, mwindow->theme->get_image_set("stop"))
511 set_tooltip(_("Stop ( 0 )"));
513 int StopButton::handle_event()
516 transport->handle_transport(STOP, 0, 0);
517 lock_window("StopButton::handle_event");
523 // c-file-style: "linux"