4 * Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "bcsignals.h"
25 #include "channeldb.h"
26 #include "channeledit.h"
27 #include "channelpicker.h"
28 #include "chantables.h"
31 #include "edlsession.h"
36 #include "playbackconfig.h"
37 #include "preferencesthread.h"
39 #include "recordgui.h"
40 #include "recordmonitor.h"
42 #include "vdevicebuz.h"
43 #include "vdeviceprefs.h"
44 #include "videodevice.h"
46 RecordChannelPicker::RecordChannelPicker(MWindow *mwindow,
48 RecordMonitor *record_monitor,
49 BC_WindowBase *parent_window,
53 : ChannelPicker(mwindow,
59 this->record = record;
60 this->record_monitor = record_monitor;
63 RecordChannelPicker::~RecordChannelPicker()
67 int RecordChannelPicker::use_select()
72 Channel* RecordChannelPicker::get_master_channel()
74 return record->master_channel;
77 void RecordChannelPicker::handle_channel_edit(int result)
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);
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();
96 mwindow->save_defaults();
99 void RecordChannelPicker::load_scan_defaults(Channel *scan_params)
101 scan_params->load_defaults(mwindow->defaults);
104 void RecordChannelPicker::save_scan_defaults(Channel *scan_params)
106 scan_params->save_defaults(mwindow->defaults);
109 BC_Theme* RecordChannelPicker::get_theme()
111 return mwindow->theme;
115 Channel* RecordChannelPicker::get_current_channel()
117 return record->get_current_channel();
120 Channel *RecordChannelPicker::get_editing_channel()
122 return record->get_editing_channel();
125 ArrayList<Channel*>* RecordChannelPicker::get_video_inputs()
127 return record->get_video_inputs();
130 Channel* RecordChannelPicker::get_channel_usage()
132 return record->master_channel;
135 void RecordChannelPicker::set_channel_number(int number)
137 if( number < 0 || number >= channeldb->size() ) return;
138 Channel *channel = channeldb->get(number);
139 if( channel ) record->set_channel(channel);
142 void RecordChannelPicker::set_brightness(int value)
146 record->picture->brightness = value;
147 record->set_video_picture();
151 void RecordChannelPicker::set_hue(int value)
155 record->picture->hue = value;
156 record->set_video_picture();
160 void RecordChannelPicker::set_color(int value)
164 record->picture->color = value;
165 record->set_video_picture();
169 void RecordChannelPicker::set_contrast(int value)
173 record->picture->contrast = value;
174 record->set_video_picture();
178 void RecordChannelPicker::set_whiteness(int value)
182 record->picture->whiteness = value;
183 record->set_video_picture();
187 int RecordChannelPicker::set_picture(int device_id, int value)
191 if(record->picture->set_item(device_id, value))
192 record->set_video_picture();
198 int RecordChannelPicker::get_brightness()
200 if(record) return record->picture->brightness;
204 int RecordChannelPicker::get_hue()
206 if(record) return record->picture->hue;
210 int RecordChannelPicker::get_color()
212 if(record) return record->picture->color;
216 int RecordChannelPicker::get_contrast()
218 if(record) return record->picture->contrast;
222 int RecordChannelPicker::get_whiteness()
224 if(record) return record->picture->whiteness;
228 int RecordChannelPicker::get_controls()
230 if(record) return record->picture->controls.total;
234 PictureItem* RecordChannelPicker::get_control(int i)
236 if(record) return record->picture->controls.values[i];
240 PictureConfig* RecordChannelPicker::get_picture_usage()
242 if(record) return record->picture;
248 void RecordChannelPicker::set_channel(Channel *channel)
250 record->set_channel(channel);
253 int RecordChannelPicker::has_signal()
255 return record->has_signal();
258 int RecordChannelPicker::create_channeldb(ArrayList<Channel*> *channeldb)
260 return record->create_channeldb(channeldb);
271 PrefsChannelPicker::PrefsChannelPicker(MWindow *mwindow,
273 ChannelDB *channeldb,
276 : ChannelPicker(mwindow,
282 // printf("PrefsChannelPicker::PrefsChannelPicker 1\n");
285 #ifdef HAVE_VIDEO4LINUX
286 VDeviceBUZ::get_inputs(&input_sources);
291 PrefsChannelPicker::~PrefsChannelPicker()
293 input_sources.remove_all_objects();
296 void PrefsChannelPicker::load_scan_defaults(Channel *scan_params)
298 scan_params->load_defaults(mwindow->defaults);
301 void PrefsChannelPicker::save_scan_defaults(Channel *scan_params)
303 scan_params->save_defaults(mwindow->defaults);
306 void PrefsChannelPicker::handle_channel_edit(int result)
308 mwindow->save_defaults();
311 BC_Theme* PrefsChannelPicker::get_theme()
313 return mwindow->theme;
317 ArrayList<Channel*>* PrefsChannelPicker::get_video_inputs()
319 return &input_sources;
322 Channel* PrefsChannelPicker::get_channel_usage()
328 void PrefsChannelPicker::set_channel(Channel *channel)
331 channel_text->update(channel->title);
334 Channel *PrefsChannelPicker::get_current_channel()
336 int number = prefs->out_config->buz_out_channel;
337 return channeldb->get(number);
340 void PrefsChannelPicker::set_channel_number(int number)
342 CLAMP(number, 0, channeldb->size() - 1);
343 prefs->out_config->buz_out_channel = number;
344 set_channel(get_current_channel());
347 int PrefsChannelPicker::has_signal()
352 void PrefsChannelPicker::set_brightness(int value)
354 prefs->out_config->brightness = value;
357 void PrefsChannelPicker::set_hue(int value)
359 prefs->out_config->hue = value;
362 void PrefsChannelPicker::set_color(int value)
364 prefs->out_config->color = value;
367 void PrefsChannelPicker::set_contrast(int value)
369 prefs->out_config->contrast = value;
372 void PrefsChannelPicker::set_whiteness(int value)
374 prefs->out_config->whiteness = value;
377 int PrefsChannelPicker::get_brightness()
379 return prefs->out_config->brightness;
382 int PrefsChannelPicker::get_hue()
384 return prefs->out_config->hue;
387 int PrefsChannelPicker::get_color()
389 return prefs->out_config->color;
392 int PrefsChannelPicker::get_contrast()
394 return prefs->out_config->contrast;
397 int PrefsChannelPicker::get_whiteness()
399 return prefs->out_config->whiteness;
407 ChannelPicker::ChannelPicker(MWindow *mwindow,
408 ChannelDB *channeldb,
411 BC_WindowBase *parent_window)
413 this->mwindow = mwindow;
414 this->parent_window = parent_window;
417 this->channeldb = channeldb;
421 update_channel_list();
424 ChannelPicker::~ChannelPicker()
427 delete channel_select;
428 delete channel_button;
429 channel_listitems.remove_all_objects();
432 void ChannelPicker::update_channel_list()
434 channel_listitems.remove_all_objects();
435 for(int i = 0; i < channeldb->size(); i++)
437 channel_listitems.append(new BC_ListBoxItem(channeldb->get(i)->title));
441 channel_text->update_list(&channel_listitems);
444 int ChannelPicker::get_w()
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;
458 BC_WindowBase* ChannelPicker::get_subwindow()
460 return parent_window;
470 void ChannelPicker::create_objects()
473 update_channel_list();
476 channel_text = new ChannelText(this, x, y);
477 channel_text->create_objects();
480 x += channel_text->get_w() + ((Theme*)get_theme())->widget_border;
481 get_subwindow()->add_subwindow(channel_select = new ChannelTumbler(this,
486 x += channel_select->get_w() + ((Theme*)get_theme())->widget_border;
487 get_subwindow()->add_subwindow(channel_button = new ChannelButton(this,
492 x += channel_button->get_w() + ((Theme*)get_theme())->widget_border;
493 get_subwindow()->add_subwindow(picture_button = new PictureButton(this,
500 int ChannelPicker::reposition()
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());
511 void ChannelPicker::close_threads()
513 channel_button->thread->close_threads();
516 const char* ChannelPicker::get_source_name(Channel *channel)
518 if(channel->entry < chanlists[channel->freqtable].count)
519 return chanlists[channel->freqtable].list[channel->entry].name;
521 return chanlists[channel->freqtable].list[0].name;
524 const char* ChannelPicker::current_channel_name()
526 if(get_current_channel())
527 return get_current_channel()->title;
531 int ChannelPicker::channel_down()
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);
542 int ChannelPicker::channel_up()
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);
557 PictureButton::PictureButton(ChannelPicker *channel_picker, int x, int y)
560 channel_picker->get_theme() ?
561 channel_picker->get_theme()->get_image_set("picture") :
564 this->channel_picker = channel_picker;
565 thread = new ChannelEditPictureThread(channel_picker);
566 set_tooltip(_("Edit picture"));
569 PictureButton::~PictureButton()
571 //printf("PictureButton::PictureButton %d\n", __LINE__);
573 //printf("PictureButton::PictureButton %d\n", __LINE__);
576 int PictureButton::handle_event()
579 thread->edit_picture();
580 lock_window("PictureButton::handle_event");
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") :
592 this->channel_picker = channel_picker;
593 thread = new ChannelEditThread(channel_picker,
594 channel_picker->channeldb);
595 set_tooltip(_("Edit channels"));
598 ChannelButton::~ChannelButton()
603 int ChannelButton::handle_event()
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(),
617 this->channel_picker = channel_picker;
620 ChannelText::~ChannelText()
624 int ChannelText::handle_event()
626 channel_picker->set_channel_number(get_number());
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
640 0, // Pixel of top of window.
641 1) // If this listbox is a popup window
643 this->channel_picker = channel_picker;
646 ChannelList::~ChannelList()
650 int ChannelList::handle_event()
657 ChannelTumbler::ChannelTumbler(ChannelPicker *channel_picker,
662 this->channel_picker = channel_picker;
664 ChannelTumbler::~ChannelTumbler()
667 int ChannelTumbler::handle_up_event()
669 channel_picker->channel_up();
672 int ChannelTumbler::handle_down_event()
674 channel_picker->channel_down();
677 int ChannelTumbler::keypress_event()
679 if(get_keypress() == PGUP)
685 if(get_keypress() == PGDN)