2 #include "automation.h"
4 #include "edlsession.h"
6 #include "floatautos.h"
10 #include "localsession.h"
11 #include "mainsession.h"
14 #include "mwindowgui.h"
15 #include "overlayframe.inc"
18 #include "trackcanvas.h"
19 #include "vpatchgui.h"
28 VPatchGUI::VPatchGUI(MWindow *mwindow, PatchBay *patchbay, VTrack *track, int x, int y)
29 : PatchGUI(mwindow, patchbay, track, x, y)
31 data_type = TRACK_VIDEO;
37 VPatchGUI::~VPatchGUI()
43 int VPatchGUI::create_objects()
48 int VPatchGUI::reposition(int x, int y)
51 int y1 = PatchGUI::reposition(x, y);
53 if(fade) fade->reposition_window(fade->get_x(),
56 y1 += mwindow->theme->fade_h;
58 if(mode) mode->reposition_window(mode->get_x(),
61 if(nudge) nudge->reposition_window(nudge->get_x(),
65 y1 += mwindow->theme->mode_h;
70 int VPatchGUI::update(int x, int y)
72 int h = track->vertical_span(mwindow->theme);
74 int y1 = PatchGUI::update(x, y);
78 if(h - y1 < mwindow->theme->fade_h)
85 FloatAuto *previous = 0, *next = 0;
86 double unit_position = mwindow->edl->local_session->selectionstart;
87 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
88 unit_position = vtrack->to_units(unit_position, 0);
89 int value = (int)((FloatAutos*)vtrack->automation->fade_autos)->get_value(
90 (int64_t)unit_position,
95 // fade->update((int)fade->get_keyframe(mwindow, this)->value);
99 if(h - y1 >= mwindow->theme->fade_h)
101 patchbay->add_subwindow(fade = new VFadePatch(mwindow,
105 patchbay->get_w() - 10));
107 y1 += mwindow->theme->fade_h;
111 if(h - y1 < mwindow->theme->mode_h)
120 mode->update(mode->get_keyframe(mwindow, this)->value);
125 if(h - y1 >= mwindow->theme->mode_h)
127 patchbay->add_subwindow(mode = new VModePatch(mwindow,
131 mode->create_objects();
132 x1 += mode->get_w() + 10;
133 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
137 patchbay->get_w() - x1 - 10));
144 y1 += mwindow->theme->mode_h;
151 void VPatchGUI::synchronize_fade(float value_change)
153 if(fade && !change_source)
155 fade->update(Units::to_int64(fade->get_value() + value_change));
161 VFadePatch::VFadePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y, int w)
169 (int64_t)get_keyframe(mwindow, patch)->value)
171 this->mwindow = mwindow;
175 float VFadePatch::update_edl()
178 double position = mwindow->edl->local_session->selectionstart;
179 Autos *fade_autos = patch->vtrack->automation->fade_autos;
180 int update_undo = !fade_autos->auto_exists_for_editing(position);
183 mwindow->undo->update_undo_before(_("fade"), LOAD_AUTOMATION);
185 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
187 float result = get_value() - current->value;
188 current->value = get_value();
191 mwindow->undo->update_undo_after();
196 int VFadePatch::handle_event()
201 set_tooltip(get_caption());
204 patch->change_source = 1;
206 float change = update_edl();
208 if(patch->track->gang)
209 patch->patchbay->synchronize_faders(change, TRACK_VIDEO, patch->track);
211 patch->change_source = 0;
214 mwindow->gui->unlock_window();
215 mwindow->restart_brender();
216 mwindow->sync_parameters(CHANGE_PARAMS);
217 mwindow->gui->lock_window("VFadePatch::handle_event");
218 if(mwindow->edl->session->auto_conf->fade)
220 mwindow->gui->canvas->draw_overlays();
221 mwindow->gui->canvas->flash();
226 FloatAuto* VFadePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
228 double unit_position = mwindow->edl->local_session->selectionstart;
229 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
230 unit_position = patch->vtrack->to_units(unit_position, 0);
233 return (FloatAuto*)patch->vtrack->automation->fade_autos->get_prev_auto(
234 (int64_t)unit_position,
242 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
245 patch->patchbay->mode_icons[0]->get_w() + 40,
249 this->mwindow = mwindow;
251 this->mode = get_keyframe(mwindow, patch)->value;
252 set_icon(patch->patchbay->mode_to_icon(this->mode));
253 set_tooltip("Overlay mode");
256 int VModePatch::handle_event()
263 double position = mwindow->edl->local_session->selectionstart;
264 Autos *mode_autos = patch->vtrack->automation->mode_autos;
265 int update_undo = !mode_autos->auto_exists_for_editing(position);
268 mwindow->undo->update_undo_before(_("mode"), LOAD_AUTOMATION);
270 current = (IntAuto*)mode_autos->get_auto_for_editing(position);
271 current->value = mode;
274 mwindow->undo->update_undo_after();
276 mwindow->sync_parameters(CHANGE_PARAMS);
278 if(mwindow->edl->session->auto_conf->mode)
280 mwindow->gui->canvas->draw_overlays();
281 mwindow->gui->canvas->flash();
283 mwindow->session->changes_made = 1;
287 IntAuto* VModePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
290 double unit_position = mwindow->edl->local_session->selectionstart;
291 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
292 unit_position = patch->vtrack->to_units(unit_position, 0);
294 return (IntAuto*)patch->vtrack->automation->mode_autos->get_prev_auto(
295 (int64_t)unit_position,
301 int VModePatch::create_objects()
303 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_NORMAL), TRANSFER_NORMAL));
304 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_ADDITION), TRANSFER_ADDITION));
305 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_SUBTRACT), TRANSFER_SUBTRACT));
306 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_MULTIPLY), TRANSFER_MULTIPLY));
307 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_DIVIDE), TRANSFER_DIVIDE));
308 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_REPLACE), TRANSFER_REPLACE));
312 void VModePatch::update(int mode)
314 set_icon(patch->patchbay->mode_to_icon(mode));
316 for(int i = 0; i < total_items(); i++)
318 VModePatchItem *item = (VModePatchItem*)get_item(i);
319 item->set_checked(item->mode == mode);
324 char* VModePatch::mode_to_text(int mode)
328 case TRANSFER_NORMAL:
332 case TRANSFER_REPLACE:
336 case TRANSFER_ADDITION:
337 return _("Addition");
340 case TRANSFER_SUBTRACT:
341 return _("Subtract");
344 case TRANSFER_MULTIPLY:
345 return _("Multiply");
348 case TRANSFER_DIVIDE:
364 VModePatchItem::VModePatchItem(VModePatch *popup, char *text, int mode)
369 if(this->mode == popup->mode) set_checked(1);
372 int VModePatchItem::handle_event()
375 popup->handle_event();