r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / vdeviceprefs.C
blobdf520eda1d95571d43360ad6a8eb80afa624fd96
1 #include "channelpicker.h"
2 #include "edl.h"
3 #include "edlsession.h"
4 #include "mwindow.h"
5 #include "vdeviceprefs.h"
6 #include "videoconfig.h"
7 #include "videodevice.inc"
8 #include "playbackconfig.h"
9 #include "preferences.h"
10 #include "preferencesthread.h"
11 #include "recordconfig.h"
12 #include <string.h>
14 #include <libintl.h>
15 #define _(String) gettext(String)
16 #define gettext_noop(String) String
17 #define N_(String) gettext_noop (String)
19 VDevicePrefs::VDevicePrefs(int x, 
20         int y, 
21         PreferencesWindow *pwindow, 
22         PreferencesDialog *dialog, 
23         VideoOutConfig *out_config,
24         VideoInConfig *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_path = 0;
37         firewire_syt = 0;
40 VDevicePrefs::~VDevicePrefs()
42         delete_objects();
43         if(menu) delete menu;
49 int VDevicePrefs::initialize()
51         int *driver = 0;
52         delete_objects();
54         switch(mode)
55         {
56                 case MODEPLAY:
57                         driver = &out_config->driver;
58                         break;
59                 
60                 case MODERECORD:
61                         driver = &in_config->driver;
62                         break;
63         }
64         this->driver = *driver;
66         if(!menu)
67         {
68                 dialog->add_subwindow(menu = new VDriverMenu(x,
69                         y + 10,
70                         this, 
71                         (mode == MODERECORD), 
72                         driver));
73                 menu->create_objects();
74         }
76         switch(this->driver)
77         {
78                 case VIDEO4LINUX:
79                         create_v4l_objs();
80                         break;
81                 case SCREENCAPTURE:
82                         create_screencap_objs();
83                         break;
84                 case CAPTURE_LML:
85                         create_lml_objs();
86                         break;
87                 case CAPTURE_BUZ:
88                 case PLAYBACK_BUZ:
89                         create_buz_objs();
90                         break;
91                 case PLAYBACK_X11:
92                 case PLAYBACK_X11_XV:
93                         create_x11_objs();
94                         break;
95                 case PLAYBACK_FIREWIRE:
96                 case CAPTURE_FIREWIRE:
97                         create_firewire_objs();
98                         break;
99         }
100         return 0;
103 int VDevicePrefs::delete_objects()
105         switch(driver)
106         {
107                 case PLAYBACK_X11:
108                 case PLAYBACK_X11_XV:
109                         delete device_title;
110                         delete device_text;
111                         break;
112                 case PLAYBACK_LML:
113                 case PLAYBACK_BUZ:
114                         delete device_title;
115                         delete device_text;
116                         delete output_title;
117                         delete channel_picker;
118                         delete buz_swap_channels;
119                         break;
120                 case VIDEO4LINUX:
121                 case SCREENCAPTURE:
122                 case CAPTURE_LML:
123                 case CAPTURE_BUZ:
124                         delete device_title;
125                         delete device_text;
126                         break;
127                 case PLAYBACK_FIREWIRE:
128                 case CAPTURE_FIREWIRE:
129                         delete port_title;
130                         delete firewire_port;
131                         delete channel_title;
132                         delete firewire_channel;
133                         if(firewire_path)
134                         {
135                                 delete device_title;
136                                 delete firewire_path;
137                         }
138                         firewire_path = 0;
139                         if(firewire_syt)
140                         {
141                                 delete firewire_syt;
142                                 delete syt_title;
143                         }
144                         delete firewire_use_dv1394;
145                         firewire_use_dv1394 = 0;
146                         firewire_syt = 0;
147                         break;
148         }
150         driver = -1;
151         return 0;
154 int VDevicePrefs::create_lml_objs()
156         char *output_char;
157         int x1 = x + menu->get_w() + 5;
159         switch(mode)
160         {
161                 case MODEPLAY: 
162                         output_char = out_config->lml_out_device;
163                         break;
164                 case MODERECORD:
165                         output_char = in_config->lml_in_device;
166                         break;
167         }
168         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, BLACK));
169         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
170         return 0;
173 int VDevicePrefs::create_buz_objs()
175         char *output_char;
176         int x1 = x + menu->get_w() + 5;
177         int x2 = x1 + 210;
178         int y1 = y;
180         switch(mode)
181         {
182                 case MODEPLAY: 
183                         output_char = out_config->buz_out_device;
184                         break;
185                 case MODERECORD:
186                         output_char = in_config->buz_in_device;
187                         break;
188         }
189         dialog->add_subwindow(device_title = new BC_Title(x1, y1, _("Device path:"), MEDIUMFONT, BLACK));
191         y1 += 20;
192         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y1, output_char));
194         if(driver == PLAYBACK_BUZ)
195         {
196                 dialog->add_subwindow(buz_swap_channels = 
197                         new VDeviceCheckBox(x2, y1, &out_config->buz_swap_fields, _("Swap fields")));
198         }
199         y1 += 30;
200         if(driver == PLAYBACK_BUZ)
201         {
202                 dialog->add_subwindow(output_title = new BC_Title(x1, y1, _("Output channel:")));
203                 y1 += 20;
204                 channel_picker = new PrefsChannelPicker(pwindow->mwindow, 
205                         this, 
206                         &pwindow->mwindow->channeldb_buz, 
207                         x1,
208                         y1);
209                 channel_picker->create_objects();
210         }
211         return 0;
214 int VDevicePrefs::create_firewire_objs()
216         int *output_int;
217         char *output_char;
218         int x1 = x + menu->get_w() + 5;
220 // Firewire path
221         switch(mode)
222         {
223                 case MODEPLAY:
224                         output_char = out_config->firewire_path;
225                         break;
226                 case MODERECORD:
227 // Our version of raw1394 doesn't support changing the input path
228                         output_char = 0;
229                         break;
230         }
232         if(output_char)
233         {
234                 dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device Path:"), MEDIUMFONT, BLACK));
235                 dialog->add_subwindow(firewire_path = new VDeviceTextBox(x1, y + 20, output_char));
236                 x1 += firewire_path->get_w() + 5;
237         }
239 // Firewire port
240         switch(mode)
241         {
242                 case MODEPLAY:
243                         output_int = &out_config->firewire_port;
244                         break;
245                 case MODERECORD:
246                         output_int = &in_config->firewire_port;
247                         break;
248         }
249         dialog->add_subwindow(port_title = new BC_Title(x1, y, _("Port:"), MEDIUMFONT, BLACK));
250         dialog->add_subwindow(firewire_port = new VDeviceIntBox(x1, y + 20, output_int));
251         x1 += firewire_port->get_w() + 5;
253 // Firewire channel
254         switch(mode)
255         {
256                 case MODEPLAY:
257                         output_int = &out_config->firewire_channel;
258                         break;
259                 case MODERECORD:
260                         output_int = &in_config->firewire_channel;
261                         break;
262         }
264         dialog->add_subwindow(channel_title = new BC_Title(x1, y, _("Channel:"), MEDIUMFONT, BLACK));
265         dialog->add_subwindow(firewire_channel = new VDeviceIntBox(x1, y + 20, output_int));
266         x1 += firewire_channel->get_w() + 5;
269 // Firewire syt
270         switch(mode)
271         {
272                 case MODEPLAY:
273                         output_int = &out_config->firewire_syt;
274                         break;
275                 case MODERECORD:
276                         output_int = 0;
277                         break;
278         }
279         if(output_int)
280         {
281                 dialog->add_subwindow(syt_title = new BC_Title(x1, y, _("Syt Offset:"), MEDIUMFONT, BLACK));
282                 dialog->add_subwindow(firewire_syt = new VDeviceIntBox(x1, y + 20, output_int));
283         }
284         x1 = x + menu->get_w() + 5;
286         switch(mode)
287         {
288                 case MODEPLAY:
289                         output_int = &out_config->firewire_use_dv1394;
290                         break;
291                 case MODERECORD:
292                         //output_int = &in_config->firewire_use_dv1394;
293                         output_int = 0;
294                         break;
295         }
297         if(output_int)
298         {
299                 dialog->add_subwindow(firewire_use_dv1394 =
300               new VDeviceCheckBox(x1, y + 45, output_int, _("Use DV1394")));
301         }
303         return 0;
306 int VDevicePrefs::create_v4l_objs()
308         char *output_char;
309         int x1 = x + menu->get_w() + 5;
310         output_char = pwindow->thread->edl->session->vconfig_in->v4l_in_device;
311         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Device path:"), MEDIUMFONT, BLACK));
312         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
313         return 0;
316 int VDevicePrefs::create_screencap_objs()
318         char *output_char;
319         int x1 = x + menu->get_w() + 5;
320         output_char = pwindow->thread->edl->session->vconfig_in->screencapture_display;
321         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Display:"), MEDIUMFONT, BLACK));
322         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
323         return 0;
326 int VDevicePrefs::create_x11_objs()
328         char *output_char;
329         int x1 = x + menu->get_w() + 5;
330         output_char = out_config->x11_host;
331         dialog->add_subwindow(device_title = new BC_Title(x1, y, _("Display for compositor:"), MEDIUMFONT, BLACK));
332         dialog->add_subwindow(device_text = new VDeviceTextBox(x1, y + 20, output_char));
333         return 0;
339 VDriverMenu::VDriverMenu(int x, 
340         int y, 
341         VDevicePrefs *device_prefs, 
342         int do_input, 
343         int *output)
344  : BC_PopupMenu(x, y, 150, driver_to_string(*output))
346         this->output = output;
347         this->do_input = do_input;
348         this->device_prefs = device_prefs;
351 VDriverMenu::~VDriverMenu()
355 char* VDriverMenu::driver_to_string(int driver)
357         switch(driver)
358         {
359                 case VIDEO4LINUX:
360                         sprintf(string, VIDEO4LINUX_TITLE);
361                         break;
362                 case SCREENCAPTURE:
363                         sprintf(string, SCREENCAPTURE_TITLE);
364                         break;
365                 case CAPTURE_BUZ:
366                         sprintf(string, CAPTURE_BUZ_TITLE);
367                         break;
368                 case CAPTURE_LML:
369                         sprintf(string, CAPTURE_LML_TITLE);
370                         break;
371                 case CAPTURE_FIREWIRE:
372                         sprintf(string, CAPTURE_FIREWIRE_TITLE);
373                         break;
374                 case PLAYBACK_X11:
375                         sprintf(string, PLAYBACK_X11_TITLE);
376                         break;
377                 case PLAYBACK_X11_XV:
378                         sprintf(string, PLAYBACK_X11_XV_TITLE);
379                         break;
380                 case PLAYBACK_LML:
381                         sprintf(string, PLAYBACK_LML_TITLE);
382                         break;
383                 case PLAYBACK_BUZ:
384                         sprintf(string, PLAYBACK_BUZ_TITLE);
385                         break;
386                 case PLAYBACK_FIREWIRE:
387                         sprintf(string, PLAYBACK_FIREWIRE_TITLE);
388                         break;
389                 default:
390                         sprintf(string, "");
391         }
392         return string;
395 int VDriverMenu::create_objects()
397         if(do_input)
398         {
399                 add_item(new VDriverItem(this, VIDEO4LINUX_TITLE, VIDEO4LINUX));
400                 add_item(new VDriverItem(this, SCREENCAPTURE_TITLE, SCREENCAPTURE));
401                 add_item(new VDriverItem(this, CAPTURE_BUZ_TITLE, CAPTURE_BUZ));
402                 add_item(new VDriverItem(this, CAPTURE_FIREWIRE_TITLE, CAPTURE_FIREWIRE));
403         }
404         else
405         {
406                 add_item(new VDriverItem(this, PLAYBACK_X11_TITLE, PLAYBACK_X11));
407                 add_item(new VDriverItem(this, PLAYBACK_X11_XV_TITLE, PLAYBACK_X11_XV));
408                 add_item(new VDriverItem(this, PLAYBACK_BUZ_TITLE, PLAYBACK_BUZ));
409                 add_item(new VDriverItem(this, PLAYBACK_FIREWIRE_TITLE, PLAYBACK_FIREWIRE));
410         }
411         return 0;
415 VDriverItem::VDriverItem(VDriverMenu *popup, char *text, int driver)
416  : BC_MenuItem(text)
418         this->popup = popup;
419         this->driver = driver;
422 VDriverItem::~VDriverItem()
426 int VDriverItem::handle_event()
428         popup->set_text(get_text());
429         *(popup->output) = driver;
430         popup->device_prefs->initialize();
431         return 1;
437 VDeviceTextBox::VDeviceTextBox(int x, int y, char *output)
438  : BC_TextBox(x, y, 200, 1, output)
440         this->output = output; 
443 int VDeviceTextBox::handle_event() 
445         strcpy(output, get_text()); 
448 VDeviceIntBox::VDeviceIntBox(int x, int y, int *output)
449  : BC_TextBox(x, y, 60, 1, *output)
451         this->output = output; 
454 int VDeviceIntBox::handle_event() 
456         *output = atol(get_text()); 
457         return 1;
462 VDeviceCheckBox::VDeviceCheckBox(int x, int y, int *output, char *text)
463  : BC_CheckBox(x, y, *output, text)
465         this->output = output;
467 int VDeviceCheckBox::handle_event()
469         *output = get_value();
470         return 1;