r954: Improve icons of the liveaudio and livevideo effects.
[cinelerra_cv.git] / cinelerra / adeviceprefs.C
blob3ba166a68c43b08d5f8f2e1638caed370e79b7c5
1 #include "adeviceprefs.h"
2 #include "audioalsa.h"
3 #include "audiodevice.inc"
4 #include "bitspopup.h"
5 #include "edl.h"
6 #include "language.h"
7 #include "playbackconfig.h"
8 #include "preferences.h"
9 #include "preferencesthread.h"
10 #include "recordconfig.h"
11 #include <string.h>
13 #define DEVICE_H 50
15 ADevicePrefs::ADevicePrefs(int x, 
16         int y, 
17         PreferencesWindow *pwindow, 
18         PreferencesDialog *dialog, 
19         AudioOutConfig *out_config, 
20         AudioInConfig *in_config, 
21         int mode)
23         reset();
24         this->pwindow = pwindow;
25         this->dialog = dialog;
26         this->driver = -1;
27         this->mode = mode;
28         this->out_config = out_config;
29         this->in_config = in_config;
30         this->x = x;
31         this->y = y;
34 ADevicePrefs::~ADevicePrefs()
36         delete_objects();
37         if(menu) delete menu;
40 void ADevicePrefs::reset()
42         menu = 0;
43         firewire_path = 0;
44         firewire_syt = 0;
45         syt_title = 0;
46         path_title = 0;
48         alsa_drivers = 0;
49         path_title = 0;
50         bits_title = 0;
51         alsa_device = 0;
52         alsa_bits = 0;
53         alsa_workaround = 0;
55         cine_bits = 0;
56         cine_path = 0;
59 int ADevicePrefs::initialize(int creation)
61         int *driver;
62         delete_objects();
64         switch(mode)
65         {
66                 case MODEPLAY:
67                         driver = &out_config->driver;
68                         break;
69                 case MODERECORD:
70                         driver = &in_config->driver;
71                         break;
72                 case MODEDUPLEX:
73                         driver = &out_config->driver;
74                         break;
75         }
76         this->driver = *driver;
78         if(!menu)
79         {
80                 dialog->add_subwindow(menu = new ADriverMenu(x, 
81                         y + 10, 
82                         this, 
83                         (mode == MODERECORD),
84                         driver));
85                 menu->create_objects();
86         }
88         switch(*driver)
89         {
90                 case AUDIO_OSS:
91                 case AUDIO_OSS_ENVY24:
92                         create_oss_objs();
93                         break;
94                 case AUDIO_ALSA:
95                         create_alsa_objs();
96                         break;
97                 case AUDIO_ESOUND:
98                         create_esound_objs();
99                         break;
100                 case AUDIO_1394:
101                 case AUDIO_DV1394:
102                 case AUDIO_IEC61883:
103                         create_firewire_objs();
104                         break;
105                 case AUDIO_CINE:
106                         create_cine_objs();
107                         break;
108         }
109         return 0;
112 int ADevicePrefs::get_h(int recording)
114         if(!recording)
115                 return DEVICE_H + 30;
116         else
117                 return DEVICE_H;
120 int ADevicePrefs::delete_objects()
122         switch(driver)
123         {
124                 case AUDIO_OSS:
125                 case AUDIO_OSS_ENVY24:
126                         delete_oss_objs();
127                         break;
128                 case AUDIO_ALSA:
129                         delete_alsa_objs();
130                         break;
131                 case AUDIO_ESOUND:
132                         delete_esound_objs();
133                         break;
134                 case AUDIO_1394:
135                 case AUDIO_DV1394:
136                 case AUDIO_IEC61883:
137                         delete_firewire_objs();
138                         break;
139         }
141         delete cine_bits;
142         delete cine_path;
144         reset();
145         driver = -1;
146         return 0;
149 int ADevicePrefs::delete_oss_objs()
151         delete path_title;
152         delete bits_title;
153         delete oss_bits;
154         for(int i = 0; i < MAXDEVICES; i++)
155         {
156                 delete oss_path[i];
157 break;
158         }
159         return 0;
162 int ADevicePrefs::delete_esound_objs()
164         delete server_title;
165         delete port_title;
166         delete esound_server;
167         delete esound_port;
168         return 0;
171 int ADevicePrefs::delete_firewire_objs()
173         delete port_title;
174         delete channel_title;
175         delete firewire_port;
176         delete firewire_channel;
177         if(firewire_path)
178         {
179                 delete path_title;
180                 delete firewire_path;
181         }
182         firewire_path = 0;
183         if(firewire_syt)
184         {
185                 delete firewire_syt;
186                 delete syt_title;
187         }
188         firewire_syt = 0;
189         return 0;
192 int ADevicePrefs::delete_alsa_objs()
194 #ifdef HAVE_ALSA
195         alsa_drivers->remove_all_objects();
196         delete alsa_drivers;
197         delete path_title;
198         delete bits_title;
199         delete alsa_device;
200         delete alsa_bits;
201         delete alsa_workaround;
202 #endif
203         return 0;
207 int ADevicePrefs::create_oss_objs()
209         char *output_char;
210         int *output_int;
211         int y1 = y;
212         BC_Resources *resources = BC_WindowBase::get_resources();
214         for(int i = 0; i < MAXDEVICES; i++)
215         {
216                 int x1 = x + menu->get_w() + 5;
217                 switch(mode)
218                 {
219                         case MODEPLAY: 
220 //                              output_int = &out_config->oss_enable[i];
221                                 break;
222                         case MODERECORD:
223 //                              output_int = &in_config->oss_enable[i];
224                                 break;
225                         case MODEDUPLEX:
226 //                              output_int = &out_config->oss_enable[i];
227                                 break;
228                 }
229 //              dialog->add_subwindow(oss_enable[i] = new OSSEnable(x1, y1 + 20, output_int));
230 //              x1 += oss_enable[i]->get_w() + 5;
231                 switch(mode)
232                 {
233                         case MODEPLAY: 
234                                 output_char = out_config->oss_out_device[i];
235                                 break;
236                         case MODERECORD:
237                                 output_char = in_config->oss_in_device[i];
238                                 break;
239                         case MODEDUPLEX:
240                                 output_char = out_config->oss_out_device[i];
241                                 break;
242                 }
243                 if(i == 0) dialog->add_subwindow(path_title = new BC_Title(x1, 
244                         y, 
245                         _("Device path:"), 
246                         MEDIUMFONT, 
247                         resources->text_default));
248                 dialog->add_subwindow(oss_path[i] = new ADeviceTextBox(x1, 
249                         y1 + 20, 
250                         output_char));
252                 x1 += oss_path[i]->get_w() + 5;
253                 if(i == 0)
254                 {
255                         switch(mode)
256                         {
257                                 case MODEPLAY: 
258                                         output_int = &out_config->oss_out_bits;
259                                         break;
260                                 case MODERECORD:
261                                         output_int = &in_config->oss_in_bits;
262                                         break;
263                                 case MODEDUPLEX:
264                                         output_int = &out_config->oss_out_bits;
265                                         break;
266                         }
267                         if(i == 0) dialog->add_subwindow(bits_title = new BC_Title(x1, y, _("Bits:"), MEDIUMFONT, resources->text_default));
268                         oss_bits = new BitsPopup(dialog, 
269                                 x1, 
270                                 y1 + 20, 
271                                 output_int, 
272                                 0, 
273                                 0, 
274                                 0,
275                                 0,
276                                 1);
277                         oss_bits->create_objects();
278                 }
280                 x1 += oss_bits->get_w() + 5;
281                 y1 += DEVICE_H;
282 break;
283         }
285         return 0;
288 int ADevicePrefs::create_alsa_objs()
290 #ifdef HAVE_ALSA
291         char *output_char;
292         int *output_int;
293         int y1 = y;
294         BC_Resources *resources = BC_WindowBase::get_resources();
296         int x1 = x + menu->get_w() + 5;
298         ArrayList<char*> *alsa_titles = new ArrayList<char*>;
299         AudioALSA::list_devices(alsa_titles, 0, mode);
301         alsa_drivers = new ArrayList<BC_ListBoxItem*>;
302         for(int i = 0; i < alsa_titles->total; i++)
303                 alsa_drivers->append(new BC_ListBoxItem(alsa_titles->values[i]));
304         alsa_titles->remove_all_objects();
305         delete alsa_titles;
307         switch(mode)
308         {
309                 case MODEPLAY: 
310                         output_char = out_config->alsa_out_device;
311                         break;
312                 case MODERECORD:
313                         output_char = in_config->alsa_in_device;
314                         break;
315                 case MODEDUPLEX:
316                         output_char = out_config->alsa_out_device;
317                         break;
318         }
319         dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device:"), MEDIUMFONT, resources->text_default));
320         alsa_device = new ALSADevice(dialog,
321                 x1, 
322                 y1 + 20, 
323                 output_char,
324                 alsa_drivers);
325         alsa_device->create_objects();
326         int x2 = x1;
328         x1 += alsa_device->get_w() + 5;
329         switch(mode)
330         {
331                 case MODEPLAY: 
332                         output_int = &out_config->alsa_out_bits;
333                         break;
334                 case MODERECORD:
335                         output_int = &in_config->alsa_in_bits;
336                         break;
337                 case MODEDUPLEX:
338                         output_int = &out_config->alsa_out_bits;
339                         break;
340         }
341         dialog->add_subwindow(bits_title = new BC_Title(x1, y, _("Bits:"), MEDIUMFONT, resources->text_default));
342         alsa_bits = new BitsPopup(dialog, 
343                 x1, 
344                 y1 + 20, 
345                 output_int, 
346                 0, 
347                 0, 
348                 0,
349                 0,
350                 1);
351         alsa_bits->create_objects();
353         y1 += alsa_bits->get_h() + 20 + 5;
354         x1 = x2;
356         if(mode == MODEPLAY)
357         {
358                 dialog->add_subwindow(alsa_workaround = 
359                         new BC_CheckBox(x1, 
360                                 y1, 
361                                 &out_config->interrupt_workaround,
362                                 _("Stop playback locks up.")));
363         }
366 #endif
368         return 0;
371 int ADevicePrefs::create_esound_objs()
373         int x1 = x + menu->get_w() + 5;
374         char *output_char;
375         int *output_int;
376         BC_Resources *resources = BC_WindowBase::get_resources();
378         switch(mode)
379         {
380                 case MODEPLAY: 
381                         output_char = out_config->esound_out_server;
382                         break;
383                 case MODERECORD:
384                         output_char = in_config->esound_in_server;
385                         break;
386                 case MODEDUPLEX:
387                         output_char = out_config->esound_out_server;
388                         break;
389         }
390         dialog->add_subwindow(server_title = new BC_Title(x1, y, _("Server:"), MEDIUMFONT, resources->text_default));
391         dialog->add_subwindow(esound_server = new ADeviceTextBox(x1, y + 20, output_char));
393         switch(mode)
394         {
395                 case MODEPLAY: 
396                         output_int = &out_config->esound_out_port;
397                         break;
398                 case MODERECORD:
399                         output_int = &in_config->esound_in_port;
400                         break;
401                 case MODEDUPLEX:
402                         output_int = &out_config->esound_out_port;
403                         break;
404         }
405         x1 += esound_server->get_w() + 5;
406         dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, resources->text_default));
407         dialog->add_subwindow(esound_port = new ADeviceIntBox(x1, y + 20, output_int));
408         return 0;
411 int ADevicePrefs::create_firewire_objs()
413         int x1 = x + menu->get_w() + 5;
414         int *output_int = 0;
415         char *output_char = 0;
416         BC_Resources *resources = BC_WindowBase::get_resources();
418 // Firewire path
419         switch(mode)
420         {
421                 case MODEPLAY:
422                         if(driver == AUDIO_DV1394)
423                                 output_char = out_config->dv1394_path;
424                         else
425                         if(driver == AUDIO_1394)
426                                 output_char = out_config->firewire_path;
427                         break;
428                 case MODERECORD:
429                         if(driver == AUDIO_DV1394 || driver == AUDIO_1394)
430                                 output_char = in_config->firewire_path;
431                         break;
432         }
434         if(output_char)
435         {
436                 dialog->add_subwindow(path_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, resources->text_default));
437                 dialog->add_subwindow(firewire_path = new ADeviceTextBox(x1, y + 20, output_char));
438                 x1 += firewire_path->get_w() + 5;
439         }
441 // Firewire port
442         switch(mode)
443         {
444                 case MODEPLAY: 
445                         if(driver == AUDIO_DV1394)
446                                 output_int = &out_config->dv1394_port;
447                         else
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, resources->text_default));
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                         if(driver == AUDIO_DV1394)
467                                 output_int = &out_config->dv1394_channel;
468                         else
469                                 output_int = &out_config->firewire_channel;
470                         break;
471                 case MODERECORD:
472                         output_int = &in_config->firewire_channel;
473                         break;
474         }
475         dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, resources->text_default));
476         dialog->add_subwindow(firewire_channel = new ADeviceIntBox(x1, y + 20, output_int));
477         x1 += firewire_channel->get_w() + 5;
479 // Syt offset
480         switch(mode)
481         {
482                 case MODEPLAY:
483                         if(driver == AUDIO_DV1394)
484                                 output_int = &out_config->dv1394_syt;
485                         else
486                         if(driver == AUDIO_1394)
487                                 output_int = &out_config->firewire_syt;
488                         else
489                                 output_int = 0;
490                         break;
491                 case MODERECORD:
492                         output_int = 0;
493                         break;
494         }
496         if(output_int)
497         {
498                 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, resources->text_default));
499                 dialog->add_subwindow(firewire_syt = new ADeviceIntBox(x1, y + 20, output_int));
500                 x1 += firewire_syt->get_w() + 5;
501         }
503         return 0;
508 int ADevicePrefs::create_cine_objs()
510         BC_Resources *resources = BC_WindowBase::get_resources();
511         int x1 = x + menu->get_w() + 5;
512         
517 ADriverMenu::ADriverMenu(int x, 
518         int y, 
519         ADevicePrefs *device_prefs, 
520         int do_input,
521         int *output)
522  : BC_PopupMenu(x, y, 125, adriver_to_string(*output), 1)
524         this->output = output;
525         this->do_input = do_input;
526         this->device_prefs = device_prefs;
529 ADriverMenu::~ADriverMenu()
533 void ADriverMenu::create_objects()
535         add_item(new ADriverItem(this, AUDIO_OSS_TITLE, AUDIO_OSS));
536         add_item(new ADriverItem(this, AUDIO_OSS_ENVY24_TITLE, AUDIO_OSS_ENVY24));
538 #ifdef HAVE_ALSA
539         add_item(new ADriverItem(this, AUDIO_ALSA_TITLE, AUDIO_ALSA));
540 #endif
542         if(!do_input) add_item(new ADriverItem(this, AUDIO_ESOUND_TITLE, AUDIO_ESOUND));
543 //      add_item(new ADriverItem(this, AUDIO_NAS_TITLE, AUDIO_NAS));
544 #ifdef HAVE_FIREWIRE
545         if(!do_input) add_item(new ADriverItem(this, AUDIO_1394_TITLE, AUDIO_1394));
546         add_item(new ADriverItem(this, AUDIO_DV1394_TITLE, AUDIO_DV1394));
547         add_item(new ADriverItem(this, AUDIO_IEC61883_TITLE, AUDIO_IEC61883));
548 #endif
549         add_item(new ADriverItem(this, AUDIO_DVB_TITLE, AUDIO_DVB));
552 char* ADriverMenu::adriver_to_string(int driver)
554         switch(driver)
555         {
556                 case AUDIO_OSS:
557                         sprintf(string, AUDIO_OSS_TITLE);
558                         break;
559                 case AUDIO_OSS_ENVY24:
560                         sprintf(string, AUDIO_OSS_ENVY24_TITLE);
561                         break;
562                 case AUDIO_ESOUND:
563                         sprintf(string, AUDIO_ESOUND_TITLE);
564                         break;
565                 case AUDIO_NAS:
566                         sprintf(string, AUDIO_NAS_TITLE);
567                         break;
568                 case AUDIO_ALSA:
569                         sprintf(string, AUDIO_ALSA_TITLE);
570                         break;
571 #ifdef HAVE_FIREWIRE
572                 case AUDIO_1394:
573                         sprintf(string, AUDIO_1394_TITLE);
574                         break;
575                 case AUDIO_DV1394:
576                         sprintf(string, AUDIO_DV1394_TITLE);
577                         break;
578                 case AUDIO_IEC61883:
579                         sprintf(string, AUDIO_IEC61883_TITLE);
580                         break;
581 #endif
582                 case AUDIO_DVB:
583                         sprintf(string, AUDIO_DVB_TITLE);
584                         break;
585         }
586         return string;
589 ADriverItem::ADriverItem(ADriverMenu *popup, char *text, int driver)
590  : BC_MenuItem(text)
592         this->popup = popup;
593         this->driver = driver;
596 ADriverItem::~ADriverItem()
600 int ADriverItem::handle_event()
602         popup->set_text(get_text());
603         *(popup->output) = driver;
604         popup->device_prefs->initialize();
605         return 1;
611 OSSEnable::OSSEnable(int x, int y, int *output)
612  : BC_CheckBox(x, y, *output)
614         this->output = output;
616 int OSSEnable::handle_event()
618         *output = get_value();
619         return 1;
625 ADeviceTextBox::ADeviceTextBox(int x, int y, char *output)
626  : BC_TextBox(x, y, 150, 1, output)
628         this->output = output; 
631 int ADeviceTextBox::handle_event() 
633         strcpy(output, get_text());
634         return 1;
637 ADeviceIntBox::ADeviceIntBox(int x, int y, int *output)
638  : BC_TextBox(x, y, 80, 1, *output)
640         this->output = output;
643 int ADeviceIntBox::handle_event() 
645         *output = atol(get_text()); 
646         return 1;
650 ALSADevice::ALSADevice(PreferencesDialog *dialog, 
651         int x, 
652         int y, 
653         char *output, 
654         ArrayList<BC_ListBoxItem*> *devices)
655  : BC_PopupTextBox(dialog,
656         devices,
657         output,
658         x, 
659         y, 
660         200,
661         200)
663         this->output = output;
666 ALSADevice::~ALSADevice()
670 int ALSADevice::handle_event()
672         strcpy(output, get_text());
673         return 1;