Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

adeviceprefs.C

Go to the documentation of this file.
00001 #include "adeviceprefs.h"
00002 #include "audioalsa.h"
00003 #include "audiodevice.inc"
00004 #include "bitspopup.h"
00005 #include "edl.h"
00006 #include "language.h"
00007 #include "playbackconfig.h"
00008 #include "preferences.h"
00009 #include "preferencesthread.h"
00010 #include "recordconfig.h"
00011 #include <string.h>
00012 
00013 #define DEVICE_H 50
00014 
00015 ADevicePrefs::ADevicePrefs(int x, 
00016         int y, 
00017         PreferencesWindow *pwindow, 
00018         PreferencesDialog *dialog, 
00019         AudioOutConfig *out_config, 
00020         AudioInConfig *in_config, 
00021         int mode)
00022 {
00023         reset();
00024         this->pwindow = pwindow;
00025         this->dialog = dialog;
00026         this->driver = -1;
00027         this->mode = mode;
00028         this->out_config = out_config;
00029         this->in_config = in_config;
00030         this->x = x;
00031         this->y = y;
00032 }
00033 
00034 ADevicePrefs::~ADevicePrefs()
00035 {
00036         delete_objects();
00037         if(menu) delete menu;
00038 }
00039 
00040 void ADevicePrefs::reset()
00041 {
00042         menu = 0;
00043         firewire_channels = 0;
00044         firewire_path = 0;
00045         firewire_syt = 0;
00046         syt_title = 0;
00047         channels_title = 0;
00048         path_title = 0;
00049 
00050         alsa_drivers = 0;
00051         path_title = 0;
00052         bits_title = 0;
00053         channels_title = 0;
00054         alsa_device = 0;
00055         alsa_bits = 0;
00056         alsa_channels = 0;
00057         alsa_workaround = 0;
00058 }
00059 
00060 int ADevicePrefs::initialize()
00061 {
00062         int *driver;
00063         delete_objects();
00064 
00065         switch(mode)
00066         {
00067                 case MODEPLAY:
00068                         driver = &out_config->driver;
00069                         break;
00070                 case MODERECORD:
00071                         driver = &in_config->driver;
00072                         break;
00073                 case MODEDUPLEX:
00074                         driver = &out_config->driver;
00075                         break;
00076         }
00077         this->driver = *driver;
00078 
00079         if(!menu)
00080         {
00081                 dialog->add_subwindow(menu = new ADriverMenu(x, 
00082                         y + 10, 
00083                         this, 
00084                         (mode == MODERECORD),
00085                         driver));
00086                 menu->create_objects();
00087         }
00088 
00089         switch(*driver)
00090         {
00091                 case AUDIO_OSS:
00092                 case AUDIO_OSS_ENVY24:
00093                         create_oss_objs();
00094                         break;
00095                 case AUDIO_ALSA:
00096                         create_alsa_objs();
00097                         break;
00098                 case AUDIO_ESOUND:
00099                         create_esound_objs();
00100                         break;
00101                 case AUDIO_1394:
00102                 case AUDIO_DV1394:
00103                 case AUDIO_IEC61883:
00104                         create_firewire_objs();
00105                         break;
00106         }
00107         return 0;
00108 }
00109 
00110 int ADevicePrefs::get_h()
00111 {
00112         return DEVICE_H + 25;
00113 }
00114 
00115 int ADevicePrefs::delete_objects()
00116 {
00117         switch(driver)
00118         {
00119                 case AUDIO_OSS:
00120                 case AUDIO_OSS_ENVY24:
00121                         delete_oss_objs();
00122                         break;
00123                 case AUDIO_ALSA:
00124                         delete_alsa_objs();
00125                         break;
00126                 case AUDIO_ESOUND:
00127                         delete_esound_objs();
00128                         break;
00129                 case AUDIO_1394:
00130                 case AUDIO_DV1394:
00131                 case AUDIO_IEC61883:
00132                         delete_firewire_objs();
00133                         break;
00134         }
00135         reset();
00136         driver = -1;
00137         return 0;
00138 }
00139 
00140 int ADevicePrefs::delete_oss_objs()
00141 {
00142         delete path_title;
00143         delete bits_title;
00144         delete channels_title;
00145         delete oss_bits;
00146         for(int i = 0; i < MAXDEVICES; i++)
00147         {
00148 //                              delete oss_enable[i];
00149                 delete oss_path[i];
00150                 delete oss_channels[i];
00151 break;
00152         }
00153         return 0;
00154 }
00155 
00156 int ADevicePrefs::delete_esound_objs()
00157 {
00158         delete server_title;
00159         delete port_title;
00160         delete esound_server;
00161         delete esound_port;
00162         return 0;
00163 }
00164 
00165 int ADevicePrefs::delete_firewire_objs()
00166 {
00167         delete port_title;
00168         delete channel_title;
00169         delete firewire_port;
00170         delete firewire_channel;
00171         if(firewire_path)
00172         {
00173                 delete path_title;
00174                 delete firewire_path;
00175         }
00176         firewire_path = 0;
00177         if(firewire_syt)
00178         {
00179                 delete firewire_syt;
00180                 delete syt_title;
00181         }
00182         firewire_syt = 0;
00183         if(firewire_channels)
00184         {
00185                 delete firewire_channels;
00186                 delete channels_title;
00187         }
00188         firewire_channels = 0;
00189         return 0;
00190 }
00191 
00192 int ADevicePrefs::delete_alsa_objs()
00193 {
00194 #ifdef HAVE_ALSA
00195         alsa_drivers->remove_all_objects();
00196         delete alsa_drivers;
00197         delete path_title;
00198         delete bits_title;
00199         delete channels_title;
00200         delete alsa_device;
00201         delete alsa_bits;
00202         delete alsa_channels;
00203         delete alsa_workaround;
00204 #endif
00205         return 0;
00206 }
00207 
00208 
00209 int ADevicePrefs::create_oss_objs()
00210 {
00211         char *output_char;
00212         int *output_int;
00213         int y1 = y;
00214         BC_Resources *resources = BC_WindowBase::get_resources();
00215 
00216         for(int i = 0; i < MAXDEVICES; i++)
00217         {
00218                 int x1 = x + menu->get_w() + 5;
00219                 switch(mode)
00220                 {
00221                         case MODEPLAY: 
00222 //                              output_int = &out_config->oss_enable[i];
00223                                 break;
00224                         case MODERECORD:
00225 //                              output_int = &in_config->oss_enable[i];
00226                                 break;
00227                         case MODEDUPLEX:
00228 //                              output_int = &out_config->oss_enable[i];
00229                                 break;
00230                 }
00231 //              dialog->add_subwindow(oss_enable[i] = new OSSEnable(x1, y1 + 20, output_int));
00232 //              x1 += oss_enable[i]->get_w() + 5;
00233                 switch(mode)
00234                 {
00235                         case MODEPLAY: 
00236                                 output_char = out_config->oss_out_device[i];
00237                                 break;
00238                         case MODERECORD:
00239                                 output_char = in_config->oss_in_device[i];
00240                                 break;
00241                         case MODEDUPLEX:
00242                                 output_char = out_config->oss_out_device[i];
00243                                 break;
00244                 }
00245                 if(i == 0) dialog->add_subwindow(path_title = new BC_Title(x1, 
00246                         y, 
00247                         _("Device path:"), 
00248                         MEDIUMFONT, 
00249                         resources->text_default));
00250                 dialog->add_subwindow(oss_path[i] = new ADeviceTextBox(x1, 
00251                         y1 + 20, 
00252                         output_char));
00253 
00254                 x1 += oss_path[i]->get_w() + 5;
00255                 if(i == 0)
00256                 {
00257                         switch(mode)
00258                         {
00259                                 case MODEPLAY: 
00260                                         output_int = &out_config->oss_out_bits;
00261                                         break;
00262                                 case MODERECORD:
00263                                         output_int = &in_config->oss_in_bits;
00264                                         break;
00265                                 case MODEDUPLEX:
00266                                         output_int = &out_config->oss_out_bits;
00267                                         break;
00268                         }
00269                         if(i == 0) dialog->add_subwindow(bits_title = new BC_Title(x1, y, _("Bits:"), MEDIUMFONT, resources->text_default));
00270                         oss_bits = new BitsPopup(dialog, 
00271                                 x1, 
00272                                 y1 + 20, 
00273                                 output_int, 
00274                                 0, 
00275                                 0, 
00276                                 0,
00277                                 0,
00278                                 1);
00279                         oss_bits->create_objects();
00280                 }
00281 
00282                 x1 += oss_bits->get_w() + 5;
00283                 switch(mode)
00284                 {
00285                         case MODEPLAY: 
00286                                 output_int = &out_config->oss_out_channels[i];
00287                                 break;
00288                         case MODERECORD:
00289                                 output_int = &in_config->oss_in_channels[i];
00290                                 break;
00291                         case MODEDUPLEX:
00292                                 output_int = &out_config->oss_out_channels[i];
00293                                 break;
00294                 }
00295                 if(i == 0) dialog->add_subwindow(channels_title = new BC_Title(x1, y1, _("Channels:"), MEDIUMFONT, resources->text_default));
00296                 dialog->add_subwindow(oss_channels[i] = new ADeviceIntBox(x1, y1 + 20, output_int));
00297                 y1 += DEVICE_H;
00298 break;
00299         }
00300 
00301         return 0;
00302 }
00303 
00304 int ADevicePrefs::create_alsa_objs()
00305 {
00306 #ifdef HAVE_ALSA
00307         char *output_char;
00308         int *output_int;
00309         int y1 = y;
00310         BC_Resources *resources = BC_WindowBase::get_resources();
00311 
00312         int x1 = x + menu->get_w() + 5;
00313 
00314         ArrayList<char*> *alsa_titles = new ArrayList<char*>;
00315         AudioALSA::list_devices(alsa_titles);
00316 
00317         alsa_drivers = new ArrayList<BC_ListBoxItem*>;
00318         for(int i = 0; i < alsa_titles->total; i++)
00319                 alsa_drivers->append(new BC_ListBoxItem(alsa_titles->values[i]));
00320         alsa_titles->remove_all_objects();
00321         delete alsa_titles;
00322 
00323         switch(mode)
00324         {
00325                 case MODEPLAY: 
00326                         output_char = out_config->alsa_out_device;
00327                         break;
00328                 case MODERECORD:
00329                         output_char = in_config->alsa_in_device;
00330                         break;
00331                 case MODEDUPLEX:
00332                         output_char = out_config->alsa_out_device;
00333                         break;
00334         }
00335         dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device:"), MEDIUMFONT, resources->text_default));
00336         alsa_device = new ALSADevice(dialog,
00337                 x1, 
00338                 y1 + 20, 
00339                 output_char,
00340                 alsa_drivers);
00341         alsa_device->create_objects();
00342         int x2 = x1;
00343 
00344         x1 += alsa_device->get_w() + 5;
00345         switch(mode)
00346         {
00347                 case MODEPLAY: 
00348                         output_int = &out_config->alsa_out_bits;
00349                         break;
00350                 case MODERECORD:
00351                         output_int = &in_config->alsa_in_bits;
00352                         break;
00353                 case MODEDUPLEX:
00354                         output_int = &out_config->alsa_out_bits;
00355                         break;
00356         }
00357         dialog->add_subwindow(bits_title = new BC_Title(x1, y, _("Bits:"), MEDIUMFONT, resources->text_default));
00358         alsa_bits = new BitsPopup(dialog, 
00359                 x1, 
00360                 y1 + 20, 
00361                 output_int, 
00362                 0, 
00363                 0, 
00364                 0,
00365                 0,
00366                 1);
00367         alsa_bits->create_objects();
00368 
00369         x1 += alsa_bits->get_w() + 5;
00370         switch(mode)
00371         {
00372                 case MODEPLAY: 
00373                         output_int = &out_config->alsa_out_channels;
00374                         break;
00375                 case MODERECORD:
00376                         output_int = &in_config->alsa_in_channels;
00377                         break;
00378                 case MODEDUPLEX:
00379                         output_int = &out_config->alsa_out_channels;
00380                         break;
00381         }
00382         dialog->add_subwindow(channels_title = new BC_Title(x1, y, _("Channels:"), MEDIUMFONT, resources->text_default));
00383         dialog->add_subwindow(alsa_channels = new ADeviceIntBox(x1, y1 + 20, output_int));
00384         y1 += alsa_channels->get_h() + 20 + 5;
00385         x1 = x2;
00386 
00387         if(mode == MODEPLAY)
00388         {
00389                 dialog->add_subwindow(alsa_workaround = 
00390                         new BC_CheckBox(x1, 
00391                                 y1, 
00392                                 &out_config->interrupt_workaround,
00393                                 _("Stop playback locks up.")));
00394         }
00395 
00396 
00397 #endif
00398 
00399         return 0;
00400 }
00401 
00402 int ADevicePrefs::create_esound_objs()
00403 {
00404         int x1 = x + menu->get_w() + 5;
00405         char *output_char;
00406         int *output_int;
00407         BC_Resources *resources = BC_WindowBase::get_resources();
00408 
00409         switch(mode)
00410         {
00411                 case MODEPLAY: 
00412                         output_char = out_config->esound_out_server;
00413                         break;
00414                 case MODERECORD:
00415                         output_char = in_config->esound_in_server;
00416                         break;
00417                 case MODEDUPLEX:
00418                         output_char = out_config->esound_out_server;
00419                         break;
00420         }
00421         dialog->add_subwindow(server_title = new BC_Title(x1, y, _("Server:"), MEDIUMFONT, resources->text_default));
00422         dialog->add_subwindow(esound_server = new ADeviceTextBox(x1, y + 20, output_char));
00423 
00424         switch(mode)
00425         {
00426                 case MODEPLAY: 
00427                         output_int = &out_config->esound_out_port;
00428                         break;
00429                 case MODERECORD:
00430                         output_int = &in_config->esound_in_port;
00431                         break;
00432                 case MODEDUPLEX:
00433                         output_int = &out_config->esound_out_port;
00434                         break;
00435         }
00436         x1 += esound_server->get_w() + 5;
00437         dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, resources->text_default));
00438         dialog->add_subwindow(esound_port = new ADeviceIntBox(x1, y + 20, output_int));
00439         return 0;
00440 }
00441 
00442 int ADevicePrefs::create_firewire_objs()
00443 {
00444         int x1 = x + menu->get_w() + 5;
00445         int *output_int = 0;
00446         char *output_char = 0;
00447         BC_Resources *resources = BC_WindowBase::get_resources();
00448 
00449 // Firewire path
00450         switch(mode)
00451         {
00452                 case MODEPLAY:
00453                         if(driver == AUDIO_DV1394)
00454                                 output_char = out_config->dv1394_path;
00455                         else
00456                         if(driver == AUDIO_1394)
00457                                 output_char = out_config->firewire_path;
00458                         break;
00459 // Our version of raw1394 doesn't support changing the path
00460                 case MODERECORD:
00461                         output_char = 0;
00462                         break;
00463         }
00464 
00465         if(output_char)
00466         {
00467                 dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
00468                 dialog->add_subwindow(firewire_path = new ADeviceTextBox(x1, y + 20, output_char));
00469                 x1 += firewire_path->get_w() + 5;
00470         }
00471 
00472 // Firewire port
00473         switch(mode)
00474         {
00475                 case MODEPLAY: 
00476                         if(driver == AUDIO_DV1394)
00477                                 output_int = &out_config->dv1394_port;
00478                         else
00479                                 output_int = &out_config->firewire_port;
00480                         break;
00481                 case MODERECORD:
00482                         output_int = &in_config->firewire_port;
00483                         break;
00484                 case MODEDUPLEX:
00485 //                      output_int = &out_config->afirewire_out_port;
00486                         break;
00487         }
00488         dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, resources->text_default));
00489         dialog->add_subwindow(firewire_port = new ADeviceIntBox(x1, y + 20, output_int));
00490 
00491         x1 += firewire_port->get_w() + 5;
00492 
00493 // Firewire channel
00494         switch(mode)
00495         {
00496                 case MODEPLAY: 
00497                         if(driver == AUDIO_DV1394)
00498                                 output_int = &out_config->dv1394_channel;
00499                         else
00500                                 output_int = &out_config->firewire_channel;
00501                         break;
00502                 case MODERECORD:
00503                         output_int = &in_config->firewire_channel;
00504                         break;
00505         }
00506         dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, resources->text_default));
00507         dialog->add_subwindow(firewire_channel = new ADeviceIntBox(x1, y + 20, output_int));
00508         x1 += firewire_channel->get_w() + 5;
00509 
00510 // Playback channels
00511         switch(mode)
00512         {
00513                 case MODEPLAY:
00514                         if(driver == AUDIO_DV1394)
00515                                 output_int = &out_config->dv1394_channels;
00516                         else
00517                                 output_int = &out_config->firewire_channels;
00518                         break;
00519                 case MODERECORD:
00520                         output_int = 0;
00521                         break;
00522         }
00523 
00524         if(output_int)
00525         {
00526                 dialog->add_subwindow(channels_title = new BC_Title(x1, y, _("Channels:"), MEDIUMFONT, resources->text_default));
00527                 dialog->add_subwindow(firewire_channels = new ADeviceIntBox(x1, y + 20, output_int));
00528                 x1 += firewire_channels->get_w() + 5;
00529         }
00530 
00531 // Syt offset
00532         switch(mode)
00533         {
00534                 case MODEPLAY:
00535                         if(driver == AUDIO_DV1394)
00536                                 output_int = &out_config->dv1394_syt;
00537                         else
00538                         if(driver == AUDIO_1394)
00539                                 output_int = &out_config->firewire_syt;
00540                         else
00541                                 output_int = 0;
00542                         break;
00543                 case MODERECORD:
00544                         output_int = 0;
00545                         break;
00546         }
00547 
00548         if(output_int)
00549         {
00550                 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, resources->text_default));
00551                 dialog->add_subwindow(firewire_syt = new ADeviceIntBox(x1, y + 20, output_int));
00552                 x1 += firewire_syt->get_w() + 5;
00553         }
00554 
00555         return 0;
00556 }
00557 
00558 ADriverMenu::ADriverMenu(int x, 
00559         int y, 
00560         ADevicePrefs *device_prefs, 
00561         int do_input,
00562         int *output)
00563  : BC_PopupMenu(x, y, 125, adriver_to_string(*output), 1)
00564 {
00565         this->output = output;
00566         this->do_input = do_input;
00567         this->device_prefs = device_prefs;
00568 }
00569 
00570 ADriverMenu::~ADriverMenu()
00571 {
00572 }
00573 
00574 void ADriverMenu::create_objects()
00575 {
00576         add_item(new ADriverItem(this, AUDIO_OSS_TITLE, AUDIO_OSS));
00577         add_item(new ADriverItem(this, AUDIO_OSS_ENVY24_TITLE, AUDIO_OSS_ENVY24));
00578 
00579 #ifdef HAVE_ALSA
00580         add_item(new ADriverItem(this, AUDIO_ALSA_TITLE, AUDIO_ALSA));
00581 #endif
00582 
00583         if(!do_input) add_item(new ADriverItem(this, AUDIO_ESOUND_TITLE, AUDIO_ESOUND));
00584 //      add_item(new ADriverItem(this, AUDIO_NAS_TITLE, AUDIO_NAS));
00585         if(!do_input) add_item(new ADriverItem(this, AUDIO_1394_TITLE, AUDIO_1394));
00586         add_item(new ADriverItem(this, AUDIO_DV1394_TITLE, AUDIO_DV1394));
00587         add_item(new ADriverItem(this, AUDIO_IEC61883_TITLE, AUDIO_IEC61883));
00588 }
00589 
00590 char* ADriverMenu::adriver_to_string(int driver)
00591 {
00592         switch(driver)
00593         {
00594                 case AUDIO_OSS:
00595                         sprintf(string, AUDIO_OSS_TITLE);
00596                         break;
00597                 case AUDIO_OSS_ENVY24:
00598                         sprintf(string, AUDIO_OSS_ENVY24_TITLE);
00599                         break;
00600                 case AUDIO_ESOUND:
00601                         sprintf(string, AUDIO_ESOUND_TITLE);
00602                         break;
00603                 case AUDIO_NAS:
00604                         sprintf(string, AUDIO_NAS_TITLE);
00605                         break;
00606                 case AUDIO_ALSA:
00607                         sprintf(string, AUDIO_ALSA_TITLE);
00608                         break;
00609                 case AUDIO_1394:
00610                         sprintf(string, AUDIO_1394_TITLE);
00611                         break;
00612                 case AUDIO_DV1394:
00613                         sprintf(string, AUDIO_DV1394_TITLE);
00614                         break;
00615                 case AUDIO_IEC61883:
00616                         sprintf(string, AUDIO_IEC61883_TITLE);
00617                         break;
00618         }
00619         return string;
00620 }
00621 
00622 ADriverItem::ADriverItem(ADriverMenu *popup, char *text, int driver)
00623  : BC_MenuItem(text)
00624 {
00625         this->popup = popup;
00626         this->driver = driver;
00627 }
00628 
00629 ADriverItem::~ADriverItem()
00630 {
00631 }
00632 
00633 int ADriverItem::handle_event()
00634 {
00635         popup->set_text(get_text());
00636         *(popup->output) = driver;
00637         popup->device_prefs->initialize();
00638         return 1;
00639 }
00640 
00641 
00642 
00643 
00644 OSSEnable::OSSEnable(int x, int y, int *output)
00645  : BC_CheckBox(x, y, *output)
00646 {
00647         this->output = output;
00648 }
00649 int OSSEnable::handle_event()
00650 {
00651         *output = get_value();
00652         return 1;
00653 }
00654 
00655 
00656 
00657 
00658 ADeviceTextBox::ADeviceTextBox(int x, int y, char *output)
00659  : BC_TextBox(x, y, 150, 1, output)
00660 { 
00661         this->output = output; 
00662 }
00663 
00664 int ADeviceTextBox::handle_event() 
00665 {
00666         strcpy(output, get_text());
00667         return 1;
00668 }
00669 
00670 ADeviceIntBox::ADeviceIntBox(int x, int y, int *output)
00671  : BC_TextBox(x, y, 80, 1, *output)
00672 { 
00673         this->output = output;
00674 }
00675 
00676 int ADeviceIntBox::handle_event() 
00677 { 
00678         *output = atol(get_text()); 
00679         return 1;
00680 }
00681 
00682 
00683 ALSADevice::ALSADevice(PreferencesDialog *dialog, 
00684         int x, 
00685         int y, 
00686         char *output, 
00687         ArrayList<BC_ListBoxItem*> *devices)
00688  : BC_PopupTextBox(dialog,
00689         devices,
00690         output,
00691         x, 
00692         y, 
00693         200,
00694         200)
00695 {
00696         this->output = output;
00697 }
00698 
00699 ALSADevice::~ALSADevice()
00700 {
00701 }
00702 
00703 int ALSADevice::handle_event()
00704 {
00705         strcpy(output, get_text());
00706         return 1;
00707 }
00708 

Generated on Sun Jan 8 13:38:49 2006 for Cinelerra-svn by  doxygen 1.4.4