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 "bitspopup.h"
28 #include "playbackconfig.h"
29 #include "preferences.h"
30 #include "preferencesthread.h"
31 #include "recordconfig.h"
36 ADevicePrefs::ADevicePrefs(int x, int y, PreferencesWindow *pwindow, PreferencesDialog *dialog,
37 AudioOutConfig *out_config, AudioInConfig *in_config, int mode)
40 this->pwindow = pwindow;
41 this->dialog = dialog;
44 this->out_config = out_config;
45 this->in_config = in_config;
50 ADevicePrefs::~ADevicePrefs()
56 void ADevicePrefs::reset()
59 follow_audio_config = 0;
76 for(int i = 0; i < MAXDEVICES; i++)
79 dvb_adapter_title = 0;
82 dvb_adapter_device = 0;
88 int ADevicePrefs::initialize(int creation)
95 driver = &out_config->driver;
98 driver = &in_config->driver;
101 driver = &out_config->driver;
104 this->driver = *driver;
107 dialog->add_subwindow(menu = new ADriverMenu(x,
110 (mode == MODERECORD),
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 return !recording ? DEVICE_H + 30 : DEVICE_H;
147 int ADevicePrefs::delete_objects()
151 case AUDIO_OSS_ENVY24:
158 delete_esound_objs();
163 delete_firewire_objs();
169 delete_v4l2mpeg_objs();
181 int ADevicePrefs::delete_oss_objs()
189 for(int i = 0; i < MAXDEVICES; i++)
198 int ADevicePrefs::delete_esound_objs()
202 delete esound_server;
207 int ADevicePrefs::delete_firewire_objs()
210 delete channel_title;
211 delete firewire_port;
212 delete firewire_channel;
216 delete firewire_path;
228 int ADevicePrefs::delete_alsa_objs()
231 if(alsa_drivers) alsa_drivers->remove_all_objects();
237 delete alsa_workaround;
242 int ADevicePrefs::delete_dvb_objs()
244 delete dvb_adapter_title;
245 delete dvb_adapter_path;
246 delete dvb_device_title;
247 delete dvb_adapter_device;
249 delete follow_audio_config;
253 int ADevicePrefs::delete_v4l2mpeg_objs()
255 delete follow_audio_config;
260 int ADevicePrefs::create_oss_objs()
262 char *output_char = 0;
265 BC_Resources *resources = BC_WindowBase::get_resources();
267 for(int i = 0; i < MAXDEVICES; i++) {
268 int x1 = x + menu->get_w() + 5;
272 output_int = &out_config->oss_enable[i];
275 output_int = &in_config->oss_enable[i];
278 output_int = &out_config->oss_enable[i];
281 dialog->add_subwindow(oss_enable[i] = new OSSEnable(x1, y1 + 20, output_int));
282 x1 += oss_enable[i]->get_w() + 5;
286 output_char = out_config->oss_out_device[i];
289 output_char = in_config->oss_in_device[i];
292 output_char = out_config->oss_out_device[i];
297 path_title = new BC_Title(x1, y, _("Device path:"),
298 MEDIUMFONT, resources->text_default);
299 dialog->add_subwindow(path_title);
302 oss_path[i] = new ADeviceTextBox(x1, y1 + 20, output_char);
303 dialog->add_subwindow(oss_path[i]);
305 x1 += oss_path[i]->get_w() + 5;
309 output_int = &out_config->oss_out_bits;
312 output_int = &in_config->oss_in_bits;
315 output_int = &out_config->oss_out_bits;
318 bits_title = new BC_Title(x1, y, _("Bits:"),
319 MEDIUMFONT, resources->text_default);
320 dialog->add_subwindow(bits_title);
321 oss_bits = new BitsPopup(dialog, x1, y1 + 20, output_int,
323 oss_bits->create_objects();
326 x1 += oss_bits->get_w() + 5;
328 break; // apparently, 'i' must be zero
334 int ADevicePrefs::create_alsa_objs()
337 char *output_char = 0;
340 BC_Resources *resources = BC_WindowBase::get_resources();
342 int x1 = x + menu->get_w() + 5;
344 ArrayList<char*> *alsa_titles = new ArrayList<char*>;
345 alsa_titles->set_array_delete();
346 AudioALSA::list_devices(alsa_titles, 0, mode);
349 alsa_drivers = new ArrayList<BC_ListBoxItem*>;
350 for(int i = 0; i < alsa_titles->total; i++)
351 alsa_drivers->append(new BC_ListBoxItem(alsa_titles->values[i]));
352 alsa_titles->remove_all_objects();
357 output_char = out_config->alsa_out_device;
360 output_char = in_config->alsa_in_device;
363 output_char = out_config->alsa_out_device;
366 path_title = new BC_Title(x1, y, _("Device:"),
367 MEDIUMFONT, resources->text_default);
368 dialog->add_subwindow(path_title);
369 alsa_device = new ALSADevice(dialog, x1, y1 + 20, output_char, alsa_drivers);
370 alsa_device->create_objects();
373 x1 += alsa_device->get_w() + 5;
376 output_int = &out_config->alsa_out_bits;
379 output_int = &in_config->alsa_in_bits;
382 output_int = &out_config->alsa_out_bits;
385 bits_title = new BC_Title(x1, y, _("Bits:"),
386 MEDIUMFONT, resources->text_default);
387 dialog->add_subwindow(bits_title);
388 alsa_bits = new BitsPopup(dialog, x1, y1 + 20, output_int, 0, 0, 0, 0, 1);
389 alsa_bits->create_objects();
391 y1 += alsa_bits->get_h() + 20 + 5;
394 if(mode == MODEPLAY) {
395 alsa_workaround = new BC_CheckBox(x1, y1,
396 &out_config->interrupt_workaround,
397 _("Stop playback locks up."));
398 dialog->add_subwindow(alsa_workaround);
406 int ADevicePrefs::create_esound_objs()
408 int x1 = x + menu->get_w() + 5;
409 char *output_char = 0;
411 BC_Resources *resources = BC_WindowBase::get_resources();
415 output_char = out_config->esound_out_server;
418 output_char = in_config->esound_in_server;
421 output_char = out_config->esound_out_server;
424 server_title = new BC_Title(x1, y, _("Server:"),
425 MEDIUMFONT, resources->text_default);
426 dialog->add_subwindow(server_title);
427 esound_server = new ADeviceTextBox(x1, y + 20, output_char);
428 dialog->add_subwindow(esound_server);
432 output_int = &out_config->esound_out_port;
435 output_int = &in_config->esound_in_port;
438 output_int = &out_config->esound_out_port;
441 x1 += esound_server->get_w() + 5;
442 port_title = new BC_Title(x1, y, _("Port:"),
443 MEDIUMFONT, resources->text_default);
444 dialog->add_subwindow(port_title);
445 esound_port = new ADeviceIntBox(x1, y + 20, output_int);
446 dialog->add_subwindow(esound_port);
450 int ADevicePrefs::create_firewire_objs()
452 int x1 = x + menu->get_w() + 5;
454 char *output_char = 0;
455 BC_Resources *resources = BC_WindowBase::get_resources();
460 if(driver == AUDIO_DV1394)
461 output_char = out_config->dv1394_path;
463 if(driver == AUDIO_1394)
464 output_char = out_config->firewire_path;
467 if(driver == AUDIO_DV1394 || driver == AUDIO_1394)
468 output_char = in_config->firewire_path;
473 dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
474 dialog->add_subwindow(firewire_path = new ADeviceTextBox(x1, y + 20, output_char));
475 x1 += firewire_path->get_w() + 5;
481 if(driver == AUDIO_DV1394)
482 output_int = &out_config->dv1394_port;
484 output_int = &out_config->firewire_port;
487 output_int = &in_config->firewire_port;
490 // output_int = &out_config->afirewire_out_port;
493 port_title = new BC_Title(x1, y, _("Port:"),
494 MEDIUMFONT, resources->text_default);
495 dialog->add_subwindow(port_title);
496 firewire_port = new ADeviceIntBox(x1, y + 20, output_int);
497 dialog->add_subwindow(firewire_port);
499 x1 += firewire_port->get_w() + 5;
504 if(driver == AUDIO_DV1394)
505 output_int = &out_config->dv1394_channel;
507 output_int = &out_config->firewire_channel;
510 output_int = &in_config->firewire_channel;
513 channel_title = new BC_Title(x1, y, _("Channel:"),
514 MEDIUMFONT, resources->text_default);
515 dialog->add_subwindow(channel_title);
516 firewire_channel = new ADeviceIntBox(x1, y + 20, output_int);
517 dialog->add_subwindow(firewire_channel);
518 x1 += firewire_channel->get_w() + 5;
523 if(driver == AUDIO_DV1394)
524 output_int = &out_config->dv1394_syt;
526 if(driver == AUDIO_1394)
527 output_int = &out_config->firewire_syt;
537 syt_title = new BC_Title(x1, y, _("Syt Offset:"),
538 MEDIUMFONT, resources->text_default);
539 dialog->add_subwindow(syt_title);
540 firewire_syt = new ADeviceIntBox(x1, y + 20, output_int);
541 dialog->add_subwindow(firewire_syt);
542 x1 += firewire_syt->get_w() + 5;
550 int ADevicePrefs::create_dvb_objs()
552 int x1 = x + menu->get_w() + 30;
554 char *output_char = in_config->dvb_in_adapter;
555 int y2 = y1 - BC_Title::calculate_h(dialog, _("DVB Adapter:"), MEDIUMFONT) - 5;
556 BC_Resources *resources = BC_WindowBase::get_resources();
557 dvb_adapter_title = new BC_Title(x1, y2, _("DVB Adapter:"),
558 MEDIUMFONT, resources->text_default);
559 dialog->add_subwindow(dvb_adapter_title);
560 dvb_adapter_path = new ADeviceTextBox(x1, y1, output_char);
561 dialog->add_subwindow(dvb_adapter_path);
562 int x2 = x1 + dvb_adapter_path->get_w() + 5;
563 dvb_device_title = new BC_Title(x2, y2, _("dev:"),
564 MEDIUMFONT, resources->text_default);
565 dialog->add_subwindow(dvb_device_title);
566 int *output_int = &in_config->dvb_in_device;
567 dvb_adapter_device = new ADeviceTumbleBox(this, x2, y1, output_int, 0, 9, 20);
568 dvb_adapter_device->create_objects();
569 x2 += dvb_device_title->get_w() + 30;
570 bits_title = new BC_Title(x2, y2, _("Bits:"),
571 MEDIUMFONT, resources->text_default);
572 dialog->add_subwindow(bits_title);
573 output_int = &in_config->dvb_in_bits;
574 dvb_bits = new BitsPopup(dialog, x2, y1, output_int, 0, 0, 0, 0, 1);
575 dvb_bits->create_objects();
576 x1 += 100; y1 += dvb_adapter_path->get_h() + 5;
577 output_int = &in_config->follow_audio;
578 follow_audio_config = new BC_CheckBox(x1, y1, output_int, _("Follow audio config"));
579 dialog->add_subwindow(follow_audio_config);
583 int ADevicePrefs::create_v4l2mpeg_objs()
585 int x1 = x + menu->get_w() + 30;
587 int y2 = y1 - BC_Title::calculate_h(dialog, _("Bits:"), MEDIUMFONT) - 5;
588 BC_Resources *resources = BC_WindowBase::get_resources();
589 bits_title = new BC_Title(x1, y2, _("Bits:"),
590 MEDIUMFONT, resources->text_default);
591 dialog->add_subwindow(bits_title);
592 int *output_int = &in_config->v4l2_in_bits;
593 v4l2_bits = new BitsPopup(dialog, x1, y1, output_int, 0, 0, 0, 0, 1);
594 v4l2_bits->create_objects();
595 x1 += v4l2_bits->get_w() + 10;
596 follow_audio_config = new BC_CheckBox(x1, y1,
597 &in_config->follow_audio, _("Follow audio config"));
598 dialog->add_subwindow(follow_audio_config);
603 ADriverMenu::ADriverMenu(int x, int y, ADevicePrefs *device_prefs,
604 int do_input, int *output)
605 : BC_PopupMenu(x, y, 125, adriver_to_string(*output), 1)
607 this->output = output;
608 this->do_input = do_input;
609 this->device_prefs = device_prefs;
612 ADriverMenu::~ADriverMenu()
616 void ADriverMenu::create_objects()
619 add_item(new ADriverItem(this, AUDIO_OSS_TITLE, AUDIO_OSS));
620 add_item(new ADriverItem(this, AUDIO_OSS_ENVY24_TITLE, AUDIO_OSS_ENVY24));
624 add_item(new ADriverItem(this, AUDIO_ALSA_TITLE, AUDIO_ALSA));
628 if(!do_input) add_item(new ADriverItem(this, AUDIO_ESOUND_TITLE, AUDIO_ESOUND));
632 if(!do_input) add_item(new ADriverItem(this, AUDIO_1394_TITLE, AUDIO_1394));
633 add_item(new ADriverItem(this, AUDIO_DV1394_TITLE, AUDIO_DV1394));
634 add_item(new ADriverItem(this, AUDIO_IEC61883_TITLE, AUDIO_IEC61883));
638 if(do_input) add_item(new ADriverItem(this, AUDIO_DVB_TITLE, AUDIO_DVB));
641 #ifdef HAVE_VIDEO4LINUX2
642 if(do_input) add_item(new ADriverItem(this, AUDIO_V4L2MPEG_TITLE, AUDIO_V4L2MPEG));
646 char* ADriverMenu::adriver_to_string(int driver)
650 sprintf(string, AUDIO_OSS_TITLE);
652 case AUDIO_OSS_ENVY24:
653 sprintf(string, AUDIO_OSS_ENVY24_TITLE);
656 sprintf(string, AUDIO_ESOUND_TITLE);
659 sprintf(string, AUDIO_NAS_TITLE);
662 sprintf(string, AUDIO_ALSA_TITLE);
666 sprintf(string, AUDIO_1394_TITLE);
669 sprintf(string, AUDIO_DV1394_TITLE);
672 sprintf(string, AUDIO_IEC61883_TITLE);
676 sprintf(string, AUDIO_DVB_TITLE);
679 sprintf(string, AUDIO_V4L2MPEG_TITLE);
685 ADriverItem::ADriverItem(ADriverMenu *popup, const char *text, int driver)
689 this->driver = driver;
692 ADriverItem::~ADriverItem()
696 int ADriverItem::handle_event()
698 popup->set_text(get_text());
699 *(popup->output) = driver;
700 popup->device_prefs->initialize(0);
701 popup->device_prefs->pwindow->show_dialog();
708 OSSEnable::OSSEnable(int x, int y, int *output)
709 : BC_CheckBox(x, y, *output)
711 this->output = output;
713 int OSSEnable::handle_event()
715 *output = get_value();
722 ADeviceTextBox::ADeviceTextBox(int x, int y, char *output)
723 : BC_TextBox(x, y, 150, 1, output)
725 this->output = output;
728 int ADeviceTextBox::handle_event()
730 strcpy(output, get_text());
734 ADeviceIntBox::ADeviceIntBox(int x, int y, int *output)
735 : BC_TextBox(x, y, 80, 1, *output)
737 this->output = output;
740 int ADeviceIntBox::handle_event()
742 *output = atol(get_text());
748 ADeviceTumbleBox::ADeviceTumbleBox(ADevicePrefs *prefs,
749 int x, int y, int *output, int min, int max, int text_w)
750 : BC_TumbleTextBox(prefs->dialog, *output, min, max, x, y, text_w)
752 this->output = output;
755 int ADeviceTumbleBox::handle_event()
757 *output = atol(get_text());
763 ALSADevice::ALSADevice(PreferencesDialog *dialog,
767 ArrayList<BC_ListBoxItem*> *devices)
768 : BC_PopupTextBox(dialog, devices, output, x, y, 200, 200)
770 this->output = output;
773 ALSADevice::~ALSADevice()
777 int ALSADevice::handle_event()
779 strcpy(output, get_text());