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();
124 case AUDIO_OSS_ENVY24:
134 create_esound_objs();
139 create_firewire_objs();
145 create_v4l2mpeg_objs();
152 int ADevicePrefs::get_h(int recording)
154 int margin = pwindow->mwindow->theme->widget_border;
155 int result = BC_Title::calculate_h(dialog, "X", MEDIUMFONT) + margin +
156 BC_TextBox::calculate_h(dialog, MEDIUMFONT, 1, 1);
158 result += BC_CheckBox::calculate_h(dialog) + margin;
164 int ADevicePrefs::delete_objects()
168 case AUDIO_OSS_ENVY24:
178 delete_esound_objs();
183 delete_firewire_objs();
189 delete_v4l2mpeg_objs();
201 int ADevicePrefs::delete_oss_objs()
207 for(int i = 0; i < MAXDEVICES; i++)
212 int ADevicePrefs::delete_esound_objs()
221 int ADevicePrefs::delete_firewire_objs()
224 delete channel_title;
225 delete firewire_port;
226 delete firewire_channel;
230 delete firewire_path;
242 int ADevicePrefs::delete_alsa_objs()
245 if(alsa_drivers) alsa_drivers->remove_all_objects();
251 delete alsa_workaround;
256 int ADevicePrefs::delete_pulse_objs()
265 int ADevicePrefs::delete_dvb_objs()
267 delete dvb_adapter_title;
268 delete dvb_adapter_path;
269 delete dvb_device_title;
270 delete dvb_adapter_device;
272 delete follow_audio_config;
276 int ADevicePrefs::delete_v4l2mpeg_objs()
278 delete follow_audio_config;
283 int ADevicePrefs::create_oss_objs()
285 char *output_char = 0;
287 int margin = pwindow->mwindow->theme->widget_border;
289 BC_Resources *resources = BC_WindowBase::get_resources();
291 for(int i = 0; i < MAXDEVICES; i++) {
292 int x1 = x + menu->get_w() + xS(5);
296 output_int = &out_config->oss_enable[i];
299 output_int = &in_config->oss_enable[i];
302 output_int = &out_config->oss_enable[i];
305 dialog->add_subwindow(oss_enable[i] = new OSSEnable(x1, y1 + yS(20), output_int));
306 x1 += oss_enable[i]->get_w() + margin;
310 output_char = out_config->oss_out_device[i];
313 output_char = in_config->oss_in_device[i];
316 output_char = out_config->oss_out_device[i];
321 path_title = new BC_Title(x1, y, _("Device path:"),
322 MEDIUMFONT, resources->text_default);
323 dialog->add_subwindow(path_title);
326 oss_path[i] = new ADeviceTextBox(
327 x1, y1 + path_title->get_h() + margin, output_char);
328 dialog->add_subwindow(oss_path[i]);
329 x1 += oss_path[i]->get_w() + margin;
333 output_int = &out_config->oss_out_bits;
336 output_int = &in_config->oss_in_bits;
339 output_int = &out_config->oss_out_bits;
342 bits_title = new BC_Title(x1, y, _("Bits:"),
343 MEDIUMFONT, resources->text_default);
344 dialog->add_subwindow(bits_title);
345 oss_bits = new BitsPopup(dialog,
346 x1, y1 + bits_title->get_h() + margin,
347 output_int, 0, 0, 0, 0, 1);
348 oss_bits->create_objects();
351 x1 += oss_bits->get_w() + margin;
359 int ADevicePrefs::create_alsa_objs()
362 char *output_char = 0;
364 int margin = pwindow->mwindow->theme->widget_border;
365 BC_Resources *resources = BC_WindowBase::get_resources();
367 int x1 = x + menu->get_w() + margin;
370 ArrayList<char*> *alsa_titles = new ArrayList<char*>;
371 alsa_titles->set_array_delete();
372 AudioALSA::list_devices(alsa_titles, 0, mode);
373 AudioALSA::add_pulse_devices(mode, alsa_titles, 0);
375 alsa_drivers = new ArrayList<BC_ListBoxItem*>;
376 for(int i = 0; i < alsa_titles->total; i++)
377 alsa_drivers->append(new BC_ListBoxItem(alsa_titles->values[i]));
378 alsa_titles->remove_all_objects();
383 output_char = out_config->alsa_out_device;
386 output_char = in_config->alsa_in_device;
389 output_char = out_config->alsa_out_device;
392 path_title = new BC_Title(x1, y, _("Device:"),
393 MEDIUMFONT, resources->text_default);
394 dialog->add_subwindow(path_title);
395 y1 += path_title->get_h() + margin;
396 alsa_device = new ALSADevice(dialog,
397 x1, y1, output_char, alsa_drivers);
398 alsa_device->create_objects();
401 x1 += alsa_device->get_w() + xS(5);
404 output_int = &out_config->alsa_out_bits;
407 output_int = &in_config->alsa_in_bits;
410 output_int = &out_config->alsa_out_bits;
413 bits_title = new BC_Title(x1, y, _("Bits:"),
414 MEDIUMFONT, resources->text_default);
415 dialog->add_subwindow(bits_title);
416 y1 = y + bits_title->get_h() + margin;
417 alsa_bits = new BitsPopup(dialog,
418 x1, y1, output_int, 0, 0, 0, 0, 1);
419 alsa_bits->create_objects();
421 y1 += alsa_bits->get_h();
424 if(mode == MODEPLAY) {
425 alsa_workaround = new BC_CheckBox(x1, y1,
426 &out_config->interrupt_workaround,
427 _("Stop playback locks up."));
428 dialog->add_subwindow(alsa_workaround);
434 int ADevicePrefs::create_esound_objs()
436 int x1 = x + menu->get_w() + xS(5);
437 char *output_char = 0;
439 BC_Resources *resources = BC_WindowBase::get_resources();
443 output_char = out_config->esound_out_server;
446 output_char = in_config->esound_in_server;
449 output_char = out_config->esound_out_server;
452 server_title = new BC_Title(x1, y, _("Server:"),
453 MEDIUMFONT, resources->text_default);
454 dialog->add_subwindow(server_title);
455 server = new ADeviceTextBox(x1, y + yS(20), output_char);
456 dialog->add_subwindow(server);
460 output_int = &out_config->esound_out_port;
463 output_int = &in_config->esound_in_port;
466 output_int = &out_config->esound_out_port;
469 x1 += server->get_w() + xS(5);
470 port_title = new BC_Title(x1, y, _("Port:"),
471 MEDIUMFONT, resources->text_default);
472 dialog->add_subwindow(port_title);
473 port = new ADeviceIntBox(x1, y + yS(20), output_int);
474 dialog->add_subwindow(port);
478 int ADevicePrefs::create_firewire_objs()
482 int x1 = x + menu->get_w() + xs5;
484 char *output_char = 0;
485 BC_Resources *resources = BC_WindowBase::get_resources();
490 if(driver == AUDIO_DV1394)
491 output_char = out_config->dv1394_path;
493 if(driver == AUDIO_1394)
494 output_char = out_config->firewire_path;
497 if(driver == AUDIO_DV1394 || driver == AUDIO_1394)
498 output_char = in_config->firewire_path;
503 dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
504 dialog->add_subwindow(firewire_path = new ADeviceTextBox(x1, y + ys20, output_char));
505 x1 += firewire_path->get_w() + xs5;
511 if(driver == AUDIO_DV1394)
512 output_int = &out_config->dv1394_port;
514 output_int = &out_config->firewire_port;
517 output_int = &in_config->firewire_port;
520 // output_int = &out_config->afirewire_out_port;
523 port_title = new BC_Title(x1, y, _("Port:"),
524 MEDIUMFONT, resources->text_default);
525 dialog->add_subwindow(port_title);
526 firewire_port = new ADeviceIntBox(x1, y + ys20, output_int);
527 dialog->add_subwindow(firewire_port);
529 x1 += firewire_port->get_w() + xs5;
534 if(driver == AUDIO_DV1394)
535 output_int = &out_config->dv1394_channel;
537 output_int = &out_config->firewire_channel;
540 output_int = &in_config->firewire_channel;
543 channel_title = new BC_Title(x1, y, _("Channel:"),
544 MEDIUMFONT, resources->text_default);
545 dialog->add_subwindow(channel_title);
546 firewire_channel = new ADeviceIntBox(x1, y + ys20, output_int);
547 dialog->add_subwindow(firewire_channel);
548 x1 += firewire_channel->get_w() + xs5;
553 if(driver == AUDIO_DV1394)
554 output_int = &out_config->dv1394_syt;
556 if(driver == AUDIO_1394)
557 output_int = &out_config->firewire_syt;
567 syt_title = new BC_Title(x1, y, _("Syt Offset:"),
568 MEDIUMFONT, resources->text_default);
569 dialog->add_subwindow(syt_title);
570 firewire_syt = new ADeviceIntBox(x1, y + ys20, output_int);
571 dialog->add_subwindow(firewire_syt);
572 x1 += firewire_syt->get_w() + xs5;
580 int ADevicePrefs::create_dvb_objs()
582 int x1 = x + menu->get_w() + xS(30);
584 char *output_char = in_config->dvb_in_adapter;
585 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - yS(5);
586 BC_Resources *resources = BC_WindowBase::get_resources();
587 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
588 MEDIUMFONT, resources->text_default);
589 dialog->add_subwindow(dvb_adapter_title);
590 dvb_adapter_path = new ADeviceTextBox(x1, y1, output_char);
591 dialog->add_subwindow(dvb_adapter_path);
592 int x2 = x1 + dvb_adapter_path->get_w() + xS(5);
593 dvb_device_title = new BC_Title(x2, y2, _("dev:"),
594 MEDIUMFONT, resources->text_default);
595 dialog->add_subwindow(dvb_device_title);
596 int *output_int = &in_config->dvb_in_device;
597 dvb_adapter_device = new ADeviceTumbleBox(this, x2, y1, output_int, 0, 9, xS(20));
598 dvb_adapter_device->create_objects();
599 x2 += dvb_device_title->get_w() + xS(30);
600 bits_title = new BC_Title(x2, y2, _("Bits:"),
601 MEDIUMFONT, resources->text_default);
602 dialog->add_subwindow(bits_title);
603 output_int = &in_config->dvb_in_bits;
604 dvb_bits = new BitsPopup(dialog, x2, y1, output_int, 0, 0, 0, 0, 1);
605 dvb_bits->create_objects();
606 x1 += xS(100); y1 += dvb_adapter_path->get_h() + yS(5);
607 output_int = &in_config->follow_audio;
608 follow_audio_config = new BC_CheckBox(x1, y1, output_int, _("Follow audio config"));
609 dialog->add_subwindow(follow_audio_config);
613 int ADevicePrefs::create_v4l2mpeg_objs()
615 int x1 = x + menu->get_w() + xS(30);
617 int y2 = y1 - BC_Title::calculate_h(dialog, _("Bits:"), MEDIUMFONT) - yS(5);
618 BC_Resources *resources = BC_WindowBase::get_resources();
619 bits_title = new BC_Title(x1, y2, _("Bits:"),
620 MEDIUMFONT, resources->text_default);
621 dialog->add_subwindow(bits_title);
622 int *output_int = &in_config->v4l2_in_bits;
623 v4l2_bits = new BitsPopup(dialog, x1, y1, output_int, 0, 0, 0, 0, 1);
624 v4l2_bits->create_objects();
625 x1 += v4l2_bits->get_w() + xS(10);
626 follow_audio_config = new BC_CheckBox(x1, y1,
627 &in_config->follow_audio, _("Follow audio config"));
628 dialog->add_subwindow(follow_audio_config);
633 int ADevicePrefs::create_pulse_objs()
636 char *output_char = 0;
639 output_char = out_config->pulse_out_server;
642 output_char = in_config->pulse_in_server;
646 x1 += menu->get_w() + xS(5);
647 dialog->add_subwindow(server_title = new BC_Title(x1, y1,
648 _("Server (blank for default):")));
649 y1 += server_title->get_h() + yS(5);
650 dialog->add_subwindow(server = new ADeviceTextBox(x1, y1, output_char));
656 ADriverMenu::ADriverMenu(int x, int y, ADevicePrefs *device_prefs,
657 int do_input, int *output)
658 : BC_PopupMenu(x, y, xS(125), adriver_to_string(*output), 1)
660 this->output = output;
661 this->do_input = do_input;
662 this->device_prefs = device_prefs;
665 ADriverMenu::~ADriverMenu()
669 void ADriverMenu::create_objects()
672 add_item(new ADriverItem(this, AUDIO_ALSA_TITLE, AUDIO_ALSA));
676 add_item(new ADriverItem(this, AUDIO_OSS_TITLE, AUDIO_OSS));
677 add_item(new ADriverItem(this, AUDIO_OSS_ENVY24_TITLE, AUDIO_OSS_ENVY24));
681 if(!do_input) add_item(new ADriverItem(this, AUDIO_ESOUND_TITLE, AUDIO_ESOUND));
685 if(!do_input) add_item(new ADriverItem(this, AUDIO_1394_TITLE, AUDIO_1394));
686 add_item(new ADriverItem(this, AUDIO_DV1394_TITLE, AUDIO_DV1394));
687 add_item(new ADriverItem(this, AUDIO_IEC61883_TITLE, AUDIO_IEC61883));
691 if(do_input) add_item(new ADriverItem(this, AUDIO_DVB_TITLE, AUDIO_DVB));
694 #ifdef HAVE_VIDEO4LINUX2
695 if(do_input) add_item(new ADriverItem(this, AUDIO_V4L2MPEG_TITLE, AUDIO_V4L2MPEG));
698 add_item(new ADriverItem(this, AUDIO_PULSE_TITLE, AUDIO_PULSE));
702 char* ADriverMenu::adriver_to_string(int driver)
706 sprintf(string, AUDIO_OSS_TITLE);
708 case AUDIO_OSS_ENVY24:
709 sprintf(string, AUDIO_OSS_ENVY24_TITLE);
712 sprintf(string, AUDIO_ESOUND_TITLE);
715 sprintf(string, AUDIO_PULSE_TITLE);
718 sprintf(string, AUDIO_NAS_TITLE);
721 sprintf(string, AUDIO_ALSA_TITLE);
725 sprintf(string, AUDIO_1394_TITLE);
728 sprintf(string, AUDIO_DV1394_TITLE);
731 sprintf(string, AUDIO_IEC61883_TITLE);
735 sprintf(string, AUDIO_DVB_TITLE);
738 sprintf(string, AUDIO_V4L2MPEG_TITLE);
744 ADriverItem::ADriverItem(ADriverMenu *popup, const char *text, int driver)
748 this->driver = driver;
751 ADriverItem::~ADriverItem()
755 int ADriverItem::handle_event()
757 popup->set_text(get_text());
758 *(popup->output) = driver;
759 popup->device_prefs->initialize(0);
760 popup->device_prefs->pwindow->show_dialog();
767 OSSEnable::OSSEnable(int x, int y, int *output)
768 : BC_CheckBox(x, y, *output)
770 this->output = output;
772 int OSSEnable::handle_event()
774 *output = get_value();
781 ADeviceTextBox::ADeviceTextBox(int x, int y, char *output)
782 : BC_TextBox(x, y, xS(150), 1, output)
784 this->output = output;
787 int ADeviceTextBox::handle_event()
789 strcpy(output, get_text());
793 ADeviceIntBox::ADeviceIntBox(int x, int y, int *output)
794 : BC_TextBox(x, y, xS(80), 1, *output)
796 this->output = output;
799 int ADeviceIntBox::handle_event()
801 *output = atol(get_text());
807 ADeviceTumbleBox::ADeviceTumbleBox(ADevicePrefs *prefs,
808 int x, int y, int *output, int min, int max, int text_w)
809 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
811 this->output = output;
814 int ADeviceTumbleBox::handle_event()
816 *output = atol(get_text());
822 ALSADevice::ALSADevice(PreferencesDialog *dialog,
826 ArrayList<BC_ListBoxItem*> *devices)
827 : BC_PopupTextBox(dialog, devices, output, x, y, xS(200), yS(200))
829 this->output = output;
832 ALSADevice::~ALSADevice()
836 int ALSADevice::handle_event()
838 strcpy(output, get_text());