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"
31 #include "localsession.h"
32 #include "mainsession.h"
35 #include "mwindowgui.h"
36 #include "overlayframe.inc"
39 #include "trackcanvas.h"
40 #include "vpatchgui.h"
49 VPatchGUI::VPatchGUI(MWindow *mwindow, PatchBay *patchbay, VTrack *track, int x, int y)
50 : PatchGUI(mwindow, patchbay, track, x, y)
52 data_type = TRACK_VIDEO;
58 VPatchGUI::~VPatchGUI()
64 void VPatchGUI::create_objects()
69 int VPatchGUI::reposition(int x, int y)
72 int y1 = PatchGUI::reposition(x, y);
74 if(fade) fade->reposition_window(fade->get_x(),
77 y1 += mwindow->theme->fade_h;
79 if(mode) mode->reposition_window(mode->get_x(),
82 if(nudge) nudge->reposition_window(nudge->get_x(),
86 y1 += mwindow->theme->mode_h;
91 int VPatchGUI::update(int x, int y)
93 int h = track->vertical_span(mwindow->theme);
95 int y1 = PatchGUI::update(x, y);
99 if(h - y1 < mwindow->theme->fade_h)
106 FloatAuto *previous = 0, *next = 0;
107 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
108 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
109 unit_position = vtrack->to_units(unit_position, 0);
110 int value = (int)((FloatAutos*)vtrack->automation->autos[AUTOMATION_FADE])->get_value(
111 (int64_t)unit_position,
116 // fade->update((int)fade->get_keyframe(mwindow, this)->value);
120 if(h - y1 >= mwindow->theme->fade_h)
122 patchbay->add_subwindow(fade = new VFadePatch(mwindow,
126 patchbay->get_w() - 10));
128 y1 += mwindow->theme->fade_h;
132 if(h - y1 < mwindow->theme->mode_h)
141 mode->update(mode->get_keyframe(mwindow, this)->value);
146 if(h - y1 >= mwindow->theme->mode_h)
148 patchbay->add_subwindow(mode = new VModePatch(mwindow,
152 mode->create_objects();
153 x1 += mode->get_w() + 10;
154 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
158 patchbay->get_w() - x1 - 10));
165 y1 += mwindow->theme->mode_h;
172 void VPatchGUI::synchronize_fade(float value_change)
174 if(fade && !change_source)
176 fade->update(Units::to_int64(fade->get_value() + value_change));
182 VFadePatch::VFadePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y, int w)
190 (int64_t)get_keyframe(mwindow, patch)->value)
192 this->mwindow = mwindow;
196 float VFadePatch::update_edl()
199 double position = mwindow->edl->local_session->get_selectionstart(1);
200 Autos *fade_autos = patch->vtrack->automation->autos[AUTOMATION_FADE];
201 int need_undo = !fade_autos->auto_exists_for_editing(position);
203 mwindow->undo->update_undo_before(_("fade"), need_undo ? 0 : this);
205 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
207 float result = get_value() - current->value;
208 current->value = get_value();
210 mwindow->undo->update_undo_after(_("fade"), LOAD_AUTOMATION);
215 int VFadePatch::handle_event()
220 set_tooltip(get_caption());
223 patch->change_source = 1;
225 float change = update_edl();
227 if(patch->track->gang && patch->track->record)
228 patch->patchbay->synchronize_faders(change, TRACK_VIDEO, patch->track);
230 patch->change_source = 0;
233 mwindow->gui->unlock_window();
234 mwindow->restart_brender();
235 mwindow->sync_parameters(CHANGE_PARAMS);
236 mwindow->gui->lock_window("VFadePatch::handle_event");
237 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE])
239 mwindow->gui->draw_overlays(1);
244 FloatAuto* VFadePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
246 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
247 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
248 unit_position = patch->vtrack->to_units(unit_position, 0);
251 return (FloatAuto*)patch->vtrack->automation->autos[AUTOMATION_FADE]->get_prev_auto(
252 (int64_t)unit_position,
260 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
263 patch->patchbay->mode_icons[0]->get_w() + 20,
266 mwindow->theme->get_image_set("mode_popup", 0),
269 this->mwindow = mwindow;
271 this->mode = get_keyframe(mwindow, patch)->value;
272 set_icon(patch->patchbay->mode_to_icon(this->mode));
273 set_tooltip(_("Overlay mode"));
276 int VModePatch::handle_event()
279 // for(int i = 0; i < total_items(); i++)
281 // VModePatchItem *item = (VModePatchItem*)get_item(i);
282 // if(item->mode == mode)
283 // item->set_checked(1);
285 // item->set_checked(0);
291 double position = mwindow->edl->local_session->get_selectionstart(1);
292 Autos *mode_autos = patch->vtrack->automation->autos[AUTOMATION_MODE];
293 int need_undo = !mode_autos->auto_exists_for_editing(position);
295 mwindow->undo->update_undo_before(_("mode"), need_undo ? 0 : this);
297 current = (IntAuto*)mode_autos->get_auto_for_editing(position);
298 current->value = mode;
300 mwindow->undo->update_undo_after(_("mode"), LOAD_AUTOMATION);
302 mwindow->sync_parameters(CHANGE_PARAMS);
304 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MODE])
306 mwindow->gui->draw_overlays(1);
308 mwindow->session->changes_made = 1;
312 IntAuto* VModePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
315 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
316 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
317 unit_position = patch->vtrack->to_units(unit_position, 0);
319 return (IntAuto*)patch->vtrack->automation->autos[AUTOMATION_MODE]->get_prev_auto(
320 (int64_t)unit_position,
326 void VModePatch::create_objects()
328 for( int mode=0; mode<TRANSFER_TYPES; ++mode )
329 add_item(new VModePatchItem(this, mode_to_text(mode), mode));
332 void VModePatch::update(int mode)
334 set_icon(patch->patchbay->mode_to_icon(mode));
335 for(int i = 0; i < total_items(); i++)
337 VModePatchItem *item = (VModePatchItem*)get_item(i);
338 item->set_checked(item->mode == mode);
343 const char* VModePatch::mode_to_text(int mode)
346 case TRANSFER_NORMAL: return _("Normal");
347 case TRANSFER_ADDITION: return _("Addition");
348 case TRANSFER_SUBTRACT: return _("Subtract");
349 case TRANSFER_MULTIPLY: return _("Multiply");
350 case TRANSFER_DIVIDE: return _("Divide");
351 case TRANSFER_REPLACE: return _("Replace");
352 case TRANSFER_MAX: return _("Max");
353 case TRANSFER_MIN: return _("Min");
354 case TRANSFER_AVERAGE: return _("Average");
355 case TRANSFER_DARKEN: return _("Darken");
356 case TRANSFER_LIGHTEN: return _("Lighten");
357 case TRANSFER_DST: return _("Dst");
358 case TRANSFER_DST_ATOP: return _("DstAtop");
359 case TRANSFER_DST_IN: return _("DstIn");
360 case TRANSFER_DST_OUT: return _("DstOut");
361 case TRANSFER_DST_OVER: return _("DstOver");
362 case TRANSFER_SRC: return _("Src");
363 case TRANSFER_SRC_ATOP: return _("SrcAtop");
364 case TRANSFER_SRC_IN: return _("SrcIn");
365 case TRANSFER_SRC_OUT: return _("SrcOut");
366 case TRANSFER_SRC_OVER: return _("SrcOver");
367 case TRANSFER_OR: return _("Or");
368 case TRANSFER_XOR: return _("Xor");
375 VModePatchItem::VModePatchItem(VModePatch *popup, const char *text, int mode)
380 if(this->mode == popup->mode) set_checked(1);
383 int VModePatchItem::handle_event()
386 // popup->set_icon(popup->patch->patchbay->mode_to_icon(mode));
387 popup->handle_event();