r870: Merge 2.1:
[cinelerra_cv.git] / cinelerra / vdeviceprefs.C
blob197cbe110af8aa534f1e65847b56e3e1e9decfee
1 #include "bcsignals.h"
2 #include "channeldb.h"
3 #include "channelpicker.h"
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
6 #endif
7 #include "edl.h"
8 #include "edlsession.h"
9 #include "formattools.h"
10 #include "language.h"
11 #include "mwindow.h"
12 #include "vdeviceprefs.h"
13 #include "videoconfig.h"
14 #include "videodevice.inc"
15 #include "playbackconfig.h"
16 #include "preferences.h"
17 #include "preferencesthread.h"
18 #include "recordconfig.h"
19 #include "recordprefs.h"
20 #include <string.h>
23 VDevicePrefs::VDevicePrefs(int x, 
24         int y, 
25         PreferencesWindow *pwindow, 
26         PreferencesDialog *dialog, 
27         VideoOutConfig *out_config,
28         VideoInConfig *in_config,
29         int mode)
31         this->pwindow = pwindow;
32         this->dialog = dialog;
33         this->driver = -1;
34         this->mode = mode;
35         this->out_config = out_config;
36         this->in_config = in_config;
37         this->x = x;
38         this->y = y;
39         menu = 0;
40         reset_objects();
44 VDevicePrefs::~VDevicePrefs()
46         delete_objects();
47         if(menu) delete menu;
48         pwindow->mwindow->channeldb_buz->save("channeldb_buz");
52 void VDevicePrefs::reset_objects()
54         device_title = 0;
55         device_text = 0;
57         port_title = 0;
58         device_port = 0;
60         number_title = 0;
61         device_number = 0;
62         
64         channel_title = 0;
65         syt_title = 0;
67         firewire_port = 0;
68         firewire_channel = 0;
69         firewire_channels = 0;
70         firewire_syt = 0;
71         firewire_path = 0;
73         buz_swap_channels = 0;
74         output_title = 0;
75         channel_picker = 0;
78 int VDevicePrefs::initialize(int creation)
80         int *driver = 0;
81         delete_objects();
83         switch(mode)
84         {
85                 case MODEPLAY:
86                         driver = &out_config->driver;
87                         break;
89                 case MODERECORD:
90                         driver = &in_config->driver;
91                         break;
92         }
93         this->driver = *driver;
95         if(!menu)
96         {
97                 dialog->add_subwindow(menu = new VDriverMenu(x,
98                         y + 10,
99                         this, 
100                         (mode == MODERECORD), 
101                         driver));
102                 menu->create_objects();
103         }
105         switch(this->driver)
106         {
107                 case VIDEO4LINUX:
108                         create_v4l_objs();
109                         break;
110                 case VIDEO4LINUX2:
111                         create_v4l2_objs();
112                         break;
113                 case VIDEO4LINUX2JPEG:
114                         create_v4l2jpeg_objs();
115                         break;
116                 case SCREENCAPTURE:
117                         create_screencap_objs();
118                         break;
119                 case CAPTURE_LML:
120                         create_lml_objs();
121                         break;
122                 case CAPTURE_BUZ:
123                 case PLAYBACK_BUZ:
124                         create_buz_objs();
125                         break;
126                 case PLAYBACK_X11:
127                 case PLAYBACK_X11_XV:
128                 case PLAYBACK_X11_GL:
129                         create_x11_objs();
130                         break;
131                 case PLAYBACK_DV1394:
132                 case PLAYBACK_FIREWIRE:
133                 case PLAYBACK_IEC61883:
134                 case CAPTURE_FIREWIRE:
135                 case CAPTURE_IEC61883:
136                         create_firewire_objs();
137                         break;
138                 case CAPTURE_DVB:
139                         create_dvb_objs();
140                         break;
141         }
145 // Update driver dependancies in file format
146         if(mode == MODERECORD && dialog && !creation)
147         {
148                 RecordPrefs *record_prefs = (RecordPrefs*)dialog;
149                 record_prefs->recording_format->update_driver(this->driver);
150         }
152         return 0;
155 int VDevicePrefs::delete_objects()
157 SET_TRACE
158         delete output_title;
159 SET_TRACE
160         delete channel_picker;
161 SET_TRACE
162         delete buz_swap_channels;
163 SET_TRACE
164         delete device_title;
165         delete device_text;
167         delete port_title;
168         delete device_port;
170         delete number_title;
171         delete device_number;
173 SET_TRACE
174 SET_TRACE
175         if(firewire_port) delete firewire_port;
176 SET_TRACE
177         if(channel_title) delete channel_title;
178 SET_TRACE
179         if(firewire_channel) delete firewire_channel;
180 SET_TRACE
181 SET_TRACE
182         if(firewire_path) delete firewire_path;
183 SET_TRACE
184         if(syt_title) delete syt_title;
185 SET_TRACE
186         if(firewire_syt) delete firewire_syt;
188 SET_TRACE
189         reset_objects();
190         driver = -1;
191         return 0;
194 int VDevicePrefs::create_dvb_objs()
196         int x1 = x + menu->get_w() + 5;
197         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Host:")));
198         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, in_config->dvb_in_host));
199         x1 += device_text->get_w() + 10;
200         dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:")));
201         device_port = new VDeviceTumbleBox(this, x1, y + 20,  &in_config->dvb_in_port, 1, 65536);
202         device_port->create_objects();
203         x1 += device_port->get_w() + 10;
204         dialog->add_subwindow(number_title = new BC_Title(x1, y, _("Adaptor:")));
205         device_number = new VDeviceTumbleBox(this, x1, y + 20,  &in_config->dvb_in_number, 0, 16);
206         device_number->create_objects();
209 int VDevicePrefs::create_lml_objs()
211         char *output_char;
212         int x1 = x + menu->get_w() + 5;
213         BC_Resources *resources = BC_WindowBase::get_resources();
215         switch(mode)
216         {
217                 case MODEPLAY: 
218                         output_char = out_config->lml_out_device;
219                         break;
220                 case MODERECORD:
221                         output_char = in_config->lml_in_device;
222                         break;
223         }
224         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
225         x1 += device_title->get_w() + 10;
226         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
227         return 0;
230 int VDevicePrefs::create_buz_objs()
232         char *output_char;
233         int x1 = x + menu->get_w() + 5;
234         int x2 = x1 + 210;
235         int y1 = y;
236         BC_Resources *resources = BC_WindowBase::get_resources();
238         switch(mode)
239         {
240                 case MODEPLAY: 
241                         output_char = out_config->buz_out_device;
242                         break;
243                 case MODERECORD:
244                         output_char = in_config->buz_in_device;
245                         break;
246         }
247         dialog->add_subwindow(device_title = new BC_Title(x1, y1, _("Device path:"), MEDIUMFONT, resources->text_default));
249         y1 += 20;
250         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
252         if(driver == PLAYBACK_BUZ)
253         {
254                 dialog->add_subwindow(buz_swap_channels = 
255                         new VDeviceCheckBox(x2, y1, &out_config->buz_swap_fields, _("Swap fields")));
256         }
257         y1 += 30;
258         if(driver == PLAYBACK_BUZ)
259         {
260                 dialog->add_subwindow(output_title = new BC_Title(x1, y1, _("Output channel:")));
261                 y1 += 20;
262                 channel_picker = new PrefsChannelPicker(pwindow->mwindow, 
263                         this, 
264                         pwindow->mwindow->channeldb_buz, 
265                         x1,
266                         y1);
267                 channel_picker->create_objects();
268         }
269         return 0;
272 int VDevicePrefs::create_firewire_objs()
274         int *output_int = 0;
275         char *output_char = 0;
276         int x1 = x + menu->get_w() + 5;
277         BC_Resources *resources = BC_WindowBase::get_resources();
279 // Firewire path
280         switch(mode)
281         {
282                 case MODEPLAY:
283                         if(driver == PLAYBACK_DV1394)
284                                 output_char = out_config->dv1394_path;
285                         else
286                         if(driver == PLAYBACK_FIREWIRE)
287                                 output_char = out_config->firewire_path;
288                         break;
289                 case MODERECORD:
290                         if(driver == CAPTURE_FIREWIRE)
291                                 output_char = in_config->firewire_path;
292                         break;
293         }
295         if(output_char)
296         {
297                 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
298                 dialog->add_subwindow(firewire_path = new VDeviceTextBox(x1, y + 20, output_char));
299                 x1 += firewire_path->get_w() + 5;
300         }
302 // Firewire port
303         switch(mode)
304         {
305                 case MODEPLAY:
306                         if(driver == PLAYBACK_DV1394)
307                                 output_int = &out_config->dv1394_port;
308                         else
309                                 output_int = &out_config->firewire_port;
310                         break;
311                 case MODERECORD:
312                         output_int = &in_config->firewire_port;
313                         break;
314         }
315         dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, resources->text_default));
316         dialog->add_subwindow(firewire_port = new VDeviceIntBox(x1, y + 20, output_int));
317         x1 += firewire_port->get_w() + 5;
319 // Firewire channel
320         switch(mode)
321         {
322                 case MODEPLAY:
323                         if(driver == PLAYBACK_DV1394)
324                                 output_int = &out_config->dv1394_channel;
325                         else
326                                 output_int = &out_config->firewire_channel;
327                         break;
328                 case MODERECORD:
329                         output_int = &in_config->firewire_channel;
330                         break;
331         }
333         dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, resources->text_default));
334         dialog->add_subwindow(firewire_channel = new VDeviceIntBox(x1, y + 20, output_int));
335         x1 += firewire_channel->get_w() + 5;
338 // Firewire syt
339         switch(mode)
340         {
341                 case MODEPLAY:
342                         if(driver == PLAYBACK_DV1394)
343                                 output_int = &out_config->dv1394_syt;
344                         else
345                         if(driver == PLAYBACK_FIREWIRE)
346                                 output_int = &out_config->firewire_syt;
347                         else
348                                 output_int = 0;
349                         break;
350                 case MODERECORD:
351                         output_int = 0;
352                         break;
353         }
354         if(output_int)
355         {
356                 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, resources->text_default));
357                 dialog->add_subwindow(firewire_syt = new VDeviceIntBox(x1, y + 20, output_int));
358         }
360         return 0;
363 int VDevicePrefs::create_v4l_objs()
365         char *output_char;
366         BC_Resources *resources = BC_WindowBase::get_resources();
367         int x1 = x + menu->get_w() + 5;
368         output_char = pwindow->thread->edl->session->vconfig_in->v4l_in_device;
369         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
370         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
371         return 0;
374 int VDevicePrefs::create_v4l2_objs()
376         char *output_char;
377         BC_Resources *resources = BC_WindowBase::get_resources();
378         int x1 = x + menu->get_w() + 5;
379         output_char = pwindow->thread->edl->session->vconfig_in->v4l2_in_device;
380         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
381         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
383         return 0;
386 int VDevicePrefs::create_v4l2jpeg_objs()
388         BC_Resources *resources = BC_WindowBase::get_resources();
389         char *output_char;
390         int x1 = x + menu->get_w() + 5;
391         output_char = pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_device;
392         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
393         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
395         return 0;
400 int VDevicePrefs::create_screencap_objs()
402         char *output_char;
403         BC_Resources *resources = BC_WindowBase::get_resources();
404         int x1 = x + menu->get_w() + 5;
405         output_char = pwindow->thread->edl->session->vconfig_in->screencapture_display;
406         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Display:"), MEDIUMFONT, resources->text_default));
407         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
408         return 0;
411 int VDevicePrefs::create_x11_objs()
413         char *output_char;
414         BC_Resources *resources = BC_WindowBase::get_resources();
415         int x1 = x + menu->get_w() + 5;
416         output_char = out_config->x11_host;
417         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Display for compositor:"), MEDIUMFONT, resources->text_default));
418         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
419         return 0;
425 VDriverMenu::VDriverMenu(int x, 
426         int y, 
427         VDevicePrefs *device_prefs, 
428         int do_input, 
429         int *output)
430  : BC_PopupMenu(x, y, 200, driver_to_string(*output))
432         this->output = output;
433         this->do_input = do_input;
434         this->device_prefs = device_prefs;
437 VDriverMenu::~VDriverMenu()
441 char* VDriverMenu::driver_to_string(int driver)
443         switch(driver)
444         {
445                 case VIDEO4LINUX:
446                         sprintf(string, VIDEO4LINUX_TITLE);
447                         break;
448                 case VIDEO4LINUX2:
449                         sprintf(string, VIDEO4LINUX2_TITLE);
450                         break;
451                 case VIDEO4LINUX2JPEG:
452                         sprintf(string, VIDEO4LINUX2JPEG_TITLE);
453                         break;
454                 case SCREENCAPTURE:
455                         sprintf(string, SCREENCAPTURE_TITLE);
456                         break;
457                 case CAPTURE_BUZ:
458                         sprintf(string, CAPTURE_BUZ_TITLE);
459                         break;
460                 case CAPTURE_LML:
461                         sprintf(string, CAPTURE_LML_TITLE);
462                         break;
463 #ifdef HAVE_FIREWIRE
464                 case CAPTURE_FIREWIRE:
465                         sprintf(string, CAPTURE_FIREWIRE_TITLE);
466                         break;
467                 case CAPTURE_IEC61883:
468                         sprintf(string, CAPTURE_IEC61883_TITLE);
469                         break;
470 #endif
471                 case CAPTURE_DVB:
472                         sprintf(string, CAPTURE_DVB_TITLE);
473                         break;
474                 case PLAYBACK_X11:
475                         sprintf(string, PLAYBACK_X11_TITLE);
476                         break;
477                 case PLAYBACK_X11_XV:
478                         sprintf(string, PLAYBACK_X11_XV_TITLE);
479                         break;
480                 case PLAYBACK_X11_GL:
481                         sprintf(string, PLAYBACK_X11_GL_TITLE);
482                         break;
483                 case PLAYBACK_LML:
484                         sprintf(string, PLAYBACK_LML_TITLE);
485                         break;
486                 case PLAYBACK_BUZ:
487                         sprintf(string, PLAYBACK_BUZ_TITLE);
488                         break;
489 #ifdef HAVE_FIREWIRE
490                 case PLAYBACK_FIREWIRE:
491                         sprintf(string, PLAYBACK_FIREWIRE_TITLE);
492                         break;
493                 case PLAYBACK_DV1394:
494                         sprintf(string, PLAYBACK_DV1394_TITLE);
495                         break;
496                 case PLAYBACK_IEC61883:
497                         sprintf(string, PLAYBACK_IEC61883_TITLE);
498                         break;
499 #endif
500                 default:
501                         sprintf(string, "");
502         }
503         return string;
506 int VDriverMenu::create_objects()
508         if(do_input)
509         {
510                 add_item(new VDriverItem(this, VIDEO4LINUX_TITLE, VIDEO4LINUX));
511 #ifdef HAVE_VIDEO4LINUX2
512                 add_item(new VDriverItem(this, VIDEO4LINUX2_TITLE, VIDEO4LINUX2));
513                 add_item(new VDriverItem(this, VIDEO4LINUX2JPEG_TITLE, VIDEO4LINUX2JPEG));
514 #endif
515                 add_item(new VDriverItem(this, SCREENCAPTURE_TITLE, SCREENCAPTURE));
516                 add_item(new VDriverItem(this, CAPTURE_BUZ_TITLE, CAPTURE_BUZ));
517 #ifdef HAVE_FIREWIRE
518                 add_item(new VDriverItem(this, CAPTURE_FIREWIRE_TITLE, CAPTURE_FIREWIRE));
519                 add_item(new VDriverItem(this, CAPTURE_IEC61883_TITLE, CAPTURE_IEC61883));
520 #endif
521                 add_item(new VDriverItem(this, CAPTURE_DVB_TITLE, CAPTURE_DVB));
522         }
523         else
524         {
525                 add_item(new VDriverItem(this, PLAYBACK_X11_TITLE, PLAYBACK_X11));
526                 add_item(new VDriverItem(this, PLAYBACK_X11_XV_TITLE, PLAYBACK_X11_XV));
527 #ifdef HAVE_GL
528                 add_item(new VDriverItem(this, PLAYBACK_X11_GL_TITLE, PLAYBACK_X11_GL));
529 #endif
530                 add_item(new VDriverItem(this, PLAYBACK_BUZ_TITLE, PLAYBACK_BUZ));
531 #ifdef HAVE_FIREWIRE
532                 add_item(new VDriverItem(this, PLAYBACK_FIREWIRE_TITLE, PLAYBACK_FIREWIRE));
533                 add_item(new VDriverItem(this, PLAYBACK_DV1394_TITLE, PLAYBACK_DV1394));
534                 add_item(new VDriverItem(this, PLAYBACK_IEC61883_TITLE, PLAYBACK_IEC61883));
535 #endif
536         }
537         return 0;
541 VDriverItem::VDriverItem(VDriverMenu *popup, char *text, int driver)
542  : BC_MenuItem(text)
544         this->popup = popup;
545         this->driver = driver;
548 VDriverItem::~VDriverItem()
552 int VDriverItem::handle_event()
554         popup->set_text(get_text());
555         *(popup->output) = driver;
556         popup->device_prefs->initialize();
557         return 1;
563 VDeviceTextBox::VDeviceTextBox(int x, int y, char *output)
564  : BC_TextBox(x, y, 200, 1, output)
566         this->output = output; 
569 int VDeviceTextBox::handle_event() 
571         strcpy(output, get_text()); 
574 VDeviceTumbleBox::VDeviceTumbleBox(VDevicePrefs *prefs, 
575         int x, 
576         int y, 
577         int *output,
578         int min,
579         int max)
580  : BC_TumbleTextBox(prefs->dialog,
581         *output,
582         min,
583         max,
584         x, 
585         y, 
586         60)
588         this->output = output; 
591 int VDeviceTumbleBox::handle_event() 
593         *output = atol(get_text()); 
594         return 1;
602 VDeviceIntBox::VDeviceIntBox(int x, int y, int *output)
603  : BC_TextBox(x, y, 60, 1, *output)
605         this->output = output; 
608 int VDeviceIntBox::handle_event() 
610         *output = atol(get_text()); 
611         return 1;
618 VDeviceCheckBox::VDeviceCheckBox(int x, int y, int *output, char *text)
619  : BC_CheckBox(x, y, *output, text)
621         this->output = output;
623 int VDeviceCheckBox::handle_event()
625         *output = get_value();
626         return 1;