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 "bcsignals.h"
26 #include "bitspopup.h"
30 #include "playbackconfig.h"
31 #include "preferences.h"
32 #include "preferencesthread.h"
33 #include "recordconfig.h"
39 ADevicePrefs::ADevicePrefs(int x, int y, PreferencesWindow *pwindow, PreferencesDialog *dialog,
40 AudioOutConfig *out_config, AudioInConfig *in_config, int mode)
43 this->pwindow = pwindow;
44 this->dialog = dialog;
47 this->out_config = out_config;
48 this->in_config = in_config;
53 ADevicePrefs::~ADevicePrefs()
59 void ADevicePrefs::reset()
62 follow_audio_config = 0;
82 for(int i = 0; i < MAXDEVICES; i++)
85 dvb_adapter_title = 0;
88 dvb_adapter_device = 0;
97 int ADevicePrefs::initialize(int creation)
104 driver = &out_config->driver;
107 driver = &in_config->driver;
110 driver = &out_config->driver;
113 this->driver = *driver;
116 dialog->add_subwindow(menu = new ADriverMenu(x,
117 y + yS(10), this, (mode == MODERECORD), driver));
118 menu->create_objects();
123 case AUDIO_OSS_ENVY24:
130 create_esound_objs();
135 create_firewire_objs();
141 create_v4l2mpeg_objs();
148 int ADevicePrefs::get_h(int recording)
150 int margin = pwindow->mwindow->theme->widget_border;
151 int result = BC_Title::calculate_h(dialog, "X", MEDIUMFONT) + margin +
152 BC_TextBox::calculate_h(dialog, MEDIUMFONT, 1, 1);
154 result += BC_CheckBox::calculate_h(dialog) + margin;
160 int ADevicePrefs::delete_objects()
164 case AUDIO_OSS_ENVY24:
171 delete_esound_objs();
176 delete_firewire_objs();
182 delete_v4l2mpeg_objs();
194 int ADevicePrefs::delete_oss_objs()
200 for(int i = 0; i < MAXDEVICES; i++)
205 int ADevicePrefs::delete_esound_objs()
209 delete esound_server;
214 int ADevicePrefs::delete_firewire_objs()
217 delete channel_title;
218 delete firewire_port;
219 delete firewire_channel;
223 delete firewire_path;
235 int ADevicePrefs::delete_alsa_objs()
238 if(alsa_drivers) alsa_drivers->remove_all_objects();
244 delete alsa_workaround;
249 int ADevicePrefs::delete_dvb_objs()
251 delete dvb_adapter_title;
252 delete dvb_adapter_path;
253 delete dvb_device_title;
254 delete dvb_adapter_device;
256 delete follow_audio_config;
260 int ADevicePrefs::delete_v4l2mpeg_objs()
262 delete follow_audio_config;
267 int ADevicePrefs::create_oss_objs()
269 char *output_char = 0;
271 int margin = pwindow->mwindow->theme->widget_border;
273 BC_Resources *resources = BC_WindowBase::get_resources();
275 for(int i = 0; i < MAXDEVICES; i++) {
276 int x1 = x + menu->get_w() + xS(5);
280 output_int = &out_config->oss_enable[i];
283 output_int = &in_config->oss_enable[i];
286 output_int = &out_config->oss_enable[i];
289 dialog->add_subwindow(oss_enable[i] = new OSSEnable(x1, y1 + yS(20), output_int));
290 x1 += oss_enable[i]->get_w() + margin;
294 output_char = out_config->oss_out_device[i];
297 output_char = in_config->oss_in_device[i];
300 output_char = out_config->oss_out_device[i];
305 path_title = new BC_Title(x1, y, _("Device path:"),
306 MEDIUMFONT, resources->text_default);
307 dialog->add_subwindow(path_title);
310 oss_path[i] = new ADeviceTextBox(
311 x1, y1 + path_title->get_h() + margin, output_char);
312 dialog->add_subwindow(oss_path[i]);
313 x1 += oss_path[i]->get_w() + margin;
317 output_int = &out_config->oss_out_bits;
320 output_int = &in_config->oss_in_bits;
323 output_int = &out_config->oss_out_bits;
326 bits_title = new BC_Title(x1, y, _("Bits:"),
327 MEDIUMFONT, resources->text_default);
328 dialog->add_subwindow(bits_title);
329 oss_bits = new BitsPopup(dialog,
330 x1, y1 + bits_title->get_h() + margin,
331 output_int, 0, 0, 0, 0, 1);
332 oss_bits->create_objects();
335 x1 += oss_bits->get_w() + margin;
343 int ADevicePrefs::create_alsa_objs()
346 char *output_char = 0;
348 int margin = pwindow->mwindow->theme->widget_border;
349 BC_Resources *resources = BC_WindowBase::get_resources();
351 int x1 = x + menu->get_w() + margin;
354 ArrayList<char*> *alsa_titles = new ArrayList<char*>;
355 alsa_titles->set_array_delete();
356 AudioALSA::list_devices(alsa_titles, 0, mode);
358 alsa_drivers = new ArrayList<BC_ListBoxItem*>;
359 for(int i = 0; i < alsa_titles->total; i++)
360 alsa_drivers->append(new BC_ListBoxItem(alsa_titles->values[i]));
361 alsa_titles->remove_all_objects();
366 output_char = out_config->alsa_out_device;
369 output_char = in_config->alsa_in_device;
372 output_char = out_config->alsa_out_device;
375 path_title = new BC_Title(x1, y, _("Device:"),
376 MEDIUMFONT, resources->text_default);
377 dialog->add_subwindow(path_title);
378 y1 += path_title->get_h() + margin;
379 alsa_device = new ALSADevice(dialog,
380 x1, y1, output_char, alsa_drivers);
381 alsa_device->create_objects();
384 x1 += alsa_device->get_w() + xS(5);
387 output_int = &out_config->alsa_out_bits;
390 output_int = &in_config->alsa_in_bits;
393 output_int = &out_config->alsa_out_bits;
396 bits_title = new BC_Title(x1, y, _("Bits:"),
397 MEDIUMFONT, resources->text_default);
398 dialog->add_subwindow(bits_title);
399 y1 = y + bits_title->get_h() + margin;
400 alsa_bits = new BitsPopup(dialog,
401 x1, y1, output_int, 0, 0, 0, 0, 1);
402 alsa_bits->create_objects();
404 y1 += alsa_bits->get_h();
407 if(mode == MODEPLAY) {
408 alsa_workaround = new BC_CheckBox(x1, y1,
409 &out_config->interrupt_workaround,
410 _("Stop playback locks up."));
411 dialog->add_subwindow(alsa_workaround);
419 int ADevicePrefs::create_esound_objs()
421 int x1 = x + menu->get_w() + xS(5);
422 char *output_char = 0;
424 BC_Resources *resources = BC_WindowBase::get_resources();
428 output_char = out_config->esound_out_server;
431 output_char = in_config->esound_in_server;
434 output_char = out_config->esound_out_server;
437 server_title = new BC_Title(x1, y, _("Server:"),
438 MEDIUMFONT, resources->text_default);
439 dialog->add_subwindow(server_title);
440 esound_server = new ADeviceTextBox(x1, y + yS(20), output_char);
441 dialog->add_subwindow(esound_server);
445 output_int = &out_config->esound_out_port;
448 output_int = &in_config->esound_in_port;
451 output_int = &out_config->esound_out_port;
454 x1 += esound_server->get_w() + xS(5);
455 port_title = new BC_Title(x1, y, _("Port:"),
456 MEDIUMFONT, resources->text_default);
457 dialog->add_subwindow(port_title);
458 esound_port = new ADeviceIntBox(x1, y + yS(20), output_int);
459 dialog->add_subwindow(esound_port);
463 int ADevicePrefs::create_firewire_objs()
467 int x1 = x + menu->get_w() + xs5;
469 char *output_char = 0;
470 BC_Resources *resources = BC_WindowBase::get_resources();
475 if(driver == AUDIO_DV1394)
476 output_char = out_config->dv1394_path;
478 if(driver == AUDIO_1394)
479 output_char = out_config->firewire_path;
482 if(driver == AUDIO_DV1394 || driver == AUDIO_1394)
483 output_char = in_config->firewire_path;
488 dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
489 dialog->add_subwindow(firewire_path = new ADeviceTextBox(x1, y + ys20, output_char));
490 x1 += firewire_path->get_w() + xs5;
496 if(driver == AUDIO_DV1394)
497 output_int = &out_config->dv1394_port;
499 output_int = &out_config->firewire_port;
502 output_int = &in_config->firewire_port;
505 // output_int = &out_config->afirewire_out_port;
508 port_title = new BC_Title(x1, y, _("Port:"),
509 MEDIUMFONT, resources->text_default);
510 dialog->add_subwindow(port_title);
511 firewire_port = new ADeviceIntBox(x1, y + ys20, output_int);
512 dialog->add_subwindow(firewire_port);
514 x1 += firewire_port->get_w() + xs5;
519 if(driver == AUDIO_DV1394)
520 output_int = &out_config->dv1394_channel;
522 output_int = &out_config->firewire_channel;
525 output_int = &in_config->firewire_channel;
528 channel_title = new BC_Title(x1, y, _("Channel:"),
529 MEDIUMFONT, resources->text_default);
530 dialog->add_subwindow(channel_title);
531 firewire_channel = new ADeviceIntBox(x1, y + ys20, output_int);
532 dialog->add_subwindow(firewire_channel);
533 x1 += firewire_channel->get_w() + xs5;
538 if(driver == AUDIO_DV1394)
539 output_int = &out_config->dv1394_syt;
541 if(driver == AUDIO_1394)
542 output_int = &out_config->firewire_syt;
552 syt_title = new BC_Title(x1, y, _("Syt Offset:"),
553 MEDIUMFONT, resources->text_default);
554 dialog->add_subwindow(syt_title);
555 firewire_syt = new ADeviceIntBox(x1, y + ys20, output_int);
556 dialog->add_subwindow(firewire_syt);
557 x1 += firewire_syt->get_w() + xs5;
565 int ADevicePrefs::create_dvb_objs()
567 int x1 = x + menu->get_w() + xS(30);
569 char *output_char = in_config->dvb_in_adapter;
570 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - yS(5);
571 BC_Resources *resources = BC_WindowBase::get_resources();
572 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
573 MEDIUMFONT, resources->text_default);
574 dialog->add_subwindow(dvb_adapter_title);
575 dvb_adapter_path = new ADeviceTextBox(x1, y1, output_char);
576 dialog->add_subwindow(dvb_adapter_path);
577 int x2 = x1 + dvb_adapter_path->get_w() + xS(5);
578 dvb_device_title = new BC_Title(x2, y2, _("dev:"),
579 MEDIUMFONT, resources->text_default);
580 dialog->add_subwindow(dvb_device_title);
581 int *output_int = &in_config->dvb_in_device;
582 dvb_adapter_device = new ADeviceTumbleBox(this, x2, y1, output_int, 0, 9, xS(20));
583 dvb_adapter_device->create_objects();
584 x2 += dvb_device_title->get_w() + xS(30);
585 bits_title = new BC_Title(x2, y2, _("Bits:"),
586 MEDIUMFONT, resources->text_default);
587 dialog->add_subwindow(bits_title);
588 output_int = &in_config->dvb_in_bits;
589 dvb_bits = new BitsPopup(dialog, x2, y1, output_int, 0, 0, 0, 0, 1);
590 dvb_bits->create_objects();
591 x1 += xS(100); y1 += dvb_adapter_path->get_h() + yS(5);
592 output_int = &in_config->follow_audio;
593 follow_audio_config = new BC_CheckBox(x1, y1, output_int, _("Follow audio config"));
594 dialog->add_subwindow(follow_audio_config);
598 int ADevicePrefs::create_v4l2mpeg_objs()
600 int x1 = x + menu->get_w() + xS(30);
602 int y2 = y1 - BC_Title::calculate_h(dialog, _("Bits:"), MEDIUMFONT) - yS(5);
603 BC_Resources *resources = BC_WindowBase::get_resources();
604 bits_title = new BC_Title(x1, y2, _("Bits:"),
605 MEDIUMFONT, resources->text_default);
606 dialog->add_subwindow(bits_title);
607 int *output_int = &in_config->v4l2_in_bits;
608 v4l2_bits = new BitsPopup(dialog, x1, y1, output_int, 0, 0, 0, 0, 1);
609 v4l2_bits->create_objects();
610 x1 += v4l2_bits->get_w() + xS(10);
611 follow_audio_config = new BC_CheckBox(x1, y1,
612 &in_config->follow_audio, _("Follow audio config"));
613 dialog->add_subwindow(follow_audio_config);
618 ADriverMenu::ADriverMenu(int x, int y, ADevicePrefs *device_prefs,
619 int do_input, int *output)
620 : BC_PopupMenu(x, y, xS(125), adriver_to_string(*output), 1)
622 this->output = output;
623 this->do_input = do_input;
624 this->device_prefs = device_prefs;
627 ADriverMenu::~ADriverMenu()
631 void ADriverMenu::create_objects()
634 add_item(new ADriverItem(this, AUDIO_ALSA_TITLE, AUDIO_ALSA));
638 add_item(new ADriverItem(this, AUDIO_OSS_TITLE, AUDIO_OSS));
639 add_item(new ADriverItem(this, AUDIO_OSS_ENVY24_TITLE, AUDIO_OSS_ENVY24));
643 if(!do_input) add_item(new ADriverItem(this, AUDIO_ESOUND_TITLE, AUDIO_ESOUND));
647 if(!do_input) add_item(new ADriverItem(this, AUDIO_1394_TITLE, AUDIO_1394));
648 add_item(new ADriverItem(this, AUDIO_DV1394_TITLE, AUDIO_DV1394));
649 add_item(new ADriverItem(this, AUDIO_IEC61883_TITLE, AUDIO_IEC61883));
653 if(do_input) add_item(new ADriverItem(this, AUDIO_DVB_TITLE, AUDIO_DVB));
656 #ifdef HAVE_VIDEO4LINUX2
657 if(do_input) add_item(new ADriverItem(this, AUDIO_V4L2MPEG_TITLE, AUDIO_V4L2MPEG));
661 char* ADriverMenu::adriver_to_string(int driver)
665 sprintf(string, AUDIO_OSS_TITLE);
667 case AUDIO_OSS_ENVY24:
668 sprintf(string, AUDIO_OSS_ENVY24_TITLE);
671 sprintf(string, AUDIO_ESOUND_TITLE);
674 sprintf(string, AUDIO_NAS_TITLE);
677 sprintf(string, AUDIO_ALSA_TITLE);
681 sprintf(string, AUDIO_1394_TITLE);
684 sprintf(string, AUDIO_DV1394_TITLE);
687 sprintf(string, AUDIO_IEC61883_TITLE);
691 sprintf(string, AUDIO_DVB_TITLE);
694 sprintf(string, AUDIO_V4L2MPEG_TITLE);
700 ADriverItem::ADriverItem(ADriverMenu *popup, const char *text, int driver)
704 this->driver = driver;
707 ADriverItem::~ADriverItem()
711 int ADriverItem::handle_event()
713 popup->set_text(get_text());
714 *(popup->output) = driver;
715 popup->device_prefs->initialize(0);
716 popup->device_prefs->pwindow->show_dialog();
723 OSSEnable::OSSEnable(int x, int y, int *output)
724 : BC_CheckBox(x, y, *output)
726 this->output = output;
728 int OSSEnable::handle_event()
730 *output = get_value();
737 ADeviceTextBox::ADeviceTextBox(int x, int y, char *output)
738 : BC_TextBox(x, y, xS(150), 1, output)
740 this->output = output;
743 int ADeviceTextBox::handle_event()
745 strcpy(output, get_text());
749 ADeviceIntBox::ADeviceIntBox(int x, int y, int *output)
750 : BC_TextBox(x, y, xS(80), 1, *output)
752 this->output = output;
755 int ADeviceIntBox::handle_event()
757 *output = atol(get_text());
763 ADeviceTumbleBox::ADeviceTumbleBox(ADevicePrefs *prefs,
764 int x, int y, int *output, int min, int max, int text_w)
765 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
767 this->output = output;
770 int ADeviceTumbleBox::handle_event()
772 *output = atol(get_text());
778 ALSADevice::ALSADevice(PreferencesDialog *dialog,
782 ArrayList<BC_ListBoxItem*> *devices)
783 : BC_PopupTextBox(dialog, devices, output, x, y, xS(200), yS(200))
785 this->output = output;
788 ALSADevice::~ALSADevice()
792 int ALSADevice::handle_event()
794 strcpy(output, get_text());