r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / adeviceprefs.C
blob916392adb34021493d112337c7a207de24514335
1 #include "adeviceprefs.h"
2 #include "audioalsa.h"
3 #include "audiodevice.inc"
4 #include "bitspopup.h"
5 #include "edl.h"
6 #include "playbackconfig.h"
7 #include "preferences.h"
8 #include "preferencesthread.h"
9 #include "recordconfig.h"
10 #include <string.h>
12 #include <libintl.h>
13 #define _(String) gettext(String)
14 #define gettext_noop(String) String
15 #define N_(String) gettext_noop (String)
17 #define DEVICE_H 25
19 ADevicePrefs::ADevicePrefs(int x, 
20         int y, 
21         PreferencesWindow *pwindow, 
22         PreferencesDialog *dialog, 
23         AudioOutConfig *out_config, 
24         AudioInConfig *in_config, 
25         int mode)
27         this->pwindow = pwindow;
28         this->dialog = dialog;
29         this->driver = -1;
30         this->mode = mode;
31         this->out_config = out_config;
32         this->in_config = in_config;
33         this->x = x;
34         this->y = y;
35         menu = 0;
36         firewire_channels = 0;
37         firewire_path = 0;
38         firewire_syt = 0;
39         firewire_use_dv1394 = 0;
40         syt_title = 0;
41         channels_title = 0;
42         path_title = 0;
45 ADevicePrefs::~ADevicePrefs()
47         delete_objects();
48         if(menu) delete menu;
53 int ADevicePrefs::initialize()
55         int *driver;
56         delete_objects();
58         switch(mode)
59         {
60                 case MODEPLAY:
61                         driver = &out_config->driver;
62                         break;
63                 case MODERECORD:
64                         driver = &in_config->driver;
65                         break;
66                 case MODEDUPLEX:
67                         driver = &out_config->driver;
68                         break;
69         }
70         this->driver = *driver;
72         if(!menu)
73         {
74                 dialog->add_subwindow(menu = new ADriverMenu(x, 
75                         y + 10, 
76                         this, 
77                         (mode == MODERECORD),
78                         driver));
79                 menu->create_objects();
80         }
82         switch(*driver)
83         {
84                 case AUDIO_OSS:
85                 case AUDIO_OSS_ENVY24:
86                         create_oss_objs();
87                         break;
88                 case AUDIO_ALSA:
89                         create_alsa_objs();
90                         break;
91                 case AUDIO_ESOUND:
92                         create_esound_objs();
93                         break;
94                 case AUDIO_1394:
95                         create_firewire_objs();
96                         break;
97         }
98         return 0;
101 int ADevicePrefs::get_h()
103         return DEVICE_H + 25;
104         return MAXDEVICES * DEVICE_H + 25;
107 int ADevicePrefs::delete_objects()
109         switch(driver)
110         {
111                 case AUDIO_OSS:
112                 case AUDIO_OSS_ENVY24:
113                         delete_oss_objs();
114                         break;
115                 case AUDIO_ALSA:
116                         delete_alsa_objs();
117                         break;
118                 case AUDIO_ESOUND:
119                         delete_esound_objs();
120                         break;
121                 case AUDIO_1394:
122                         delete_firewire_objs();
123                         break;
124         }
125         driver = -1;
126         return 0;
129 int ADevicePrefs::delete_oss_objs()
131         delete path_title;
132         delete bits_title;
133         delete channels_title;
134         delete oss_bits;
135         for(int i = 0; i < MAXDEVICES; i++)
136         {
137 //                              delete oss_enable[i];
138                 delete oss_path[i];
139                 delete oss_channels[i];
140 break;
141         }
142         return 0;
145 int ADevicePrefs::delete_esound_objs()
147         delete server_title;
148         delete port_title;
149         delete esound_server;
150         delete esound_port;
151         return 0;
154 int ADevicePrefs::delete_firewire_objs()
156         delete port_title;
157         delete channel_title;
158         delete firewire_port;
159         delete firewire_channel;
160         if(firewire_path)
161         {
162                 delete path_title;
163                 delete firewire_path;
164         }
165         firewire_path = 0;
166         if(firewire_syt)
167         {
168                 delete firewire_syt;
169                 delete syt_title;
170         }
171         firewire_syt = 0;
172         if(firewire_channels)
173         {
174                 delete firewire_channels;
175                 delete channels_title;
176         }
177         firewire_channels = 0;
178         if(firewire_use_dv1394)
179         {
180                 delete firewire_use_dv1394;
181         }
182         firewire_use_dv1394 = 0;
183         return 0;
186 int ADevicePrefs::delete_alsa_objs()
188 #ifdef HAVE_ALSA
189         alsa_drivers->remove_all_objects();
190         delete alsa_drivers;
191         delete path_title;
192         delete bits_title;
193         delete channels_title;
194         delete alsa_device;
195         delete alsa_bits;
196         delete alsa_channels;
197 #endif
198         return 0;
202 int ADevicePrefs::create_oss_objs()
204         char *output_char;
205         int *output_int;
206         int y1 = y;
208         for(int i = 0; i < MAXDEVICES; i++)
209         {
210                 int x1 = x + menu->get_w() + 5;
211                 switch(mode)
212                 {
213                         case MODEPLAY: 
214 //                              output_int = &out_config->oss_enable[i];
215                                 break;
216                         case MODERECORD:
217 //                              output_int = &in_config->oss_enable[i];
218                                 break;
219                         case MODEDUPLEX:
220 //                              output_int = &out_config->oss_enable[i];
221                                 break;
222                 }
223 //              dialog->add_subwindow(oss_enable[i] = new OSSEnable(x1, y1 + 20, output_int));
224 //              x1 += oss_enable[i]->get_w() + 5;
225                 switch(mode)
226                 {
227                         case MODEPLAY: 
228                                 output_char = out_config->oss_out_device[i];
229                                 break;
230                         case MODERECORD:
231                                 output_char = in_config->oss_in_device[i];
232                                 break;
233                         case MODEDUPLEX:
234                                 output_char = out_config->oss_out_device[i];
235                                 break;
236                 }
237                 if(i == 0) dialog->add_subwindow(path_title = new BC_Title(x1, 
238                         y, 
239                         _("Device path:"), 
240                         MEDIUMFONT, 
241                         BLACK));
242                 dialog->add_subwindow(oss_path[i] = new ADeviceTextBox(x1, 
243                         y1 + 20, 
244                         output_char));
246                 x1 += oss_path[i]->get_w() + 5;
247                 if(i == 0)
248                 {
249                         switch(mode)
250                         {
251                                 case MODEPLAY: 
252                                         output_int = &out_config->oss_out_bits;
253                                         break;
254                                 case MODERECORD:
255                                         output_int = &in_config->oss_in_bits;
256                                         break;
257                                 case MODEDUPLEX:
258                                         output_int = &out_config->oss_out_bits;
259                                         break;
260                         }
261                         if(i == 0) dialog->add_subwindow(bits_title = new BC_Title(x1, y, _("Bits:"), MEDIUMFONT, BLACK));
262                         oss_bits = new BitsPopup(dialog, 
263                                 x1, 
264                                 y1 + 20, 
265                                 output_int, 
266                                 0, 
267                                 0, 
268                                 0,
269                                 0,
270                                 1);
271                         oss_bits->create_objects();
272                 }
274                 x1 += oss_bits->get_w() + 5;
275                 switch(mode)
276                 {
277                         case MODEPLAY: 
278                                 output_int = &out_config->oss_out_channels[i];
279                                 break;
280                         case MODERECORD:
281                                 output_int = &in_config->oss_in_channels[i];
282                                 break;
283                         case MODEDUPLEX:
284                                 output_int = &out_config->oss_out_channels[i];
285                                 break;
286                 }
287                 if(i == 0) dialog->add_subwindow(channels_title = new BC_Title(x1, y1, _("Channels:"), MEDIUMFONT, BLACK));
288                 dialog->add_subwindow(oss_channels[i] = new ADeviceIntBox(x1, y1 + 20, output_int));
289                 y1 += DEVICE_H;
290 break;
291         }
293         return 0;
296 int ADevicePrefs::create_alsa_objs()
298 #ifdef HAVE_ALSA
299         char *output_char;
300         int *output_int;
301         int y1 = y;
303         int x1 = x + menu->get_w() + 5;
305         ArrayList<char*> *alsa_titles = new ArrayList<char*>;
306         AudioALSA::list_devices(alsa_titles);
308         alsa_drivers = new ArrayList<BC_ListBoxItem*>;
309         for(int i = 0; i < alsa_titles->total; i++)
310                 alsa_drivers->append(new BC_ListBoxItem(alsa_titles->values[i]));
311         alsa_titles->remove_all_objects();
312         delete alsa_titles;
314         switch(mode)
315         {
316                 case MODEPLAY: 
317                         output_char = out_config->alsa_out_device;
318                         break;
319                 case MODERECORD:
320                         output_char = in_config->alsa_in_device;
321                         break;
322                 case MODEDUPLEX:
323                         output_char = out_config->alsa_out_device;
324                         break;
325         }
326         dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device:"), MEDIUMFONT, BLACK));
327         alsa_device = new ALSADevice(dialog,
328                 x1, 
329                 y1 + 20, 
330                 output_char,
331                 alsa_drivers);
332         alsa_device->create_objects();
334         x1 += alsa_device->get_w() + 5;
335         switch(mode)
336         {
337                 case MODEPLAY: 
338                         output_int = &out_config->alsa_out_bits;
339                         break;
340                 case MODERECORD:
341                         output_int = &in_config->alsa_in_bits;
342                         break;
343                 case MODEDUPLEX:
344                         output_int = &out_config->alsa_out_bits;
345                         break;
346         }
347         dialog->add_subwindow(bits_title = new BC_Title(x1, y, _("Bits:"), MEDIUMFONT, BLACK));
348         alsa_bits = new BitsPopup(dialog, 
349                 x1, 
350                 y1 + 20, 
351                 output_int, 
352                 0, 
353                 0, 
354                 0,
355                 0,
356                 0);
357         alsa_bits->create_objects();
359         x1 += alsa_bits->get_w() + 5;
360         switch(mode)
361         {
362                 case MODEPLAY: 
363                         output_int = &out_config->alsa_out_channels;
364                         break;
365                 case MODERECORD:
366                         output_int = &in_config->alsa_in_channels;
367                         break;
368                 case MODEDUPLEX:
369                         output_int = &out_config->alsa_out_channels;
370                         break;
371         }
372         dialog->add_subwindow(channels_title = new BC_Title(x1, y, _("Channels:"), MEDIUMFONT, BLACK));
373         dialog->add_subwindow(alsa_channels = new ADeviceIntBox(x1, y1 + 20, output_int));
374         y1 += DEVICE_H;
375 #endif
377         return 0;
380 int ADevicePrefs::create_esound_objs()
382         int x1 = x + menu->get_w() + 5;
383         char *output_char;
384         int *output_int;
386         switch(mode)
387         {
388                 case MODEPLAY: 
389                         output_char = out_config->esound_out_server;
390                         break;
391                 case MODERECORD:
392                         output_char = in_config->esound_in_server;
393                         break;
394                 case MODEDUPLEX:
395                         output_char = out_config->esound_out_server;
396                         break;
397         }
398         dialog->add_subwindow(server_title = new BC_Title(x1, y, _("Server:"), MEDIUMFONT, BLACK));
399         dialog->add_subwindow(esound_server = new ADeviceTextBox(x1, y + 20, output_char));
401         switch(mode)
402         {
403                 case MODEPLAY: 
404                         output_int = &out_config->esound_out_port;
405                         break;
406                 case MODERECORD:
407                         output_int = &in_config->esound_in_port;
408                         break;
409                 case MODEDUPLEX:
410                         output_int = &out_config->esound_out_port;
411                         break;
412         }
413         x1 += esound_server->get_w() + 5;
414         dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, BLACK));
415         dialog->add_subwindow(esound_port = new ADeviceIntBox(x1, y + 20, output_int));
416         return 0;
419 int ADevicePrefs::create_firewire_objs()
421         int x1 = x + menu->get_w() + 5;
422         int *output_int;
423         char *output_char;
425 // Firewire path
426         switch(mode)
427         {
428                 case MODEPLAY:
429                         output_char = out_config->firewire_path;
430                         break;
431 // Our version of raw1394 doesn't support changing the path
432                 case MODERECORD:
433                         output_char = 0;
434                         break;
435         }
437         if(output_char)
438         {
439                 dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, BLACK));
440                 dialog->add_subwindow(firewire_path = new ADeviceTextBox(x1, y + 20, output_char));
441                 x1 += firewire_path->get_w() + 5;
442         }
444 // Firewire port
445         switch(mode)
446         {
447                 case MODEPLAY: 
448                         output_int = &out_config->firewire_port;
449                         break;
450                 case MODERECORD:
451                         output_int = &in_config->firewire_port;
452                         break;
453                 case MODEDUPLEX:
454 //                      output_int = &out_config->afirewire_out_port;
455                         break;
456         }
457         dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, BLACK));
458         dialog->add_subwindow(firewire_port = new ADeviceIntBox(x1, y + 20, output_int));
460         x1 += firewire_port->get_w() + 5;
462 // Firewire channel
463         switch(mode)
464         {
465                 case MODEPLAY: 
466                         output_int = &out_config->firewire_channel;
467                         break;
468                 case MODERECORD:
469                         output_int = &in_config->firewire_channel;
470                         break;
471         }
472         dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, BLACK));
473         dialog->add_subwindow(firewire_channel = new ADeviceIntBox(x1, y + 20, output_int));
474         x1 += firewire_channel->get_w() + 5;
476 // Playback channels
477         switch(mode)
478         {
479                 case MODEPLAY:
480                         output_int = &out_config->firewire_channels;
481                         break;
482                 case MODERECORD:
483                         output_int = 0;
484                         break;
485         }
487         if(output_int)
488         {
489                 dialog->add_subwindow(channels_title = new BC_Title(x1, y, _("Channels:"), MEDIUMFONT, BLACK));
490                 dialog->add_subwindow(firewire_channels = new ADeviceIntBox(x1, y + 20, output_int));
491                 x1 += firewire_channels->get_w() + 5;
492         }
494 // Syt offset
495         switch(mode)
496         {
497                 case MODEPLAY:
498                         output_int = &out_config->firewire_syt;
499                         break;
500                 case MODERECORD:
501                         output_int = 0;
502                         break;
503         }
505         if(output_int)
506         {
507                 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, BLACK));
508                 dialog->add_subwindow(firewire_syt = new ADeviceIntBox(x1, y + 20, output_int));
509                 x1 += firewire_syt->get_w() + 5;
510         }
512         x1 = x + menu->get_w() + 5;
514         switch(mode)
515         {
516                 case MODEPLAY:
517                         output_int = &out_config->firewire_use_dv1394;
518                         break;
519                 case MODERECORD:
520                         output_int = 0;
521                         break;
522         }
524         if(output_int)
525         {
526                 dialog->add_subwindow(firewire_use_dv1394 =
527                                 new BC_CheckBox(x1, y + 45, output_int, _("Use DV1394")));
528         }
530         return 0;
533 ADriverMenu::ADriverMenu(int x, 
534         int y, 
535         ADevicePrefs *device_prefs, 
536         int do_input,
537         int *output)
538  : BC_PopupMenu(x, y, 125, adriver_to_string(*output), 1)
540         this->output = output;
541         this->do_input = do_input;
542         this->device_prefs = device_prefs;
545 ADriverMenu::~ADriverMenu()
549 void ADriverMenu::create_objects()
551         add_item(new ADriverItem(this, AUDIO_OSS_TITLE, AUDIO_OSS));
552         add_item(new ADriverItem(this, AUDIO_OSS_ENVY24_TITLE, AUDIO_OSS_ENVY24));
554 #ifdef HAVE_ALSA
555         add_item(new ADriverItem(this, AUDIO_ALSA_TITLE, AUDIO_ALSA));
556 #endif
558         if(!do_input) add_item(new ADriverItem(this, AUDIO_ESOUND_TITLE, AUDIO_ESOUND));
559 //      add_item(new ADriverItem(this, AUDIO_NAS_TITLE, AUDIO_NAS));
560 //      if(do_input) 
561         add_item(new ADriverItem(this, AUDIO_1394_TITLE, AUDIO_1394));
564 char* ADriverMenu::adriver_to_string(int driver)
566         switch(driver)
567         {
568                 case AUDIO_OSS:
569                         sprintf(string, AUDIO_OSS_TITLE);
570                         break;
571                 case AUDIO_OSS_ENVY24:
572                         sprintf(string, AUDIO_OSS_ENVY24_TITLE);
573                         break;
574                 case AUDIO_ESOUND:
575                         sprintf(string, AUDIO_ESOUND_TITLE);
576                         break;
577                 case AUDIO_NAS:
578                         sprintf(string, AUDIO_NAS_TITLE);
579                         break;
580                 case AUDIO_ALSA:
581                         sprintf(string, AUDIO_ALSA_TITLE);
582                         break;
583                 case AUDIO_1394:
584                         sprintf(string, AUDIO_1394_TITLE);
585                         break;
586         }
587         return string;
590 ADriverItem::ADriverItem(ADriverMenu *popup, char *text, int driver)
591  : BC_MenuItem(text)
593         this->popup = popup;
594         this->driver = driver;
597 ADriverItem::~ADriverItem()
601 int ADriverItem::handle_event()
603         popup->set_text(get_text());
604         *(popup->output) = driver;
605         popup->device_prefs->initialize();
606         return 1;
612 OSSEnable::OSSEnable(int x, int y, int *output)
613  : BC_CheckBox(x, y, *output)
615         this->output = output;
617 int OSSEnable::handle_event()
619         *output = get_value();
620         return 1;
626 ADeviceTextBox::ADeviceTextBox(int x, int y, char *output)
627  : BC_TextBox(x, y, 150, 1, output)
629         this->output = output; 
632 int ADeviceTextBox::handle_event() 
634         strcpy(output, get_text());
635         return 1;
638 ADeviceIntBox::ADeviceIntBox(int x, int y, int *output)
639  : BC_TextBox(x, y, 80, 1, *output)
641         this->output = output;
644 int ADeviceIntBox::handle_event() 
646         *output = atol(get_text()); 
647         return 1;
650 ADeviceCheckBox::ADeviceCheckBox(int x, int y, int *output, char *text)
651  : BC_CheckBox(x, y, *output, text)
653    this->output = output;
655 int ADeviceCheckBox::handle_event()
657    *output = get_value();
658    return 1;
662 ALSADevice::ALSADevice(PreferencesDialog *dialog, 
663         int x, 
664         int y, 
665         char *output, 
666         ArrayList<BC_ListBoxItem*> *devices)
667  : BC_PopupTextBox(dialog,
668         devices,
669         output,
670         x, 
671         y, 
672         200,
673         200)
675         this->output = output;
678 ALSADevice::~ALSADevice()
682 int ALSADevice::handle_event()
684         strcpy(output, get_text());
685         return 1;