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, PLAY_FORWARD, previous, next);
112 fade->update(fade->get_w(), value,
113 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_VIDEO_FADE],
114 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_VIDEO_FADE]);
115 // fade->update((int)fade->get_keyframe(mwindow, this)->value);
119 if(h - y1 >= mwindow->theme->fade_h)
121 patchbay->add_subwindow(fade = new VFadePatch(mwindow,
125 patchbay->get_w() - 10));
127 y1 += mwindow->theme->fade_h;
131 if(h - y1 < mwindow->theme->mode_h)
140 mode->update(mode->get_keyframe(mwindow, this)->value);
145 if(h - y1 >= mwindow->theme->mode_h)
147 patchbay->add_subwindow(mode = new VModePatch(mwindow,
151 mode->create_objects();
152 x1 += mode->get_w() + 10;
153 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
157 patchbay->get_w() - x1 - 10));
164 y1 += mwindow->theme->mode_h;
171 void VPatchGUI::synchronize_fade(float value_change)
173 if(fade && !change_source)
175 fade->update(Units::to_int64(fade->get_value() + value_change));
181 VFadePatch::VFadePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y, int w)
187 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_VIDEO_FADE],
188 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_VIDEO_FADE],
189 (int64_t)get_keyframe(mwindow, patch)->get_value())
191 this->mwindow = mwindow;
195 float VFadePatch::update_edl()
198 double position = mwindow->edl->local_session->get_selectionstart(1);
199 Autos *fade_autos = patch->vtrack->automation->autos[AUTOMATION_FADE];
200 int need_undo = !fade_autos->auto_exists_for_editing(position);
202 mwindow->undo->update_undo_before(_("fade"), need_undo ? 0 : this);
204 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
206 float result = get_value() - current->get_value();
207 current->set_value(get_value());
209 mwindow->undo->update_undo_after(_("fade"), LOAD_AUTOMATION);
214 int VFadePatch::handle_event()
219 set_tooltip(get_caption());
222 patch->change_source = 1;
224 float change = update_edl();
226 if(patch->track->gang && patch->track->record)
227 patch->patchbay->synchronize_faders(change, TRACK_VIDEO, patch->track);
229 patch->change_source = 0;
232 mwindow->gui->unlock_window();
233 mwindow->restart_brender();
234 mwindow->sync_parameters(CHANGE_PARAMS);
235 mwindow->gui->lock_window("VFadePatch::handle_event");
236 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE])
238 mwindow->gui->draw_overlays(1);
243 FloatAuto* VFadePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
245 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
246 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
247 unit_position = patch->vtrack->to_units(unit_position, 0);
250 return (FloatAuto*)patch->vtrack->automation->autos[AUTOMATION_FADE]->get_prev_auto(
251 (int64_t)unit_position,
259 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
262 patch->patchbay->mode_icons[0]->get_w() + 20,
265 mwindow->theme->get_image_set("mode_popup", 0),
268 this->mwindow = mwindow;
270 this->mode = get_keyframe(mwindow, patch)->value;
271 set_icon(patch->patchbay->mode_to_icon(this->mode));
272 set_tooltip(_("Overlay mode"));
275 int VModePatch::handle_event()
278 // for(int i = 0; i < total_items(); i++)
280 // VModePatchItem *item = (VModePatchItem*)get_item(i);
281 // if(item->mode == mode)
282 // item->set_checked(1);
284 // item->set_checked(0);
290 double position = mwindow->edl->local_session->get_selectionstart(1);
291 Autos *mode_autos = patch->vtrack->automation->autos[AUTOMATION_MODE];
292 int need_undo = !mode_autos->auto_exists_for_editing(position);
294 mwindow->undo->update_undo_before(_("mode"), need_undo ? 0 : this);
296 current = (IntAuto*)mode_autos->get_auto_for_editing(position);
297 current->value = mode;
299 mwindow->undo->update_undo_after(_("mode"), LOAD_AUTOMATION);
301 mwindow->sync_parameters(CHANGE_PARAMS);
303 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MODE])
305 mwindow->gui->draw_overlays(1);
307 mwindow->session->changes_made = 1;
311 IntAuto* VModePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
314 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
315 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
316 unit_position = patch->vtrack->to_units(unit_position, 0);
318 return (IntAuto*)patch->vtrack->automation->autos[AUTOMATION_MODE]->get_prev_auto(
319 (int64_t)unit_position,
325 void VModePatch::create_objects()
327 for( int mode=0; mode<TRANSFER_TYPES; ++mode )
328 add_item(new VModePatchItem(this, mode_to_text(mode), mode));
331 void VModePatch::update(int mode)
333 set_icon(patch->patchbay->mode_to_icon(mode));
334 for(int i = 0; i < total_items(); i++)
336 VModePatchItem *item = (VModePatchItem*)get_item(i);
337 item->set_checked(item->mode == mode);
342 const char* VModePatch::mode_to_text(int mode)
345 case TRANSFER_NORMAL: return _("Normal");
346 case TRANSFER_ADDITION: return _("Addition");
347 case TRANSFER_SUBTRACT: return _("Subtract");
348 case TRANSFER_MULTIPLY: return _("Multiply");
349 case TRANSFER_DIVIDE: return _("Divide");
350 case TRANSFER_REPLACE: return _("Replace");
351 case TRANSFER_MAX: return _("Max");
352 case TRANSFER_MIN: return _("Min");
353 case TRANSFER_AVERAGE: return _("Average");
354 case TRANSFER_DARKEN: return _("Darken");
355 case TRANSFER_LIGHTEN: return _("Lighten");
356 case TRANSFER_DST: return _("Dst");
357 case TRANSFER_DST_ATOP: return _("DstAtop");
358 case TRANSFER_DST_IN: return _("DstIn");
359 case TRANSFER_DST_OUT: return _("DstOut");
360 case TRANSFER_DST_OVER: return _("DstOver");
361 case TRANSFER_SRC: return _("Src");
362 case TRANSFER_SRC_ATOP: return _("SrcAtop");
363 case TRANSFER_SRC_IN: return _("SrcIn");
364 case TRANSFER_SRC_OUT: return _("SrcOut");
365 case TRANSFER_SRC_OVER: return _("SrcOver");
366 case TRANSFER_OR: return _("Or");
367 case TRANSFER_XOR: return _("Xor");
374 VModePatchItem::VModePatchItem(VModePatch *popup, const char *text, int mode)
379 if(this->mode == popup->mode) set_checked(1);
382 int VModePatchItem::handle_event()
385 // popup->set_icon(popup->patch->patchbay->mode_to_icon(mode));
386 popup->handle_event();