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,
113 (mode == MODERECORD),
115 menu->create_objects();
120 case AUDIO_OSS_ENVY24:
127 create_esound_objs();
132 create_firewire_objs();
138 create_v4l2mpeg_objs();
145 int ADevicePrefs::get_h(int recording)
147 int margin = pwindow->mwindow->theme->widget_border;
148 int result = BC_Title::calculate_h(dialog, "X", MEDIUMFONT) + margin +
149 BC_TextBox::calculate_h(dialog, MEDIUMFONT, 1, 1);
151 result += BC_CheckBox::calculate_h(dialog) + margin;
157 int ADevicePrefs::delete_objects()
161 case AUDIO_OSS_ENVY24:
168 delete_esound_objs();
173 delete_firewire_objs();
179 delete_v4l2mpeg_objs();
191 int ADevicePrefs::delete_oss_objs()
199 for(int i = 0; i < MAXDEVICES; i++)
208 int ADevicePrefs::delete_esound_objs()
212 delete esound_server;
217 int ADevicePrefs::delete_firewire_objs()
220 delete channel_title;
221 delete firewire_port;
222 delete firewire_channel;
226 delete firewire_path;
238 int ADevicePrefs::delete_alsa_objs()
241 if(alsa_drivers) alsa_drivers->remove_all_objects();
247 delete alsa_workaround;
252 int ADevicePrefs::delete_dvb_objs()
254 delete dvb_adapter_title;
255 delete dvb_adapter_path;
256 delete dvb_device_title;
257 delete dvb_adapter_device;
259 delete follow_audio_config;
263 int ADevicePrefs::delete_v4l2mpeg_objs()
265 delete follow_audio_config;
270 int ADevicePrefs::create_oss_objs()
272 char *output_char = 0;
274 int margin = pwindow->mwindow->theme->widget_border;
276 BC_Resources *resources = BC_WindowBase::get_resources();
278 for(int i = 0; i < MAXDEVICES; i++) {
279 int x1 = x + menu->get_w() + 5;
283 output_int = &out_config->oss_enable[i];
286 output_int = &in_config->oss_enable[i];
289 output_int = &out_config->oss_enable[i];
292 dialog->add_subwindow(oss_enable[i] = new OSSEnable(x1, y1 + 20, output_int));
293 x1 += oss_enable[i]->get_w() + margin;
297 output_char = out_config->oss_out_device[i];
300 output_char = in_config->oss_in_device[i];
303 output_char = out_config->oss_out_device[i];
308 path_title = new BC_Title(x1, y, _("Device path:"),
309 MEDIUMFONT, resources->text_default);
310 dialog->add_subwindow(path_title);
313 oss_path[i] = new ADeviceTextBox(
314 x1, y1 + path_title->get_h() + margin, output_char);
315 dialog->add_subwindow(oss_path[i]);
316 x1 += oss_path[i]->get_w() + margin;
320 output_int = &out_config->oss_out_bits;
323 output_int = &in_config->oss_in_bits;
326 output_int = &out_config->oss_out_bits;
329 bits_title = new BC_Title(x1, y, _("Bits:"),
330 MEDIUMFONT, resources->text_default);
331 dialog->add_subwindow(bits_title);
332 oss_bits = new BitsPopup(dialog,
333 x1, y1 + bits_title->get_h() + margin,
334 output_int, 0, 0, 0, 0, 1);
335 oss_bits->create_objects();
338 x1 += oss_bits->get_w() + margin;
346 int ADevicePrefs::create_alsa_objs()
349 char *output_char = 0;
351 int margin = pwindow->mwindow->theme->widget_border;
352 BC_Resources *resources = BC_WindowBase::get_resources();
354 int x1 = x + menu->get_w() + margin;
357 ArrayList<char*> *alsa_titles = new ArrayList<char*>;
358 alsa_titles->set_array_delete();
359 AudioALSA::list_devices(alsa_titles, 0, mode);
361 alsa_drivers = new ArrayList<BC_ListBoxItem*>;
362 for(int i = 0; i < alsa_titles->total; i++)
363 alsa_drivers->append(new BC_ListBoxItem(alsa_titles->values[i]));
364 alsa_titles->remove_all_objects();
369 output_char = out_config->alsa_out_device;
372 output_char = in_config->alsa_in_device;
375 output_char = out_config->alsa_out_device;
378 path_title = new BC_Title(x1, y, _("Device:"),
379 MEDIUMFONT, resources->text_default);
380 dialog->add_subwindow(path_title);
381 y1 += path_title->get_h() + margin;
382 alsa_device = new ALSADevice(dialog,
383 x1, y1, output_char, alsa_drivers);
384 alsa_device->create_objects();
387 x1 += alsa_device->get_w() + 5;
390 output_int = &out_config->alsa_out_bits;
393 output_int = &in_config->alsa_in_bits;
396 output_int = &out_config->alsa_out_bits;
399 bits_title = new BC_Title(x1, y, _("Bits:"),
400 MEDIUMFONT, resources->text_default);
401 dialog->add_subwindow(bits_title);
402 y1 = y + bits_title->get_h() + margin;
403 alsa_bits = new BitsPopup(dialog,
404 x1, y1, output_int, 0, 0, 0, 0, 1);
405 alsa_bits->create_objects();
407 y1 += alsa_bits->get_h();
410 if(mode == MODEPLAY) {
411 alsa_workaround = new BC_CheckBox(x1, y1,
412 &out_config->interrupt_workaround,
413 _("Stop playback locks up."));
414 dialog->add_subwindow(alsa_workaround);
422 int ADevicePrefs::create_esound_objs()
424 int x1 = x + menu->get_w() + 5;
425 char *output_char = 0;
427 BC_Resources *resources = BC_WindowBase::get_resources();
431 output_char = out_config->esound_out_server;
434 output_char = in_config->esound_in_server;
437 output_char = out_config->esound_out_server;
440 server_title = new BC_Title(x1, y, _("Server:"),
441 MEDIUMFONT, resources->text_default);
442 dialog->add_subwindow(server_title);
443 esound_server = new ADeviceTextBox(x1, y + 20, output_char);
444 dialog->add_subwindow(esound_server);
448 output_int = &out_config->esound_out_port;
451 output_int = &in_config->esound_in_port;
454 output_int = &out_config->esound_out_port;
457 x1 += esound_server->get_w() + 5;
458 port_title = new BC_Title(x1, y, _("Port:"),
459 MEDIUMFONT, resources->text_default);
460 dialog->add_subwindow(port_title);
461 esound_port = new ADeviceIntBox(x1, y + 20, output_int);
462 dialog->add_subwindow(esound_port);
466 int ADevicePrefs::create_firewire_objs()
468 int x1 = x + menu->get_w() + 5;
470 char *output_char = 0;
471 BC_Resources *resources = BC_WindowBase::get_resources();
476 if(driver == AUDIO_DV1394)
477 output_char = out_config->dv1394_path;
479 if(driver == AUDIO_1394)
480 output_char = out_config->firewire_path;
483 if(driver == AUDIO_DV1394 || driver == AUDIO_1394)
484 output_char = in_config->firewire_path;
489 dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
490 dialog->add_subwindow(firewire_path = new ADeviceTextBox(x1, y + 20, output_char));
491 x1 += firewire_path->get_w() + 5;
497 if(driver == AUDIO_DV1394)
498 output_int = &out_config->dv1394_port;
500 output_int = &out_config->firewire_port;
503 output_int = &in_config->firewire_port;
506 // output_int = &out_config->afirewire_out_port;
509 port_title = new BC_Title(x1, y, _("Port:"),
510 MEDIUMFONT, resources->text_default);
511 dialog->add_subwindow(port_title);
512 firewire_port = new ADeviceIntBox(x1, y + 20, output_int);
513 dialog->add_subwindow(firewire_port);
515 x1 += firewire_port->get_w() + 5;
520 if(driver == AUDIO_DV1394)
521 output_int = &out_config->dv1394_channel;
523 output_int = &out_config->firewire_channel;
526 output_int = &in_config->firewire_channel;
529 channel_title = new BC_Title(x1, y, _("Channel:"),
530 MEDIUMFONT, resources->text_default);
531 dialog->add_subwindow(channel_title);
532 firewire_channel = new ADeviceIntBox(x1, y + 20, output_int);
533 dialog->add_subwindow(firewire_channel);
534 x1 += firewire_channel->get_w() + 5;
539 if(driver == AUDIO_DV1394)
540 output_int = &out_config->dv1394_syt;
542 if(driver == AUDIO_1394)
543 output_int = &out_config->firewire_syt;
553 syt_title = new BC_Title(x1, y, _("Syt Offset:"),
554 MEDIUMFONT, resources->text_default);
555 dialog->add_subwindow(syt_title);
556 firewire_syt = new ADeviceIntBox(x1, y + 20, output_int);
557 dialog->add_subwindow(firewire_syt);
558 x1 += firewire_syt->get_w() + 5;
566 int ADevicePrefs::create_dvb_objs()
568 int x1 = x + menu->get_w() + 30;
570 char *output_char = in_config->dvb_in_adapter;
571 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - 5;
572 BC_Resources *resources = BC_WindowBase::get_resources();
573 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
574 MEDIUMFONT, resources->text_default);
575 dialog->add_subwindow(dvb_adapter_title);
576 dvb_adapter_path = new ADeviceTextBox(x1, y1, output_char);
577 dialog->add_subwindow(dvb_adapter_path);
578 int x2 = x1 + dvb_adapter_path->get_w() + 5;
579 dvb_device_title = new BC_Title(x2, y2, _("dev:"),
580 MEDIUMFONT, resources->text_default);
581 dialog->add_subwindow(dvb_device_title);
582 int *output_int = &in_config->dvb_in_device;
583 dvb_adapter_device = new ADeviceTumbleBox(this, x2, y1, output_int, 0, 9, 20);
584 dvb_adapter_device->create_objects();
585 x2 += dvb_device_title->get_w() + 30;
586 bits_title = new BC_Title(x2, y2, _("Bits:"),
587 MEDIUMFONT, resources->text_default);
588 dialog->add_subwindow(bits_title);
589 output_int = &in_config->dvb_in_bits;
590 dvb_bits = new BitsPopup(dialog, x2, y1, output_int, 0, 0, 0, 0, 1);
591 dvb_bits->create_objects();
592 x1 += 100; y1 += dvb_adapter_path->get_h() + 5;
593 output_int = &in_config->follow_audio;
594 follow_audio_config = new BC_CheckBox(x1, y1, output_int, _("Follow audio config"));
595 dialog->add_subwindow(follow_audio_config);
599 int ADevicePrefs::create_v4l2mpeg_objs()
601 int x1 = x + menu->get_w() + 30;
603 int y2 = y1 - BC_Title::calculate_h(dialog, _("Bits:"), MEDIUMFONT) - 5;
604 BC_Resources *resources = BC_WindowBase::get_resources();
605 bits_title = new BC_Title(x1, y2, _("Bits:"),
606 MEDIUMFONT, resources->text_default);
607 dialog->add_subwindow(bits_title);
608 int *output_int = &in_config->v4l2_in_bits;
609 v4l2_bits = new BitsPopup(dialog, x1, y1, output_int, 0, 0, 0, 0, 1);
610 v4l2_bits->create_objects();
611 x1 += v4l2_bits->get_w() + 10;
612 follow_audio_config = new BC_CheckBox(x1, y1,
613 &in_config->follow_audio, _("Follow audio config"));
614 dialog->add_subwindow(follow_audio_config);
619 ADriverMenu::ADriverMenu(int x, int y, ADevicePrefs *device_prefs,
620 int do_input, int *output)
621 : BC_PopupMenu(x, y, 125, adriver_to_string(*output), 1)
623 this->output = output;
624 this->do_input = do_input;
625 this->device_prefs = device_prefs;
628 ADriverMenu::~ADriverMenu()
632 void ADriverMenu::create_objects()
635 add_item(new ADriverItem(this, AUDIO_ALSA_TITLE, AUDIO_ALSA));
639 add_item(new ADriverItem(this, AUDIO_OSS_TITLE, AUDIO_OSS));
640 add_item(new ADriverItem(this, AUDIO_OSS_ENVY24_TITLE, AUDIO_OSS_ENVY24));
644 if(!do_input) add_item(new ADriverItem(this, AUDIO_ESOUND_TITLE, AUDIO_ESOUND));
648 if(!do_input) add_item(new ADriverItem(this, AUDIO_1394_TITLE, AUDIO_1394));
649 add_item(new ADriverItem(this, AUDIO_DV1394_TITLE, AUDIO_DV1394));
650 add_item(new ADriverItem(this, AUDIO_IEC61883_TITLE, AUDIO_IEC61883));
654 if(do_input) add_item(new ADriverItem(this, AUDIO_DVB_TITLE, AUDIO_DVB));
657 #ifdef HAVE_VIDEO4LINUX2
658 if(do_input) add_item(new ADriverItem(this, AUDIO_V4L2MPEG_TITLE, AUDIO_V4L2MPEG));
662 char* ADriverMenu::adriver_to_string(int driver)
666 sprintf(string, AUDIO_OSS_TITLE);
668 case AUDIO_OSS_ENVY24:
669 sprintf(string, AUDIO_OSS_ENVY24_TITLE);
672 sprintf(string, AUDIO_ESOUND_TITLE);
675 sprintf(string, AUDIO_NAS_TITLE);
678 sprintf(string, AUDIO_ALSA_TITLE);
682 sprintf(string, AUDIO_1394_TITLE);
685 sprintf(string, AUDIO_DV1394_TITLE);
688 sprintf(string, AUDIO_IEC61883_TITLE);
692 sprintf(string, AUDIO_DVB_TITLE);
695 sprintf(string, AUDIO_V4L2MPEG_TITLE);
701 ADriverItem::ADriverItem(ADriverMenu *popup, const char *text, int driver)
705 this->driver = driver;
708 ADriverItem::~ADriverItem()
712 int ADriverItem::handle_event()
714 popup->set_text(get_text());
715 *(popup->output) = driver;
716 popup->device_prefs->initialize(0);
717 popup->device_prefs->pwindow->show_dialog();
724 OSSEnable::OSSEnable(int x, int y, int *output)
725 : BC_CheckBox(x, y, *output)
727 this->output = output;
729 int OSSEnable::handle_event()
731 *output = get_value();
738 ADeviceTextBox::ADeviceTextBox(int x, int y, char *output)
739 : BC_TextBox(x, y, 150, 1, output)
741 this->output = output;
744 int ADeviceTextBox::handle_event()
746 strcpy(output, get_text());
750 ADeviceIntBox::ADeviceIntBox(int x, int y, int *output)
751 : BC_TextBox(x, y, 80, 1, *output)
753 this->output = output;
756 int ADeviceIntBox::handle_event()
758 *output = atol(get_text());
764 ADeviceTumbleBox::ADeviceTumbleBox(ADevicePrefs *prefs,
765 int x, int y, int *output, int min, int max, int text_w)
766 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
768 this->output = output;
771 int ADeviceTumbleBox::handle_event()
773 *output = atol(get_text());
779 ALSADevice::ALSADevice(PreferencesDialog *dialog,
783 ArrayList<BC_ListBoxItem*> *devices)
784 : BC_PopupTextBox(dialog, devices, output, x, y, 200, 200)
786 this->output = output;
789 ALSADevice::~ALSADevice()
793 int ALSADevice::handle_event()
795 strcpy(output, get_text());