4 * Copyright (C) 1997-2014 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 "automation.h"
25 #include "edlsession.h"
26 #include "floatauto.h"
27 #include "floatautos.h"
28 #include "gwindowgui.h"
32 #include "localsession.h"
33 #include "mainsession.h"
36 #include "mwindowgui.h"
37 #include "overlayframe.inc"
40 #include "trackcanvas.h"
41 #include "vpatchgui.h"
48 VPatchGUI::VPatchGUI(MWindow *mwindow, PatchBay *patchbay, VTrack *track, int x, int y)
49 : PatchGUI(mwindow, patchbay, track, x, y)
51 data_type = TRACK_VIDEO;
57 VPatchGUI::~VPatchGUI()
59 if( fade ) delete fade;
60 if( mode ) delete mode;
63 void VPatchGUI::create_objects()
68 int VPatchGUI::reposition(int x, int y)
71 int y1 = PatchGUI::reposition(x, y);
74 fade->reposition_window(fade->get_x(), y1+y);
75 y1 += mwindow->theme->fade_h;
77 mix->reposition_window(mix->get_x(), y1+y);
79 mode->reposition_window(mode->get_x(), y1+y);
81 nudge->reposition_window(nudge->get_x(), y1+y);
82 y1 += mwindow->theme->mode_h;
86 int VPatchGUI::update(int x, int y)
88 int h = track->vertical_span(mwindow->theme);
90 int y1 = PatchGUI::update(x, y);
92 int y2 = y1 + mwindow->theme->fade_h;
95 delete fade; fade = 0;
98 fade->update(fade->get_w(), mwindow->get_float_auto(this, AUTOMATION_FADE)->get_value(),
99 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_VIDEO_FADE],
100 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_VIDEO_FADE]);
104 patchbay->add_subwindow(fade = new VFadePatch(mwindow, this, x1+x, y1+y,
105 patchbay->get_w() - 10));
109 y2 = y1 + mwindow->theme->mode_h;
113 delete mode; mode = 0;
114 delete nudge; nudge = 0;
117 if( mwindow->session->selected_zwindow >= 0 ) {
118 int v = mwindow->mixer_track_active(track);
121 mode->update(mwindow->get_int_auto(this, AUTOMATION_MODE)->value);
126 patchbay->add_subwindow(mix = new VMixPatch(mwindow, this, x1+x, y1+y+5));
128 patchbay->add_subwindow(mode = new VModePatch(mwindow, this, x1+x, y1+y));
129 mode->create_objects();
131 patchbay->add_subwindow(nudge = new NudgePatch(mwindow, this, x1+x, y1+y,
132 patchbay->get_w() - x1-x - 10));
140 void VPatchGUI::synchronize_fade(float value_change)
142 if( fade && !change_source ) {
143 fade->update(Units::to_int64(fade->get_value() + value_change));
149 VFadePatch::VFadePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y, int w)
150 : BC_ISlider(x, y, 0, w, w,
151 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_VIDEO_FADE],
152 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_VIDEO_FADE],
153 (int64_t)mwindow->get_float_auto(patch,AUTOMATION_FADE)->get_value())
155 this->mwindow = mwindow;
159 float VFadePatch::update_edl()
162 double position = mwindow->edl->local_session->get_selectionstart(1);
163 Autos *fade_autos = patch->vtrack->automation->autos[AUTOMATION_FADE];
164 int need_undo = !fade_autos->auto_exists_for_editing(position);
166 mwindow->undo->update_undo_before(_("fade"), need_undo ? 0 : this);
168 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
170 float result = get_value() - current->get_value();
171 current->set_value(get_value());
173 mwindow->undo->update_undo_after(_("fade"), LOAD_AUTOMATION);
178 int VFadePatch::handle_event()
182 set_tooltip(get_caption());
185 patch->change_source = 1;
187 float change = update_edl();
189 if( patch->track->gang && patch->track->record )
190 patch->patchbay->synchronize_faders(change, TRACK_VIDEO, patch->track);
192 patch->change_source = 0;
195 mwindow->gui->unlock_window();
196 mwindow->restart_brender();
197 mwindow->sync_parameters(CHANGE_PARAMS);
198 mwindow->gui->lock_window("VFadePatch::handle_event");
199 if( mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE] ) {
200 mwindow->gui->draw_overlays(1);
206 VKeyFadePatch::VKeyFadePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
207 : BC_SubWindow(x,y, patch->patchbay->get_w(),20,
208 GWindowGUI::auto_colors[AUTOMATION_FADE])
210 this->mwindow = mwindow;
214 void VKeyFadePatch::create_objects()
216 vkey_fade_value = new VKeyFadeValue(this);
217 add_subwindow(vkey_fade_value);
218 vkey_fade_value->activate();
222 VKeyFadeValue::VKeyFadeValue(VKeyFadePatch *vkey_fade_patch)
223 : VFadePatch(vkey_fade_patch->mwindow, vkey_fade_patch->patch,
224 0,0, vkey_fade_patch->get_w())
226 this->vkey_fade_patch = vkey_fade_patch;
229 int VKeyFadeValue::button_release_event()
231 VFadePatch::button_release_event();
235 int VKeyFadeValue::handle_event()
237 VPatchGUI *patch = vkey_fade_patch->patch;
238 int ret = VFadePatch::handle_event();
239 VFadePatch *fade = patch->fade;
241 fade->update(get_value());
246 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
247 : BC_PopupMenu(x, y, patch->patchbay->mode_icons[0]->get_w() + 20,
248 "", 1, mwindow->theme->get_image_set("mode_popup", 0), 10)
250 this->mwindow = mwindow;
252 this->mode = mwindow->get_int_auto(patch, AUTOMATION_MODE)->value;
253 set_icon(patch->patchbay->mode_to_icon(this->mode));
254 set_tooltip(_("Overlay mode"));
257 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch)
258 : BC_PopupMenu(0, 0, 0, "", 0)
260 this->mwindow = mwindow;
262 this->mode = mwindow->get_int_auto(patch, AUTOMATION_MODE)->value;
266 int VModePatch::handle_event()
269 // for( int i = 0; i < total_items(); i++ )
271 // VModePatchItem *item = (VModePatchItem*)get_item(i);
272 // if( item->mode == mode )
273 // item->set_checked(1);
275 // item->set_checked(0);
281 double position = mwindow->edl->local_session->get_selectionstart(1);
282 Autos *mode_autos = patch->vtrack->automation->autos[AUTOMATION_MODE];
283 int need_undo = !mode_autos->auto_exists_for_editing(position);
285 mwindow->undo->update_undo_before(_("mode"), need_undo ? 0 : this);
287 current = (IntAuto*)mode_autos->get_auto_for_editing(position);
288 current->value = mode;
290 mwindow->undo->update_undo_after(_("mode"), LOAD_AUTOMATION);
292 mwindow->sync_parameters(CHANGE_PARAMS);
294 if( mwindow->edl->session->auto_conf->autos[AUTOMATION_MODE] ) {
295 mwindow->gui->draw_overlays(1);
297 mwindow->session->changes_made = 1;
301 void VModePatch::create_objects()
303 VModePatchItem *mode_item;
304 VModePatchSubMenu *submenu;
305 add_item(mode_item = new VModePatchItem(this, mode_to_text(TRANSFER_NORMAL), TRANSFER_NORMAL));
306 add_item(mode_item = new VModePatchItem(this, _("Arithmetic..."), -1));
307 mode_item->add_submenu(submenu = new VModePatchSubMenu(mode_item));
308 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_ADDITION), TRANSFER_ADDITION));
309 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SUBTRACT), TRANSFER_SUBTRACT));
310 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DIVIDE), TRANSFER_DIVIDE));
311 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_MULTIPLY), TRANSFER_MULTIPLY));
312 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_REPLACE), TRANSFER_REPLACE));
313 add_item(mode_item = new VModePatchItem(this, _("PorterDuff..."), -1));
314 mode_item->add_submenu(submenu = new VModePatchSubMenu(mode_item));
315 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DST), TRANSFER_DST));
316 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DST_ATOP), TRANSFER_DST_ATOP));
317 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DST_IN), TRANSFER_DST_IN));
318 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DST_OUT), TRANSFER_DST_OUT));
319 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DST_OVER), TRANSFER_DST_OVER));
320 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SRC), TRANSFER_SRC));
321 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SRC_ATOP), TRANSFER_SRC_ATOP));
322 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SRC_IN), TRANSFER_SRC_IN));
323 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SRC_OUT), TRANSFER_SRC_OUT));
324 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SRC_OVER), TRANSFER_SRC_OVER));
325 add_item(mode_item = new VModePatchItem(this, _("Logical..."), -1));
326 mode_item->add_submenu(submenu = new VModePatchSubMenu(mode_item));
327 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_MIN), TRANSFER_MIN));
328 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_MAX), TRANSFER_MAX));
329 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DARKEN), TRANSFER_DARKEN));
330 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_LIGHTEN), TRANSFER_LIGHTEN));
331 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_AND), TRANSFER_AND));
332 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_OR), TRANSFER_OR));
333 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_XOR), TRANSFER_XOR));
334 add_item(mode_item = new VModePatchItem(this, _("Graphic Art..."), -1));
335 mode_item->add_submenu(submenu = new VModePatchSubMenu(mode_item));
336 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_OVERLAY), TRANSFER_OVERLAY));
337 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SCREEN), TRANSFER_SCREEN));
338 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_BURN), TRANSFER_BURN));
339 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DODGE), TRANSFER_DODGE));
340 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_DIFFERENCE),TRANSFER_DIFFERENCE));
341 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_HARDLIGHT),TRANSFER_HARDLIGHT));
342 submenu->add_submenuitem(new VModeSubMenuItem(submenu, mode_to_text(TRANSFER_SOFTLIGHT),TRANSFER_SOFTLIGHT));
345 void VModePatch::update(int mode)
347 set_icon(patch->patchbay->mode_to_icon(mode));
348 for( int i = 0; i < total_items(); i++ ) {
349 VModePatchItem *item = (VModePatchItem*)get_item(i);
350 item->set_checked(item->mode == mode);
351 VModePatchSubMenu *submenu = (VModePatchSubMenu *)item->get_submenu();
352 if( !submenu ) continue;
353 int n = submenu->total_items();
354 for( int j=0; j<n; ++j ) {
355 VModePatchItem *subitem = (VModePatchItem*)submenu->get_item(j);
356 subitem->set_checked(subitem->mode == mode);
362 const char* VModePatch::mode_to_text(int mode)
365 case TRANSFER_NORMAL: return _("Normal");
366 case TRANSFER_ADDITION: return _("Addition");
367 case TRANSFER_SUBTRACT: return _("Subtract");
368 case TRANSFER_MULTIPLY: return _("Multiply");
369 case TRANSFER_DIVIDE: return _("Divide");
370 case TRANSFER_REPLACE: return _("Replace");
371 case TRANSFER_MAX: return _("Max");
372 case TRANSFER_MIN: return _("Min");
373 case TRANSFER_DARKEN: return _("Darken");
374 case TRANSFER_LIGHTEN: return _("Lighten");
375 case TRANSFER_DST: return _("Dst");
376 case TRANSFER_DST_ATOP: return _("DstAtop");
377 case TRANSFER_DST_IN: return _("DstIn");
378 case TRANSFER_DST_OUT: return _("DstOut");
379 case TRANSFER_DST_OVER: return _("DstOver");
380 case TRANSFER_SRC: return _("Src");
381 case TRANSFER_SRC_ATOP: return _("SrcAtop");
382 case TRANSFER_SRC_IN: return _("SrcIn");
383 case TRANSFER_SRC_OUT: return _("SrcOut");
384 case TRANSFER_SRC_OVER: return _("SrcOver");
385 case TRANSFER_AND: return _("AND");
386 case TRANSFER_OR: return _("OR");
387 case TRANSFER_XOR: return _("XOR");
388 case TRANSFER_OVERLAY: return _("Overlay");
389 case TRANSFER_SCREEN: return _("Screen");
390 case TRANSFER_BURN: return _("Burn");
391 case TRANSFER_DODGE: return _("Dodge");
392 case TRANSFER_HARDLIGHT: return _("Hardlight");
393 case TRANSFER_SOFTLIGHT: return _("Softlight");
394 case TRANSFER_DIFFERENCE: return _("Difference");
401 VModePatchItem::VModePatchItem(VModePatch *popup, const char *text, int mode)
406 if( this->mode == popup->mode ) set_checked(1);
409 int VModePatchItem::handle_event()
413 // popup->set_icon(popup->patch->patchbay->mode_to_icon(mode));
414 popup->handle_event();
419 VModePatchSubMenu::VModePatchSubMenu(VModePatchItem *mode_item)
421 this->mode_item = mode_item;
423 VModePatchSubMenu::~VModePatchSubMenu()
427 VModeSubMenuItem::VModeSubMenuItem(VModePatchSubMenu *submenu, const char *text, int mode)
430 this->submenu = submenu;
432 VModePatch *popup = submenu->mode_item->popup;
433 if( this->mode == popup->mode ) set_checked(1);
435 VModeSubMenuItem::~VModeSubMenuItem()
439 int VModeSubMenuItem::handle_event()
441 VModePatch *popup = submenu->mode_item->popup;
443 // popup->set_icon(popup->patch->patchbay->mode_to_icon(mode));
444 popup->handle_event();
449 VKeyModePatch::VKeyModePatch(MWindow *mwindow, VPatchGUI *patch)
450 : VModePatch(mwindow, patch)
454 int VKeyModePatch::button_release_event()
456 VModePatch::button_release_event();
460 int VKeyModePatch::handle_event()
462 int ret = VModePatch::handle_event();
463 VModePatch *mode = patch->mode;
465 mode->update(this->mode);
470 VMixPatch::VMixPatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
471 : MixPatch(mwindow, patch, x, y)
473 set_tooltip(_("Mixer"));
476 VMixPatch::~VMixPatch()