4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "adeviceprefs.h"
24 #include "audioalsa.h"
25 #include "audiodevice.inc"
26 #include "audiopulse.h"
27 #include "bcsignals.h"
28 #include "bitspopup.h"
32 #include "playbackconfig.h"
33 #include "preferences.h"
34 #include "preferencesthread.h"
35 #include "recordconfig.h"
41 ADevicePrefs::ADevicePrefs(int x, int y, PreferencesWindow *pwindow, PreferencesDialog *dialog,
42 AudioOutConfig *out_config, AudioInConfig *in_config, int mode)
45 this->pwindow = pwindow;
46 this->dialog = dialog;
49 this->out_config = out_config;
50 this->in_config = in_config;
55 ADevicePrefs::~ADevicePrefs()
61 void ADevicePrefs::reset()
64 follow_audio_config = 0;
84 for(int i = 0; i < MAXDEVICES; i++)
87 dvb_adapter_title = 0;
90 dvb_adapter_device = 0;
99 int ADevicePrefs::initialize(int creation)
106 driver = &out_config->driver;
109 driver = &in_config->driver;
112 driver = &out_config->driver;
115 this->driver = *driver;
118 dialog->add_subwindow(menu = new ADriverMenu(x,
119 y + yS(10), this, (mode == MODERECORD), driver));
120 menu->create_objects();
121 menu->context_help_set_keyword("Audio Out section");
126 case AUDIO_OSS_ENVY24:
136 create_esound_objs();
141 create_firewire_objs();
147 create_v4l2mpeg_objs();
154 int ADevicePrefs::get_h(int recording)
156 int margin = pwindow->mwindow->theme->widget_border;
157 int result = BC_Title::calculate_h(dialog, "X", MEDIUMFONT) + margin +
158 BC_TextBox::calculate_h(dialog, MEDIUMFONT, 1, 1);
160 result += BC_CheckBox::calculate_h(dialog) + margin;
166 int ADevicePrefs::delete_objects()
170 case AUDIO_OSS_ENVY24:
180 delete_esound_objs();
185 delete_firewire_objs();
191 delete_v4l2mpeg_objs();
203 int ADevicePrefs::delete_oss_objs()
209 for(int i = 0; i < MAXDEVICES; i++)
214 int ADevicePrefs::delete_esound_objs()
223 int ADevicePrefs::delete_firewire_objs()
226 delete channel_title;
227 delete firewire_port;
228 delete firewire_channel;
232 delete firewire_path;
244 int ADevicePrefs::delete_alsa_objs()
247 if(alsa_drivers) alsa_drivers->remove_all_objects();
253 delete alsa_workaround;
258 int ADevicePrefs::delete_pulse_objs()
267 int ADevicePrefs::delete_dvb_objs()
269 delete dvb_adapter_title;
270 delete dvb_adapter_path;
271 delete dvb_device_title;
272 delete dvb_adapter_device;
274 delete follow_audio_config;
278 int ADevicePrefs::delete_v4l2mpeg_objs()
280 delete follow_audio_config;
285 int ADevicePrefs::create_oss_objs()
287 char *output_char = 0;
289 int margin = pwindow->mwindow->theme->widget_border;
291 BC_Resources *resources = BC_WindowBase::get_resources();
293 for(int i = 0; i < MAXDEVICES; i++) {
294 int x1 = x + menu->get_w() + xS(5);
298 output_int = &out_config->oss_enable[i];
301 output_int = &in_config->oss_enable[i];
304 output_int = &out_config->oss_enable[i];
307 dialog->add_subwindow(oss_enable[i] = new OSSEnable(x1, y1 + yS(20), output_int));
308 x1 += oss_enable[i]->get_w() + margin;
312 output_char = out_config->oss_out_device[i];
315 output_char = in_config->oss_in_device[i];
318 output_char = out_config->oss_out_device[i];
323 path_title = new BC_Title(x1, y, _("Device path:"),
324 MEDIUMFONT, resources->text_default);
325 dialog->add_subwindow(path_title);
326 path_title->context_help_set_keyword("Audio Out section");
329 oss_path[i] = new ADeviceTextBox(
330 x1, y1 + path_title->get_h() + margin, output_char);
331 dialog->add_subwindow(oss_path[i]);
332 oss_path[i]->context_help_set_keyword("Audio Out section");
333 x1 += oss_path[i]->get_w() + margin;
337 output_int = &out_config->oss_out_bits;
340 output_int = &in_config->oss_in_bits;
343 output_int = &out_config->oss_out_bits;
346 bits_title = new BC_Title(x1, y, _("Bits:"),
347 MEDIUMFONT, resources->text_default);
348 dialog->add_subwindow(bits_title);
349 bits_title->context_help_set_keyword("Audio Out section");
350 oss_bits = new BitsPopup(dialog,
351 x1, y1 + bits_title->get_h() + margin,
352 output_int, 0, 0, 0, 0, 1);
353 oss_bits->create_objects();
356 x1 += oss_bits->get_w() + margin;
364 int ADevicePrefs::create_alsa_objs()
367 char *output_char = 0;
369 int margin = pwindow->mwindow->theme->widget_border;
370 BC_Resources *resources = BC_WindowBase::get_resources();
372 int x1 = x + menu->get_w() + margin;
375 ArrayList<char*> *alsa_titles = new ArrayList<char*>;
376 alsa_titles->set_array_delete();
377 AudioALSA::list_devices(alsa_titles, 0, mode);
378 AudioALSA::add_pulse_devices(mode, alsa_titles, 0);
380 alsa_drivers = new ArrayList<BC_ListBoxItem*>;
381 for(int i = 0; i < alsa_titles->total; i++)
382 alsa_drivers->append(new BC_ListBoxItem(alsa_titles->values[i]));
383 alsa_titles->remove_all_objects();
388 output_char = out_config->alsa_out_device;
391 output_char = in_config->alsa_in_device;
394 output_char = out_config->alsa_out_device;
397 path_title = new BC_Title(x1, y, _("Device:"),
398 MEDIUMFONT, resources->text_default);
399 dialog->add_subwindow(path_title);
400 path_title->context_help_set_keyword("Audio Out section");
401 y1 += path_title->get_h() + margin;
402 alsa_device = new ALSADevice(dialog,
403 x1, y1, output_char, alsa_drivers);
404 alsa_device->create_objects();
407 x1 += alsa_device->get_w() + xS(5);
410 output_int = &out_config->alsa_out_bits;
413 output_int = &in_config->alsa_in_bits;
416 output_int = &out_config->alsa_out_bits;
419 bits_title = new BC_Title(x1, y, _("Bits:"),
420 MEDIUMFONT, resources->text_default);
421 dialog->add_subwindow(bits_title);
422 bits_title->context_help_set_keyword("Audio Out section");
423 y1 = y + bits_title->get_h() + margin;
424 alsa_bits = new BitsPopup(dialog,
425 x1, y1, output_int, 0, 0, 0, 0, 1);
426 alsa_bits->create_objects();
428 y1 += alsa_bits->get_h();
431 if(mode == MODEPLAY) {
432 alsa_workaround = new BC_CheckBox(x1, y1,
433 &out_config->interrupt_workaround,
434 _("Stop playback locks up."));
435 dialog->add_subwindow(alsa_workaround);
436 alsa_workaround->context_help_set_keyword("Audio Out section");
442 int ADevicePrefs::create_esound_objs()
444 int x1 = x + menu->get_w() + xS(5);
445 char *output_char = 0;
447 BC_Resources *resources = BC_WindowBase::get_resources();
451 output_char = out_config->esound_out_server;
454 output_char = in_config->esound_in_server;
457 output_char = out_config->esound_out_server;
460 server_title = new BC_Title(x1, y, _("Server:"),
461 MEDIUMFONT, resources->text_default);
462 dialog->add_subwindow(server_title);
463 server_title->context_help_set_keyword("Audio Out section");
464 server = new ADeviceTextBox(x1, y + yS(20), output_char);
465 dialog->add_subwindow(server);
466 server->context_help_set_keyword("Audio Out section");
470 output_int = &out_config->esound_out_port;
473 output_int = &in_config->esound_in_port;
476 output_int = &out_config->esound_out_port;
479 x1 += server->get_w() + xS(5);
480 port_title = new BC_Title(x1, y, _("Port:"),
481 MEDIUMFONT, resources->text_default);
482 dialog->add_subwindow(port_title);
483 port_title->context_help_set_keyword("Audio Out section");
484 port = new ADeviceIntBox(x1, y + yS(20), output_int);
485 dialog->add_subwindow(port);
486 port->context_help_set_keyword("Audio Out section");
490 int ADevicePrefs::create_firewire_objs()
494 int x1 = x + menu->get_w() + xs5;
496 char *output_char = 0;
497 BC_Resources *resources = BC_WindowBase::get_resources();
502 if(driver == AUDIO_DV1394)
503 output_char = out_config->dv1394_path;
505 if(driver == AUDIO_1394)
506 output_char = out_config->firewire_path;
509 if(driver == AUDIO_DV1394 || driver == AUDIO_1394)
510 output_char = in_config->firewire_path;
515 dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
516 path_title->context_help_set_keyword("Audio Out section");
517 dialog->add_subwindow(firewire_path = new ADeviceTextBox(x1, y + ys20, output_char));
518 firewire_path->context_help_set_keyword("Audio Out section");
519 x1 += firewire_path->get_w() + xs5;
525 if(driver == AUDIO_DV1394)
526 output_int = &out_config->dv1394_port;
528 output_int = &out_config->firewire_port;
531 output_int = &in_config->firewire_port;
534 // output_int = &out_config->afirewire_out_port;
537 port_title = new BC_Title(x1, y, _("Port:"),
538 MEDIUMFONT, resources->text_default);
539 dialog->add_subwindow(port_title);
540 port_title->context_help_set_keyword("Audio Out section");
541 firewire_port = new ADeviceIntBox(x1, y + ys20, output_int);
542 dialog->add_subwindow(firewire_port);
543 firewire_port->context_help_set_keyword("Audio Out section");
545 x1 += firewire_port->get_w() + xs5;
550 if(driver == AUDIO_DV1394)
551 output_int = &out_config->dv1394_channel;
553 output_int = &out_config->firewire_channel;
556 output_int = &in_config->firewire_channel;
559 channel_title = new BC_Title(x1, y, _("Channel:"),
560 MEDIUMFONT, resources->text_default);
561 dialog->add_subwindow(channel_title);
562 channel_title->context_help_set_keyword("Audio Out section");
563 firewire_channel = new ADeviceIntBox(x1, y + ys20, output_int);
564 dialog->add_subwindow(firewire_channel);
565 firewire_channel->context_help_set_keyword("Audio Out section");
566 x1 += firewire_channel->get_w() + xs5;
571 if(driver == AUDIO_DV1394)
572 output_int = &out_config->dv1394_syt;
574 if(driver == AUDIO_1394)
575 output_int = &out_config->firewire_syt;
585 syt_title = new BC_Title(x1, y, _("Syt Offset:"),
586 MEDIUMFONT, resources->text_default);
587 dialog->add_subwindow(syt_title);
588 syt_title->context_help_set_keyword("Audio Out section");
589 firewire_syt = new ADeviceIntBox(x1, y + ys20, output_int);
590 dialog->add_subwindow(firewire_syt);
591 firewire_syt->context_help_set_keyword("Audio Out section");
592 x1 += firewire_syt->get_w() + xs5;
600 int ADevicePrefs::create_dvb_objs()
602 int x1 = x + menu->get_w() + xS(30);
604 char *output_char = in_config->dvb_in_adapter;
605 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - yS(5);
606 BC_Resources *resources = BC_WindowBase::get_resources();
607 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
608 MEDIUMFONT, resources->text_default);
609 dialog->add_subwindow(dvb_adapter_title);
610 dvb_adapter_title->context_help_set_keyword("Audio Out section");
611 dvb_adapter_path = new ADeviceTextBox(x1, y1, output_char);
612 dialog->add_subwindow(dvb_adapter_path);
613 dvb_adapter_path->context_help_set_keyword("Audio Out section");
614 int x2 = x1 + dvb_adapter_path->get_w() + xS(5);
615 dvb_device_title = new BC_Title(x2, y2, _("dev:"),
616 MEDIUMFONT, resources->text_default);
617 dialog->add_subwindow(dvb_device_title);
618 dvb_device_title->context_help_set_keyword("Audio Out section");
619 int *output_int = &in_config->dvb_in_device;
620 dvb_adapter_device = new ADeviceTumbleBox(this, x2, y1, output_int, 0, 9, xS(20));
621 dvb_adapter_device->create_objects();
622 x2 += dvb_device_title->get_w() + xS(30);
623 bits_title = new BC_Title(x2, y2, _("Bits:"),
624 MEDIUMFONT, resources->text_default);
625 dialog->add_subwindow(bits_title);
626 bits_title->context_help_set_keyword("Audio Out section");
627 output_int = &in_config->dvb_in_bits;
628 dvb_bits = new BitsPopup(dialog, x2, y1, output_int, 0, 0, 0, 0, 1);
629 dvb_bits->create_objects();
630 x1 += xS(100); y1 += dvb_adapter_path->get_h() + yS(5);
631 output_int = &in_config->follow_audio;
632 follow_audio_config = new BC_CheckBox(x1, y1, output_int, _("Follow audio config"));
633 dialog->add_subwindow(follow_audio_config);
634 follow_audio_config->context_help_set_keyword("Audio Out section");
638 int ADevicePrefs::create_v4l2mpeg_objs()
640 int x1 = x + menu->get_w() + xS(30);
642 int y2 = y1 - BC_Title::calculate_h(dialog, _("Bits:"), MEDIUMFONT) - yS(5);
643 BC_Resources *resources = BC_WindowBase::get_resources();
644 bits_title = new BC_Title(x1, y2, _("Bits:"),
645 MEDIUMFONT, resources->text_default);
646 dialog->add_subwindow(bits_title);
647 bits_title->context_help_set_keyword("Audio Out section");
648 int *output_int = &in_config->v4l2_in_bits;
649 v4l2_bits = new BitsPopup(dialog, x1, y1, output_int, 0, 0, 0, 0, 1);
650 v4l2_bits->create_objects();
651 x1 += v4l2_bits->get_w() + xS(10);
652 follow_audio_config = new BC_CheckBox(x1, y1,
653 &in_config->follow_audio, _("Follow audio config"));
654 dialog->add_subwindow(follow_audio_config);
655 follow_audio_config->context_help_set_keyword("Audio Out section");
660 int ADevicePrefs::create_pulse_objs()
663 char *output_char = 0;
666 output_char = out_config->pulse_out_server;
669 output_char = in_config->pulse_in_server;
673 x1 += menu->get_w() + xS(5);
674 dialog->add_subwindow(server_title = new BC_Title(x1, y1,
675 _("Server (blank for default):")));
676 server_title->context_help_set_keyword("Audio Out section");
677 y1 += server_title->get_h() + yS(5);
678 dialog->add_subwindow(server = new ADeviceTextBox(x1, y1, output_char));
679 server->context_help_set_keyword("Audio Out section");
685 ADriverMenu::ADriverMenu(int x, int y, ADevicePrefs *device_prefs,
686 int do_input, int *output)
687 : BC_PopupMenu(x, y, xS(125), adriver_to_string(*output), 1)
689 this->output = output;
690 this->do_input = do_input;
691 this->device_prefs = device_prefs;
694 ADriverMenu::~ADriverMenu()
698 void ADriverMenu::create_objects()
701 add_item(new ADriverItem(this, AUDIO_ALSA_TITLE, AUDIO_ALSA));
705 add_item(new ADriverItem(this, AUDIO_OSS_TITLE, AUDIO_OSS));
706 add_item(new ADriverItem(this, AUDIO_OSS_ENVY24_TITLE, AUDIO_OSS_ENVY24));
710 if(!do_input) add_item(new ADriverItem(this, AUDIO_ESOUND_TITLE, AUDIO_ESOUND));
714 if(!do_input) add_item(new ADriverItem(this, AUDIO_1394_TITLE, AUDIO_1394));
715 add_item(new ADriverItem(this, AUDIO_DV1394_TITLE, AUDIO_DV1394));
716 add_item(new ADriverItem(this, AUDIO_IEC61883_TITLE, AUDIO_IEC61883));
720 if(do_input) add_item(new ADriverItem(this, AUDIO_DVB_TITLE, AUDIO_DVB));
723 #ifdef HAVE_VIDEO4LINUX2
724 if(do_input) add_item(new ADriverItem(this, AUDIO_V4L2MPEG_TITLE, AUDIO_V4L2MPEG));
727 add_item(new ADriverItem(this, AUDIO_PULSE_TITLE, AUDIO_PULSE));
731 char* ADriverMenu::adriver_to_string(int driver)
735 sprintf(string, AUDIO_OSS_TITLE);
737 case AUDIO_OSS_ENVY24:
738 sprintf(string, AUDIO_OSS_ENVY24_TITLE);
741 sprintf(string, AUDIO_ESOUND_TITLE);
744 sprintf(string, AUDIO_PULSE_TITLE);
747 sprintf(string, AUDIO_NAS_TITLE);
750 sprintf(string, AUDIO_ALSA_TITLE);
754 sprintf(string, AUDIO_1394_TITLE);
757 sprintf(string, AUDIO_DV1394_TITLE);
760 sprintf(string, AUDIO_IEC61883_TITLE);
764 sprintf(string, AUDIO_DVB_TITLE);
767 sprintf(string, AUDIO_V4L2MPEG_TITLE);
773 ADriverItem::ADriverItem(ADriverMenu *popup, const char *text, int driver)
777 this->driver = driver;
780 ADriverItem::~ADriverItem()
784 int ADriverItem::handle_event()
786 popup->set_text(get_text());
787 *(popup->output) = driver;
788 popup->device_prefs->initialize(0);
789 popup->device_prefs->pwindow->show_dialog();
796 OSSEnable::OSSEnable(int x, int y, int *output)
797 : BC_CheckBox(x, y, *output)
799 this->output = output;
801 int OSSEnable::handle_event()
803 *output = get_value();
810 ADeviceTextBox::ADeviceTextBox(int x, int y, char *output)
811 : BC_TextBox(x, y, xS(150), 1, output)
813 this->output = output;
816 int ADeviceTextBox::handle_event()
818 strcpy(output, get_text());
822 ADeviceIntBox::ADeviceIntBox(int x, int y, int *output)
823 : BC_TextBox(x, y, xS(80), 1, *output)
825 this->output = output;
828 int ADeviceIntBox::handle_event()
830 *output = atol(get_text());
836 ADeviceTumbleBox::ADeviceTumbleBox(ADevicePrefs *prefs,
837 int x, int y, int *output, int min, int max, int text_w)
838 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
840 this->output = output;
843 int ADeviceTumbleBox::handle_event()
845 *output = atol(get_text());
851 ALSADevice::ALSADevice(PreferencesDialog *dialog,
855 ArrayList<BC_ListBoxItem*> *devices)
856 : BC_PopupTextBox(dialog, devices, output, x, y, xS(200), yS(200))
858 this->output = output;
861 ALSADevice::~ALSADevice()
865 int ALSADevice::handle_event()
867 strcpy(output, get_text());