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);
374 alsa_drivers = new ArrayList<BC_ListBoxItem*>;
375 for(int i = 0; i < alsa_titles->total; i++)
376 alsa_drivers->append(new BC_ListBoxItem(alsa_titles->values[i]));
377 alsa_titles->remove_all_objects();
382 output_char = out_config->alsa_out_device;
385 output_char = in_config->alsa_in_device;
388 output_char = out_config->alsa_out_device;
391 path_title = new BC_Title(x1, y, _("Device:"),
392 MEDIUMFONT, resources->text_default);
393 dialog->add_subwindow(path_title);
394 y1 += path_title->get_h() + margin;
395 alsa_device = new ALSADevice(dialog,
396 x1, y1, output_char, alsa_drivers);
397 alsa_device->create_objects();
400 x1 += alsa_device->get_w() + xS(5);
403 output_int = &out_config->alsa_out_bits;
406 output_int = &in_config->alsa_in_bits;
409 output_int = &out_config->alsa_out_bits;
412 bits_title = new BC_Title(x1, y, _("Bits:"),
413 MEDIUMFONT, resources->text_default);
414 dialog->add_subwindow(bits_title);
415 y1 = y + bits_title->get_h() + margin;
416 alsa_bits = new BitsPopup(dialog,
417 x1, y1, output_int, 0, 0, 0, 0, 1);
418 alsa_bits->create_objects();
420 y1 += alsa_bits->get_h();
423 if(mode == MODEPLAY) {
424 alsa_workaround = new BC_CheckBox(x1, y1,
425 &out_config->interrupt_workaround,
426 _("Stop playback locks up."));
427 dialog->add_subwindow(alsa_workaround);
433 int ADevicePrefs::create_esound_objs()
435 int x1 = x + menu->get_w() + xS(5);
436 char *output_char = 0;
438 BC_Resources *resources = BC_WindowBase::get_resources();
442 output_char = out_config->esound_out_server;
445 output_char = in_config->esound_in_server;
448 output_char = out_config->esound_out_server;
451 server_title = new BC_Title(x1, y, _("Server:"),
452 MEDIUMFONT, resources->text_default);
453 dialog->add_subwindow(server_title);
454 server = new ADeviceTextBox(x1, y + yS(20), output_char);
455 dialog->add_subwindow(server);
459 output_int = &out_config->esound_out_port;
462 output_int = &in_config->esound_in_port;
465 output_int = &out_config->esound_out_port;
468 x1 += server->get_w() + xS(5);
469 port_title = new BC_Title(x1, y, _("Port:"),
470 MEDIUMFONT, resources->text_default);
471 dialog->add_subwindow(port_title);
472 port = new ADeviceIntBox(x1, y + yS(20), output_int);
473 dialog->add_subwindow(port);
477 int ADevicePrefs::create_firewire_objs()
481 int x1 = x + menu->get_w() + xs5;
483 char *output_char = 0;
484 BC_Resources *resources = BC_WindowBase::get_resources();
489 if(driver == AUDIO_DV1394)
490 output_char = out_config->dv1394_path;
492 if(driver == AUDIO_1394)
493 output_char = out_config->firewire_path;
496 if(driver == AUDIO_DV1394 || driver == AUDIO_1394)
497 output_char = in_config->firewire_path;
502 dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
503 dialog->add_subwindow(firewire_path = new ADeviceTextBox(x1, y + ys20, output_char));
504 x1 += firewire_path->get_w() + xs5;
510 if(driver == AUDIO_DV1394)
511 output_int = &out_config->dv1394_port;
513 output_int = &out_config->firewire_port;
516 output_int = &in_config->firewire_port;
519 // output_int = &out_config->afirewire_out_port;
522 port_title = new BC_Title(x1, y, _("Port:"),
523 MEDIUMFONT, resources->text_default);
524 dialog->add_subwindow(port_title);
525 firewire_port = new ADeviceIntBox(x1, y + ys20, output_int);
526 dialog->add_subwindow(firewire_port);
528 x1 += firewire_port->get_w() + xs5;
533 if(driver == AUDIO_DV1394)
534 output_int = &out_config->dv1394_channel;
536 output_int = &out_config->firewire_channel;
539 output_int = &in_config->firewire_channel;
542 channel_title = new BC_Title(x1, y, _("Channel:"),
543 MEDIUMFONT, resources->text_default);
544 dialog->add_subwindow(channel_title);
545 firewire_channel = new ADeviceIntBox(x1, y + ys20, output_int);
546 dialog->add_subwindow(firewire_channel);
547 x1 += firewire_channel->get_w() + xs5;
552 if(driver == AUDIO_DV1394)
553 output_int = &out_config->dv1394_syt;
555 if(driver == AUDIO_1394)
556 output_int = &out_config->firewire_syt;
566 syt_title = new BC_Title(x1, y, _("Syt Offset:"),
567 MEDIUMFONT, resources->text_default);
568 dialog->add_subwindow(syt_title);
569 firewire_syt = new ADeviceIntBox(x1, y + ys20, output_int);
570 dialog->add_subwindow(firewire_syt);
571 x1 += firewire_syt->get_w() + xs5;
579 int ADevicePrefs::create_dvb_objs()
581 int x1 = x + menu->get_w() + xS(30);
583 char *output_char = in_config->dvb_in_adapter;
584 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - yS(5);
585 BC_Resources *resources = BC_WindowBase::get_resources();
586 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
587 MEDIUMFONT, resources->text_default);
588 dialog->add_subwindow(dvb_adapter_title);
589 dvb_adapter_path = new ADeviceTextBox(x1, y1, output_char);
590 dialog->add_subwindow(dvb_adapter_path);
591 int x2 = x1 + dvb_adapter_path->get_w() + xS(5);
592 dvb_device_title = new BC_Title(x2, y2, _("dev:"),
593 MEDIUMFONT, resources->text_default);
594 dialog->add_subwindow(dvb_device_title);
595 int *output_int = &in_config->dvb_in_device;
596 dvb_adapter_device = new ADeviceTumbleBox(this, x2, y1, output_int, 0, 9, xS(20));
597 dvb_adapter_device->create_objects();
598 x2 += dvb_device_title->get_w() + xS(30);
599 bits_title = new BC_Title(x2, y2, _("Bits:"),
600 MEDIUMFONT, resources->text_default);
601 dialog->add_subwindow(bits_title);
602 output_int = &in_config->dvb_in_bits;
603 dvb_bits = new BitsPopup(dialog, x2, y1, output_int, 0, 0, 0, 0, 1);
604 dvb_bits->create_objects();
605 x1 += xS(100); y1 += dvb_adapter_path->get_h() + yS(5);
606 output_int = &in_config->follow_audio;
607 follow_audio_config = new BC_CheckBox(x1, y1, output_int, _("Follow audio config"));
608 dialog->add_subwindow(follow_audio_config);
612 int ADevicePrefs::create_v4l2mpeg_objs()
614 int x1 = x + menu->get_w() + xS(30);
616 int y2 = y1 - BC_Title::calculate_h(dialog, _("Bits:"), MEDIUMFONT) - yS(5);
617 BC_Resources *resources = BC_WindowBase::get_resources();
618 bits_title = new BC_Title(x1, y2, _("Bits:"),
619 MEDIUMFONT, resources->text_default);
620 dialog->add_subwindow(bits_title);
621 int *output_int = &in_config->v4l2_in_bits;
622 v4l2_bits = new BitsPopup(dialog, x1, y1, output_int, 0, 0, 0, 0, 1);
623 v4l2_bits->create_objects();
624 x1 += v4l2_bits->get_w() + xS(10);
625 follow_audio_config = new BC_CheckBox(x1, y1,
626 &in_config->follow_audio, _("Follow audio config"));
627 dialog->add_subwindow(follow_audio_config);
632 int ADevicePrefs::create_pulse_objs()
635 char *output_char = 0;
638 output_char = out_config->pulse_out_server;
641 output_char = in_config->pulse_in_server;
645 x1 += menu->get_w() + xS(5);
646 dialog->add_subwindow(server_title = new BC_Title(x1, y1,
647 _("Server (blank for default):")));
648 y1 += server_title->get_h() + yS(5);
649 dialog->add_subwindow(server = new ADeviceTextBox(x1, y1, output_char));
655 ADriverMenu::ADriverMenu(int x, int y, ADevicePrefs *device_prefs,
656 int do_input, int *output)
657 : BC_PopupMenu(x, y, xS(125), adriver_to_string(*output), 1)
659 this->output = output;
660 this->do_input = do_input;
661 this->device_prefs = device_prefs;
664 ADriverMenu::~ADriverMenu()
668 void ADriverMenu::create_objects()
671 add_item(new ADriverItem(this, AUDIO_ALSA_TITLE, AUDIO_ALSA));
675 add_item(new ADriverItem(this, AUDIO_OSS_TITLE, AUDIO_OSS));
676 add_item(new ADriverItem(this, AUDIO_OSS_ENVY24_TITLE, AUDIO_OSS_ENVY24));
680 if(!do_input) add_item(new ADriverItem(this, AUDIO_ESOUND_TITLE, AUDIO_ESOUND));
684 if(!do_input) add_item(new ADriverItem(this, AUDIO_1394_TITLE, AUDIO_1394));
685 add_item(new ADriverItem(this, AUDIO_DV1394_TITLE, AUDIO_DV1394));
686 add_item(new ADriverItem(this, AUDIO_IEC61883_TITLE, AUDIO_IEC61883));
690 if(do_input) add_item(new ADriverItem(this, AUDIO_DVB_TITLE, AUDIO_DVB));
693 #ifdef HAVE_VIDEO4LINUX2
694 if(do_input) add_item(new ADriverItem(this, AUDIO_V4L2MPEG_TITLE, AUDIO_V4L2MPEG));
697 add_item(new ADriverItem(this, AUDIO_PULSE_TITLE, AUDIO_PULSE));
701 char* ADriverMenu::adriver_to_string(int driver)
705 sprintf(string, AUDIO_OSS_TITLE);
707 case AUDIO_OSS_ENVY24:
708 sprintf(string, AUDIO_OSS_ENVY24_TITLE);
711 sprintf(string, AUDIO_ESOUND_TITLE);
714 sprintf(string, AUDIO_PULSE_TITLE);
717 sprintf(string, AUDIO_NAS_TITLE);
720 sprintf(string, AUDIO_ALSA_TITLE);
724 sprintf(string, AUDIO_1394_TITLE);
727 sprintf(string, AUDIO_DV1394_TITLE);
730 sprintf(string, AUDIO_IEC61883_TITLE);
734 sprintf(string, AUDIO_DVB_TITLE);
737 sprintf(string, AUDIO_V4L2MPEG_TITLE);
743 ADriverItem::ADriverItem(ADriverMenu *popup, const char *text, int driver)
747 this->driver = driver;
750 ADriverItem::~ADriverItem()
754 int ADriverItem::handle_event()
756 popup->set_text(get_text());
757 *(popup->output) = driver;
758 popup->device_prefs->initialize(0);
759 popup->device_prefs->pwindow->show_dialog();
766 OSSEnable::OSSEnable(int x, int y, int *output)
767 : BC_CheckBox(x, y, *output)
769 this->output = output;
771 int OSSEnable::handle_event()
773 *output = get_value();
780 ADeviceTextBox::ADeviceTextBox(int x, int y, char *output)
781 : BC_TextBox(x, y, xS(150), 1, output)
783 this->output = output;
786 int ADeviceTextBox::handle_event()
788 strcpy(output, get_text());
792 ADeviceIntBox::ADeviceIntBox(int x, int y, int *output)
793 : BC_TextBox(x, y, xS(80), 1, *output)
795 this->output = output;
798 int ADeviceIntBox::handle_event()
800 *output = atol(get_text());
806 ADeviceTumbleBox::ADeviceTumbleBox(ADevicePrefs *prefs,
807 int x, int y, int *output, int min, int max, int text_w)
808 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
810 this->output = output;
813 int ADeviceTumbleBox::handle_event()
815 *output = atol(get_text());
821 ALSADevice::ALSADevice(PreferencesDialog *dialog,
825 ArrayList<BC_ListBoxItem*> *devices)
826 : BC_PopupTextBox(dialog, devices, output, x, y, xS(200), yS(200))
828 this->output = output;
831 ALSADevice::~ALSADevice()
835 int ALSADevice::handle_event()
837 strcpy(output, get_text());