r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / channelpicker.C
blob06b1a35325ccd79bab0678967a2bd3dea0e64232
1 #include "channel.h"
2 #include "channeledit.h"
3 #include "channelpicker.h"
4 #include "chantables.h"
5 #include "clip.h"
6 #include "keys.h"
7 #include "mwindow.h"
8 #include "playbackconfig.h"
9 #include "preferencesthread.h"
10 #include "record.h"
11 #include "recordmonitor.h"
12 #include "theme.h"
13 #include "vdevicebuz.h"
14 #include "vdeviceprefs.h"
16 #include <libintl.h>
17 #define _(String) gettext(String)
18 #define gettext_noop(String) String
19 #define N_(String) gettext_noop (String)
22 PrefsChannelPicker::PrefsChannelPicker(MWindow *mwindow, 
23                 VDevicePrefs *prefs, 
24                 ArrayList<Channel*> *channeldb, 
25                 int x,
26                 int y)
27  : ChannelPicker(mwindow, 
28                 0, 
29                 0,
30                 channeldb, 
31                 x,
32                 y)
34 //      printf("PrefsChannelPicker::PrefsChannelPicker 1\n");
35         this->prefs = prefs;
36         VDeviceBUZ::get_inputs(&input_sources);
39 PrefsChannelPicker::~PrefsChannelPicker()
41         input_sources.remove_all_objects();
44 BC_WindowBase* PrefsChannelPicker::get_subwindow()
46         return prefs->dialog;
49 Channel* PrefsChannelPicker::get_current_channel_struct()
51         int number = get_current_channel_number();
53         if(number >= 0 && number < channeldb->total)
54         {
55                 return channeldb->values[number];
56         }
57         return 0;
60 int PrefsChannelPicker::get_current_channel_number()
62         return prefs->out_config->buz_out_channel;
65 ArrayList<char*>* PrefsChannelPicker::get_video_inputs()
67         return &input_sources;
70 void PrefsChannelPicker::set_channel(Channel *channel)
72         if(channel)
73                 channel_text->update(channel->title);
76 void PrefsChannelPicker::set_channel_number(int number)
78 // CLAMP doesn't work
79         CLAMP(number, 0, channeldb->total - 1);
80 //printf("PrefsChannelPicker::set_channel_number %d\n", number);
81         prefs->out_config->buz_out_channel = number;
82         set_channel(get_current_channel_struct());
85 int PrefsChannelPicker::set_brightness(int value)
87         prefs->out_config->brightness = value;
90 int PrefsChannelPicker::set_hue(int value)
92         prefs->out_config->hue = value;
95 int PrefsChannelPicker::set_color(int value)
97         prefs->out_config->color = value;
100 int PrefsChannelPicker::set_contrast(int value)
102         prefs->out_config->contrast = value;
105 int PrefsChannelPicker::set_whiteness(int value)
107         prefs->out_config->whiteness = value;
110 int PrefsChannelPicker::get_brightness()
112         return prefs->out_config->brightness;
115 int PrefsChannelPicker::get_hue()
117         return prefs->out_config->hue;
120 int PrefsChannelPicker::get_color()
122         return prefs->out_config->color;
125 int PrefsChannelPicker::get_contrast()
127         return prefs->out_config->contrast;
130 int PrefsChannelPicker::get_whiteness()
132         return prefs->out_config->whiteness;
144 ChannelPicker::ChannelPicker(MWindow *mwindow, 
145                 Record *record, 
146                 RecordMonitor *record_monitor,
147                 ArrayList<Channel*> *channeldb, 
148                 int x,
149                 int y)
151         this->mwindow = mwindow;
152         this->record = record;
153         this->record_monitor = record_monitor;
154         this->x = x;
155         this->y = y;
156         this->channeldb = channeldb;
157         current_channel = new Channel;
158         channel_text = 0;
159         update_channel_list();
162 ChannelPicker::~ChannelPicker()
164         delete channel_text;
165         delete channel_select;
166         delete channel_button;
167         delete current_channel;
168         channel_listitems.remove_all_objects();
171 void ChannelPicker::update_channel_list()
173 //printf("ChannelPicker::update_channel_list 1\n");
174         channel_listitems.remove_all_objects();
175         for(int i = 0; i < channeldb->total; i++)
176         {
177                 channel_listitems.append(new BC_ListBoxItem(channeldb->values[i]->title));
178         }
180         if(channel_text)
181                 channel_text->update_list(&channel_listitems);
182 //printf("ChannelPicker::update_channel_list 2\n");
192 BC_WindowBase* ChannelPicker::get_subwindow()
194         return record_monitor->window;
197 Channel* ChannelPicker::get_current_channel_struct()
199 //printf("ChannelPicker::get_current_channel_struct 1\n");
200         return record->get_current_channel_struct();
203 int ChannelPicker::get_current_channel_number()
205         return record->get_editing_channel();
208 ArrayList<char*>* ChannelPicker::get_video_inputs() 
210         return record->get_video_inputs();
213 void ChannelPicker::set_channel_number(int number)
215         record->set_channel(number);
218 void ChannelPicker::set_channel(Channel *channel)
220         record->set_channel(channel);
223 int ChannelPicker::set_brightness(int value)
225         record->video_brightness = value;
226         record->set_video_picture();
227         return 0;
230 int ChannelPicker::set_hue(int value)
232         record->video_hue = value;
233         record->set_video_picture();
234         return 0;
237 int ChannelPicker::set_color(int value)
239         record->video_color = value;
240         record->set_video_picture();
241         return 0;
244 int ChannelPicker::set_contrast(int value)
246         record->video_contrast = value;
247         record->set_video_picture();
248         return 0;
251 int ChannelPicker::set_whiteness(int value)
253         record->video_whiteness = value;
254         record->set_video_picture();
255         return 0;
258 int ChannelPicker::get_brightness()
260         return record->video_brightness;
263 int ChannelPicker::get_hue()
265         return record->video_hue;
268 int ChannelPicker::get_color()
270         return record->video_color;
273 int ChannelPicker::get_contrast()
275         return record->video_contrast;
278 int ChannelPicker::get_whiteness()
280         return record->video_whiteness;
289 int ChannelPicker::create_objects()
291         channel_text = 0;
292         update_channel_list();
293 //printf("ChannelPicker::create_objects 1\n");
294         channel_text = new ChannelText(mwindow, this, x, y);
295 //printf("ChannelPicker::create_objects 1\n");
296         channel_text->create_objects();
297 //printf("ChannelPicker::create_objects 1\n");
298         x += channel_text->get_w();
299         get_subwindow()->add_subwindow(channel_select = new ChannelTumbler(mwindow, this, x, y));
300 //printf("ChannelPicker::create_objects 1\n");
301         x += channel_select->get_w() + 5;
302         get_subwindow()->add_subwindow(channel_button = new ChannelButton(mwindow, this, x, y - 1));
303 //printf("ChannelPicker::create_objects 2\n");
304         return 0;
307 int ChannelPicker::reposition()
309         channel_text->reposition_window(channel_text->get_x(),
310                 channel_text->get_y());
311         channel_select->reposition_window(channel_select->get_x(),
312                 channel_select->get_y());
313         channel_button->reposition_window(channel_button->get_x(),
314                 channel_button->get_y());
315         return 0;
318 int ChannelPicker::close_threads()
320         channel_button->thread->close_threads();
321         return 0;
324 char* ChannelPicker::get_source_name(Channel *channel)
326         if(channel->entry < chanlists[channel->freqtable].count)
327                 return chanlists[channel->freqtable].list[channel->entry].name;
328         else
329                 return chanlists[channel->freqtable].list[0].name;
332 char* ChannelPicker::current_channel_name()
334         if(get_current_channel_struct())
335         {
336                 return get_current_channel_struct()->title;
337         }
338         else
339                 return _("Channel");
342 int ChannelPicker::channel_down()
344         int number = get_current_channel_number() - 1;
345         if(number < 0) number = 0;
346         CLAMP(number, 0, channeldb->total - 1);
347         set_channel_number(number);
348         return 0;
351 int ChannelPicker::channel_up()
353         int number = get_current_channel_number() + 1;
354         if(number >= channeldb->total) number = channeldb->total - 1;
355         CLAMP(number, 0, channeldb->total - 1);
356         set_channel_number(number);
357         return 0;
362 ChannelButton::ChannelButton(MWindow *mwindow, ChannelPicker *channel_picker, int x, int y)
363  : BC_Button(x, y, mwindow->theme->channel_data)
365         this->channel_picker = channel_picker;
366         this->mwindow = mwindow;
367         thread = new ChannelEditThread(mwindow, 
368                 channel_picker, 
369                 channel_picker->channeldb,
370                 channel_picker->record);
371         set_tooltip(_("Edit channels"));
374 ChannelButton::~ChannelButton()
376         delete thread;
379 int ChannelButton::handle_event()
381         thread->start();
382         return 1;
386 ChannelText::ChannelText(MWindow *mwindow, 
387         ChannelPicker *channel_picker, 
388         int x, 
389         int y)
390  : BC_PopupTextBox(channel_picker->get_subwindow(),
391         &channel_picker->channel_listitems,
392         channel_picker->current_channel_name(),
393         x, 
394         y, 
395         150, 
396         300)
398         this->channel_picker = channel_picker;
399         this->mwindow = mwindow;
402 ChannelText::~ChannelText()
406 int ChannelText::handle_event()
408         channel_picker->set_channel_number(get_number());
409         return 0;
415 ChannelList::ChannelList(MWindow *mwindow, ChannelPicker *channel_picker, int x, int y)
416  : BC_ListBox(x, 
417                 y, 
418                 100, 
419                 200,
420                 LISTBOX_TEXT,                   // Display text list or icons
421                 &channel_picker->channel_listitems, // Each column has an ArrayList of BC_ListBoxItems.
422                 0,                       // Titles for columns.  Set to 0 for no titles
423                 0,                      // width of each column
424                 1,                     // Total columns.
425                 0,                    // Pixel of top of window.
426                 1)                   // If this listbox is a popup window
428         this->mwindow = mwindow;
429         this->channel_picker = channel_picker;
432 ChannelList::~ChannelList()
435         
436 int ChannelList::handle_event()
438         return 0;
443 ChannelTumbler::ChannelTumbler(MWindow *mwindow, 
444         ChannelPicker *channel_picker, 
445         int x, 
446         int y)
447  : BC_Tumbler(x, y)
449         this->mwindow = mwindow;
450         this->channel_picker = channel_picker;
452 ChannelTumbler::~ChannelTumbler()
455 int ChannelTumbler::handle_up_event()
457         channel_picker->channel_up();
458         return 1;
460 int ChannelTumbler::handle_down_event()
462         channel_picker->channel_down();
463         return 1;
465 int ChannelTumbler::keypress_event()
467         if(get_keypress() == PGUP)
468         {
469                 handle_up_event();
470                 return 1;
471         }
472         else
473         if(get_keypress() == PGDN)
474         {
475                 handle_down_event();
476                 return 1;
477         }
478         else
479         return 0;