asset drag/drop to viewers, bluebanana bug, listbox fontlist highlight
[goodguy/history.git] / cinelerra-5.1 / cinelerra / vdeviceprefs.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2011 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 "bcsignals.h"
23 #include "channeldb.h"
24 #include "channelpicker.h"
25 #include "edl.h"
26 #include "edlsession.h"
27 #include "formattools.h"
28 #include "language.h"
29 #include "mwindow.h"
30 #include "mainsession.h"
31 #include "vdeviceprefs.h"
32 #include "videoconfig.h"
33 #include "videodevice.inc"
34 #include "overlayframe.inc"
35 #include "playbackconfig.h"
36 #include "preferences.h"
37 #include "preferencesthread.h"
38 #include "recordconfig.h"
39 #include "recordprefs.h"
40 #include <string.h>
41
42
43 VDevicePrefs::VDevicePrefs(int x,
44         int y,
45         PreferencesWindow *pwindow,
46         PreferencesDialog *dialog,
47         VideoOutConfig *out_config,
48         VideoInConfig *in_config,
49         int mode)
50 {
51         this->pwindow = pwindow;
52         this->dialog = dialog;
53         this->driver = DEV_UNKNOWN;
54         this->mode = mode;
55         this->out_config = out_config;
56         this->in_config = in_config;
57         this->x = x;
58         this->y = y;
59         menu = 0;
60         reset_objects();
61
62 }
63
64 VDevicePrefs::~VDevicePrefs()
65 {
66         delete_objects();
67         if(menu) delete menu;
68         int config = -1;
69         switch( pwindow->thread->current_dialog ) {
70         case PreferencesThread::PLAYBACK_A:  config = 0;  break;
71         case PreferencesThread::PLAYBACK_B:  config = 1;  break;
72         }
73         if( config >= 0 )
74                 pwindow->mwindow->session->save_x11_host(config, out_config->x11_host);
75 }
76
77
78 void VDevicePrefs::reset_objects()
79 {
80         device_title = 0;
81         port_title = 0;
82         follow_video_config = 0;
83         dvb_adapter_title = 0;
84         dvb_adapter_device = 0;
85         channel_title = 0;
86         output_title = 0;
87         syt_title = 0;
88
89         device_text = 0;
90         firewire_port = 0;
91         firewire_channel = 0;
92         firewire_channels = 0;
93         firewire_syt = 0;
94         firewire_path = 0;
95         fields_title = 0;
96         device_fields = 0;
97
98         channel_picker = 0;
99 }
100
101 int VDevicePrefs::initialize(int creation)
102 {
103         int *driver = 0;
104         delete_objects();
105
106         switch(mode)
107         {
108                 case MODEPLAY:
109                         driver = &out_config->driver;
110                         break;
111
112                 case MODERECORD:
113                         driver = &in_config->driver;
114                         break;
115         }
116         this->driver = *driver;
117
118         if(!menu)
119         {
120                 dialog->add_subwindow(menu = new VDriverMenu(x,
121                         y + 10,
122                         this,
123                         (mode == MODERECORD),
124                         driver));
125                 menu->create_objects();
126         }
127
128         switch(this->driver)
129         {
130                 case DEV_UNKNOWN:
131                         break;
132                 case VIDEO4LINUX2:
133                 case CAPTURE_JPEG_WEBCAM:
134                 case CAPTURE_YUYV_WEBCAM:
135                         create_v4l2_objs();
136                         break;
137                 case VIDEO4LINUX2JPEG:
138                         create_v4l2jpeg_objs();
139                         break;
140                 case VIDEO4LINUX2MPEG:
141                         create_v4l2mpeg_objs();
142                         break;
143                 case SCREENCAPTURE:
144                         create_screencap_objs();
145                         break;
146                 case PLAYBACK_X11:
147                 case PLAYBACK_X11_XV:
148                 case PLAYBACK_X11_GL:
149                         create_x11_objs();
150                         break;
151                 case PLAYBACK_DV1394:
152                 case PLAYBACK_FIREWIRE:
153                 case PLAYBACK_IEC61883:
154                 case CAPTURE_FIREWIRE:
155                 case CAPTURE_IEC61883:
156                         create_firewire_objs();
157                         break;
158                 case CAPTURE_DVB:
159                         create_dvb_objs();
160                         break;
161         }
162
163
164
165 // Update driver dependancies in file format
166         if(mode == MODERECORD && dialog && !creation)
167         {
168                 RecordPrefs *record_prefs = (RecordPrefs*)dialog;
169                 record_prefs->recording_format->update_driver(this->driver);
170         }
171
172         return 0;
173 }
174
175 int VDevicePrefs::delete_objects()
176 {
177         delete output_title;
178         delete channel_picker;
179         delete device_title;
180         delete device_text;
181         delete dvb_adapter_device;
182         delete follow_video_config;
183         delete dvb_adapter_title;
184
185         delete port_title;
186
187         if(firewire_port) delete firewire_port;
188         if(channel_title) delete channel_title;
189         if(firewire_channel) delete firewire_channel;
190         if(firewire_path) delete firewire_path;
191         if(syt_title) delete syt_title;
192         if(firewire_syt) delete firewire_syt;
193         if(fields_title) delete fields_title;
194         if(device_fields) delete device_fields;
195
196         reset_objects();
197         driver = -1;
198         return 0;
199 }
200
201 void VDevicePrefs::create_dvb_objs()
202 {
203         int x1 = x + menu->get_w() + 30;
204         int y1 = y + 10;
205         char *output_char = in_config->dvb_in_adapter;
206         int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - 5;
207         BC_Resources *resources = BC_WindowBase::get_resources();
208         dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
209                         MEDIUMFONT, resources->text_default);
210         dialog->add_subwindow(dvb_adapter_title);
211         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
212         int x2 = x1 + device_text->get_w() + 5;
213         device_title = new BC_Title(x2, y2, _("dev:"),
214                         MEDIUMFONT, resources->text_default);
215         dialog->add_subwindow(device_title);
216         int *output_int = &in_config->dvb_in_device;
217         dvb_adapter_device = new VDeviceTumbleBox(this, x2, y1, output_int, 0, 9, 20);
218         dvb_adapter_device->create_objects();
219         x1 += 64;  y1 += device_text->get_h() + 5;
220         follow_video_config = new BC_CheckBox(x1, y1,
221                         &in_config->follow_video, _("Follow video config"));
222         dialog->add_subwindow(follow_video_config);
223 }
224
225 int VDevicePrefs::create_firewire_objs()
226 {
227         int *output_int = 0;
228         char *output_char = 0;
229         int x1 = x + menu->get_w() + 5;
230         BC_Resources *resources = BC_WindowBase::get_resources();
231
232 // Firewire path
233         switch(mode)
234         {
235                 case MODEPLAY:
236                         if(driver == PLAYBACK_DV1394)
237                                 output_char = out_config->dv1394_path;
238                         else
239                         if(driver == PLAYBACK_FIREWIRE)
240                                 output_char = out_config->firewire_path;
241                         break;
242                 case MODERECORD:
243                         if(driver == CAPTURE_FIREWIRE)
244                                 output_char = in_config->firewire_path;
245                         break;
246         }
247
248         if(output_char)
249         {
250                 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
251                 dialog->add_subwindow(firewire_path = new VDeviceTextBox(x1, y + 20, output_char));
252                 x1 += firewire_path->get_w() + 5;
253         }
254
255 // Firewire port
256         switch(mode)
257         {
258                 case MODEPLAY:
259                         if(driver == PLAYBACK_DV1394)
260                                 output_int = &out_config->dv1394_port;
261                         else
262                                 output_int = &out_config->firewire_port;
263                         break;
264                 case MODERECORD:
265                         output_int = &in_config->firewire_port;
266                         break;
267         }
268         dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, resources->text_default));
269         dialog->add_subwindow(firewire_port = new VDeviceIntBox(x1, y + 20, output_int));
270         x1 += firewire_port->get_w() + 5;
271
272 // Firewire channel
273         switch(mode)
274         {
275                 case MODEPLAY:
276                         if(driver == PLAYBACK_DV1394)
277                                 output_int = &out_config->dv1394_channel;
278                         else
279                                 output_int = &out_config->firewire_channel;
280                         break;
281                 case MODERECORD:
282                         output_int = &in_config->firewire_channel;
283                         break;
284         }
285
286         dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, resources->text_default));
287         dialog->add_subwindow(firewire_channel = new VDeviceIntBox(x1, y + 20, output_int));
288         x1 += firewire_channel->get_w() + 5;
289
290
291 // Firewire syt
292         switch(mode)
293         {
294                 case MODEPLAY:
295                         if(driver == PLAYBACK_DV1394)
296                                 output_int = &out_config->dv1394_syt;
297                         else
298                         if(driver == PLAYBACK_FIREWIRE)
299                                 output_int = &out_config->firewire_syt;
300                         else
301                                 output_int = 0;
302                         break;
303                 case MODERECORD:
304                         output_int = 0;
305                         break;
306         }
307         if(output_int)
308         {
309                 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, resources->text_default));
310                 dialog->add_subwindow(firewire_syt = new VDeviceIntBox(x1, y + 20, output_int));
311         }
312
313         return 0;
314 }
315
316 int VDevicePrefs::create_v4l2_objs()
317 {
318         char *output_char;
319         BC_Resources *resources = BC_WindowBase::get_resources();
320         int x1 = x + menu->get_w() + 5;
321         output_char = pwindow->thread->edl->session->vconfig_in->v4l2_in_device;
322         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
323         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
324
325         return 0;
326 }
327
328 int VDevicePrefs::create_v4l2jpeg_objs()
329 {
330         BC_Resources *resources = BC_WindowBase::get_resources();
331         int x1 = x + menu->get_w() + 5;
332         char *output_char = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_device[0];
333         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
334         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
335         x1 += max(device_title->get_w(),device_text->get_w()) + 5;
336         int *output_int = &pwindow->thread->edl->session->vconfig_in->v4l2jpeg_in_fields;
337         fields_title = new BC_Title(x1, y, _("Fields:"), MEDIUMFONT, resources->text_default);
338         dialog->add_subwindow(fields_title);
339         device_fields = new VDeviceTumbleBox(this, x1, y + 20, output_int, 1, 2, 20);
340         device_fields->create_objects();
341         return 0;
342 }
343
344 int VDevicePrefs::create_v4l2mpeg_objs()
345 {
346         char *output_char;
347         BC_Resources *resources = BC_WindowBase::get_resources();
348         int x1 = x + menu->get_w() + 5;
349         output_char = pwindow->thread->edl->session->vconfig_in->v4l2mpeg_in_device;
350         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, resources->text_default));
351         int y1 = y + 20;
352         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
353         x1 += 64;  y1 += device_text->get_h() + 5;
354         follow_video_config = new BC_CheckBox(x1, y1,
355                         &in_config->follow_video, _("Follow video config"));
356         dialog->add_subwindow(follow_video_config);
357         return 0;
358 }
359
360
361 int VDevicePrefs::create_screencap_objs()
362 {
363         char *output_char;
364         BC_Resources *resources = BC_WindowBase::get_resources();
365         int x1 = x + menu->get_w() + 5;
366         output_char = pwindow->thread->edl->session->vconfig_in->screencapture_display;
367         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Display:"), MEDIUMFONT, resources->text_default));
368         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
369         return 0;
370 }
371
372 int VDevicePrefs::create_x11_objs()
373 {
374         char *output_char;
375         BC_Resources *resources = BC_WindowBase::get_resources();
376         int x1 = x + menu->get_w() + 5;
377         output_char = out_config->x11_host;
378         const char *x11_display;
379         switch( pwindow->thread->current_dialog ) {
380         default:
381         case PreferencesThread::PLAYBACK_A:
382                 x11_display = _("Default A Display:");  break;
383                 break;
384         case PreferencesThread::PLAYBACK_B:
385                 x11_display = _("Default B Display:");  break;
386                 break;
387         }
388         dialog->add_subwindow(device_title = new BC_Title(x1, y, x11_display,
389                         MEDIUMFONT, resources->text_default));
390         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
391         return 0;
392 }
393
394
395
396
397 VDriverMenu::VDriverMenu(int x,
398         int y,
399         VDevicePrefs *device_prefs,
400         int do_input,
401         int *output)
402  : BC_PopupMenu(x, y, 200, driver_to_string(*output))
403 {
404         this->output = output;
405         this->do_input = do_input;
406         this->device_prefs = device_prefs;
407 }
408
409 VDriverMenu::~VDriverMenu()
410 {
411 }
412
413 char* VDriverMenu::driver_to_string(int driver)
414 {
415         switch(driver)
416         {
417                 case DEV_UNKNOWN:
418                         sprintf(string, DEV_UNKNOWN_TITLE);
419                         break;
420                 case VIDEO4LINUX2:
421                         sprintf(string, VIDEO4LINUX2_TITLE);
422                         break;
423                 case CAPTURE_JPEG_WEBCAM:
424                         sprintf(string, CAPTURE_JPEG_WEBCAM_TITLE);
425                         break;
426                 case CAPTURE_YUYV_WEBCAM:
427                         sprintf(string, CAPTURE_YUYV_WEBCAM_TITLE);
428                         break;
429                 case VIDEO4LINUX2JPEG:
430                         sprintf(string, VIDEO4LINUX2JPEG_TITLE);
431                         break;
432                 case VIDEO4LINUX2MPEG:
433                         sprintf(string, VIDEO4LINUX2MPEG_TITLE);
434                         break;
435                 case SCREENCAPTURE:
436                         sprintf(string, SCREENCAPTURE_TITLE);
437                         break;
438 #ifdef HAVE_FIREWIRE
439                 case CAPTURE_FIREWIRE:
440                         sprintf(string, CAPTURE_FIREWIRE_TITLE);
441                         break;
442                 case CAPTURE_IEC61883:
443                         sprintf(string, CAPTURE_IEC61883_TITLE);
444                         break;
445 #endif
446                 case CAPTURE_DVB:
447                         sprintf(string, CAPTURE_DVB_TITLE);
448                         break;
449                 case PLAYBACK_X11:
450                         sprintf(string, PLAYBACK_X11_TITLE);
451                         break;
452                 case PLAYBACK_X11_XV:
453                         sprintf(string, PLAYBACK_X11_XV_TITLE);
454                         break;
455                 case PLAYBACK_X11_GL:
456                         sprintf(string, PLAYBACK_X11_GL_TITLE);
457                         break;
458 #ifdef HAVE_FIREWIRE
459                 case PLAYBACK_FIREWIRE:
460                         sprintf(string, PLAYBACK_FIREWIRE_TITLE);
461                         break;
462                 case PLAYBACK_DV1394:
463                         sprintf(string, PLAYBACK_DV1394_TITLE);
464                         break;
465                 case PLAYBACK_IEC61883:
466                         sprintf(string, PLAYBACK_IEC61883_TITLE);
467                         break;
468 #endif
469                 default:
470                         string[0] = 0;
471         }
472         return string;
473 }
474
475 void VDriverMenu::create_objects()
476 {
477         if(do_input)
478         {
479 #ifdef HAVE_VIDEO4LINUX2
480                 add_item(new VDriverItem(this, VIDEO4LINUX2_TITLE, VIDEO4LINUX2));
481                 add_item(new VDriverItem(this, CAPTURE_JPEG_WEBCAM_TITLE, CAPTURE_JPEG_WEBCAM));
482                 add_item(new VDriverItem(this, CAPTURE_YUYV_WEBCAM_TITLE, CAPTURE_YUYV_WEBCAM));
483                 add_item(new VDriverItem(this, VIDEO4LINUX2JPEG_TITLE, VIDEO4LINUX2JPEG));
484                 add_item(new VDriverItem(this, VIDEO4LINUX2MPEG_TITLE, VIDEO4LINUX2MPEG));
485 #endif
486
487                 add_item(new VDriverItem(this, SCREENCAPTURE_TITLE, SCREENCAPTURE));
488 #ifdef HAVE_FIREWIRE
489                 add_item(new VDriverItem(this, CAPTURE_FIREWIRE_TITLE, CAPTURE_FIREWIRE));
490                 add_item(new VDriverItem(this, CAPTURE_IEC61883_TITLE, CAPTURE_IEC61883));
491 #endif
492 #ifdef HAVE_DVB
493                 add_item(new VDriverItem(this, CAPTURE_DVB_TITLE, CAPTURE_DVB));
494 #endif
495         }
496         else
497         {
498                 add_item(new VDriverItem(this, PLAYBACK_X11_TITLE, PLAYBACK_X11));
499                 add_item(new VDriverItem(this, PLAYBACK_X11_XV_TITLE, PLAYBACK_X11_XV));
500 #ifdef HAVE_GL
501 // Check runtime glx version. pbuffer needs >= 1.3
502                 if(get_opengl_server_version() >= 103)
503                         add_item(new VDriverItem(this, PLAYBACK_X11_GL_TITLE, PLAYBACK_X11_GL));
504 #endif
505 #ifdef HAVE_FIREWIRE
506                 add_item(new VDriverItem(this, PLAYBACK_FIREWIRE_TITLE, PLAYBACK_FIREWIRE));
507                 add_item(new VDriverItem(this, PLAYBACK_DV1394_TITLE, PLAYBACK_DV1394));
508                 add_item(new VDriverItem(this, PLAYBACK_IEC61883_TITLE, PLAYBACK_IEC61883));
509 #endif
510         }
511 }
512
513
514 VDriverItem::VDriverItem(VDriverMenu *popup, const char *text, int driver)
515  : BC_MenuItem(text)
516 {
517         this->popup = popup;
518         this->driver = driver;
519 }
520
521 VDriverItem::~VDriverItem()
522 {
523 }
524
525 int VDriverItem::handle_event()
526 {
527         popup->set_text(get_text());
528         *(popup->output) = driver;
529         popup->device_prefs->initialize(0);
530         popup->device_prefs->pwindow->show_dialog();
531         return 1;
532 }
533
534
535
536
537 VDeviceTextBox::VDeviceTextBox(int x, int y, char *output)
538  : BC_TextBox(x, y, 200, 1, output)
539 {
540         this->output = output;
541 }
542
543 int VDeviceTextBox::handle_event()
544 {
545 // Suggestions
546         calculate_suggestions(0);
547
548         strcpy(output, get_text());
549         return 1;
550 }
551
552 VDeviceTumbleBox::VDeviceTumbleBox(VDevicePrefs *prefs,
553         int x, int y, int *output, int min, int max, int text_w)
554  : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
555 {
556         this->output = output;
557 }
558
559 int VDeviceTumbleBox::handle_event()
560 {
561         *output = atol(get_text());
562         return 1;
563 }
564
565
566
567
568
569
570 VDeviceIntBox::VDeviceIntBox(int x, int y, int *output)
571  : BC_TextBox(x, y, 60, 1, *output)
572 {
573         this->output = output;
574 }
575
576 int VDeviceIntBox::handle_event()
577 {
578         *output = atol(get_text());
579         return 1;
580 }
581
582
583
584
585
586 VDeviceCheckBox::VDeviceCheckBox(int x, int y, int *output, char *text)
587  : BC_CheckBox(x, y, *output, text)
588 {
589         this->output = output;
590 }
591 int VDeviceCheckBox::handle_event()
592 {
593         *output = get_value();
594         return 1;
595 }
596
597
598
599
600 VScalingItem::VScalingItem(VScalingEquation *popup, int interpolation)
601  : BC_MenuItem(popup->interpolation_to_string(interpolation))
602 {
603         this->popup = popup;
604         this->interpolation = interpolation;
605 }
606
607 VScalingItem::~VScalingItem()
608 {
609 }
610
611 int VScalingItem::handle_event()
612 {
613         popup->set_text(get_text());
614         *(popup->output) = interpolation;
615         return 1;
616 }
617
618
619 VScalingEquation::VScalingEquation(int x, int y, int *output)
620  : BC_PopupMenu(x, y, 175, interpolation_to_string(*output))
621 {
622         this->output = output;
623 }
624
625 VScalingEquation::~VScalingEquation()
626 {
627 }
628
629 const char *VScalingEquation::interpolation_to_string(int type)
630 {
631         switch( type ) {
632         case NEAREST_NEIGHBOR:  return _("Nearest Neighbor");
633         case CUBIC_CUBIC:       return _("BiCubic / BiCubic");
634         case CUBIC_LINEAR:      return _("BiCubic / BiLinear");
635         case LINEAR_LINEAR:     return _("BiLinear / BiLinear");
636         case LANCZOS_LANCZOS:   return _("Lanczos / Lanczos");
637         }
638         return _("Unknown");
639 }
640
641 void VScalingEquation::create_objects()
642 {
643         add_item(new VScalingItem(this, NEAREST_NEIGHBOR));
644         add_item(new VScalingItem(this, CUBIC_CUBIC));
645         add_item(new VScalingItem(this, CUBIC_LINEAR));
646         add_item(new VScalingItem(this, LINEAR_LINEAR));
647         add_item(new VScalingItem(this, LANCZOS_LANCZOS));
648 }
649