rework proxy scaler, fix crop-gui coord, video_data tweak for proxy_format
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / vpatchgui.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2014 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 "autoconf.h"
23 #include "automation.h"
24 #include "edl.h"
25 #include "edlsession.h"
26 #include "floatauto.h"
27 #include "floatautos.h"
28 #include "gwindowgui.h"
29 #include "intauto.h"
30 #include "intautos.h"
31 #include "keys.h"
32 #include "language.h"
33 #include "localsession.h"
34 #include "mainsession.h"
35 #include "mainundo.h"
36 #include "mwindow.h"
37 #include "mwindowgui.h"
38 #include "overlayframe.inc"
39 #include "patchbay.h"
40 #include "theme.h"
41 #include "trackcanvas.h"
42 #include "vpatchgui.h"
43 #include "vtrack.h"
44 #include "vwindow.h"
45
46 #include <string.h>
47
48
49 VPatchGUI::VPatchGUI(MWindow *mwindow, PatchBay *patchbay, VTrack *track, int x, int y)
50  : PatchGUI(mwindow, patchbay, track, x, y)
51 {
52         data_type = TRACK_VIDEO;
53         this->vtrack = track;
54         mode = 0;
55         fade = 0;
56 }
57
58 VPatchGUI::~VPatchGUI()
59 {
60         if( fade ) delete fade;
61         if( mode ) delete mode;
62 }
63
64 void VPatchGUI::create_objects()
65 {
66         update(x, y);
67 }
68
69 int VPatchGUI::reposition(int x, int y)
70 {
71         //int x1 = 0;
72         int y1 = PatchGUI::reposition(x, y);
73
74         if( fade )
75                 fade->reposition_window(fade->get_x(), y1+y);
76         y1 += mwindow->theme->fade_h;
77         if( mix )
78                 mix->reposition_window(mix->get_x(), y1+y);
79         if( mode )
80                 mode->reposition_window(mode->get_x(), y1+y);
81         if( nudge )
82                 nudge->reposition_window(nudge->get_x(), y1+y);
83         y1 += mwindow->theme->mode_h;
84         return y1;
85 }
86
87 int VPatchGUI::update(int x, int y)
88 {
89         int h = track->vertical_span(mwindow->theme);
90         int x1 = 0;
91         int y1 = PatchGUI::update(x, y);
92
93         int y2 = y1 + mwindow->theme->fade_h;
94         if( fade ) {
95                 if( h < y2 ) {
96                         delete fade;  fade = 0;
97                 }
98                 else {
99                         FloatAuto *previous = 0, *next = 0;
100                         double unit_position = mwindow->edl->local_session->get_selectionstart(1);
101                         int64_t unit_pos = vtrack->to_units(unit_position, 0);
102                         FloatAutos *ptr = (FloatAutos*)track->automation->autos[AUTOMATION_FADE];
103                         float value = ptr->get_value(unit_pos, PLAY_FORWARD, previous, next);
104                         fade->update(fade->get_w(), value,
105                                      mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_VIDEO_FADE],
106                                      mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_VIDEO_FADE]);
107                 }
108         }
109         else if( h >= y2 ) {
110                 int64_t v = mwindow->get_float_auto(this, AUTOMATION_FADE)->get_value();
111                 patchbay->add_subwindow(fade = new VFadePatch(this, x1+x, y1+y,
112                         patchbay->get_w() - 10, v));
113         }
114         y1 = y2;
115
116         y2 = y1 + mwindow->theme->mode_h;
117         if( mode ) {
118                 if( h < y2 ) {
119                         delete mix;    mix = 0;
120                         delete mode;   mode = 0;
121                         delete nudge;  nudge = 0;
122                 }
123                 else {
124                         if( mwindow->session->selected_zwindow >= 0 ) {
125                                 int v = mwindow->mixer_track_active(track);
126                                 mix->update(v);
127                         }
128                         mode->update(mwindow->get_int_auto(this, AUTOMATION_MODE)->value);
129                         nudge->update();
130                 }
131         }
132         else if( h >= y2 ) {
133                 patchbay->add_subwindow(mix = new VMixPatch(mwindow, this, x1+x, y1+y+5));
134                 x1 += mix->get_w();
135                 patchbay->add_subwindow(mode = new VModePatch(mwindow, this, x1+x, y1+y));
136                 mode->create_objects();
137                 x1 += mode->get_w();
138                 patchbay->add_subwindow(nudge = new NudgePatch(mwindow, this, x1+x, y1+y,
139                         patchbay->get_w() - x1-x - 10));
140         }
141         y1 = y2;
142
143         return y1;
144 }
145
146 VFadePatch::VFadePatch(VPatchGUI *patch, int x, int y, int w, int64_t v)
147  : BC_ISlider(x, y, 0, w, w,
148                 patch->mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_VIDEO_FADE],
149                 patch->mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_VIDEO_FADE],
150                 v)
151 {
152         this->patch = patch;
153 }
154
155 void VPatchGUI::update_faders(float v)
156 {
157         if( fade )
158                 fade->update(v);
159
160         change_source = 1;
161         double position = mwindow->edl->local_session->get_selectionstart(1);
162         Autos *fade_autos = vtrack->automation->autos[AUTOMATION_FADE];
163         int need_undo = !fade_autos->auto_exists_for_editing(position);
164
165         mwindow->undo->update_undo_before(_("fade"), need_undo ? 0 : this);
166         FloatAuto *current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
167         float change = v - current->get_value();
168         current->set_value(v);
169
170         if( track->gang && track->record )
171                 patchbay->synchronize_faders(change, TRACK_AUDIO, track);
172         mwindow->undo->update_undo_after(_("fade"), LOAD_AUTOMATION);
173         change_source = 0;
174
175         mwindow->sync_parameters(CHANGE_PARAMS);
176
177         if( mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE] ) {
178                 mwindow->gui->draw_overlays(1);
179         }
180 }
181
182 int VFadePatch::handle_event()
183 {
184         if( shift_down() ) {
185                 update(100);
186                 set_tooltip(get_caption());
187         }
188         patch->update_faders(get_value());
189         return 1;
190 }
191
192 VKeyFadePatch::VKeyFadePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
193  : BC_SubWindow(x,y, 200,20, GWindowGUI::auto_colors[AUTOMATION_FADE])
194 {
195         this->mwindow = mwindow;
196         this->patch = patch;
197 }
198
199 void VKeyFadePatch::create_objects()
200 {
201         int x = 0, y = 0;
202         int64_t v = mwindow->get_float_auto(patch, AUTOMATION_FADE)->get_value();
203         add_subwindow(vkey_fade_text = new VKeyFadeText(this, x, y, 64, v));
204         x += vkey_fade_text->get_w();
205         VFrame **lok_images = mwindow->theme->get_image_set("lok");
206         int w1 = get_w() - x - lok_images[0]->get_w();
207         add_subwindow(vkey_fade_slider = new VKeyFadeSlider(this, x, y, w1, v));
208         x += vkey_fade_slider->get_w();
209         add_subwindow(vkey_fade_ok = new VKeyFadeOK(this, x, y, lok_images));
210         activate();
211         show_window();
212 }
213
214 void VKeyFadePatch::update(int64_t v)
215 {
216         vkey_fade_text->update(v);
217         vkey_fade_slider->update(v);
218         patch->update_faders(v);
219 }
220
221 VKeyFadeOK::VKeyFadeOK(VKeyFadePatch *vkey_fade_patch, int x, int y, VFrame **images)
222  : BC_Button(x, y, images)
223 {
224         this->vkey_fade_patch = vkey_fade_patch;
225 }
226
227 int VKeyFadeOK::handle_event()
228 {
229         MWindowGUI *mgui = vkey_fade_patch->mwindow->gui;
230         delete mgui->keyvalue_popup;
231         mgui->keyvalue_popup = 0;
232         return 1;
233 }
234
235 VKeyFadeText::VKeyFadeText(VKeyFadePatch *vkey_fade_patch, int x, int y, int w, int64_t v)
236  : BC_TextBox(x, y, w, 1, v, 1, MEDIUMFONT)
237 {
238         this->vkey_fade_patch = vkey_fade_patch;
239 }
240
241 int VKeyFadeText::handle_event()
242 {
243         int64_t v = atoi(get_text());
244         vkey_fade_patch->update(v);
245         return get_keypress() != RETURN ? 1 :
246                 vkey_fade_patch->vkey_fade_ok->handle_event();
247 }
248
249 VKeyFadeSlider::VKeyFadeSlider(VKeyFadePatch *vkey_fade_patch,
250         int x, int y, int w, int64_t v)
251  : VFadePatch(vkey_fade_patch->patch, x,y, w, v)
252 {
253         this->vkey_fade_patch = vkey_fade_patch;
254 }
255
256 int VKeyFadeSlider::handle_event()
257 {
258         int64_t v = get_value();
259         vkey_fade_patch->update(v);
260         return 1;
261 }
262
263
264 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
265  : BC_PopupMenu(x, y, patch->patchbay->mode_icons[0]->get_w() + 20,
266         "", 1, mwindow->theme->get_image_set("mode_popup", 0), 0)
267 {
268         this->mwindow = mwindow;
269         this->patch = patch;
270         this->mode = mwindow->get_int_auto(patch, AUTOMATION_MODE)->value;
271         set_icon(patch->patchbay->mode_to_icon(this->mode));
272         set_tooltip(_("Overlay mode"));
273 }
274
275 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch)
276  : BC_PopupMenu(0, 0, 0, "", 0)
277 {
278         this->mwindow = mwindow;
279         this->patch = patch;
280         this->mode = mwindow->get_int_auto(patch, AUTOMATION_MODE)->value;
281 }
282
283
284 int VModePatch::handle_event()
285 {
286 // Set menu items
287 //      for( int i = 0; i < total_items(); i++ )
288 //      {
289 //              VModePatchItem *item = (VModePatchItem*)get_item(i);
290 //              if( item->mode == mode )
291 //                      item->set_checked(1);
292 //              else
293 //                      item->set_checked(0);
294 //      }
295         update(mode);
296
297 // Set keyframe
298         IntAuto *current;
299         double position = mwindow->edl->local_session->get_selectionstart(1);
300         Autos *mode_autos = patch->vtrack->automation->autos[AUTOMATION_MODE];
301         int need_undo = !mode_autos->auto_exists_for_editing(position);
302
303         mwindow->undo->update_undo_before(_("mode"), need_undo ? 0 : this);
304
305         current = (IntAuto*)mode_autos->get_auto_for_editing(position);
306         current->value = mode;
307
308         mwindow->undo->update_undo_after(_("mode"), LOAD_AUTOMATION);
309
310         mwindow->sync_parameters(CHANGE_PARAMS);
311
312         if( mwindow->edl->session->auto_conf->autos[AUTOMATION_MODE] ) {
313                 mwindow->gui->draw_overlays(1);
314         }
315         mwindow->session->changes_made = 1;
316         return 1;
317 }
318
319 void VModePatch::create_objects()
320 {
321         VModePatchItem *mode_item;
322         VModePatchSubMenu *submenu;
323         add_item(mode_item = new VModePatchItem(this, mode_to_text(TRANSFER_NORMAL),  TRANSFER_NORMAL));
324         add_item(mode_item = new VModePatchItem(this, _("Arithmetic..."), -1));
325         mode_item->add_submenu(submenu = new VModePatchSubMenu(mode_item));
326         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_ADDITION), TRANSFER_ADDITION));
327         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SUBTRACT), TRANSFER_SUBTRACT));
328         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DIVIDE),   TRANSFER_DIVIDE));
329         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_MULTIPLY), TRANSFER_MULTIPLY));
330         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_REPLACE),  TRANSFER_REPLACE));
331         add_item(mode_item = new VModePatchItem(this, _("PorterDuff..."), -1));
332         mode_item->add_submenu(submenu = new VModePatchSubMenu(mode_item));
333         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DST),      TRANSFER_DST));
334         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DST_ATOP), TRANSFER_DST_ATOP));
335         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DST_IN),   TRANSFER_DST_IN));
336         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DST_OUT),  TRANSFER_DST_OUT));
337         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DST_OVER), TRANSFER_DST_OVER));
338         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SRC),      TRANSFER_SRC));
339         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SRC_ATOP), TRANSFER_SRC_ATOP));
340         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SRC_IN),   TRANSFER_SRC_IN));
341         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SRC_OUT),  TRANSFER_SRC_OUT));
342         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SRC_OVER), TRANSFER_SRC_OVER));
343         add_item(mode_item = new VModePatchItem(this, _("Logical..."), -1));
344         mode_item->add_submenu(submenu = new VModePatchSubMenu(mode_item));
345         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_MIN),      TRANSFER_MIN));
346         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_MAX),      TRANSFER_MAX));
347         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DARKEN),   TRANSFER_DARKEN));
348         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_LIGHTEN),  TRANSFER_LIGHTEN));
349         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_AND),      TRANSFER_AND));
350         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_OR),       TRANSFER_OR));
351         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_XOR),      TRANSFER_XOR));
352         add_item(mode_item = new VModePatchItem(this, _("Graphic Art..."), -1));
353         mode_item->add_submenu(submenu = new VModePatchSubMenu(mode_item));
354         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_OVERLAY),  TRANSFER_OVERLAY));
355         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SCREEN),   TRANSFER_SCREEN));
356         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_BURN),     TRANSFER_BURN));
357         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DODGE),    TRANSFER_DODGE));
358         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DIFFERENCE),TRANSFER_DIFFERENCE));
359         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_HARDLIGHT),TRANSFER_HARDLIGHT));
360         submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SOFTLIGHT),TRANSFER_SOFTLIGHT));
361 }
362
363 void VModePatch::update(int mode)
364 {
365         set_icon(patch->patchbay->mode_to_icon(mode));
366         for( int i = 0; i < total_items(); i++ ) {
367                 VModePatchItem *item = (VModePatchItem*)get_item(i);
368                 item->set_checked(item->mode == mode);
369                 VModePatchSubMenu *submenu = (VModePatchSubMenu *)item->get_submenu();
370                 if( !submenu ) continue;
371                 int n = submenu->total_items();
372                 for( int j=0; j<n; ++j ) {
373                         VModePatchItem *subitem = (VModePatchItem*)submenu->get_item(j);
374                         subitem->set_checked(subitem->mode == mode);
375                 }
376         }
377 }
378
379
380 const char* VModePatch::mode_to_text(int mode)
381 {
382         switch( mode ) {
383         case TRANSFER_NORMAL:           return _("Normal");
384         case TRANSFER_ADDITION:         return _("Addition");
385         case TRANSFER_SUBTRACT:         return _("Subtract");
386         case TRANSFER_MULTIPLY:         return _("Multiply");
387         case TRANSFER_DIVIDE:           return _("Divide");
388         case TRANSFER_REPLACE:          return _("Replace");
389         case TRANSFER_MAX:              return _("Max");
390         case TRANSFER_MIN:              return _("Min");
391         case TRANSFER_DARKEN:           return _("Darken");
392         case TRANSFER_LIGHTEN:          return _("Lighten");
393         case TRANSFER_DST:              return _("Dst");
394         case TRANSFER_DST_ATOP:         return _("DstAtop");
395         case TRANSFER_DST_IN:           return _("DstIn");
396         case TRANSFER_DST_OUT:          return _("DstOut");
397         case TRANSFER_DST_OVER:         return _("DstOver");
398         case TRANSFER_SRC:              return _("Src");
399         case TRANSFER_SRC_ATOP:         return _("SrcAtop");
400         case TRANSFER_SRC_IN:           return _("SrcIn");
401         case TRANSFER_SRC_OUT:          return _("SrcOut");
402         case TRANSFER_SRC_OVER:         return _("SrcOver");
403         case TRANSFER_AND:              return _("AND");
404         case TRANSFER_OR:               return _("OR");
405         case TRANSFER_XOR:              return _("XOR");
406         case TRANSFER_OVERLAY:          return _("Overlay");
407         case TRANSFER_SCREEN:           return _("Screen");
408         case TRANSFER_BURN:             return _("Burn");
409         case TRANSFER_DODGE:            return _("Dodge");
410         case TRANSFER_HARDLIGHT:        return _("Hardlight");
411         case TRANSFER_SOFTLIGHT:        return _("Softlight");
412         case TRANSFER_DIFFERENCE:       return _("Difference");
413         }
414         return _("Normal");
415 }
416
417
418
419 VModePatchItem::VModePatchItem(VModePatch *popup, const char *text, int mode)
420  : BC_MenuItem(text)
421 {
422         this->popup = popup;
423         this->mode = mode;
424         if( this->mode == popup->mode ) set_checked(1);
425 }
426
427 int VModePatchItem::handle_event()
428 {
429         if( mode >= 0 ) {
430                 popup->mode = mode;
431 //              popup->set_icon(popup->patch->patchbay->mode_to_icon(mode));
432                 popup->handle_event();
433         }
434         return 1;
435 }
436
437 VModePatchSubMenu::VModePatchSubMenu(VModePatchItem *mode_item)
438 {
439         this->mode_item = mode_item;
440 }
441 VModePatchSubMenu::~VModePatchSubMenu()
442 {
443 }
444
445 VModeSubMenuItem::VModeSubMenuItem(VModePatchSubMenu *submenu, const char *text, int mode)
446  : BC_MenuItem(text)
447 {
448         this->submenu = submenu;
449         this->mode = mode;
450         VModePatch *popup = submenu->mode_item->popup;
451         if( this->mode == popup->mode ) set_checked(1);
452 }
453 VModeSubMenuItem::~VModeSubMenuItem()
454 {
455 }
456
457 int VModeSubMenuItem::handle_event()
458 {
459         VModePatch *popup = submenu->mode_item->popup;
460         popup->mode = mode;
461 //      popup->set_icon(popup->patch->patchbay->mode_to_icon(mode));
462         popup->handle_event();
463         return 1;
464 }
465
466
467 VKeyModePatch::VKeyModePatch(MWindow *mwindow, VPatchGUI *patch)
468  : VModePatch(mwindow, patch)
469 {
470 }
471
472 int VKeyModePatch::handle_event()
473 {
474         int ret = VModePatch::handle_event();
475         VModePatch *mode = patch->mode;
476         if( mode )
477                 mode->update(this->mode);
478         return ret;
479 }
480
481
482 VMixPatch::VMixPatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
483  : MixPatch(mwindow, patch, x, y)
484 {
485         set_tooltip(_("Mixer"));
486 }
487
488 VMixPatch::~VMixPatch()
489 {
490 }
491