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"
50 VPatchGUI::VPatchGUI(MWindow *mwindow, PatchBay *patchbay, VTrack *track, int x, int y)
51 : PatchGUI(mwindow, patchbay, track, x, y)
53 data_type = TRACK_VIDEO;
59 VPatchGUI::~VPatchGUI()
65 void VPatchGUI::create_objects()
70 int VPatchGUI::reposition(int x, int y)
73 int y1 = PatchGUI::reposition(x, y);
75 if(fade) fade->reposition_window(fade->get_x(),
78 y1 += mwindow->theme->fade_h;
80 if(mode) mode->reposition_window(mode->get_x(),
83 if(nudge) nudge->reposition_window(nudge->get_x(),
87 y1 += mwindow->theme->mode_h;
92 int VPatchGUI::update(int x, int y)
94 int h = track->vertical_span(mwindow->theme);
96 int y1 = PatchGUI::update(x, y);
100 if(h - y1 < mwindow->theme->fade_h)
107 fade->update(fade->get_w(), mwindow->get_float_auto(this, AUTOMATION_FADE)->get_value(),
108 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_VIDEO_FADE],
109 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_VIDEO_FADE]);
113 if(h - y1 >= mwindow->theme->fade_h)
115 patchbay->add_subwindow(fade = new VFadePatch(mwindow,
119 patchbay->get_w() - 10));
121 y1 += mwindow->theme->fade_h;
125 if(h - y1 < mwindow->theme->mode_h)
134 mode->update(mwindow->get_int_auto(this, AUTOMATION_MODE)->value);
139 if(h - y1 >= mwindow->theme->mode_h)
141 patchbay->add_subwindow(mode = new VModePatch(mwindow,
145 mode->create_objects();
146 x1 += mode->get_w() + 10;
147 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
151 patchbay->get_w() - x1 - 10));
158 y1 += mwindow->theme->mode_h;
165 void VPatchGUI::synchronize_fade(float value_change)
167 if(fade && !change_source)
169 fade->update(Units::to_int64(fade->get_value() + value_change));
175 VFadePatch::VFadePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y, int w)
176 : BC_ISlider(x, y, 0, w, w,
177 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_VIDEO_FADE],
178 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_VIDEO_FADE],
179 (int64_t)mwindow->get_float_auto(patch,AUTOMATION_FADE)->get_value())
181 this->mwindow = mwindow;
185 float VFadePatch::update_edl()
188 double position = mwindow->edl->local_session->get_selectionstart(1);
189 Autos *fade_autos = patch->vtrack->automation->autos[AUTOMATION_FADE];
190 int need_undo = !fade_autos->auto_exists_for_editing(position);
192 mwindow->undo->update_undo_before(_("fade"), need_undo ? 0 : this);
194 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
196 float result = get_value() - current->get_value();
197 current->set_value(get_value());
199 mwindow->undo->update_undo_after(_("fade"), LOAD_AUTOMATION);
204 int VFadePatch::handle_event()
209 set_tooltip(get_caption());
212 patch->change_source = 1;
214 float change = update_edl();
216 if(patch->track->gang && patch->track->record)
217 patch->patchbay->synchronize_faders(change, TRACK_VIDEO, patch->track);
219 patch->change_source = 0;
222 mwindow->gui->unlock_window();
223 mwindow->restart_brender();
224 mwindow->sync_parameters(CHANGE_PARAMS);
225 mwindow->gui->lock_window("VFadePatch::handle_event");
226 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE])
228 mwindow->gui->draw_overlays(1);
234 VKeyFadePatch::VKeyFadePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
235 : BC_SubWindow(x,y, patch->patchbay->get_w(),20,
236 GWindowGUI::auto_colors[AUTOMATION_FADE])
238 this->mwindow = mwindow;
242 void VKeyFadePatch::create_objects()
244 vkey_fade_value = new VKeyFadeValue(this);
245 add_subwindow(vkey_fade_value);
246 vkey_fade_value->activate();
250 VKeyFadeValue::VKeyFadeValue(VKeyFadePatch *vkey_fade_patch)
251 : VFadePatch(vkey_fade_patch->mwindow, vkey_fade_patch->patch,
252 0,0, vkey_fade_patch->get_w())
254 this->vkey_fade_patch = vkey_fade_patch;
257 int VKeyFadeValue::button_release_event()
259 VFadePatch::button_release_event();
263 int VKeyFadeValue::handle_event()
265 VPatchGUI *patch = vkey_fade_patch->patch;
266 int ret = VFadePatch::handle_event();
267 VFadePatch *fade = patch->fade;
269 fade->update(get_value());
277 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
278 : BC_PopupMenu(x, y, patch->patchbay->mode_icons[0]->get_w() + 20,
279 "", 1, mwindow->theme->get_image_set("mode_popup", 0), 10)
281 this->mwindow = mwindow;
283 this->mode = mwindow->get_int_auto(patch, AUTOMATION_MODE)->value;
284 set_icon(patch->patchbay->mode_to_icon(this->mode));
285 set_tooltip(_("Overlay mode"));
288 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch)
289 : BC_PopupMenu(0, 0, 0, "", 0)
291 this->mwindow = mwindow;
293 this->mode = mwindow->get_int_auto(patch, AUTOMATION_MODE)->value;
297 int VModePatch::handle_event()
300 // for(int i = 0; i < total_items(); i++)
302 // VModePatchItem *item = (VModePatchItem*)get_item(i);
303 // if(item->mode == mode)
304 // item->set_checked(1);
306 // item->set_checked(0);
312 double position = mwindow->edl->local_session->get_selectionstart(1);
313 Autos *mode_autos = patch->vtrack->automation->autos[AUTOMATION_MODE];
314 int need_undo = !mode_autos->auto_exists_for_editing(position);
316 mwindow->undo->update_undo_before(_("mode"), need_undo ? 0 : this);
318 current = (IntAuto*)mode_autos->get_auto_for_editing(position);
319 current->value = mode;
321 mwindow->undo->update_undo_after(_("mode"), LOAD_AUTOMATION);
323 mwindow->sync_parameters(CHANGE_PARAMS);
325 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MODE])
327 mwindow->gui->draw_overlays(1);
329 mwindow->session->changes_made = 1;
333 void VModePatch::create_objects()
335 for( int mode=0; mode<TRANSFER_TYPES; ++mode )
336 add_item(new VModePatchItem(this, mode_to_text(mode), mode));
339 void VModePatch::update(int mode)
341 set_icon(patch->patchbay->mode_to_icon(mode));
342 for(int i = 0; i < total_items(); i++)
344 VModePatchItem *item = (VModePatchItem*)get_item(i);
345 item->set_checked(item->mode == mode);
350 const char* VModePatch::mode_to_text(int mode)
353 case TRANSFER_NORMAL: return _("Normal");
354 case TRANSFER_ADDITION: return _("Addition");
355 case TRANSFER_SUBTRACT: return _("Subtract");
356 case TRANSFER_MULTIPLY: return _("Multiply");
357 case TRANSFER_DIVIDE: return _("Divide");
358 case TRANSFER_REPLACE: return _("Replace");
359 case TRANSFER_MAX: return _("Max");
360 case TRANSFER_MIN: return _("Min");
361 case TRANSFER_AVERAGE: return _("Average");
362 case TRANSFER_DARKEN: return _("Darken");
363 case TRANSFER_LIGHTEN: return _("Lighten");
364 case TRANSFER_DST: return _("Dst");
365 case TRANSFER_DST_ATOP: return _("DstAtop");
366 case TRANSFER_DST_IN: return _("DstIn");
367 case TRANSFER_DST_OUT: return _("DstOut");
368 case TRANSFER_DST_OVER: return _("DstOver");
369 case TRANSFER_SRC: return _("Src");
370 case TRANSFER_SRC_ATOP: return _("SrcAtop");
371 case TRANSFER_SRC_IN: return _("SrcIn");
372 case TRANSFER_SRC_OUT: return _("SrcOut");
373 case TRANSFER_SRC_OVER: return _("SrcOver");
374 case TRANSFER_OR: return _("Or");
375 case TRANSFER_XOR: return _("Xor");
382 VModePatchItem::VModePatchItem(VModePatch *popup, const char *text, int mode)
387 if(this->mode == popup->mode) set_checked(1);
390 int VModePatchItem::handle_event()
393 // popup->set_icon(popup->patch->patchbay->mode_to_icon(mode));
394 popup->handle_event();
399 VKeyModePatch::VKeyModePatch(MWindow *mwindow, VPatchGUI *patch)
400 : VModePatch(mwindow, patch)
404 int VKeyModePatch::button_release_event()
406 VModePatch::button_release_event();
410 int VKeyModePatch::handle_event()
412 int ret = VModePatch::handle_event();
413 VModePatch *mode = patch->mode;
415 mode->update(this->mode);