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()
197 for(int i = 0; i < MAXDEVICES; i++)
202 int ADevicePrefs::delete_esound_objs()
206 delete esound_server;
211 int ADevicePrefs::delete_firewire_objs()
214 delete channel_title;
215 delete firewire_port;
216 delete firewire_channel;
220 delete firewire_path;
232 int ADevicePrefs::delete_alsa_objs()
235 if(alsa_drivers) alsa_drivers->remove_all_objects();
241 delete alsa_workaround;
246 int ADevicePrefs::delete_dvb_objs()
248 delete dvb_adapter_title;
249 delete dvb_adapter_path;
250 delete dvb_device_title;
251 delete dvb_adapter_device;
253 delete follow_audio_config;
257 int ADevicePrefs::delete_v4l2mpeg_objs()
259 delete follow_audio_config;
264 int ADevicePrefs::create_oss_objs()
266 char *output_char = 0;
268 int margin = pwindow->mwindow->theme->widget_border;
270 BC_Resources *resources = BC_WindowBase::get_resources();
272 for(int i = 0; i < MAXDEVICES; i++) {
273 int x1 = x + menu->get_w() + 5;
277 output_int = &out_config->oss_enable[i];
280 output_int = &in_config->oss_enable[i];
283 output_int = &out_config->oss_enable[i];
286 dialog->add_subwindow(oss_enable[i] = new OSSEnable(x1, y1 + 20, output_int));
287 x1 += oss_enable[i]->get_w() + margin;
291 output_char = out_config->oss_out_device[i];
294 output_char = in_config->oss_in_device[i];
297 output_char = out_config->oss_out_device[i];
302 path_title = new BC_Title(x1, y, _("Device path:"),
303 MEDIUMFONT, resources->text_default);
304 dialog->add_subwindow(path_title);
307 oss_path[i] = new ADeviceTextBox(
308 x1, y1 + path_title->get_h() + margin, output_char);
309 dialog->add_subwindow(oss_path[i]);
310 x1 += oss_path[i]->get_w() + margin;
314 output_int = &out_config->oss_out_bits;
317 output_int = &in_config->oss_in_bits;
320 output_int = &out_config->oss_out_bits;
323 bits_title = new BC_Title(x1, y, _("Bits:"),
324 MEDIUMFONT, resources->text_default);
325 dialog->add_subwindow(bits_title);
326 oss_bits = new BitsPopup(dialog,
327 x1, y1 + bits_title->get_h() + margin,
328 output_int, 0, 0, 0, 0, 1);
329 oss_bits->create_objects();
332 x1 += oss_bits->get_w() + margin;
340 int ADevicePrefs::create_alsa_objs()
343 char *output_char = 0;
345 int margin = pwindow->mwindow->theme->widget_border;
346 BC_Resources *resources = BC_WindowBase::get_resources();
348 int x1 = x + menu->get_w() + margin;
351 ArrayList<char*> *alsa_titles = new ArrayList<char*>;
352 alsa_titles->set_array_delete();
353 AudioALSA::list_devices(alsa_titles, 0, mode);
355 alsa_drivers = new ArrayList<BC_ListBoxItem*>;
356 for(int i = 0; i < alsa_titles->total; i++)
357 alsa_drivers->append(new BC_ListBoxItem(alsa_titles->values[i]));
358 alsa_titles->remove_all_objects();
363 output_char = out_config->alsa_out_device;
366 output_char = in_config->alsa_in_device;
369 output_char = out_config->alsa_out_device;
372 path_title = new BC_Title(x1, y, _("Device:"),
373 MEDIUMFONT, resources->text_default);
374 dialog->add_subwindow(path_title);
375 y1 += path_title->get_h() + margin;
376 alsa_device = new ALSADevice(dialog,
377 x1, y1, output_char, alsa_drivers);
378 alsa_device->create_objects();
381 x1 += alsa_device->get_w() + 5;
384 output_int = &out_config->alsa_out_bits;
387 output_int = &in_config->alsa_in_bits;
390 output_int = &out_config->alsa_out_bits;
393 bits_title = new BC_Title(x1, y, _("Bits:"),
394 MEDIUMFONT, resources->text_default);
395 dialog->add_subwindow(bits_title);
396 y1 = y + bits_title->get_h() + margin;
397 alsa_bits = new BitsPopup(dialog,
398 x1, y1, output_int, 0, 0, 0, 0, 1);
399 alsa_bits->create_objects();
401 y1 += alsa_bits->get_h();
404 if(mode == MODEPLAY) {
405 alsa_workaround = new BC_CheckBox(x1, y1,
406 &out_config->interrupt_workaround,
407 _("Stop playback locks up."));
408 dialog->add_subwindow(alsa_workaround);
416 int ADevicePrefs::create_esound_objs()
418 int x1 = x + menu->get_w() + 5;
419 char *output_char = 0;
421 BC_Resources *resources = BC_WindowBase::get_resources();
425 output_char = out_config->esound_out_server;
428 output_char = in_config->esound_in_server;
431 output_char = out_config->esound_out_server;
434 server_title = new BC_Title(x1, y, _("Server:"),
435 MEDIUMFONT, resources->text_default);
436 dialog->add_subwindow(server_title);
437 esound_server = new ADeviceTextBox(x1, y + 20, output_char);
438 dialog->add_subwindow(esound_server);
442 output_int = &out_config->esound_out_port;
445 output_int = &in_config->esound_in_port;
448 output_int = &out_config->esound_out_port;
451 x1 += esound_server->get_w() + 5;
452 port_title = new BC_Title(x1, y, _("Port:"),
453 MEDIUMFONT, resources->text_default);
454 dialog->add_subwindow(port_title);
455 esound_port = new ADeviceIntBox(x1, y + 20, output_int);
456 dialog->add_subwindow(esound_port);
460 int ADevicePrefs::create_firewire_objs()
462 int x1 = x + menu->get_w() + 5;
464 char *output_char = 0;
465 BC_Resources *resources = BC_WindowBase::get_resources();
470 if(driver == AUDIO_DV1394)
471 output_char = out_config->dv1394_path;
473 if(driver == AUDIO_1394)
474 output_char = out_config->firewire_path;
477 if(driver == AUDIO_DV1394 || driver == AUDIO_1394)
478 output_char = in_config->firewire_path;
483 dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
484 dialog->add_subwindow(firewire_path = new ADeviceTextBox(x1, y + 20, output_char));
485 x1 += firewire_path->get_w() + 5;
491 if(driver == AUDIO_DV1394)
492 output_int = &out_config->dv1394_port;
494 output_int = &out_config->firewire_port;
497 output_int = &in_config->firewire_port;
500 // output_int = &out_config->afirewire_out_port;
503 port_title = new BC_Title(x1, y, _("Port:"),
504 MEDIUMFONT, resources->text_default);
505 dialog->add_subwindow(port_title);
506 firewire_port = new ADeviceIntBox(x1, y + 20, output_int);
507 dialog->add_subwindow(firewire_port);
509 x1 += firewire_port->get_w() + 5;
514 if(driver == AUDIO_DV1394)
515 output_int = &out_config->dv1394_channel;
517 output_int = &out_config->firewire_channel;
520 output_int = &in_config->firewire_channel;
523 channel_title = new BC_Title(x1, y, _("Channel:"),
524 MEDIUMFONT, resources->text_default);
525 dialog->add_subwindow(channel_title);
526 firewire_channel = new ADeviceIntBox(x1, y + 20, output_int);
527 dialog->add_subwindow(firewire_channel);
528 x1 += firewire_channel->get_w() + 5;
533 if(driver == AUDIO_DV1394)
534 output_int = &out_config->dv1394_syt;
536 if(driver == AUDIO_1394)
537 output_int = &out_config->firewire_syt;
547 syt_title = new BC_Title(x1, y, _("Syt Offset:"),
548 MEDIUMFONT, resources->text_default);
549 dialog->add_subwindow(syt_title);
550 firewire_syt = new ADeviceIntBox(x1, y + 20, output_int);
551 dialog->add_subwindow(firewire_syt);
552 x1 += firewire_syt->get_w() + 5;
560 int ADevicePrefs::create_dvb_objs()
562 int x1 = x + menu->get_w() + 30;
564 char *output_char = in_config->dvb_in_adapter;
565 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - 5;
566 BC_Resources *resources = BC_WindowBase::get_resources();
567 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
568 MEDIUMFONT, resources->text_default);
569 dialog->add_subwindow(dvb_adapter_title);
570 dvb_adapter_path = new ADeviceTextBox(x1, y1, output_char);
571 dialog->add_subwindow(dvb_adapter_path);
572 int x2 = x1 + dvb_adapter_path->get_w() + 5;
573 dvb_device_title = new BC_Title(x2, y2, _("dev:"),
574 MEDIUMFONT, resources->text_default);
575 dialog->add_subwindow(dvb_device_title);
576 int *output_int = &in_config->dvb_in_device;
577 dvb_adapter_device = new ADeviceTumbleBox(this, x2, y1, output_int, 0, 9, 20);
578 dvb_adapter_device->create_objects();
579 x2 += dvb_device_title->get_w() + 30;
580 bits_title = new BC_Title(x2, y2, _("Bits:"),
581 MEDIUMFONT, resources->text_default);
582 dialog->add_subwindow(bits_title);
583 output_int = &in_config->dvb_in_bits;
584 dvb_bits = new BitsPopup(dialog, x2, y1, output_int, 0, 0, 0, 0, 1);
585 dvb_bits->create_objects();
586 x1 += 100; y1 += dvb_adapter_path->get_h() + 5;
587 output_int = &in_config->follow_audio;
588 follow_audio_config = new BC_CheckBox(x1, y1, output_int, _("Follow audio config"));
589 dialog->add_subwindow(follow_audio_config);
593 int ADevicePrefs::create_v4l2mpeg_objs()
595 int x1 = x + menu->get_w() + 30;
597 int y2 = y1 - BC_Title::calculate_h(dialog, _("Bits:"), MEDIUMFONT) - 5;
598 BC_Resources *resources = BC_WindowBase::get_resources();
599 bits_title = new BC_Title(x1, y2, _("Bits:"),
600 MEDIUMFONT, resources->text_default);
601 dialog->add_subwindow(bits_title);
602 int *output_int = &in_config->v4l2_in_bits;
603 v4l2_bits = new BitsPopup(dialog, x1, y1, output_int, 0, 0, 0, 0, 1);
604 v4l2_bits->create_objects();
605 x1 += v4l2_bits->get_w() + 10;
606 follow_audio_config = new BC_CheckBox(x1, y1,
607 &in_config->follow_audio, _("Follow audio config"));
608 dialog->add_subwindow(follow_audio_config);
613 ADriverMenu::ADriverMenu(int x, int y, ADevicePrefs *device_prefs,
614 int do_input, int *output)
615 : BC_PopupMenu(x, y, 125, adriver_to_string(*output), 1)
617 this->output = output;
618 this->do_input = do_input;
619 this->device_prefs = device_prefs;
622 ADriverMenu::~ADriverMenu()
626 void ADriverMenu::create_objects()
629 add_item(new ADriverItem(this, AUDIO_ALSA_TITLE, AUDIO_ALSA));
633 add_item(new ADriverItem(this, AUDIO_OSS_TITLE, AUDIO_OSS));
634 add_item(new ADriverItem(this, AUDIO_OSS_ENVY24_TITLE, AUDIO_OSS_ENVY24));
638 if(!do_input) add_item(new ADriverItem(this, AUDIO_ESOUND_TITLE, AUDIO_ESOUND));
642 if(!do_input) add_item(new ADriverItem(this, AUDIO_1394_TITLE, AUDIO_1394));
643 add_item(new ADriverItem(this, AUDIO_DV1394_TITLE, AUDIO_DV1394));
644 add_item(new ADriverItem(this, AUDIO_IEC61883_TITLE, AUDIO_IEC61883));
648 if(do_input) add_item(new ADriverItem(this, AUDIO_DVB_TITLE, AUDIO_DVB));
651 #ifdef HAVE_VIDEO4LINUX2
652 if(do_input) add_item(new ADriverItem(this, AUDIO_V4L2MPEG_TITLE, AUDIO_V4L2MPEG));
656 char* ADriverMenu::adriver_to_string(int driver)
660 sprintf(string, AUDIO_OSS_TITLE);
662 case AUDIO_OSS_ENVY24:
663 sprintf(string, AUDIO_OSS_ENVY24_TITLE);
666 sprintf(string, AUDIO_ESOUND_TITLE);
669 sprintf(string, AUDIO_NAS_TITLE);
672 sprintf(string, AUDIO_ALSA_TITLE);
676 sprintf(string, AUDIO_1394_TITLE);
679 sprintf(string, AUDIO_DV1394_TITLE);
682 sprintf(string, AUDIO_IEC61883_TITLE);
686 sprintf(string, AUDIO_DVB_TITLE);
689 sprintf(string, AUDIO_V4L2MPEG_TITLE);
695 ADriverItem::ADriverItem(ADriverMenu *popup, const char *text, int driver)
699 this->driver = driver;
702 ADriverItem::~ADriverItem()
706 int ADriverItem::handle_event()
708 popup->set_text(get_text());
709 *(popup->output) = driver;
710 popup->device_prefs->initialize(0);
711 popup->device_prefs->pwindow->show_dialog();
718 OSSEnable::OSSEnable(int x, int y, int *output)
719 : BC_CheckBox(x, y, *output)
721 this->output = output;
723 int OSSEnable::handle_event()
725 *output = get_value();
732 ADeviceTextBox::ADeviceTextBox(int x, int y, char *output)
733 : BC_TextBox(x, y, 150, 1, output)
735 this->output = output;
738 int ADeviceTextBox::handle_event()
740 strcpy(output, get_text());
744 ADeviceIntBox::ADeviceIntBox(int x, int y, int *output)
745 : BC_TextBox(x, y, 80, 1, *output)
747 this->output = output;
750 int ADeviceIntBox::handle_event()
752 *output = atol(get_text());
758 ADeviceTumbleBox::ADeviceTumbleBox(ADevicePrefs *prefs,
759 int x, int y, int *output, int min, int max, int text_w)
760 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
762 this->output = output;
765 int ADeviceTumbleBox::handle_event()
767 *output = atol(get_text());
773 ALSADevice::ALSADevice(PreferencesDialog *dialog,
777 ArrayList<BC_ListBoxItem*> *devices)
778 : BC_PopupTextBox(dialog, devices, output, x, y, 200, 200)
780 this->output = output;
783 ALSADevice::~ALSADevice()
787 int ALSADevice::handle_event()
789 strcpy(output, get_text());