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,
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->get_selectionstart(1);
179 Autos *fade_autos = patch->vtrack->automation->autos[AUTOMATION_FADE];
180 int need_undo = !fade_autos->auto_exists_for_editing(position);
183 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
185 float result = get_value() - current->value;
186 current->value = get_value();
188 mwindow->undo->update_undo(_("fade"), LOAD_AUTOMATION, need_undo ? 0 : this);
193 int VFadePatch::handle_event()
198 set_tooltip(get_caption());
201 patch->change_source = 1;
203 float change = update_edl();
205 if(patch->track->gang)
206 patch->patchbay->synchronize_faders(change, TRACK_VIDEO, patch->track);
208 patch->change_source = 0;
211 mwindow->gui->unlock_window();
212 mwindow->restart_brender();
213 mwindow->sync_parameters(CHANGE_PARAMS);
214 mwindow->gui->lock_window("VFadePatch::handle_event");
215 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE])
217 mwindow->gui->canvas->draw_overlays();
218 mwindow->gui->canvas->flash();
223 FloatAuto* VFadePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
225 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
226 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
227 unit_position = patch->vtrack->to_units(unit_position, 0);
230 return (FloatAuto*)patch->vtrack->automation->autos[AUTOMATION_FADE]->get_prev_auto(
231 (int64_t)unit_position,
239 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
242 patch->patchbay->mode_icons[0]->get_w() + 20,
245 mwindow->theme->get_image_set("mode_popup", 0),
248 this->mwindow = mwindow;
250 this->mode = get_keyframe(mwindow, patch)->value;
251 set_icon(patch->patchbay->mode_to_icon(this->mode));
252 set_tooltip("Overlay mode");
255 int VModePatch::handle_event()
258 // for(int i = 0; i < total_items(); i++)
260 // VModePatchItem *item = (VModePatchItem*)get_item(i);
261 // if(item->mode == mode)
262 // item->set_checked(1);
264 // item->set_checked(0);
270 double position = mwindow->edl->local_session->get_selectionstart(1);
271 Autos *mode_autos = patch->vtrack->automation->autos[AUTOMATION_MODE];
272 int need_undo = !mode_autos->auto_exists_for_editing(position);
275 current = (IntAuto*)mode_autos->get_auto_for_editing(position);
276 current->value = mode;
278 mwindow->undo->update_undo(_("mode"), LOAD_AUTOMATION, need_undo ? 0 : this);
280 mwindow->sync_parameters(CHANGE_PARAMS);
282 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MODE])
284 mwindow->gui->canvas->draw_overlays();
285 mwindow->gui->canvas->flash();
287 mwindow->session->changes_made = 1;
291 IntAuto* VModePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
294 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
295 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
296 unit_position = patch->vtrack->to_units(unit_position, 0);
298 return (IntAuto*)patch->vtrack->automation->autos[AUTOMATION_MODE]->get_prev_auto(
299 (int64_t)unit_position,
305 int VModePatch::create_objects()
307 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_NORMAL), TRANSFER_NORMAL));
308 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_ADDITION), TRANSFER_ADDITION));
309 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_SUBTRACT), TRANSFER_SUBTRACT));
310 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_MULTIPLY), TRANSFER_MULTIPLY));
311 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_DIVIDE), TRANSFER_DIVIDE));
312 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_REPLACE), TRANSFER_REPLACE));
316 void VModePatch::update(int mode)
318 set_icon(patch->patchbay->mode_to_icon(mode));
319 for(int i = 0; i < total_items(); i++)
321 VModePatchItem *item = (VModePatchItem*)get_item(i);
322 item->set_checked(item->mode == mode);
327 char* VModePatch::mode_to_text(int mode)
331 case TRANSFER_NORMAL:
335 case TRANSFER_REPLACE:
339 case TRANSFER_ADDITION:
340 return _("Addition");
343 case TRANSFER_SUBTRACT:
344 return _("Subtract");
347 case TRANSFER_MULTIPLY:
348 return _("Multiply");
351 case TRANSFER_DIVIDE:
367 VModePatchItem::VModePatchItem(VModePatch *popup, char *text, int mode)
372 if(this->mode == popup->mode) set_checked(1);
375 int VModePatchItem::handle_event()
378 // popup->set_icon(popup->patch->patchbay->mode_to_icon(mode));
379 popup->handle_event();