r1014: Enable horizontal scrolling with the mouse wheel by pressing Ctrl.
[cinelerra_cv/ct.git] / cinelerra / channelpicker.C
blobe025340a80f108e0cd95c9eccd7440549e8a665a
1 #include "batch.h"
2 #include "bcsignals.h"
3 #include "channel.h"
4 #include "channeldb.h"
5 #include "channeledit.h"
6 #include "channelpicker.h"
7 #include "chantables.h"
8 #include "clip.h"
9 #include "edl.h"
10 #include "edlsession.h"
11 #include "keys.h"
12 #include "language.h"
13 #include "mwindow.h"
14 #include "picture.h"
15 #include "playbackconfig.h"
16 #include "preferencesthread.h"
17 #include "record.h"
18 #include "recordgui.h"
19 #include "recordmonitor.h"
20 #include "theme.h"
21 #include "vdevicebuz.h"
22 #include "vdeviceprefs.h"
23 #include "videodevice.h"
25 RecordChannelPicker::RecordChannelPicker(MWindow *mwindow, 
26         Record *record,
27         RecordMonitor *record_monitor,
28         BC_WindowBase *parent_window, 
29         ChannelDB *channeldb, 
30         int x,
31         int y)
32  : ChannelPicker(channeldb, 
33                 x,
34                 y,
35                 parent_window)
37         this->mwindow = mwindow;
38         this->record = record;
39         this->record_monitor = record_monitor;
42 RecordChannelPicker::~RecordChannelPicker()
46 int RecordChannelPicker::use_select()
48         return 1;
51 Channel* RecordChannelPicker::get_master_channel()
53         return record->master_channel;
56 void RecordChannelPicker::handle_channel_edit(int result)
58         if(!result)
59         {
60                 record->record_gui->lock_window("RecordChannelPicker::handle_channel_edit 1");
61                 record->record_gui->update_batch_sources();
63                 record->set_channel(current_channel);
64                 record->record_gui->unlock_window();
65                 record->save_defaults();
66                 VideoDevice::save_channeldb(record->channeldb,
67                         mwindow->edl->session->vconfig_in);
68         }
69         else
70         {
71                 record->record_gui->lock_window("RecordChannelPicker::handle_channel_edit 2");
72                 record->set_channel(record->get_editing_batch()->channel);
73                 record->record_gui->unlock_window();
74         }
76         mwindow->save_defaults();
79 void RecordChannelPicker::load_scan_defaults(Channel *scan_params)
81         scan_params->load_defaults(mwindow->defaults);
84 void RecordChannelPicker::save_scan_defaults(Channel *scan_params)
86         scan_params->save_defaults(mwindow->defaults);
89 BC_Theme* RecordChannelPicker::get_theme()
91         return mwindow->theme;
95 Channel* RecordChannelPicker::get_current_channel_struct()
97         return record->get_current_channel_struct();
100 int RecordChannelPicker::get_current_channel_number()
102         return record->get_editing_channel();
105 ArrayList<Channel*>* RecordChannelPicker::get_video_inputs() 
107         return record->get_video_inputs();
110 Channel* RecordChannelPicker::get_channel_usage()
112         return record->master_channel;
115 void RecordChannelPicker::set_channel_number(int number)
117         record->set_channel(number);
120 int RecordChannelPicker::set_brightness(int value)
122         if(record)
123         {
124                 record->picture->brightness = value;
125                 record->set_video_picture();
126         }
127         return 0;
130 int RecordChannelPicker::set_hue(int value)
132         if(record)
133         {
134                 record->picture->hue = value;
135                 record->set_video_picture();
136         }
137         return 0;
140 int RecordChannelPicker::set_color(int value)
142         if(record)
143         {
144                 record->picture->color = value;
145                 record->set_video_picture();
146         }
147         return 0;
150 int RecordChannelPicker::set_contrast(int value)
152         if(record)
153         {
154                 record->picture->contrast = value;
155                 record->set_video_picture();
156         }
157         return 0;
160 int RecordChannelPicker::set_whiteness(int value)
162         if(record)
163         {
164                 record->picture->whiteness = value;
165                 record->set_video_picture();
166         }
167         return 0;
170 int RecordChannelPicker::set_picture(int device_id, int value)
172         if(record) 
173         {
174                 record->picture->set_item(device_id, value);
175                 record->set_video_picture();
176         }
177         return 0;
181 int RecordChannelPicker::get_brightness()
183         if(record) return record->picture->brightness;
184         return 0;
187 int RecordChannelPicker::get_hue()
189         if(record) return record->picture->hue;
190         return 0;
193 int RecordChannelPicker::get_color()
195         if(record) return record->picture->color;
196         return 0;
199 int RecordChannelPicker::get_contrast()
201         if(record) return record->picture->contrast;
202         return 0;
205 int RecordChannelPicker::get_whiteness()
207         if(record) return record->picture->whiteness;
208         return 0;
211 int RecordChannelPicker::get_controls()
213         if(record) return record->picture->controls.total;
214         return 0;
217 PictureItem* RecordChannelPicker::get_control(int i)
219         if(record) return record->picture->controls.values[i];
220         return 0;
223 PictureConfig* RecordChannelPicker::get_picture_usage()
225         if(record) return record->picture;
226         return 0;
231 void RecordChannelPicker::set_channel(Channel *channel)
233         record->set_channel(channel);
236 int RecordChannelPicker::has_signal()
238         return record->has_signal();
249 PrefsChannelPicker::PrefsChannelPicker(MWindow *mwindow, 
250                 VDevicePrefs *prefs, 
251                 ChannelDB *channeldb, 
252                 int x,
253                 int y)
254  : ChannelPicker(channeldb, 
255                 x,
256                 y,
257                 prefs->dialog)
259 //      printf("PrefsChannelPicker::PrefsChannelPicker 1\n");
260         this->mwindow = mwindow;
261         this->prefs = prefs;
262         VDeviceBUZ::get_inputs(&input_sources);
265 PrefsChannelPicker::~PrefsChannelPicker()
267         input_sources.remove_all_objects();
270 void PrefsChannelPicker::load_scan_defaults(Channel *scan_params)
272         scan_params->load_defaults(mwindow->defaults);
275 void PrefsChannelPicker::save_scan_defaults(Channel *scan_params)
277         scan_params->save_defaults(mwindow->defaults);
280 void PrefsChannelPicker::handle_channel_edit(int result)
282         mwindow->save_defaults();
285 BC_Theme* PrefsChannelPicker::get_theme()
287         return mwindow->theme;
291 Channel* PrefsChannelPicker::get_current_channel_struct()
293         int number = get_current_channel_number();
295         if(number >= 0 && number < channeldb->size())
296         {
297                 return channeldb->get(number);
298         }
299         return 0;
302 int PrefsChannelPicker::get_current_channel_number()
304         return prefs->out_config->buz_out_channel;
307 ArrayList<Channel*>* PrefsChannelPicker::get_video_inputs()
309         return &input_sources;
312 Channel* PrefsChannelPicker::get_channel_usage()
314         return 0;
318 void PrefsChannelPicker::set_channel(Channel *channel)
320         if(channel)
321                 channel_text->update(channel->title);
324 void PrefsChannelPicker::set_channel_number(int number)
326         CLAMP(number, 0, channeldb->size() - 1);
327         prefs->out_config->buz_out_channel = number;
328         set_channel(get_current_channel_struct());
331 int PrefsChannelPicker::has_signal()
333         return 0;
336 int PrefsChannelPicker::set_brightness(int value)
338         prefs->out_config->brightness = value;
341 int PrefsChannelPicker::set_hue(int value)
343         prefs->out_config->hue = value;
346 int PrefsChannelPicker::set_color(int value)
348         prefs->out_config->color = value;
351 int PrefsChannelPicker::set_contrast(int value)
353         prefs->out_config->contrast = value;
356 int PrefsChannelPicker::set_whiteness(int value)
358         prefs->out_config->whiteness = value;
361 int PrefsChannelPicker::get_brightness()
363         return prefs->out_config->brightness;
366 int PrefsChannelPicker::get_hue()
368         return prefs->out_config->hue;
371 int PrefsChannelPicker::get_color()
373         return prefs->out_config->color;
376 int PrefsChannelPicker::get_contrast()
378         return prefs->out_config->contrast;
381 int PrefsChannelPicker::get_whiteness()
383         return prefs->out_config->whiteness;
391 ChannelPicker::ChannelPicker(ChannelDB *channeldb, 
392                 int x,
393                 int y,
394                 BC_WindowBase *parent_window)
396         this->parent_window = parent_window;
397         this->x = x;
398         this->y = y;
399         this->channeldb = channeldb;
400         current_channel = new Channel;
401         channel_text = 0;
402         channel_select = 0;
403         channel_button = 0;
404         current_channel = 0;
405         update_channel_list();
408 ChannelPicker::~ChannelPicker()
410         delete channel_text;
411         delete channel_select;
412         delete channel_button;
413         delete current_channel;
414         channel_listitems.remove_all_objects();
417 void ChannelPicker::update_channel_list()
419         channel_listitems.remove_all_objects();
420         for(int i = 0; i < channeldb->size(); i++)
421         {
422                 channel_listitems.append(new BC_ListBoxItem(channeldb->get(i)->title));
423         }
425         if(channel_text)
426                 channel_text->update_list(&channel_listitems);
436 BC_WindowBase* ChannelPicker::get_subwindow()
438         return parent_window;
439         return 0;
448 int ChannelPicker::create_objects()
450         channel_text = 0;
451         update_channel_list();
452         channel_text = new ChannelText(this, x, y);
453         channel_text->create_objects();
454         x += channel_text->get_w();
455         get_subwindow()->add_subwindow(channel_select = new ChannelTumbler(this, 
456                 x, 
457                 y));
458         x += channel_select->get_w() + 5;
459         get_subwindow()->add_subwindow(channel_button = new ChannelButton(this, 
460                 x, 
461                 y - 1));
462         return 0;
465 int ChannelPicker::reposition()
467         channel_text->reposition_window(channel_text->get_x(),
468                 channel_text->get_y());
469         channel_select->reposition_window(channel_select->get_x(),
470                 channel_select->get_y());
471         channel_button->reposition_window(channel_button->get_x(),
472                 channel_button->get_y());
473         return 0;
476 int ChannelPicker::close_threads()
478         channel_button->thread->close_threads();
479         return 0;
482 char* ChannelPicker::get_source_name(Channel *channel)
484         if(channel->entry < chanlists[channel->freqtable].count)
485                 return chanlists[channel->freqtable].list[channel->entry].name;
486         else
487                 return chanlists[channel->freqtable].list[0].name;
490 char* ChannelPicker::current_channel_name()
492         if(get_current_channel_struct())
493         {
494                 return get_current_channel_struct()->title;
495         }
496         else
497                 return _("Channel");
500 int ChannelPicker::channel_down()
502         int number = get_current_channel_number() - 1;
503         if(number < 0) number = 0;
504         CLAMP(number, 0, channeldb->size() - 1);
505         set_channel_number(number);
506         return 0;
509 int ChannelPicker::channel_up()
511         int number = get_current_channel_number() + 1;
512         if(number >= channeldb->size()) number = channeldb->size() - 1;
513         CLAMP(number, 0, channeldb->size() - 1);
514         set_channel_number(number);
515         return 0;
520 ChannelButton::ChannelButton(ChannelPicker *channel_picker, 
521         int x, 
522         int y)
523  : BC_Button(x, 
524         y, 
525         channel_picker->get_theme() ? 
526                 channel_picker->get_theme()->get_image_set("channel") :
527                 0)
529         this->channel_picker = channel_picker;
530         thread = new ChannelEditThread(channel_picker, 
531                 channel_picker->channeldb);
532         set_tooltip(_("Edit channels"));
535 ChannelButton::~ChannelButton()
537         delete thread;
540 int ChannelButton::handle_event()
542         thread->start();
543         return 1;
547 ChannelText::ChannelText(ChannelPicker *channel_picker, 
548         int x, 
549         int y)
550  : BC_PopupTextBox(channel_picker->get_subwindow(),
551         &channel_picker->channel_listitems,
552         channel_picker->current_channel_name(),
553         x, 
554         y, 
555         150, 
556         300)
559         this->channel_picker = channel_picker;
562 ChannelText::~ChannelText()
566 int ChannelText::handle_event()
568         channel_picker->set_channel_number(get_number());
569         return 0;
575 ChannelList::ChannelList(ChannelPicker *channel_picker, int x, int y)
576  : BC_ListBox(x, 
577                 y, 
578                 100, 
579                 200,
580                 LISTBOX_TEXT,                   // Display text list or icons
581                 &channel_picker->channel_listitems, // Each column has an ArrayList of BC_ListBoxItems.
582                 0,                       // Titles for columns.  Set to 0 for no titles
583                 0,                      // width of each column
584                 1,                     // Total columns.
585                 0,                    // Pixel of top of window.
586                 1)                   // If this listbox is a popup window
588         this->channel_picker = channel_picker;
591 ChannelList::~ChannelList()
594         
595 int ChannelList::handle_event()
597         return 0;
602 ChannelTumbler::ChannelTumbler(ChannelPicker *channel_picker, 
603         int x, 
604         int y)
605  : BC_Tumbler(x, y)
607         this->channel_picker = channel_picker;
609 ChannelTumbler::~ChannelTumbler()
612 int ChannelTumbler::handle_up_event()
614         channel_picker->channel_up();
615         return 1;
617 int ChannelTumbler::handle_down_event()
619         channel_picker->channel_down();
620         return 1;
622 int ChannelTumbler::keypress_event()
624         if(get_keypress() == PGUP)
625         {
626                 handle_up_event();
627                 return 1;
628         }
629         else
630         if(get_keypress() == PGDN)
631         {
632                 handle_down_event();
633                 return 1;
634         }
635         else
636         return 0;