r632: Boost up the requirement for mjpegtools to 1.6.3
[cinelerra_cv/mob.git] / cinelerra / vdeviceprefs.C
blobe4095d1de2fadca7cc7b7d8a049b55716526a87d
1 #include "channelpicker.h"
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
5 #include "edl.h"
6 #include "edlsession.h"
7 #include "language.h"
8 #include "mwindow.h"
9 #include "vdeviceprefs.h"
10 #include "videoconfig.h"
11 #include "videodevice.inc"
12 #include "playbackconfig.h"
13 #include "preferences.h"
14 #include "preferencesthread.h"
15 #include "recordconfig.h"
16 #include <string.h>
19 VDevicePrefs::VDevicePrefs(int x, 
20         int y, 
21         PreferencesWindow *pwindow, 
22         PreferencesDialog *dialog, 
23         VideoOutConfig *out_config,
24         VideoInConfig *in_config,
25         int mode)
27         this->pwindow = pwindow;
28         this->dialog = dialog;
29         this->driver = -1;
30         this->mode = mode;
31         this->out_config = out_config;
32         this->in_config = in_config;
33         this->x = x;
34         this->y = y;
35         menu = 0;
36         reset_objects();
40 VDevicePrefs::~VDevicePrefs()
42         delete_objects();
43         if(menu) delete menu;
47 void VDevicePrefs::reset_objects()
49         device_text = 0;
51         port_title = 0;
52         channel_title = 0;
53         device_title = 0;
54         syt_title = 0;
56         firewire_port = 0;
57         firewire_channel = 0;
58         firewire_channels = 0;
59         firewire_syt = 0;
60         firewire_path = 0;
63 int VDevicePrefs::initialize()
65         int *driver = 0;
66         delete_objects();
68         switch(mode)
69         {
70                 case MODEPLAY:
71                         driver = &out_config->driver;
72                         break;
74                 case MODERECORD:
75                         driver = &in_config->driver;
76                         break;
77         }
78         this->driver = *driver;
80         if(!menu)
81         {
82                 dialog->add_subwindow(menu = new VDriverMenu(x,
83                         y + 10,
84                         this, 
85                         (mode == MODERECORD), 
86                         driver));
87                 menu->create_objects();
88         }
90         switch(this->driver)
91         {
92                 case VIDEO4LINUX:
93                         create_v4l_objs();
94                         break;
95                 case VIDEO4LINUX2:
96                         create_v4l2_objs();
97                         break;
98                 case VIDEO4LINUX2JPEG:
99                         create_v4l2jpeg_objs();
100                         break;
101                 case SCREENCAPTURE:
102                         create_screencap_objs();
103                         break;
104                 case CAPTURE_LML:
105                         create_lml_objs();
106                         break;
107                 case CAPTURE_BUZ:
108                 case PLAYBACK_BUZ:
109                         create_buz_objs();
110                         break;
111                 case PLAYBACK_X11:
112                 case PLAYBACK_X11_XV:
113                         create_x11_objs();
114                         break;
115                 case PLAYBACK_DV1394:
116                 case PLAYBACK_FIREWIRE:
117                 case CAPTURE_FIREWIRE:
118                         create_firewire_objs();
119                         break;
120         }
121         return 0;
124 int VDevicePrefs::delete_objects()
126         switch(driver)
127         {
128                 case PLAYBACK_LML:
129                 case PLAYBACK_BUZ:
130                         delete output_title;
131                         delete channel_picker;
132                         delete buz_swap_channels;
133                         break;
134         }
137         
138         if(device_text) delete device_text;
140         if(port_title) delete port_title;
141         if(firewire_port) delete firewire_port;
142         if(channel_title) delete channel_title;
143         if(firewire_channel) delete firewire_channel;
144         if(device_title) delete device_title;
145         if(firewire_path) delete firewire_path;
146         if(syt_title) delete syt_title;
147         if(firewire_syt) delete firewire_syt;
149         reset_objects();
150         driver = -1;
151         return 0;
154 int VDevicePrefs::create_lml_objs()
156         char *output_char;
157         int x1 = x + menu->get_w() + 5;
159         switch(mode)
160         {
161                 case MODEPLAY: 
162                         output_char = out_config->lml_out_device;
163                         break;
164                 case MODERECORD:
165                         output_char = in_config->lml_in_device;
166                         break;
167         }
168         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, BLACK));
169         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
170         return 0;
173 int VDevicePrefs::create_buz_objs()
175         char *output_char;
176         int x1 = x + menu->get_w() + 5;
177         int x2 = x1 + 210;
178         int y1 = y;
180         switch(mode)
181         {
182                 case MODEPLAY: 
183                         output_char = out_config->buz_out_device;
184                         break;
185                 case MODERECORD:
186                         output_char = in_config->buz_in_device;
187                         break;
188         }
189         dialog->add_subwindow(device_title = new BC_Title(x1, y1, _("Device path:"), MEDIUMFONT, BLACK));
191         y1 += 20;
192         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
194         if(driver == PLAYBACK_BUZ)
195         {
196                 dialog->add_subwindow(buz_swap_channels = 
197                         new VDeviceCheckBox(x2, y1, &out_config->buz_swap_fields, _("Swap fields")));
198         }
199         y1 += 30;
200         if(driver == PLAYBACK_BUZ)
201         {
202                 dialog->add_subwindow(output_title = new BC_Title(x1, y1, _("Output channel:")));
203                 y1 += 20;
204                 channel_picker = new PrefsChannelPicker(pwindow->mwindow, 
205                         this, 
206                         pwindow->mwindow->channeldb_buz, 
207                         x1,
208                         y1);
209                 channel_picker->create_objects();
210         }
211         return 0;
214 int VDevicePrefs::create_firewire_objs()
216         int *output_int;
217         char *output_char;
218         int x1 = x + menu->get_w() + 5;
220 // Firewire path
221         switch(mode)
222         {
223                 case MODEPLAY:
224                         if(driver == PLAYBACK_DV1394)
225                                 output_char = out_config->dv1394_path;
226                         else
227                                 output_char = out_config->firewire_path;
228                         break;
229                 case MODERECORD:
230 // Our version of raw1394 doesn't support changing the input path
231                         output_char = 0;
232                         break;
233         }
235         if(output_char)
236         {
237                 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, BLACK));
238                 dialog->add_subwindow(firewire_path = new VDeviceTextBox(x1, y + 20, output_char));
239                 x1 += firewire_path->get_w() + 5;
240         }
242 // Firewire port
243         switch(mode)
244         {
245                 case MODEPLAY:
246                         if(driver == PLAYBACK_DV1394)
247                                 output_int = &out_config->dv1394_port;
248                         else
249                                 output_int = &out_config->firewire_port;
250                         break;
251                 case MODERECORD:
252                         output_int = &in_config->firewire_port;
253                         break;
254         }
255         dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, BLACK));
256         dialog->add_subwindow(firewire_port = new VDeviceIntBox(x1, y + 20, output_int));
257         x1 += firewire_port->get_w() + 5;
259 // Firewire channel
260         switch(mode)
261         {
262                 case MODEPLAY:
263                         if(driver == PLAYBACK_DV1394)
264                                 output_int = &out_config->dv1394_channel;
265                         else
266                                 output_int = &out_config->firewire_channel;
267                         break;
268                 case MODERECORD:
269                         output_int = &in_config->firewire_channel;
270                         break;
271         }
273         dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, BLACK));
274         dialog->add_subwindow(firewire_channel = new VDeviceIntBox(x1, y + 20, output_int));
275         x1 += firewire_channel->get_w() + 5;
278 // Firewire syt
279         switch(mode)
280         {
281                 case MODEPLAY:
282                         if(driver == PLAYBACK_DV1394)
283                                 output_int = &out_config->dv1394_syt;
284                         else
285                                 output_int = &out_config->firewire_syt;
286                         break;
287                 case MODERECORD:
288                         output_int = 0;
289                         break;
290         }
291         if(output_int)
292         {
293                 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, BLACK));
294                 dialog->add_subwindow(firewire_syt = new VDeviceIntBox(x1, y + 20, output_int));
295         }
297         return 0;
300 int VDevicePrefs::create_v4l_objs()
302         char *output_char;
303         int x1 = x + menu->get_w() + 5;
304         output_char = pwindow->thread->edl->session->vconfig_in->v4l_in_device;
305         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, BLACK));
306         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
307         return 0;
310 int VDevicePrefs::create_v4l2_objs()
312         char *output_char;
313         int x1 = x + menu->get_w() + 5;
314         output_char = pwindow->thread->edl->session->vconfig_in->v4l2_in_device;
315         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, BLACK));
316         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
317         return 0;
320 int VDevicePrefs::create_v4l2jpeg_objs()
322         char *output_char;
323         int x1 = x + menu->get_w() + 5;
324         output_char = pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_device;
325         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, BLACK));
326         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
327         return 0;
332 int VDevicePrefs::create_screencap_objs()
334         char *output_char;
335         int x1 = x + menu->get_w() + 5;
336         output_char = pwindow->thread->edl->session->vconfig_in->screencapture_display;
337         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Display:"), MEDIUMFONT, BLACK));
338         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
339         return 0;
342 int VDevicePrefs::create_x11_objs()
344         char *output_char;
345         int x1 = x + menu->get_w() + 5;
346         output_char = out_config->x11_host;
347         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Display for compositor:"), MEDIUMFONT, BLACK));
348         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
349         return 0;
355 VDriverMenu::VDriverMenu(int x, 
356         int y, 
357         VDevicePrefs *device_prefs, 
358         int do_input, 
359         int *output)
360  : BC_PopupMenu(x, y, 200, driver_to_string(*output))
362         this->output = output;
363         this->do_input = do_input;
364         this->device_prefs = device_prefs;
367 VDriverMenu::~VDriverMenu()
371 char* VDriverMenu::driver_to_string(int driver)
373         switch(driver)
374         {
375                 case VIDEO4LINUX:
376                         sprintf(string, VIDEO4LINUX_TITLE);
377                         break;
378                 case VIDEO4LINUX2:
379                         sprintf(string, VIDEO4LINUX2_TITLE);
380                         break;
381                 case VIDEO4LINUX2JPEG:
382                         sprintf(string, VIDEO4LINUX2JPEG_TITLE);
383                         break;
384                 case SCREENCAPTURE:
385                         sprintf(string, SCREENCAPTURE_TITLE);
386                         break;
387                 case CAPTURE_BUZ:
388                         sprintf(string, CAPTURE_BUZ_TITLE);
389                         break;
390                 case CAPTURE_LML:
391                         sprintf(string, CAPTURE_LML_TITLE);
392                         break;
393                 case CAPTURE_FIREWIRE:
394                         sprintf(string, CAPTURE_FIREWIRE_TITLE);
395                         break;
396                 case PLAYBACK_X11:
397                         sprintf(string, PLAYBACK_X11_TITLE);
398                         break;
399                 case PLAYBACK_X11_XV:
400                         sprintf(string, PLAYBACK_X11_XV_TITLE);
401                         break;
402                 case PLAYBACK_LML:
403                         sprintf(string, PLAYBACK_LML_TITLE);
404                         break;
405                 case PLAYBACK_BUZ:
406                         sprintf(string, PLAYBACK_BUZ_TITLE);
407                         break;
408                 case PLAYBACK_FIREWIRE:
409                         sprintf(string, PLAYBACK_FIREWIRE_TITLE);
410                         break;
411                 case PLAYBACK_DV1394:
412                         sprintf(string, PLAYBACK_DV1394_TITLE);
413                         break;
414                 default:
415                         sprintf(string, "");
416         }
417         return string;
420 int VDriverMenu::create_objects()
422         if(do_input)
423         {
424                 add_item(new VDriverItem(this, VIDEO4LINUX_TITLE, VIDEO4LINUX));
425 #ifdef HAVE_VIDEO4LINUX2
426                 add_item(new VDriverItem(this, VIDEO4LINUX2_TITLE, VIDEO4LINUX2));
427                 add_item(new VDriverItem(this, VIDEO4LINUX2JPEG_TITLE, VIDEO4LINUX2JPEG));
428 #endif
429                 add_item(new VDriverItem(this, SCREENCAPTURE_TITLE, SCREENCAPTURE));
430                 add_item(new VDriverItem(this, CAPTURE_BUZ_TITLE, CAPTURE_BUZ));
431                 add_item(new VDriverItem(this, CAPTURE_FIREWIRE_TITLE, CAPTURE_FIREWIRE));
432         }
433         else
434         {
435                 add_item(new VDriverItem(this, PLAYBACK_X11_TITLE, PLAYBACK_X11));
436                 add_item(new VDriverItem(this, PLAYBACK_X11_XV_TITLE, PLAYBACK_X11_XV));
437                 add_item(new VDriverItem(this, PLAYBACK_BUZ_TITLE, PLAYBACK_BUZ));
438                 add_item(new VDriverItem(this, PLAYBACK_FIREWIRE_TITLE, PLAYBACK_FIREWIRE));
439                 add_item(new VDriverItem(this, PLAYBACK_DV1394_TITLE, PLAYBACK_DV1394));
440         }
441         return 0;
445 VDriverItem::VDriverItem(VDriverMenu *popup, char *text, int driver)
446  : BC_MenuItem(text)
448         this->popup = popup;
449         this->driver = driver;
452 VDriverItem::~VDriverItem()
456 int VDriverItem::handle_event()
458         popup->set_text(get_text());
459         *(popup->output) = driver;
460         popup->device_prefs->initialize();
461         return 1;
467 VDeviceTextBox::VDeviceTextBox(int x, int y, char *output)
468  : BC_TextBox(x, y, 200, 1, output)
470         this->output = output; 
473 int VDeviceTextBox::handle_event() 
475         strcpy(output, get_text()); 
478 VDeviceIntBox::VDeviceIntBox(int x, int y, int *output)
479  : BC_TextBox(x, y, 60, 1, *output)
481         this->output = output; 
484 int VDeviceIntBox::handle_event() 
486         *output = atol(get_text()); 
487         return 1;
492 VDeviceCheckBox::VDeviceCheckBox(int x, int y, int *output, char *text)
493  : BC_CheckBox(x, y, *output, text)
495         this->output = output;
497 int VDeviceCheckBox::handle_event()
499         *output = get_value();
500         return 1;