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;
79 for(int i = 0; i < MAXDEVICES; i++)
82 dvb_adapter_title = 0;
85 dvb_adapter_device = 0;
91 int ADevicePrefs::initialize(int creation)
98 driver = &out_config->driver;
101 driver = &in_config->driver;
104 driver = &out_config->driver;
107 this->driver = *driver;
110 dialog->add_subwindow(menu = new ADriverMenu(x,
111 y + yS(10), this, (mode == MODERECORD), driver));
112 menu->create_objects();
117 case AUDIO_OSS_ENVY24:
124 create_esound_objs();
129 create_firewire_objs();
135 create_v4l2mpeg_objs();
142 int ADevicePrefs::get_h(int recording)
144 int margin = pwindow->mwindow->theme->widget_border;
145 int result = BC_Title::calculate_h(dialog, "X", MEDIUMFONT) + margin +
146 BC_TextBox::calculate_h(dialog, MEDIUMFONT, 1, 1);
148 result += BC_CheckBox::calculate_h(dialog) + margin;
154 int ADevicePrefs::delete_objects()
158 case AUDIO_OSS_ENVY24:
165 delete_esound_objs();
170 delete_firewire_objs();
176 delete_v4l2mpeg_objs();
188 int ADevicePrefs::delete_oss_objs()
194 for(int i = 0; i < MAXDEVICES; i++)
199 int ADevicePrefs::delete_esound_objs()
203 delete esound_server;
208 int ADevicePrefs::delete_firewire_objs()
211 delete channel_title;
212 delete firewire_port;
213 delete firewire_channel;
217 delete firewire_path;
229 int ADevicePrefs::delete_alsa_objs()
232 if(alsa_drivers) alsa_drivers->remove_all_objects();
238 delete alsa_workaround;
243 int ADevicePrefs::delete_dvb_objs()
245 delete dvb_adapter_title;
246 delete dvb_adapter_path;
247 delete dvb_device_title;
248 delete dvb_adapter_device;
250 delete follow_audio_config;
254 int ADevicePrefs::delete_v4l2mpeg_objs()
256 delete follow_audio_config;
261 int ADevicePrefs::create_oss_objs()
263 char *output_char = 0;
265 int margin = pwindow->mwindow->theme->widget_border;
267 BC_Resources *resources = BC_WindowBase::get_resources();
269 for(int i = 0; i < MAXDEVICES; i++) {
270 int x1 = x + menu->get_w() + xS(5);
274 output_int = &out_config->oss_enable[i];
277 output_int = &in_config->oss_enable[i];
280 output_int = &out_config->oss_enable[i];
283 dialog->add_subwindow(oss_enable[i] = new OSSEnable(x1, y1 + yS(20), output_int));
284 x1 += oss_enable[i]->get_w() + margin;
288 output_char = out_config->oss_out_device[i];
291 output_char = in_config->oss_in_device[i];
294 output_char = out_config->oss_out_device[i];
299 path_title = new BC_Title(x1, y, _("Device path:"),
300 MEDIUMFONT, resources->text_default);
301 dialog->add_subwindow(path_title);
304 oss_path[i] = new ADeviceTextBox(
305 x1, y1 + path_title->get_h() + margin, output_char);
306 dialog->add_subwindow(oss_path[i]);
307 x1 += oss_path[i]->get_w() + margin;
311 output_int = &out_config->oss_out_bits;
314 output_int = &in_config->oss_in_bits;
317 output_int = &out_config->oss_out_bits;
320 bits_title = new BC_Title(x1, y, _("Bits:"),
321 MEDIUMFONT, resources->text_default);
322 dialog->add_subwindow(bits_title);
323 oss_bits = new BitsPopup(dialog,
324 x1, y1 + bits_title->get_h() + margin,
325 output_int, 0, 0, 0, 0, 1);
326 oss_bits->create_objects();
329 x1 += oss_bits->get_w() + margin;
337 int ADevicePrefs::create_alsa_objs()
340 char *output_char = 0;
342 int margin = pwindow->mwindow->theme->widget_border;
343 BC_Resources *resources = BC_WindowBase::get_resources();
345 int x1 = x + menu->get_w() + margin;
348 ArrayList<char*> *alsa_titles = new ArrayList<char*>;
349 alsa_titles->set_array_delete();
350 AudioALSA::list_devices(alsa_titles, 0, mode);
352 alsa_drivers = new ArrayList<BC_ListBoxItem*>;
353 for(int i = 0; i < alsa_titles->total; i++)
354 alsa_drivers->append(new BC_ListBoxItem(alsa_titles->values[i]));
355 alsa_titles->remove_all_objects();
360 output_char = out_config->alsa_out_device;
363 output_char = in_config->alsa_in_device;
366 output_char = out_config->alsa_out_device;
369 path_title = new BC_Title(x1, y, _("Device:"),
370 MEDIUMFONT, resources->text_default);
371 dialog->add_subwindow(path_title);
372 y1 += path_title->get_h() + margin;
373 alsa_device = new ALSADevice(dialog,
374 x1, y1, output_char, alsa_drivers);
375 alsa_device->create_objects();
378 x1 += alsa_device->get_w() + xS(5);
381 output_int = &out_config->alsa_out_bits;
384 output_int = &in_config->alsa_in_bits;
387 output_int = &out_config->alsa_out_bits;
390 bits_title = new BC_Title(x1, y, _("Bits:"),
391 MEDIUMFONT, resources->text_default);
392 dialog->add_subwindow(bits_title);
393 y1 = y + bits_title->get_h() + margin;
394 alsa_bits = new BitsPopup(dialog,
395 x1, y1, output_int, 0, 0, 0, 0, 1);
396 alsa_bits->create_objects();
398 y1 += alsa_bits->get_h();
401 if(mode == MODEPLAY) {
402 alsa_workaround = new BC_CheckBox(x1, y1,
403 &out_config->interrupt_workaround,
404 _("Stop playback locks up."));
405 dialog->add_subwindow(alsa_workaround);
413 int ADevicePrefs::create_esound_objs()
415 int x1 = x + menu->get_w() + xS(5);
416 char *output_char = 0;
418 BC_Resources *resources = BC_WindowBase::get_resources();
422 output_char = out_config->esound_out_server;
425 output_char = in_config->esound_in_server;
428 output_char = out_config->esound_out_server;
431 server_title = new BC_Title(x1, y, _("Server:"),
432 MEDIUMFONT, resources->text_default);
433 dialog->add_subwindow(server_title);
434 esound_server = new ADeviceTextBox(x1, y + yS(20), output_char);
435 dialog->add_subwindow(esound_server);
439 output_int = &out_config->esound_out_port;
442 output_int = &in_config->esound_in_port;
445 output_int = &out_config->esound_out_port;
448 x1 += esound_server->get_w() + xS(5);
449 port_title = new BC_Title(x1, y, _("Port:"),
450 MEDIUMFONT, resources->text_default);
451 dialog->add_subwindow(port_title);
452 esound_port = new ADeviceIntBox(x1, y + yS(20), output_int);
453 dialog->add_subwindow(esound_port);
457 int ADevicePrefs::create_firewire_objs()
461 int x1 = x + menu->get_w() + xs5;
463 char *output_char = 0;
464 BC_Resources *resources = BC_WindowBase::get_resources();
469 if(driver == AUDIO_DV1394)
470 output_char = out_config->dv1394_path;
472 if(driver == AUDIO_1394)
473 output_char = out_config->firewire_path;
476 if(driver == AUDIO_DV1394 || driver == AUDIO_1394)
477 output_char = in_config->firewire_path;
482 dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
483 dialog->add_subwindow(firewire_path = new ADeviceTextBox(x1, y + ys20, output_char));
484 x1 += firewire_path->get_w() + xs5;
490 if(driver == AUDIO_DV1394)
491 output_int = &out_config->dv1394_port;
493 output_int = &out_config->firewire_port;
496 output_int = &in_config->firewire_port;
499 // output_int = &out_config->afirewire_out_port;
502 port_title = new BC_Title(x1, y, _("Port:"),
503 MEDIUMFONT, resources->text_default);
504 dialog->add_subwindow(port_title);
505 firewire_port = new ADeviceIntBox(x1, y + ys20, output_int);
506 dialog->add_subwindow(firewire_port);
508 x1 += firewire_port->get_w() + xs5;
513 if(driver == AUDIO_DV1394)
514 output_int = &out_config->dv1394_channel;
516 output_int = &out_config->firewire_channel;
519 output_int = &in_config->firewire_channel;
522 channel_title = new BC_Title(x1, y, _("Channel:"),
523 MEDIUMFONT, resources->text_default);
524 dialog->add_subwindow(channel_title);
525 firewire_channel = new ADeviceIntBox(x1, y + ys20, output_int);
526 dialog->add_subwindow(firewire_channel);
527 x1 += firewire_channel->get_w() + xs5;
532 if(driver == AUDIO_DV1394)
533 output_int = &out_config->dv1394_syt;
535 if(driver == AUDIO_1394)
536 output_int = &out_config->firewire_syt;
546 syt_title = new BC_Title(x1, y, _("Syt Offset:"),
547 MEDIUMFONT, resources->text_default);
548 dialog->add_subwindow(syt_title);
549 firewire_syt = new ADeviceIntBox(x1, y + ys20, output_int);
550 dialog->add_subwindow(firewire_syt);
551 x1 += firewire_syt->get_w() + xs5;
559 int ADevicePrefs::create_dvb_objs()
561 int x1 = x + menu->get_w() + xS(30);
563 char *output_char = in_config->dvb_in_adapter;
564 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - yS(5);
565 BC_Resources *resources = BC_WindowBase::get_resources();
566 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
567 MEDIUMFONT, resources->text_default);
568 dialog->add_subwindow(dvb_adapter_title);
569 dvb_adapter_path = new ADeviceTextBox(x1, y1, output_char);
570 dialog->add_subwindow(dvb_adapter_path);
571 int x2 = x1 + dvb_adapter_path->get_w() + xS(5);
572 dvb_device_title = new BC_Title(x2, y2, _("dev:"),
573 MEDIUMFONT, resources->text_default);
574 dialog->add_subwindow(dvb_device_title);
575 int *output_int = &in_config->dvb_in_device;
576 dvb_adapter_device = new ADeviceTumbleBox(this, x2, y1, output_int, 0, 9, xS(20));
577 dvb_adapter_device->create_objects();
578 x2 += dvb_device_title->get_w() + xS(30);
579 bits_title = new BC_Title(x2, y2, _("Bits:"),
580 MEDIUMFONT, resources->text_default);
581 dialog->add_subwindow(bits_title);
582 output_int = &in_config->dvb_in_bits;
583 dvb_bits = new BitsPopup(dialog, x2, y1, output_int, 0, 0, 0, 0, 1);
584 dvb_bits->create_objects();
585 x1 += xS(100); y1 += dvb_adapter_path->get_h() + yS(5);
586 output_int = &in_config->follow_audio;
587 follow_audio_config = new BC_CheckBox(x1, y1, output_int, _("Follow audio config"));
588 dialog->add_subwindow(follow_audio_config);
592 int ADevicePrefs::create_v4l2mpeg_objs()
594 int x1 = x + menu->get_w() + xS(30);
596 int y2 = y1 - BC_Title::calculate_h(dialog, _("Bits:"), MEDIUMFONT) - yS(5);
597 BC_Resources *resources = BC_WindowBase::get_resources();
598 bits_title = new BC_Title(x1, y2, _("Bits:"),
599 MEDIUMFONT, resources->text_default);
600 dialog->add_subwindow(bits_title);
601 int *output_int = &in_config->v4l2_in_bits;
602 v4l2_bits = new BitsPopup(dialog, x1, y1, output_int, 0, 0, 0, 0, 1);
603 v4l2_bits->create_objects();
604 x1 += v4l2_bits->get_w() + xS(10);
605 follow_audio_config = new BC_CheckBox(x1, y1,
606 &in_config->follow_audio, _("Follow audio config"));
607 dialog->add_subwindow(follow_audio_config);
612 ADriverMenu::ADriverMenu(int x, int y, ADevicePrefs *device_prefs,
613 int do_input, int *output)
614 : BC_PopupMenu(x, y, xS(125), adriver_to_string(*output), 1)
616 this->output = output;
617 this->do_input = do_input;
618 this->device_prefs = device_prefs;
621 ADriverMenu::~ADriverMenu()
625 void ADriverMenu::create_objects()
628 add_item(new ADriverItem(this, AUDIO_ALSA_TITLE, AUDIO_ALSA));
632 add_item(new ADriverItem(this, AUDIO_OSS_TITLE, AUDIO_OSS));
633 add_item(new ADriverItem(this, AUDIO_OSS_ENVY24_TITLE, AUDIO_OSS_ENVY24));
637 if(!do_input) add_item(new ADriverItem(this, AUDIO_ESOUND_TITLE, AUDIO_ESOUND));
641 if(!do_input) add_item(new ADriverItem(this, AUDIO_1394_TITLE, AUDIO_1394));
642 add_item(new ADriverItem(this, AUDIO_DV1394_TITLE, AUDIO_DV1394));
643 add_item(new ADriverItem(this, AUDIO_IEC61883_TITLE, AUDIO_IEC61883));
647 if(do_input) add_item(new ADriverItem(this, AUDIO_DVB_TITLE, AUDIO_DVB));
650 #ifdef HAVE_VIDEO4LINUX2
651 if(do_input) add_item(new ADriverItem(this, AUDIO_V4L2MPEG_TITLE, AUDIO_V4L2MPEG));
655 char* ADriverMenu::adriver_to_string(int driver)
659 sprintf(string, AUDIO_OSS_TITLE);
661 case AUDIO_OSS_ENVY24:
662 sprintf(string, AUDIO_OSS_ENVY24_TITLE);
665 sprintf(string, AUDIO_ESOUND_TITLE);
668 sprintf(string, AUDIO_NAS_TITLE);
671 sprintf(string, AUDIO_ALSA_TITLE);
675 sprintf(string, AUDIO_1394_TITLE);
678 sprintf(string, AUDIO_DV1394_TITLE);
681 sprintf(string, AUDIO_IEC61883_TITLE);
685 sprintf(string, AUDIO_DVB_TITLE);
688 sprintf(string, AUDIO_V4L2MPEG_TITLE);
694 ADriverItem::ADriverItem(ADriverMenu *popup, const char *text, int driver)
698 this->driver = driver;
701 ADriverItem::~ADriverItem()
705 int ADriverItem::handle_event()
707 popup->set_text(get_text());
708 *(popup->output) = driver;
709 popup->device_prefs->initialize(0);
710 popup->device_prefs->pwindow->show_dialog();
717 OSSEnable::OSSEnable(int x, int y, int *output)
718 : BC_CheckBox(x, y, *output)
720 this->output = output;
722 int OSSEnable::handle_event()
724 *output = get_value();
731 ADeviceTextBox::ADeviceTextBox(int x, int y, char *output)
732 : BC_TextBox(x, y, xS(150), 1, output)
734 this->output = output;
737 int ADeviceTextBox::handle_event()
739 strcpy(output, get_text());
743 ADeviceIntBox::ADeviceIntBox(int x, int y, int *output)
744 : BC_TextBox(x, y, xS(80), 1, *output)
746 this->output = output;
749 int ADeviceIntBox::handle_event()
751 *output = atol(get_text());
757 ADeviceTumbleBox::ADeviceTumbleBox(ADevicePrefs *prefs,
758 int x, int y, int *output, int min, int max, int text_w)
759 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
761 this->output = output;
764 int ADeviceTumbleBox::handle_event()
766 *output = atol(get_text());
772 ALSADevice::ALSADevice(PreferencesDialog *dialog,
776 ArrayList<BC_ListBoxItem*> *devices)
777 : BC_PopupTextBox(dialog, devices, output, x, y, xS(200), yS(200))
779 this->output = output;
782 ALSADevice::~ALSADevice()
786 int ALSADevice::handle_event()
788 strcpy(output, get_text());