4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "adeviceprefs.h"
23 #include "audioalsa.h"
24 #include "audiodevice.inc"
25 #include "audiopulse.h"
26 #include "bcsignals.h"
27 #include "bitspopup.h"
31 #include "playbackconfig.h"
32 #include "preferences.h"
33 #include "preferencesthread.h"
34 #include "recordconfig.h"
40 ADevicePrefs::ADevicePrefs(int x, int y, PreferencesWindow *pwindow, PreferencesDialog *dialog,
41 AudioOutConfig *out_config, AudioInConfig *in_config, int mode)
44 this->pwindow = pwindow;
45 this->dialog = dialog;
48 this->out_config = out_config;
49 this->in_config = in_config;
54 ADevicePrefs::~ADevicePrefs()
60 void ADevicePrefs::reset()
63 follow_audio_config = 0;
83 for(int i = 0; i < MAXDEVICES; i++)
86 dvb_adapter_title = 0;
89 dvb_adapter_device = 0;
98 int ADevicePrefs::initialize(int creation)
105 driver = &out_config->driver;
108 driver = &in_config->driver;
111 driver = &out_config->driver;
114 this->driver = *driver;
117 dialog->add_subwindow(menu = new ADriverMenu(x,
118 y + yS(10), this, (mode == MODERECORD), driver));
119 menu->create_objects();
120 menu->context_help_set_keyword("Audio Out section");
125 case AUDIO_OSS_ENVY24:
135 create_esound_objs();
140 create_firewire_objs();
146 create_v4l2mpeg_objs();
153 int ADevicePrefs::get_h(int recording)
155 int margin = pwindow->mwindow->theme->widget_border;
156 int result = BC_Title::calculate_h(dialog, "X", MEDIUMFONT) + margin +
157 BC_TextBox::calculate_h(dialog, MEDIUMFONT, 1, 1);
159 result += BC_CheckBox::calculate_h(dialog) + margin;
165 int ADevicePrefs::delete_objects()
169 case AUDIO_OSS_ENVY24:
179 delete_esound_objs();
184 delete_firewire_objs();
190 delete_v4l2mpeg_objs();
202 int ADevicePrefs::delete_oss_objs()
208 for(int i = 0; i < MAXDEVICES; i++)
213 int ADevicePrefs::delete_esound_objs()
222 int ADevicePrefs::delete_firewire_objs()
225 delete channel_title;
226 delete firewire_port;
227 delete firewire_channel;
231 delete firewire_path;
243 int ADevicePrefs::delete_alsa_objs()
246 if(alsa_drivers) alsa_drivers->remove_all_objects();
252 delete alsa_workaround;
257 int ADevicePrefs::delete_pulse_objs()
266 int ADevicePrefs::delete_dvb_objs()
268 delete dvb_adapter_title;
269 delete dvb_adapter_path;
270 delete dvb_device_title;
271 delete dvb_adapter_device;
273 delete follow_audio_config;
277 int ADevicePrefs::delete_v4l2mpeg_objs()
279 delete follow_audio_config;
284 int ADevicePrefs::create_oss_objs()
286 char *output_char = 0;
288 int margin = pwindow->mwindow->theme->widget_border;
290 BC_Resources *resources = BC_WindowBase::get_resources();
292 for(int i = 0; i < MAXDEVICES; i++) {
293 int x1 = x + menu->get_w() + xS(5);
297 output_int = &out_config->oss_enable[i];
300 output_int = &in_config->oss_enable[i];
303 output_int = &out_config->oss_enable[i];
306 dialog->add_subwindow(oss_enable[i] = new OSSEnable(x1, y1 + yS(20), output_int));
307 x1 += oss_enable[i]->get_w() + margin;
311 output_char = out_config->oss_out_device[i];
314 output_char = in_config->oss_in_device[i];
317 output_char = out_config->oss_out_device[i];
322 path_title = new BC_Title(x1, y, _("Device path:"),
323 MEDIUMFONT, resources->text_default);
324 dialog->add_subwindow(path_title);
325 path_title->context_help_set_keyword("Audio Out section");
328 oss_path[i] = new ADeviceTextBox(
329 x1, y1 + path_title->get_h() + margin, output_char);
330 dialog->add_subwindow(oss_path[i]);
331 oss_path[i]->context_help_set_keyword("Audio Out section");
332 x1 += oss_path[i]->get_w() + margin;
336 output_int = &out_config->oss_out_bits;
339 output_int = &in_config->oss_in_bits;
342 output_int = &out_config->oss_out_bits;
345 bits_title = new BC_Title(x1, y, _("Bits:"),
346 MEDIUMFONT, resources->text_default);
347 dialog->add_subwindow(bits_title);
348 bits_title->context_help_set_keyword("Audio Out section");
349 oss_bits = new BitsPopup(dialog,
350 x1, y1 + bits_title->get_h() + margin,
351 output_int, 0, 0, 0, 0, 1);
352 oss_bits->create_objects();
355 x1 += oss_bits->get_w() + margin;
363 int ADevicePrefs::create_alsa_objs()
366 char *output_char = 0;
368 int margin = pwindow->mwindow->theme->widget_border;
369 BC_Resources *resources = BC_WindowBase::get_resources();
371 int x1 = x + menu->get_w() + margin;
374 ArrayList<char*> *alsa_titles = new ArrayList<char*>;
375 alsa_titles->set_array_delete();
376 AudioALSA::list_devices(alsa_titles, 0, mode);
377 AudioALSA::add_pulse_devices(mode, alsa_titles, 0);
379 alsa_drivers = new ArrayList<BC_ListBoxItem*>;
380 for(int i = 0; i < alsa_titles->total; i++)
381 alsa_drivers->append(new BC_ListBoxItem(alsa_titles->values[i]));
382 alsa_titles->remove_all_objects();
387 output_char = out_config->alsa_out_device;
390 output_char = in_config->alsa_in_device;
393 output_char = out_config->alsa_out_device;
396 path_title = new BC_Title(x1, y, _("Device:"),
397 MEDIUMFONT, resources->text_default);
398 dialog->add_subwindow(path_title);
399 path_title->context_help_set_keyword("Audio Out section");
400 y1 += path_title->get_h() + margin;
401 alsa_device = new ALSADevice(dialog,
402 x1, y1, output_char, alsa_drivers);
403 alsa_device->create_objects();
406 x1 += alsa_device->get_w() + xS(5);
409 output_int = &out_config->alsa_out_bits;
412 output_int = &in_config->alsa_in_bits;
415 output_int = &out_config->alsa_out_bits;
418 bits_title = new BC_Title(x1, y, _("Bits:"),
419 MEDIUMFONT, resources->text_default);
420 dialog->add_subwindow(bits_title);
421 bits_title->context_help_set_keyword("Audio Out section");
422 y1 = y + bits_title->get_h() + margin;
423 alsa_bits = new BitsPopup(dialog,
424 x1, y1, output_int, 0, 0, 0, 0, 1);
425 alsa_bits->create_objects();
427 y1 += alsa_bits->get_h();
430 if(mode == MODEPLAY) {
431 alsa_workaround = new BC_CheckBox(x1, y1,
432 &out_config->interrupt_workaround,
433 _("Stop playback locks up."));
434 dialog->add_subwindow(alsa_workaround);
435 alsa_workaround->context_help_set_keyword("Audio Out section");
441 int ADevicePrefs::create_esound_objs()
443 int x1 = x + menu->get_w() + xS(5);
444 char *output_char = 0;
446 BC_Resources *resources = BC_WindowBase::get_resources();
450 output_char = out_config->esound_out_server;
453 output_char = in_config->esound_in_server;
456 output_char = out_config->esound_out_server;
459 server_title = new BC_Title(x1, y, _("Server:"),
460 MEDIUMFONT, resources->text_default);
461 dialog->add_subwindow(server_title);
462 server_title->context_help_set_keyword("Audio Out section");
463 server = new ADeviceTextBox(x1, y + yS(20), output_char);
464 dialog->add_subwindow(server);
465 server->context_help_set_keyword("Audio Out section");
469 output_int = &out_config->esound_out_port;
472 output_int = &in_config->esound_in_port;
475 output_int = &out_config->esound_out_port;
478 x1 += server->get_w() + xS(5);
479 port_title = new BC_Title(x1, y, _("Port:"),
480 MEDIUMFONT, resources->text_default);
481 dialog->add_subwindow(port_title);
482 port_title->context_help_set_keyword("Audio Out section");
483 port = new ADeviceIntBox(x1, y + yS(20), output_int);
484 dialog->add_subwindow(port);
485 port->context_help_set_keyword("Audio Out section");
489 int ADevicePrefs::create_firewire_objs()
493 int x1 = x + menu->get_w() + xs5;
495 char *output_char = 0;
496 BC_Resources *resources = BC_WindowBase::get_resources();
501 if(driver == AUDIO_DV1394)
502 output_char = out_config->dv1394_path;
504 if(driver == AUDIO_1394)
505 output_char = out_config->firewire_path;
508 if(driver == AUDIO_DV1394 || driver == AUDIO_1394)
509 output_char = in_config->firewire_path;
514 dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
515 path_title->context_help_set_keyword("Audio Out section");
516 dialog->add_subwindow(firewire_path = new ADeviceTextBox(x1, y + ys20, output_char));
517 firewire_path->context_help_set_keyword("Audio Out section");
518 x1 += firewire_path->get_w() + xs5;
524 if(driver == AUDIO_DV1394)
525 output_int = &out_config->dv1394_port;
527 output_int = &out_config->firewire_port;
530 output_int = &in_config->firewire_port;
533 // output_int = &out_config->afirewire_out_port;
536 port_title = new BC_Title(x1, y, _("Port:"),
537 MEDIUMFONT, resources->text_default);
538 dialog->add_subwindow(port_title);
539 port_title->context_help_set_keyword("Audio Out section");
540 firewire_port = new ADeviceIntBox(x1, y + ys20, output_int);
541 dialog->add_subwindow(firewire_port);
542 firewire_port->context_help_set_keyword("Audio Out section");
544 x1 += firewire_port->get_w() + xs5;
549 if(driver == AUDIO_DV1394)
550 output_int = &out_config->dv1394_channel;
552 output_int = &out_config->firewire_channel;
555 output_int = &in_config->firewire_channel;
558 channel_title = new BC_Title(x1, y, _("Channel:"),
559 MEDIUMFONT, resources->text_default);
560 dialog->add_subwindow(channel_title);
561 channel_title->context_help_set_keyword("Audio Out section");
562 firewire_channel = new ADeviceIntBox(x1, y + ys20, output_int);
563 dialog->add_subwindow(firewire_channel);
564 firewire_channel->context_help_set_keyword("Audio Out section");
565 x1 += firewire_channel->get_w() + xs5;
570 if(driver == AUDIO_DV1394)
571 output_int = &out_config->dv1394_syt;
573 if(driver == AUDIO_1394)
574 output_int = &out_config->firewire_syt;
584 syt_title = new BC_Title(x1, y, _("Syt Offset:"),
585 MEDIUMFONT, resources->text_default);
586 dialog->add_subwindow(syt_title);
587 syt_title->context_help_set_keyword("Audio Out section");
588 firewire_syt = new ADeviceIntBox(x1, y + ys20, output_int);
589 dialog->add_subwindow(firewire_syt);
590 firewire_syt->context_help_set_keyword("Audio Out section");
591 x1 += firewire_syt->get_w() + xs5;
599 int ADevicePrefs::create_dvb_objs()
601 int x1 = x + menu->get_w() + xS(30);
603 char *output_char = in_config->dvb_in_adapter;
604 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - yS(5);
605 BC_Resources *resources = BC_WindowBase::get_resources();
606 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
607 MEDIUMFONT, resources->text_default);
608 dialog->add_subwindow(dvb_adapter_title);
609 dvb_adapter_title->context_help_set_keyword("Audio Out section");
610 dvb_adapter_path = new ADeviceTextBox(x1, y1, output_char);
611 dialog->add_subwindow(dvb_adapter_path);
612 dvb_adapter_path->context_help_set_keyword("Audio Out section");
613 int x2 = x1 + dvb_adapter_path->get_w() + xS(5);
614 dvb_device_title = new BC_Title(x2, y2, _("dev:"),
615 MEDIUMFONT, resources->text_default);
616 dialog->add_subwindow(dvb_device_title);
617 dvb_device_title->context_help_set_keyword("Audio Out section");
618 int *output_int = &in_config->dvb_in_device;
619 dvb_adapter_device = new ADeviceTumbleBox(this, x2, y1, output_int, 0, 9, xS(20));
620 dvb_adapter_device->create_objects();
621 x2 += dvb_device_title->get_w() + xS(30);
622 bits_title = new BC_Title(x2, y2, _("Bits:"),
623 MEDIUMFONT, resources->text_default);
624 dialog->add_subwindow(bits_title);
625 bits_title->context_help_set_keyword("Audio Out section");
626 output_int = &in_config->dvb_in_bits;
627 dvb_bits = new BitsPopup(dialog, x2, y1, output_int, 0, 0, 0, 0, 1);
628 dvb_bits->create_objects();
629 x1 += xS(100); y1 += dvb_adapter_path->get_h() + yS(5);
630 output_int = &in_config->follow_audio;
631 follow_audio_config = new BC_CheckBox(x1, y1, output_int, _("Follow audio config"));
632 dialog->add_subwindow(follow_audio_config);
633 follow_audio_config->context_help_set_keyword("Audio Out section");
637 int ADevicePrefs::create_v4l2mpeg_objs()
639 int x1 = x + menu->get_w() + xS(30);
641 int y2 = y1 - BC_Title::calculate_h(dialog, _("Bits:"), MEDIUMFONT) - yS(5);
642 BC_Resources *resources = BC_WindowBase::get_resources();
643 bits_title = new BC_Title(x1, y2, _("Bits:"),
644 MEDIUMFONT, resources->text_default);
645 dialog->add_subwindow(bits_title);
646 bits_title->context_help_set_keyword("Audio Out section");
647 int *output_int = &in_config->v4l2_in_bits;
648 v4l2_bits = new BitsPopup(dialog, x1, y1, output_int, 0, 0, 0, 0, 1);
649 v4l2_bits->create_objects();
650 x1 += v4l2_bits->get_w() + xS(10);
651 follow_audio_config = new BC_CheckBox(x1, y1,
652 &in_config->follow_audio, _("Follow audio config"));
653 dialog->add_subwindow(follow_audio_config);
654 follow_audio_config->context_help_set_keyword("Audio Out section");
659 int ADevicePrefs::create_pulse_objs()
662 char *output_char = 0;
665 output_char = out_config->pulse_out_server;
668 output_char = in_config->pulse_in_server;
672 x1 += menu->get_w() + xS(5);
673 dialog->add_subwindow(server_title = new BC_Title(x1, y1,
674 _("Server (blank for default):")));
675 server_title->context_help_set_keyword("Audio Out section");
676 y1 += server_title->get_h() + yS(5);
677 dialog->add_subwindow(server = new ADeviceTextBox(x1, y1, output_char));
678 server->context_help_set_keyword("Audio Out section");
684 ADriverMenu::ADriverMenu(int x, int y, ADevicePrefs *device_prefs,
685 int do_input, int *output)
686 : BC_PopupMenu(x, y, xS(125), adriver_to_string(*output), 1)
688 this->output = output;
689 this->do_input = do_input;
690 this->device_prefs = device_prefs;
693 ADriverMenu::~ADriverMenu()
697 void ADriverMenu::create_objects()
700 add_item(new ADriverItem(this, AUDIO_ALSA_TITLE, AUDIO_ALSA));
704 add_item(new ADriverItem(this, AUDIO_OSS_TITLE, AUDIO_OSS));
705 add_item(new ADriverItem(this, AUDIO_OSS_ENVY24_TITLE, AUDIO_OSS_ENVY24));
709 if(!do_input) add_item(new ADriverItem(this, AUDIO_ESOUND_TITLE, AUDIO_ESOUND));
713 if(!do_input) add_item(new ADriverItem(this, AUDIO_1394_TITLE, AUDIO_1394));
714 add_item(new ADriverItem(this, AUDIO_DV1394_TITLE, AUDIO_DV1394));
715 add_item(new ADriverItem(this, AUDIO_IEC61883_TITLE, AUDIO_IEC61883));
719 if(do_input) add_item(new ADriverItem(this, AUDIO_DVB_TITLE, AUDIO_DVB));
722 #ifdef HAVE_VIDEO4LINUX2
723 if(do_input) add_item(new ADriverItem(this, AUDIO_V4L2MPEG_TITLE, AUDIO_V4L2MPEG));
726 add_item(new ADriverItem(this, AUDIO_PULSE_TITLE, AUDIO_PULSE));
730 char* ADriverMenu::adriver_to_string(int driver)
734 sprintf(string, AUDIO_OSS_TITLE);
736 case AUDIO_OSS_ENVY24:
737 sprintf(string, AUDIO_OSS_ENVY24_TITLE);
740 sprintf(string, AUDIO_ESOUND_TITLE);
743 sprintf(string, AUDIO_PULSE_TITLE);
746 sprintf(string, AUDIO_NAS_TITLE);
749 sprintf(string, AUDIO_ALSA_TITLE);
753 sprintf(string, AUDIO_1394_TITLE);
756 sprintf(string, AUDIO_DV1394_TITLE);
759 sprintf(string, AUDIO_IEC61883_TITLE);
763 sprintf(string, AUDIO_DVB_TITLE);
766 sprintf(string, AUDIO_V4L2MPEG_TITLE);
772 ADriverItem::ADriverItem(ADriverMenu *popup, const char *text, int driver)
776 this->driver = driver;
779 ADriverItem::~ADriverItem()
783 int ADriverItem::handle_event()
785 popup->set_text(get_text());
786 *(popup->output) = driver;
787 popup->device_prefs->initialize(0);
788 popup->device_prefs->pwindow->show_dialog();
795 OSSEnable::OSSEnable(int x, int y, int *output)
796 : BC_CheckBox(x, y, *output)
798 this->output = output;
800 int OSSEnable::handle_event()
802 *output = get_value();
809 ADeviceTextBox::ADeviceTextBox(int x, int y, char *output)
810 : BC_TextBox(x, y, xS(150), 1, output)
812 this->output = output;
815 int ADeviceTextBox::handle_event()
817 strcpy(output, get_text());
821 ADeviceIntBox::ADeviceIntBox(int x, int y, int *output)
822 : BC_TextBox(x, y, xS(80), 1, *output)
824 this->output = output;
827 int ADeviceIntBox::handle_event()
829 *output = atol(get_text());
835 ADeviceTumbleBox::ADeviceTumbleBox(ADevicePrefs *prefs,
836 int x, int y, int *output, int min, int max, int text_w)
837 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
839 this->output = output;
842 int ADeviceTumbleBox::handle_event()
844 *output = atol(get_text());
850 ALSADevice::ALSADevice(PreferencesDialog *dialog,
854 ArrayList<BC_ListBoxItem*> *devices)
855 : BC_PopupTextBox(dialog, devices, output, x, y, xS(200), yS(200))
857 this->output = output;
860 ALSADevice::~ALSADevice()
864 int ALSADevice::handle_event()
866 strcpy(output, get_text());