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 int RecordChannelPicker::set_brightness(int value)
146 record->picture->brightness = value;
147 record->set_video_picture();
152 int RecordChannelPicker::set_hue(int value)
156 record->picture->hue = value;
157 record->set_video_picture();
162 int RecordChannelPicker::set_color(int value)
166 record->picture->color = value;
167 record->set_video_picture();
172 int RecordChannelPicker::set_contrast(int value)
176 record->picture->contrast = value;
177 record->set_video_picture();
182 int RecordChannelPicker::set_whiteness(int value)
186 record->picture->whiteness = value;
187 record->set_video_picture();
192 int RecordChannelPicker::set_picture(int device_id, int value)
196 if(record->picture->set_item(device_id, value))
197 record->set_video_picture();
203 int RecordChannelPicker::get_brightness()
205 if(record) return record->picture->brightness;
209 int RecordChannelPicker::get_hue()
211 if(record) return record->picture->hue;
215 int RecordChannelPicker::get_color()
217 if(record) return record->picture->color;
221 int RecordChannelPicker::get_contrast()
223 if(record) return record->picture->contrast;
227 int RecordChannelPicker::get_whiteness()
229 if(record) return record->picture->whiteness;
233 int RecordChannelPicker::get_controls()
235 if(record) return record->picture->controls.total;
239 PictureItem* RecordChannelPicker::get_control(int i)
241 if(record) return record->picture->controls.values[i];
245 PictureConfig* RecordChannelPicker::get_picture_usage()
247 if(record) return record->picture;
253 void RecordChannelPicker::set_channel(Channel *channel)
255 record->set_channel(channel);
258 int RecordChannelPicker::has_signal()
260 return record->has_signal();
263 int RecordChannelPicker::create_channeldb(ArrayList<Channel*> *channeldb)
265 return record->create_channeldb(channeldb);
276 PrefsChannelPicker::PrefsChannelPicker(MWindow *mwindow,
278 ChannelDB *channeldb,
281 : ChannelPicker(mwindow,
287 // printf("PrefsChannelPicker::PrefsChannelPicker 1\n");
290 #ifdef HAVE_VIDEO4LINUX
291 VDeviceBUZ::get_inputs(&input_sources);
296 PrefsChannelPicker::~PrefsChannelPicker()
298 input_sources.remove_all_objects();
301 void PrefsChannelPicker::load_scan_defaults(Channel *scan_params)
303 scan_params->load_defaults(mwindow->defaults);
306 void PrefsChannelPicker::save_scan_defaults(Channel *scan_params)
308 scan_params->save_defaults(mwindow->defaults);
311 void PrefsChannelPicker::handle_channel_edit(int result)
313 mwindow->save_defaults();
316 BC_Theme* PrefsChannelPicker::get_theme()
318 return mwindow->theme;
322 ArrayList<Channel*>* PrefsChannelPicker::get_video_inputs()
324 return &input_sources;
327 Channel* PrefsChannelPicker::get_channel_usage()
333 void PrefsChannelPicker::set_channel(Channel *channel)
336 channel_text->update(channel->title);
339 Channel *PrefsChannelPicker::get_current_channel()
341 int number = prefs->out_config->buz_out_channel;
342 return channeldb->get(number);
345 void PrefsChannelPicker::set_channel_number(int number)
347 CLAMP(number, 0, channeldb->size() - 1);
348 prefs->out_config->buz_out_channel = number;
349 set_channel(get_current_channel());
352 int PrefsChannelPicker::has_signal()
357 int PrefsChannelPicker::set_brightness(int value)
359 prefs->out_config->brightness = value;
363 int PrefsChannelPicker::set_hue(int value)
365 prefs->out_config->hue = value;
369 int PrefsChannelPicker::set_color(int value)
371 prefs->out_config->color = value;
375 int PrefsChannelPicker::set_contrast(int value)
377 prefs->out_config->contrast = value;
381 int PrefsChannelPicker::set_whiteness(int value)
383 prefs->out_config->whiteness = value;
387 int PrefsChannelPicker::get_brightness()
389 return prefs->out_config->brightness;
392 int PrefsChannelPicker::get_hue()
394 return prefs->out_config->hue;
397 int PrefsChannelPicker::get_color()
399 return prefs->out_config->color;
402 int PrefsChannelPicker::get_contrast()
404 return prefs->out_config->contrast;
407 int PrefsChannelPicker::get_whiteness()
409 return prefs->out_config->whiteness;
417 ChannelPicker::ChannelPicker(MWindow *mwindow,
418 ChannelDB *channeldb,
421 BC_WindowBase *parent_window)
423 this->mwindow = mwindow;
424 this->parent_window = parent_window;
427 this->channeldb = channeldb;
431 update_channel_list();
434 ChannelPicker::~ChannelPicker()
437 delete channel_select;
438 delete channel_button;
439 channel_listitems.remove_all_objects();
442 void ChannelPicker::update_channel_list()
444 channel_listitems.remove_all_objects();
445 for(int i = 0; i < channeldb->size(); i++)
447 channel_listitems.append(new BC_ListBoxItem(channeldb->get(i)->title));
451 channel_text->update_list(&channel_listitems);
454 int ChannelPicker::get_w()
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;
468 BC_WindowBase* ChannelPicker::get_subwindow()
470 return parent_window;
480 void ChannelPicker::create_objects()
483 update_channel_list();
486 channel_text = new ChannelText(this, x, y);
487 channel_text->create_objects();
490 x += channel_text->get_w() + ((Theme*)get_theme())->widget_border;
491 get_subwindow()->add_subwindow(channel_select = new ChannelTumbler(this,
496 x += channel_select->get_w() + ((Theme*)get_theme())->widget_border;
497 get_subwindow()->add_subwindow(channel_button = new ChannelButton(this,
502 x += channel_button->get_w() + ((Theme*)get_theme())->widget_border;
503 get_subwindow()->add_subwindow(picture_button = new PictureButton(this,
510 int ChannelPicker::reposition()
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());
521 int ChannelPicker::close_threads()
523 channel_button->thread->close_threads();
527 const char* ChannelPicker::get_source_name(Channel *channel)
529 if(channel->entry < chanlists[channel->freqtable].count)
530 return chanlists[channel->freqtable].list[channel->entry].name;
532 return chanlists[channel->freqtable].list[0].name;
535 const char* ChannelPicker::current_channel_name()
537 if(get_current_channel())
539 return get_current_channel()->title;
545 int ChannelPicker::channel_down()
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);
556 int ChannelPicker::channel_up()
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);
571 PictureButton::PictureButton(ChannelPicker *channel_picker, int x, int y)
574 channel_picker->get_theme() ?
575 channel_picker->get_theme()->get_image_set("picture") :
578 this->channel_picker = channel_picker;
579 thread = new ChannelEditPictureThread(channel_picker);
580 set_tooltip(_("Edit picture"));
583 PictureButton::~PictureButton()
585 //printf("PictureButton::PictureButton %d\n", __LINE__);
587 //printf("PictureButton::PictureButton %d\n", __LINE__);
590 int PictureButton::handle_event()
593 thread->edit_picture();
594 lock_window("PictureButton::handle_event");
601 ChannelButton::ChannelButton(ChannelPicker *channel_picker,
606 channel_picker->get_theme() ?
607 channel_picker->get_theme()->get_image_set("channel") :
610 this->channel_picker = channel_picker;
611 thread = new ChannelEditThread(channel_picker,
612 channel_picker->channeldb);
613 set_tooltip(_("Edit channels"));
616 ChannelButton::~ChannelButton()
621 int ChannelButton::handle_event()
628 ChannelText::ChannelText(ChannelPicker *channel_picker,
631 : BC_PopupTextBox(channel_picker->get_subwindow(),
632 &channel_picker->channel_listitems,
633 channel_picker->current_channel_name(),
640 this->channel_picker = channel_picker;
643 ChannelText::~ChannelText()
647 int ChannelText::handle_event()
649 channel_picker->set_channel_number(get_number());
656 ChannelList::ChannelList(ChannelPicker *channel_picker, int x, int y)
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
666 0, // Pixel of top of window.
667 1) // If this listbox is a popup window
669 this->channel_picker = channel_picker;
672 ChannelList::~ChannelList()
676 int ChannelList::handle_event()
683 ChannelTumbler::ChannelTumbler(ChannelPicker *channel_picker,
688 this->channel_picker = channel_picker;
690 ChannelTumbler::~ChannelTumbler()
693 int ChannelTumbler::handle_up_event()
695 channel_picker->channel_up();
698 int ChannelTumbler::handle_down_event()
700 channel_picker->channel_down();
703 int ChannelTumbler::keypress_event()
705 if(get_keypress() == PGUP)
711 if(get_keypress() == PGDN)