rework keyframe hide popup, keyframe auto render, textbox set_selection wide text
[goodguy/history.git] / cinelerra-5.1 / cinelerra / channelpicker.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "batch.h"
23 #include "bcsignals.h"
24 #include "channel.h"
25 #include "channeldb.h"
26 #include "channeledit.h"
27 #include "channelpicker.h"
28 #include "chantables.h"
29 #include "clip.h"
30 #include "edl.h"
31 #include "edlsession.h"
32 #include "keys.h"
33 #include "language.h"
34 #include "mwindow.h"
35 #include "picture.h"
36 #include "playbackconfig.h"
37 #include "preferencesthread.h"
38 #include "record.h"
39 #include "recordgui.h"
40 #include "recordmonitor.h"
41 #include "theme.h"
42 #include "vdevicebuz.h"
43 #include "vdeviceprefs.h"
44 #include "videodevice.h"
45
46 RecordChannelPicker::RecordChannelPicker(MWindow *mwindow,
47         Record *record,
48         RecordMonitor *record_monitor,
49         BC_WindowBase *parent_window,
50         ChannelDB *channeldb,
51         int x,
52         int y)
53  : ChannelPicker(mwindow,
54                 channeldb,
55                 x,
56                 y,
57                 parent_window)
58 {
59         this->record = record;
60         this->record_monitor = record_monitor;
61 }
62
63 RecordChannelPicker::~RecordChannelPicker()
64 {
65 }
66
67 int RecordChannelPicker::use_select()
68 {
69         return 1;
70 }
71
72 Channel* RecordChannelPicker::get_master_channel()
73 {
74         return record->master_channel;
75 }
76
77 void RecordChannelPicker::handle_channel_edit(int result)
78 {
79         if(!result)
80         {
81                 record->record_gui->lock_window("RecordChannelPicker::handle_channel_edit 1");
82                 record->record_gui->update_batch_sources();
83                 record->set_channel(get_master_channel());
84                 record->record_gui->unlock_window();
85                 record->save_defaults();
86                 VideoDevice::save_channeldb(record->channeldb,
87                         mwindow->edl->session->vconfig_in);
88         }
89         else
90         {
91                 record->record_gui->lock_window("RecordChannelPicker::handle_channel_edit 2");
92                 record->set_channel(record->get_current_channel());
93                 record->record_gui->unlock_window();
94         }
95
96         mwindow->save_defaults();
97 }
98
99 void RecordChannelPicker::load_scan_defaults(Channel *scan_params)
100 {
101         scan_params->load_defaults(mwindow->defaults);
102 }
103
104 void RecordChannelPicker::save_scan_defaults(Channel *scan_params)
105 {
106         scan_params->save_defaults(mwindow->defaults);
107 }
108
109 BC_Theme* RecordChannelPicker::get_theme()
110 {
111         return mwindow->theme;
112 }
113
114
115 Channel* RecordChannelPicker::get_current_channel()
116 {
117         return record->get_current_channel();
118 }
119
120 Channel *RecordChannelPicker::get_editing_channel()
121 {
122         return record->get_editing_channel();
123 }
124
125 ArrayList<Channel*>* RecordChannelPicker::get_video_inputs()
126 {
127         return record->get_video_inputs();
128 }
129
130 Channel* RecordChannelPicker::get_channel_usage()
131 {
132         return record->master_channel;
133 }
134
135 void RecordChannelPicker::set_channel_number(int number)
136 {
137         if( number < 0 || number >= channeldb->size() ) return;
138         Channel *channel = channeldb->get(number);
139         if( channel ) record->set_channel(channel);
140 }
141
142 void RecordChannelPicker::set_brightness(int value)
143 {
144         if(record)
145         {
146                 record->picture->brightness = value;
147                 record->set_video_picture();
148         }
149 }
150
151 void RecordChannelPicker::set_hue(int value)
152 {
153         if(record)
154         {
155                 record->picture->hue = value;
156                 record->set_video_picture();
157         }
158 }
159
160 void RecordChannelPicker::set_color(int value)
161 {
162         if(record)
163         {
164                 record->picture->color = value;
165                 record->set_video_picture();
166         }
167 }
168
169 void RecordChannelPicker::set_contrast(int value)
170 {
171         if(record)
172         {
173                 record->picture->contrast = value;
174                 record->set_video_picture();
175         }
176 }
177
178 void RecordChannelPicker::set_whiteness(int value)
179 {
180         if(record)
181         {
182                 record->picture->whiteness = value;
183                 record->set_video_picture();
184         }
185 }
186
187 int RecordChannelPicker::set_picture(int device_id, int value)
188 {
189         if(record)
190         {
191                 if(record->picture->set_item(device_id, value))
192                         record->set_video_picture();
193         }
194         return 0;
195 }
196
197
198 int RecordChannelPicker::get_brightness()
199 {
200         if(record) return record->picture->brightness;
201         return 0;
202 }
203
204 int RecordChannelPicker::get_hue()
205 {
206         if(record) return record->picture->hue;
207         return 0;
208 }
209
210 int RecordChannelPicker::get_color()
211 {
212         if(record) return record->picture->color;
213         return 0;
214 }
215
216 int RecordChannelPicker::get_contrast()
217 {
218         if(record) return record->picture->contrast;
219         return 0;
220 }
221
222 int RecordChannelPicker::get_whiteness()
223 {
224         if(record) return record->picture->whiteness;
225         return 0;
226 }
227
228 int RecordChannelPicker::get_controls()
229 {
230         if(record) return record->picture->controls.total;
231         return 0;
232 }
233
234 PictureItem* RecordChannelPicker::get_control(int i)
235 {
236         if(record) return record->picture->controls.values[i];
237         return 0;
238 }
239
240 PictureConfig* RecordChannelPicker::get_picture_usage()
241 {
242         if(record) return record->picture;
243         return 0;
244 }
245
246
247
248 void RecordChannelPicker::set_channel(Channel *channel)
249 {
250         record->set_channel(channel);
251 }
252
253 int RecordChannelPicker::has_signal()
254 {
255         return record->has_signal();
256 }
257
258 int RecordChannelPicker::create_channeldb(ArrayList<Channel*> *channeldb)
259 {
260         return record->create_channeldb(channeldb);
261 }
262
263
264
265
266
267
268
269
270
271 PrefsChannelPicker::PrefsChannelPicker(MWindow *mwindow,
272                 VDevicePrefs *prefs,
273                 ChannelDB *channeldb,
274                 int x,
275                 int y)
276  : ChannelPicker(mwindow,
277                 channeldb,
278                 x,
279                 y,
280                 prefs->dialog)
281 {
282 //      printf("PrefsChannelPicker::PrefsChannelPicker 1\n");
283         this->prefs = prefs;
284
285 #ifdef HAVE_VIDEO4LINUX
286         VDeviceBUZ::get_inputs(&input_sources);
287 #endif
288
289 }
290
291 PrefsChannelPicker::~PrefsChannelPicker()
292 {
293         input_sources.remove_all_objects();
294 }
295
296 void PrefsChannelPicker::load_scan_defaults(Channel *scan_params)
297 {
298         scan_params->load_defaults(mwindow->defaults);
299 }
300
301 void PrefsChannelPicker::save_scan_defaults(Channel *scan_params)
302 {
303         scan_params->save_defaults(mwindow->defaults);
304 }
305
306 void PrefsChannelPicker::handle_channel_edit(int result)
307 {
308         mwindow->save_defaults();
309 }
310
311 BC_Theme* PrefsChannelPicker::get_theme()
312 {
313         return mwindow->theme;
314 }
315
316
317 ArrayList<Channel*>* PrefsChannelPicker::get_video_inputs()
318 {
319         return &input_sources;
320 }
321
322 Channel* PrefsChannelPicker::get_channel_usage()
323 {
324         return 0;
325 }
326
327
328 void PrefsChannelPicker::set_channel(Channel *channel)
329 {
330         if(channel)
331                 channel_text->update(channel->title);
332 }
333
334 Channel *PrefsChannelPicker::get_current_channel()
335 {
336         int number = prefs->out_config->buz_out_channel;
337         return channeldb->get(number);
338 }
339
340 void PrefsChannelPicker::set_channel_number(int number)
341 {
342         CLAMP(number, 0, channeldb->size() - 1);
343         prefs->out_config->buz_out_channel = number;
344         set_channel(get_current_channel());
345 }
346
347 int PrefsChannelPicker::has_signal()
348 {
349         return 0;
350 }
351
352 void PrefsChannelPicker::set_brightness(int value)
353 {
354         prefs->out_config->brightness = value;
355 }
356
357 void PrefsChannelPicker::set_hue(int value)
358 {
359         prefs->out_config->hue = value;
360 }
361
362 void PrefsChannelPicker::set_color(int value)
363 {
364         prefs->out_config->color = value;
365 }
366
367 void PrefsChannelPicker::set_contrast(int value)
368 {
369         prefs->out_config->contrast = value;
370 }
371
372 void PrefsChannelPicker::set_whiteness(int value)
373 {
374         prefs->out_config->whiteness = value;
375 }
376
377 int PrefsChannelPicker::get_brightness()
378 {
379         return prefs->out_config->brightness;
380 }
381
382 int PrefsChannelPicker::get_hue()
383 {
384         return prefs->out_config->hue;
385 }
386
387 int PrefsChannelPicker::get_color()
388 {
389         return prefs->out_config->color;
390 }
391
392 int PrefsChannelPicker::get_contrast()
393 {
394         return prefs->out_config->contrast;
395 }
396
397 int PrefsChannelPicker::get_whiteness()
398 {
399         return prefs->out_config->whiteness;
400 }
401
402
403
404
405
406
407 ChannelPicker::ChannelPicker(MWindow *mwindow,
408                 ChannelDB *channeldb,
409                 int x,
410                 int y,
411                 BC_WindowBase *parent_window)
412 {
413         this->mwindow = mwindow;
414         this->parent_window = parent_window;
415         this->x = x;
416         this->y = y;
417         this->channeldb = channeldb;
418         channel_text = 0;
419         channel_select = 0;
420         channel_button = 0;
421         update_channel_list();
422 }
423
424 ChannelPicker::~ChannelPicker()
425 {
426         delete channel_text;
427         delete channel_select;
428         delete channel_button;
429         channel_listitems.remove_all_objects();
430 }
431
432 void ChannelPicker::update_channel_list()
433 {
434         channel_listitems.remove_all_objects();
435         for(int i = 0; i < channeldb->size(); i++)
436         {
437                 channel_listitems.append(new BC_ListBoxItem(channeldb->get(i)->title));
438         }
439
440         if(channel_text)
441                 channel_text->update_list(&channel_listitems);
442 }
443
444 int ChannelPicker::get_w()
445 {
446         return channel_text->get_w() +
447                 channel_select->get_w() +
448                 channel_button->get_w() +
449                 picture_button->get_w() +
450                 ((Theme*)get_theme())->widget_border * 4;
451 }
452
453
454
455
456
457
458 BC_WindowBase* ChannelPicker::get_subwindow()
459 {
460         return parent_window;
461         return 0;
462 }
463
464
465
466
467
468
469
470 void ChannelPicker::create_objects()
471 {
472         channel_text = 0;
473         update_channel_list();
474
475
476         channel_text = new ChannelText(this, x, y);
477         channel_text->create_objects();
478
479
480         x += channel_text->get_w() + ((Theme*)get_theme())->widget_border;
481         get_subwindow()->add_subwindow(channel_select = new ChannelTumbler(this,
482                 x,
483                 y));
484
485
486         x += channel_select->get_w() + ((Theme*)get_theme())->widget_border;
487         get_subwindow()->add_subwindow(channel_button = new ChannelButton(this,
488                 x,
489                 y - 1));
490
491 //PRINT_TRACE
492         x += channel_button->get_w() + ((Theme*)get_theme())->widget_border;
493         get_subwindow()->add_subwindow(picture_button = new PictureButton(this,
494                 x,
495                 y - 1));
496 //PRINT_TRACE
497
498 }
499
500 int ChannelPicker::reposition()
501 {
502         channel_text->reposition_window(channel_text->get_x(),
503                 channel_text->get_y());
504         channel_select->reposition_window(channel_select->get_x(),
505                 channel_select->get_y());
506         channel_button->reposition_window(channel_button->get_x(),
507                 channel_button->get_y());
508         return 0;
509 }
510
511 void ChannelPicker::close_threads()
512 {
513         channel_button->thread->close_threads();
514 }
515
516 const char* ChannelPicker::get_source_name(Channel *channel)
517 {
518         if(channel->entry < chanlists[channel->freqtable].count)
519                 return chanlists[channel->freqtable].list[channel->entry].name;
520         else
521                 return chanlists[channel->freqtable].list[0].name;
522 }
523
524 const char* ChannelPicker::current_channel_name()
525 {
526         if(get_current_channel())
527                 return get_current_channel()->title;
528         return _("Channel");
529 }
530
531 int ChannelPicker::channel_down()
532 {
533         Channel *channel = get_current_channel();
534         if( !channel ) return 1;
535         int number = channeldb->number_of(channel);
536         if( number < 0 ) return 1;
537         if( --number < 0 ) number = 0;
538         set_channel_number(number);
539         return 0;
540 }
541
542 int ChannelPicker::channel_up()
543 {
544         Channel *channel = get_current_channel();
545         if( !channel ) return 1;
546         int number = channeldb->number_of(channel);
547         if( number < 0 ) return 1;
548         if( ++number >= channeldb->size() ) number = channeldb->size()-1;
549         set_channel_number(number);
550         return 0;
551 }
552
553
554
555
556
557 PictureButton::PictureButton(ChannelPicker *channel_picker, int x, int y)
558  : BC_Button(x,
559         y,
560         channel_picker->get_theme() ?
561                 channel_picker->get_theme()->get_image_set("picture") :
562                 0)
563 {
564         this->channel_picker = channel_picker;
565         thread = new ChannelEditPictureThread(channel_picker);
566         set_tooltip(_("Edit picture"));
567 }
568
569 PictureButton::~PictureButton()
570 {
571 //printf("PictureButton::PictureButton %d\n", __LINE__);
572         delete thread;
573 //printf("PictureButton::PictureButton %d\n", __LINE__);
574 }
575
576 int PictureButton::handle_event()
577 {
578         unlock_window();
579         thread->edit_picture();
580         lock_window("PictureButton::handle_event");
581         return 1;
582 }
583
584
585
586
587 ChannelButton::ChannelButton(ChannelPicker *channel_picker, int x, int y)
588  : BC_Button(x, y, channel_picker->get_theme() ?
589                 channel_picker->get_theme()->get_image_set("channel") :
590                 0)
591 {
592         this->channel_picker = channel_picker;
593         thread = new ChannelEditThread(channel_picker,
594                 channel_picker->channeldb);
595         set_tooltip(_("Edit channels"));
596 }
597
598 ChannelButton::~ChannelButton()
599 {
600         delete thread;
601 }
602
603 int ChannelButton::handle_event()
604 {
605         thread->start();
606         return 1;
607 }
608
609
610 ChannelText::ChannelText(ChannelPicker *channel_picker, int x, int y)
611  : BC_PopupTextBox(channel_picker->get_subwindow(),
612         &channel_picker->channel_listitems,
613         channel_picker->current_channel_name(),
614         x, y, 200, 300)
615 {
616
617         this->channel_picker = channel_picker;
618 }
619
620 ChannelText::~ChannelText()
621 {
622 }
623
624 int ChannelText::handle_event()
625 {
626         channel_picker->set_channel_number(get_number());
627         return 0;
628 }
629
630
631
632
633 ChannelList::ChannelList(ChannelPicker *channel_picker, int x, int y)
634  : BC_ListBox(x, y, 100, 200,
635         LISTBOX_TEXT,  // Display text list or icons
636         &channel_picker->channel_listitems, // Each column has an ArrayList of BC_ListBoxItems.
637         0,    // Titles for columns.  Set to 0 for no titles
638         0,    // width of each column
639         1,    // Total columns.
640         0,    // Pixel of top of window.
641         1)    // If this listbox is a popup window
642 {
643         this->channel_picker = channel_picker;
644 }
645
646 ChannelList::~ChannelList()
647 {
648 }
649
650 int ChannelList::handle_event()
651 {
652         return 0;
653 }
654
655
656
657 ChannelTumbler::ChannelTumbler(ChannelPicker *channel_picker,
658         int x,
659         int y)
660  : BC_Tumbler(x, y)
661 {
662         this->channel_picker = channel_picker;
663 }
664 ChannelTumbler::~ChannelTumbler()
665 {
666 }
667 int ChannelTumbler::handle_up_event()
668 {
669         channel_picker->channel_up();
670         return 1;
671 }
672 int ChannelTumbler::handle_down_event()
673 {
674         channel_picker->channel_down();
675         return 1;
676 }
677 int ChannelTumbler::keypress_event()
678 {
679         if(get_keypress() == PGUP)
680         {
681                 handle_up_event();
682                 return 1;
683         }
684         else
685         if(get_keypress() == PGDN)
686         {
687                 handle_down_event();
688                 return 1;
689         }
690         else
691         return 0;
692 }
693
694