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