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->get_selectionstart(1);
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->autos[AUTOMATION_FADE])->get_value(
90 (int64_t)unit_position,
94 fade->update(fade->get_w(),
96 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_VIDEO_FADE],
97 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_VIDEO_FADE]);
98 // fade->update((int)fade->get_keyframe(mwindow, this)->value);
102 if(h - y1 >= mwindow->theme->fade_h)
104 patchbay->add_subwindow(fade = new VFadePatch(mwindow,
108 patchbay->get_w() - 10));
110 y1 += mwindow->theme->fade_h;
114 if(h - y1 < mwindow->theme->mode_h)
123 mode->update(mode->get_keyframe(mwindow, this)->value);
128 if(h - y1 >= mwindow->theme->mode_h)
130 patchbay->add_subwindow(mode = new VModePatch(mwindow,
134 mode->create_objects();
135 x1 += mode->get_w() + 10;
136 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
140 patchbay->get_w() - x1 - 10));
147 y1 += mwindow->theme->mode_h;
154 void VPatchGUI::synchronize_fade(float value_change)
156 if(fade && !change_source)
158 fade->update(Units::to_int64(fade->get_value() + value_change));
164 VFadePatch::VFadePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y, int w)
170 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_VIDEO_FADE],
171 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_VIDEO_FADE],
172 (int64_t)get_keyframe(mwindow, patch)->value)
174 this->mwindow = mwindow;
178 float VFadePatch::update_edl()
181 double position = mwindow->edl->local_session->get_selectionstart(1);
182 Autos *fade_autos = patch->vtrack->automation->autos[AUTOMATION_FADE];
183 int need_undo = !fade_autos->auto_exists_for_editing(position);
186 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
188 float result = get_value() - current->value;
189 current->value = get_value();
191 mwindow->undo->update_undo(_("fade"), LOAD_AUTOMATION, need_undo ? 0 : this);
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->autos[AUTOMATION_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->get_selectionstart(1);
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->autos[AUTOMATION_FADE]->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() + 20,
248 mwindow->theme->get_image_set("mode_popup", 0),
251 this->mwindow = mwindow;
253 this->mode = get_keyframe(mwindow, patch)->value;
254 set_icon(patch->patchbay->mode_to_icon(this->mode));
255 set_tooltip("Overlay mode");
258 int VModePatch::handle_event()
261 // for(int i = 0; i < total_items(); i++)
263 // VModePatchItem *item = (VModePatchItem*)get_item(i);
264 // if(item->mode == mode)
265 // item->set_checked(1);
267 // item->set_checked(0);
273 double position = mwindow->edl->local_session->get_selectionstart(1);
274 Autos *mode_autos = patch->vtrack->automation->autos[AUTOMATION_MODE];
275 int need_undo = !mode_autos->auto_exists_for_editing(position);
278 current = (IntAuto*)mode_autos->get_auto_for_editing(position);
279 current->value = mode;
281 mwindow->undo->update_undo(_("mode"), LOAD_AUTOMATION, need_undo ? 0 : this);
283 mwindow->sync_parameters(CHANGE_PARAMS);
285 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MODE])
287 mwindow->gui->canvas->draw_overlays();
288 mwindow->gui->canvas->flash();
290 mwindow->session->changes_made = 1;
294 IntAuto* VModePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
297 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
298 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
299 unit_position = patch->vtrack->to_units(unit_position, 0);
301 return (IntAuto*)patch->vtrack->automation->autos[AUTOMATION_MODE]->get_prev_auto(
302 (int64_t)unit_position,
308 int VModePatch::create_objects()
310 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_NORMAL), TRANSFER_NORMAL));
311 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_ADDITION), TRANSFER_ADDITION));
312 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_SUBTRACT), TRANSFER_SUBTRACT));
313 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_MULTIPLY), TRANSFER_MULTIPLY));
314 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_DIVIDE), TRANSFER_DIVIDE));
315 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_REPLACE), TRANSFER_REPLACE));
316 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_MAX), TRANSFER_MAX));
320 void VModePatch::update(int mode)
322 set_icon(patch->patchbay->mode_to_icon(mode));
323 for(int i = 0; i < total_items(); i++)
325 VModePatchItem *item = (VModePatchItem*)get_item(i);
326 item->set_checked(item->mode == mode);
331 char* VModePatch::mode_to_text(int mode)
335 case TRANSFER_NORMAL:
339 case TRANSFER_REPLACE:
343 case TRANSFER_ADDITION:
344 return _("Addition");
347 case TRANSFER_SUBTRACT:
348 return _("Subtract");
351 case TRANSFER_MULTIPLY:
352 return _("Multiply");
355 case TRANSFER_DIVIDE:
375 VModePatchItem::VModePatchItem(VModePatch *popup, 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();