4 #include "playbackengine.h"
5 #include "playtransport.h"
6 #include "preferences.h"
8 #include "transportque.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,
22 this->subwindow = subwindow;
23 this->mwindow = mwindow;
31 PlayTransport::~PlayTransport()
34 delete frame_forward_play;
36 delete frame_reverse_play;
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();
89 void PlayTransport::reposition_buttons(int x, int 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)
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();
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();
166 int PlayTransport::keypress_event()
168 //printf("PlayTransport::keypress_event 1\n");
169 if(subwindow->shift_down()) return 0;
172 //printf("PlayTransport::keypress_event %x\n", subwindow->get_keypress());
173 subwindow->unlock_window();
174 switch(subwindow->get_keypress())
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;
189 subwindow->lock_window();
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);
219 case SINGLE_FRAME_REWIND:
220 case SINGLE_FRAME_FWD:
225 //printf("PlayTransport::handle_transport 3 %d %d\n", engine->command->command, command);
226 if(engine->command->command == command &&
227 !engine->command->single_frame())
229 //printf("PlayTransport::handle_transport 4 %d\n", command);
230 engine->que->send_command(STOP,
234 engine->interrupt_playback(wait_tracking);
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)
243 //printf("PlayTransport::handle_transport 5 %d\n", command);
244 engine->que->send_command(STOP,
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,
256 //printf("PlayTransport::handle_transport 5\n");
259 // Start from scratch
261 //printf("PlayTransport::handle_transport 6 %d\n", command);
262 engine->que->send_command(command,
273 //printf("PlayTransport 1\n");
274 engine->que->send_command(STOP,
278 //printf("PlayTransport 1\n");
279 engine->interrupt_playback(wait_tracking);
280 //printf("PlayTransport 2\n");
285 EDL* PlayTransport::get_edl()
290 int PlayTransport::pause_transport()
292 if(active_button) active_button->set_mode(PLAY_MODE);
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);
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;
315 PTransportButton::~PTransportButton()
319 int PTransportButton::set_mode(int mode)
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()
334 transport->goto_start();
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()
347 transport->handle_transport(FAST_REWIND);
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()
362 transport->handle_transport(NORMAL_REWIND);
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()
377 transport->handle_transport(SINGLE_FRAME_REWIND);
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");
393 transport->handle_transport(NORMAL_FWD);
395 //printf("PlayButton::handle_event 2\n");
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()
411 transport->handle_transport(SINGLE_FRAME_FWD);
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()
426 transport->handle_transport(FAST_FWD);
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()
439 transport->goto_end();
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");
453 //printf("StopButton::handle_event 1\n");
454 transport->handle_transport(STOP);
455 //printf("StopButton::handle_event 1\n");
457 //printf("StopButton::handle_event 2\n");