initial commit
[goodguy/history.git] / cinelerra-5.0 / 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 int RecordChannelPicker::set_brightness(int value)
143 {
144         if(record)
145         {
146                 record->picture->brightness = value;
147                 record->set_video_picture();
148         }
149         return 0;
150 }
151
152 int RecordChannelPicker::set_hue(int value)
153 {
154         if(record)
155         {
156                 record->picture->hue = value;
157                 record->set_video_picture();
158         }
159         return 0;
160 }
161
162 int RecordChannelPicker::set_color(int value)
163 {
164         if(record)
165         {
166                 record->picture->color = value;
167                 record->set_video_picture();
168         }
169         return 0;
170 }
171
172 int RecordChannelPicker::set_contrast(int value)
173 {
174         if(record)
175         {
176                 record->picture->contrast = value;
177                 record->set_video_picture();
178         }
179         return 0;
180 }
181
182 int RecordChannelPicker::set_whiteness(int value)
183 {
184         if(record)
185         {
186                 record->picture->whiteness = value;
187                 record->set_video_picture();
188         }
189         return 0;
190 }
191
192 int RecordChannelPicker::set_picture(int device_id, int value)
193 {
194         if(record) 
195         {
196                 if(record->picture->set_item(device_id, value))
197                         record->set_video_picture();
198         }
199         return 0;
200 }
201
202
203 int RecordChannelPicker::get_brightness()
204 {
205         if(record) return record->picture->brightness;
206         return 0;
207 }
208
209 int RecordChannelPicker::get_hue()
210 {
211         if(record) return record->picture->hue;
212         return 0;
213 }
214
215 int RecordChannelPicker::get_color()
216 {
217         if(record) return record->picture->color;
218         return 0;
219 }
220
221 int RecordChannelPicker::get_contrast()
222 {
223         if(record) return record->picture->contrast;
224         return 0;
225 }
226
227 int RecordChannelPicker::get_whiteness()
228 {
229         if(record) return record->picture->whiteness;
230         return 0;
231 }
232
233 int RecordChannelPicker::get_controls()
234 {
235         if(record) return record->picture->controls.total;
236         return 0;
237 }
238
239 PictureItem* RecordChannelPicker::get_control(int i)
240 {
241         if(record) return record->picture->controls.values[i];
242         return 0;
243 }
244
245 PictureConfig* RecordChannelPicker::get_picture_usage()
246 {
247         if(record) return record->picture;
248         return 0;
249 }
250
251
252
253 void RecordChannelPicker::set_channel(Channel *channel)
254 {
255         record->set_channel(channel);
256 }
257
258 int RecordChannelPicker::has_signal()
259 {
260         return record->has_signal();
261 }
262
263 int RecordChannelPicker::create_channeldb(ArrayList<Channel*> *channeldb)
264 {
265         return record->create_channeldb(channeldb);
266 }
267
268
269
270
271
272
273
274
275
276 PrefsChannelPicker::PrefsChannelPicker(MWindow *mwindow, 
277                 VDevicePrefs *prefs, 
278                 ChannelDB *channeldb, 
279                 int x,
280                 int y)
281  : ChannelPicker(mwindow,
282                 channeldb, 
283                 x,
284                 y,
285                 prefs->dialog)
286 {
287 //      printf("PrefsChannelPicker::PrefsChannelPicker 1\n");
288         this->prefs = prefs;
289
290 #ifdef HAVE_VIDEO4LINUX
291         VDeviceBUZ::get_inputs(&input_sources);
292 #endif
293
294 }
295
296 PrefsChannelPicker::~PrefsChannelPicker()
297 {
298         input_sources.remove_all_objects();
299 }
300
301 void PrefsChannelPicker::load_scan_defaults(Channel *scan_params)
302 {
303         scan_params->load_defaults(mwindow->defaults);
304 }
305
306 void PrefsChannelPicker::save_scan_defaults(Channel *scan_params)
307 {
308         scan_params->save_defaults(mwindow->defaults);
309 }
310
311 void PrefsChannelPicker::handle_channel_edit(int result)
312 {
313         mwindow->save_defaults();
314 }
315
316 BC_Theme* PrefsChannelPicker::get_theme()
317 {
318         return mwindow->theme;
319 }
320
321
322 ArrayList<Channel*>* PrefsChannelPicker::get_video_inputs()
323 {
324         return &input_sources;
325 }
326
327 Channel* PrefsChannelPicker::get_channel_usage()
328 {
329         return 0;
330 }
331
332
333 void PrefsChannelPicker::set_channel(Channel *channel)
334 {
335         if(channel)
336                 channel_text->update(channel->title);
337 }
338
339 Channel *PrefsChannelPicker::get_current_channel()
340 {
341         int number = prefs->out_config->buz_out_channel;
342         return channeldb->get(number);
343 }
344
345 void PrefsChannelPicker::set_channel_number(int number)
346 {
347         CLAMP(number, 0, channeldb->size() - 1);
348         prefs->out_config->buz_out_channel = number;
349         set_channel(get_current_channel());
350 }
351
352 int PrefsChannelPicker::has_signal()
353 {
354         return 0;
355 }
356
357 int PrefsChannelPicker::set_brightness(int value)
358 {
359         prefs->out_config->brightness = value;
360         return 0;
361 }
362
363 int PrefsChannelPicker::set_hue(int value)
364 {
365         prefs->out_config->hue = value;
366         return 0;
367 }
368
369 int PrefsChannelPicker::set_color(int value)
370 {
371         prefs->out_config->color = value;
372         return 0;
373 }
374
375 int PrefsChannelPicker::set_contrast(int value)
376 {
377         prefs->out_config->contrast = value;
378         return 0;
379 }
380
381 int PrefsChannelPicker::set_whiteness(int value)
382 {
383         prefs->out_config->whiteness = value;
384         return 0;
385 }
386
387 int PrefsChannelPicker::get_brightness()
388 {
389         return prefs->out_config->brightness;
390 }
391
392 int PrefsChannelPicker::get_hue()
393 {
394         return prefs->out_config->hue;
395 }
396
397 int PrefsChannelPicker::get_color()
398 {
399         return prefs->out_config->color;
400 }
401
402 int PrefsChannelPicker::get_contrast()
403 {
404         return prefs->out_config->contrast;
405 }
406
407 int PrefsChannelPicker::get_whiteness()
408 {
409         return prefs->out_config->whiteness;
410 }
411
412
413
414
415
416
417 ChannelPicker::ChannelPicker(MWindow *mwindow,
418                 ChannelDB *channeldb, 
419                 int x,
420                 int y,
421                 BC_WindowBase *parent_window)
422 {
423         this->mwindow = mwindow;
424         this->parent_window = parent_window;
425         this->x = x;
426         this->y = y;
427         this->channeldb = channeldb;
428         channel_text = 0;
429         channel_select = 0;
430         channel_button = 0;
431         update_channel_list();
432 }
433
434 ChannelPicker::~ChannelPicker()
435 {
436         delete channel_text;
437         delete channel_select;
438         delete channel_button;
439         channel_listitems.remove_all_objects();
440 }
441
442 void ChannelPicker::update_channel_list()
443 {
444         channel_listitems.remove_all_objects();
445         for(int i = 0; i < channeldb->size(); i++)
446         {
447                 channel_listitems.append(new BC_ListBoxItem(channeldb->get(i)->title));
448         }
449
450         if(channel_text)
451                 channel_text->update_list(&channel_listitems);
452 }
453
454 int ChannelPicker::get_w()
455 {
456         return channel_text->get_w() + 
457                 channel_select->get_w() + 
458                 channel_button->get_w() +
459                 picture_button->get_w() +
460                 ((Theme*)get_theme())->widget_border * 4;
461 }
462
463
464
465
466
467
468 BC_WindowBase* ChannelPicker::get_subwindow()
469 {
470         return parent_window;
471         return 0;
472 }
473
474
475
476
477
478
479
480 void ChannelPicker::create_objects()
481 {
482         channel_text = 0;
483         update_channel_list();
484
485
486         channel_text = new ChannelText(this, x, y);
487         channel_text->create_objects();
488
489
490         x += channel_text->get_w() + ((Theme*)get_theme())->widget_border;
491         get_subwindow()->add_subwindow(channel_select = new ChannelTumbler(this, 
492                 x, 
493                 y));
494
495
496         x += channel_select->get_w() + ((Theme*)get_theme())->widget_border;
497         get_subwindow()->add_subwindow(channel_button = new ChannelButton(this, 
498                 x, 
499                 y - 1));
500
501 //PRINT_TRACE
502         x += channel_button->get_w() + ((Theme*)get_theme())->widget_border;
503         get_subwindow()->add_subwindow(picture_button = new PictureButton(this, 
504                 x, 
505                 y - 1));
506 //PRINT_TRACE
507         
508 }
509
510 int ChannelPicker::reposition()
511 {
512         channel_text->reposition_window(channel_text->get_x(),
513                 channel_text->get_y());
514         channel_select->reposition_window(channel_select->get_x(),
515                 channel_select->get_y());
516         channel_button->reposition_window(channel_button->get_x(),
517                 channel_button->get_y());
518         return 0;
519 }
520
521 int ChannelPicker::close_threads()
522 {
523         channel_button->thread->close_threads();
524         return 0;
525 }
526
527 const char* ChannelPicker::get_source_name(Channel *channel)
528 {
529         if(channel->entry < chanlists[channel->freqtable].count)
530                 return chanlists[channel->freqtable].list[channel->entry].name;
531         else
532                 return chanlists[channel->freqtable].list[0].name;
533 }
534
535 const char* ChannelPicker::current_channel_name()
536 {
537         if(get_current_channel())
538         {
539                 return get_current_channel()->title;
540         }
541         else
542                 return _("Channel");
543 }
544
545 int ChannelPicker::channel_down()
546 {
547         Channel *channel = get_current_channel();
548         if( !channel ) return 1;
549         int number = channeldb->number_of(channel);
550         if( number < 0 ) return 1;
551         if( --number < 0 ) number = 0;
552         set_channel_number(number);
553         return 0;
554 }
555
556 int ChannelPicker::channel_up()
557 {
558         Channel *channel = get_current_channel();
559         if( !channel ) return 1;
560         int number = channeldb->number_of(channel);
561         if( number < 0 ) return 1;
562         if( ++number >= channeldb->size() ) number = channeldb->size()-1;
563         set_channel_number(number);
564         return 0;
565 }
566
567
568
569
570
571 PictureButton::PictureButton(ChannelPicker *channel_picker, int x, int y)
572  : BC_Button(x, 
573         y, 
574         channel_picker->get_theme() ? 
575                 channel_picker->get_theme()->get_image_set("picture") :
576                 0)
577 {
578         this->channel_picker = channel_picker;
579         thread = new ChannelEditPictureThread(channel_picker);
580         set_tooltip(_("Edit picture"));
581 }
582
583 PictureButton::~PictureButton()
584 {
585 //printf("PictureButton::PictureButton %d\n", __LINE__);
586         delete thread;
587 //printf("PictureButton::PictureButton %d\n", __LINE__);
588 }
589
590 int PictureButton::handle_event()
591 {
592         unlock_window();
593         thread->edit_picture();
594         lock_window("PictureButton::handle_event");
595         return 1;
596 }
597
598
599
600
601 ChannelButton::ChannelButton(ChannelPicker *channel_picker, 
602         int x, 
603         int y)
604  : BC_Button(x, 
605         y, 
606         channel_picker->get_theme() ? 
607                 channel_picker->get_theme()->get_image_set("channel") :
608                 0)
609 {
610         this->channel_picker = channel_picker;
611         thread = new ChannelEditThread(channel_picker, 
612                 channel_picker->channeldb);
613         set_tooltip(_("Edit channels"));
614 }
615
616 ChannelButton::~ChannelButton()
617 {
618         delete thread;
619 }
620
621 int ChannelButton::handle_event()
622 {
623         thread->start();
624         return 1;
625 }
626
627
628 ChannelText::ChannelText(ChannelPicker *channel_picker, 
629         int x, 
630         int y)
631  : BC_PopupTextBox(channel_picker->get_subwindow(),
632         &channel_picker->channel_listitems,
633         channel_picker->current_channel_name(),
634         x, 
635         y, 
636         200, 
637         300)
638 {
639
640         this->channel_picker = channel_picker;
641 }
642
643 ChannelText::~ChannelText()
644 {
645 }
646
647 int ChannelText::handle_event()
648 {
649         channel_picker->set_channel_number(get_number());
650         return 0;
651 }
652
653
654
655
656 ChannelList::ChannelList(ChannelPicker *channel_picker, int x, int y)
657  : BC_ListBox(x, 
658                 y, 
659                 100, 
660                 200,
661                 LISTBOX_TEXT,                   // Display text list or icons
662                 &channel_picker->channel_listitems, // Each column has an ArrayList of BC_ListBoxItems.
663                 0,                       // Titles for columns.  Set to 0 for no titles
664                 0,                      // width of each column
665                 1,                     // Total columns.
666                 0,                    // Pixel of top of window.
667                 1)                   // If this listbox is a popup window
668 {
669         this->channel_picker = channel_picker;
670 }
671
672 ChannelList::~ChannelList()
673 {
674 }
675         
676 int ChannelList::handle_event()
677 {
678         return 0;
679 }
680
681
682
683 ChannelTumbler::ChannelTumbler(ChannelPicker *channel_picker, 
684         int x, 
685         int y)
686  : BC_Tumbler(x, y)
687 {
688         this->channel_picker = channel_picker;
689 }
690 ChannelTumbler::~ChannelTumbler()
691 {
692 }
693 int ChannelTumbler::handle_up_event()
694 {
695         channel_picker->channel_up();
696         return 1;
697 }
698 int ChannelTumbler::handle_down_event()
699 {
700         channel_picker->channel_down();
701         return 1;
702 }
703 int ChannelTumbler::keypress_event()
704 {
705         if(get_keypress() == PGUP)
706         {
707                 handle_up_event();
708                 return 1;
709         }
710         else
711         if(get_keypress() == PGDN)
712         {
713                 handle_down_event();
714                 return 1;
715         }
716         else
717         return 0;
718 }
719
720