initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / avc1394transport.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22 #include "avc1394transport.h"
23 #include "bcsignals.h"
24 #include "keys.h"
25 #include "language.h"
26 #include "recordmonitor.h"
27
28 #include <unistd.h>
29
30 #define POLL_INTERVAL 20000
31
32 AVC1394TransportThread::AVC1394TransportThread(BC_Title *label, 
33         AVC1394Control *avc)
34  : Thread(1, 0, 0)
35 {
36         this->label = label;
37         this->avc = avc;
38         done = 0;
39 }
40
41 AVC1394TransportThread::~AVC1394TransportThread()
42 {
43         done = 1;
44         cancel();
45         join();
46 }
47
48 void AVC1394TransportThread::run()
49 {
50         char *text;
51         sleep(5);
52         while(!done)
53         {
54                 Thread::disable_cancel();
55                 text = avc->timecode();
56                 label->lock_window("AVC1394TransportThread::run 1");
57 // Sometimes text is set to NULL for some reason...
58                 if(text == NULL)
59                         label->update("Unknown");
60                 else
61                         label->update(text);
62                 label->unlock_window();
63                 Thread::enable_cancel();
64                 usleep(POLL_INTERVAL);
65         }
66 }
67
68
69
70
71
72
73
74 AVC1394Transport::AVC1394Transport(MWindow *mwindow,
75                 AVC1394Control *avc,
76                 BC_WindowBase *window,
77                 int x,
78                 int y)
79 {
80         this->mwindow = mwindow;
81         this->avc = avc;
82         this->window = window;
83         this->x = x;
84         this->y = y;
85 }
86
87 AVC1394Transport::~AVC1394Transport()
88 {
89
90 }
91
92 void AVC1394Transport::create_objects()
93 {
94         int x = this->x, y = this->y;
95
96         window->add_subwindow(start_button = new AVC1394GUISeekStart(mwindow, avc, x, y));
97         x += start_button->get_w();
98         window->add_subwindow(rewind_button = new AVC1394GUIRewind(mwindow, avc, x, y));
99         x += rewind_button->get_w();
100         window->add_subwindow(reverse_button = new  AVC1394GUIReverse(mwindow, avc, x, y));
101         x += reverse_button->get_w();
102         window->add_subwindow(stop_button = new  AVC1394GUIStop(mwindow, avc, x, y));
103     x += stop_button->get_w();
104         window->add_subwindow(pause_button = new AVC1394GUIPause(mwindow, avc, x, y));
105         x += pause_button->get_w();
106         window->add_subwindow(play_button = new  AVC1394GUIPlay(mwindow, avc, x, y));
107     x += play_button->get_w();
108         window->add_subwindow(fforward_button = new  AVC1394GUIFForward(mwindow, avc, x, y));
109         x += fforward_button->get_w();
110         window->add_subwindow(end_button = new AVC1394GUISeekEnd(mwindow, avc, x, y));
111         x += end_button->get_w();
112
113         x_end = x + 10;
114
115 }
116
117 int AVC1394Transport::keypress_event(int keypress)
118 {
119         switch(keypress)
120         {
121                 case ' ':
122                         if(avc->current_command == PAUSE)
123                         {
124                                 avc->current_command = NORMAL_FWD;
125                                 avc->play();
126                         }
127                         else
128                         {
129                                 avc->current_command = PAUSE;
130                                 avc->pause();
131                         }
132                         break;
133         }
134         return 0;
135 }
136
137 void AVC1394Transport::reposition_window(int x, int y)
138 {
139         this->x = x;
140         this->y = y;
141
142         start_button->reposition_window(x, y);
143         x += start_button->get_w();
144         rewind_button->reposition_window(x, y);
145    x += rewind_button->get_w();
146         reverse_button->reposition_window(x, y);
147    x += reverse_button->get_w();
148         stop_button->reposition_window(x, y);
149    x += stop_button->get_w();
150         pause_button->reposition_window(x, y);
151         x += pause_button->get_w();
152         play_button->reposition_window(x, y);
153    x += play_button->get_w();
154         fforward_button->reposition_window(x, y);
155         x += fforward_button->get_w();
156         end_button->reposition_window(x, y);
157
158         x_end = x + 10;
159 }
160
161
162
163
164
165
166
167
168
169
170 AVC1394GUISeekStart::AVC1394GUISeekStart(MWindow *mwindow, AVC1394Control *avc, int x, int y)
171  : BC_Button(x, y, mwindow->theme->get_image_set("rewind"))
172 {
173    this->avc = avc;
174    set_tooltip(_("Rewind ( Home )"));
175 }
176
177 AVC1394GUISeekStart::~AVC1394GUISeekStart()
178 {
179 }
180
181 int AVC1394GUISeekStart::handle_event()
182 {
183         avc->current_command = COMMAND_NONE;
184     avc->seek("00:00:00:00");
185     return 1;
186 }
187
188 int  AVC1394GUISeekStart::keypress_event()
189 {
190         if(get_keypress() == HOME) return handle_event();
191         return 0;
192 }
193
194
195 AVC1394GUIRewind::AVC1394GUIRewind(MWindow *mwindow, AVC1394Control *avc, int x, int y)
196  : BC_Button(x, y, mwindow->theme->get_image_set("fastrev"))
197 {
198         this->avc = avc;
199         set_tooltip(_("Fast Reverse ( + )"));
200 }
201
202 AVC1394GUIRewind::~AVC1394GUIRewind()
203 {
204 }
205
206 int AVC1394GUIRewind::handle_event()
207 {
208         avc->current_command = FAST_REWIND;
209         avc->rewind();
210         return 1;
211 }
212
213 int  AVC1394GUIRewind::keypress_event()
214 {
215         if(get_keypress() == KPPLUS) return handle_event();
216         return 0;
217 }
218
219 AVC1394GUIReverse::AVC1394GUIReverse(MWindow *mwindow, AVC1394Control *avc, int x, int y)
220  : BC_Button(x, y, mwindow->theme->get_image_set("reverse"))
221 {
222         this->avc = avc;
223         set_tooltip(_("Reverse Play ( 6 )"));
224 }
225
226 AVC1394GUIReverse::~AVC1394GUIReverse()
227 {
228 }
229
230 int AVC1394GUIReverse::handle_event()
231 {
232         if(avc->current_command == NORMAL_REWIND)
233         {
234                 avc->current_command = PAUSE;
235                 avc->pause();
236         }
237         else
238         {
239                 avc->current_command = NORMAL_REWIND;
240                 avc->reverse();
241         }
242         return 1;
243 }
244
245 int AVC1394GUIReverse::keypress_event()
246 {
247         if(get_keypress() == KP6) return handle_event();
248         return 0;
249 }
250
251 AVC1394GUIStop::AVC1394GUIStop(MWindow *mwindow, AVC1394Control *avc, int x, int y)
252  : BC_Button(x, y, mwindow->theme->get_image_set("stop"))
253 {
254         this->avc = avc;
255         set_tooltip(_("Stop ( 0 )"));
256 }
257
258 AVC1394GUIStop::~AVC1394GUIStop()
259 {
260 }
261
262 int AVC1394GUIStop::handle_event()
263 {
264         avc->current_command = COMMAND_NONE;
265         avc->stop();
266         return 1;
267 }
268
269 int AVC1394GUIStop::keypress_event()
270 {
271         if(get_keypress() == KPINS) return handle_event();
272         return 0;
273 }
274
275 AVC1394GUIPlay::AVC1394GUIPlay(MWindow *mwindow, AVC1394Control *avc, int x, int y)
276  : BC_Button(x, y, mwindow->theme->get_image_set("play"))
277 {
278         this->avc = avc;
279         mode = 0;
280         set_tooltip(_("Play ( 3 )"));
281 }
282
283 AVC1394GUIPlay::~AVC1394GUIPlay()
284 {
285 }
286
287 int AVC1394GUIPlay::handle_event()
288 {
289         if(avc->current_command == NORMAL_FWD)
290         {
291                 avc->current_command = PAUSE;
292                 avc->pause();
293         }
294         else
295         {
296                 avc->current_command = NORMAL_FWD;
297                 avc->play();
298         }
299         return 1;
300 }
301
302 int AVC1394GUIPlay::keypress_event()
303 {
304         if(get_keypress() == KP3) return handle_event();
305         return 0;
306 }
307
308 AVC1394GUIPause::AVC1394GUIPause(MWindow *mwindow, AVC1394Control *avc, int x,
309 int y)
310  : BC_Button(x, y, mwindow->theme->get_image_set("pause"))
311 {
312         this->avc = avc;
313         set_tooltip(_("Pause"));
314 }
315
316 AVC1394GUIPause::~AVC1394GUIPause()
317 {
318 }
319
320 int AVC1394GUIPause::handle_event()
321 {
322         avc->current_command = PAUSE;
323     avc->pause();
324     return 1;
325 }
326
327 int AVC1394GUIPause::keypress_event()
328 {
329     return 0;
330 }
331
332 AVC1394GUIFForward::AVC1394GUIFForward(MWindow *mwindow, AVC1394Control *avc, int x, int y)
333  : BC_Button(x, y, mwindow->theme->get_image_set("fastfwd"))
334 {
335    this->avc = avc;
336    set_tooltip(_("Fast Forward ( Enter )"));
337 }
338
339 AVC1394GUIFForward::~AVC1394GUIFForward()
340 {
341 }
342
343 int AVC1394GUIFForward::handle_event()
344 {
345         avc->current_command = FAST_FWD;
346     avc->fforward();
347     return 1;
348 }
349
350 int AVC1394GUIFForward::keypress_event()
351 {
352         if(get_keypress() == KPENTER) return handle_event();
353     return 0;
354 }
355
356
357 AVC1394GUISeekEnd::AVC1394GUISeekEnd(MWindow *mwindow, 
358         AVC1394Control *avc, 
359         int x, 
360         int y)
361  : BC_Button(x, y, mwindow->theme->get_image_set("end"))
362 {
363    this->avc = avc;
364    set_tooltip(_("Jump to end ( End )"));
365 }
366
367 AVC1394GUISeekEnd::~AVC1394GUISeekEnd()
368 {
369 }
370
371 int AVC1394GUISeekEnd::handle_event()
372 {
373    avc->current_command = COMMAND_NONE;
374    avc->seek("ff:ff:ff:ff");
375    return 1;
376 }
377
378 int AVC1394GUISeekEnd::keypress_event()
379 {
380         if(get_keypress() == END) return handle_event();
381      return 0;
382 }
383