2 #include "automation.h"
4 #include "edlsession.h"
6 #include "floatautos.h"
9 #include "localsession.h"
10 #include "mainsession.h"
13 #include "mwindowgui.h"
14 #include "overlayframe.inc"
17 #include "trackcanvas.h"
18 #include "vpatchgui.h"
24 #define _(String) gettext(String)
25 #define gettext_noop(String) String
26 #define N_(String) gettext_noop (String)
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(x1 + x,
55 y1 += mwindow->theme->fade_h;
56 if(mode) mode->reposition_window(x1 + x,
58 y1 += mwindow->theme->mode_h;
62 int VPatchGUI::update(int x, int y)
64 int h = track->vertical_span(mwindow->theme);
66 int y1 = PatchGUI::update(x, y);
70 if(h - y1 < mwindow->theme->fade_h)
77 FloatAuto *previous = 0, *next = 0;
78 double unit_position = mwindow->edl->local_session->selectionstart;
79 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
80 unit_position = vtrack->to_units(unit_position, 0);
81 int value = (int)((FloatAutos*)vtrack->automation->fade_autos)->get_value(
82 (int64_t)unit_position,
87 // fade->update((int)fade->get_keyframe(mwindow, this)->value);
91 if(h - y1 >= mwindow->theme->fade_h)
93 patchbay->add_subwindow(fade = new VFadePatch(mwindow,
97 patchbay->get_w() - 10));
99 y1 += mwindow->theme->fade_h;
103 if(h - y1 < mwindow->theme->mode_h)
110 mode->update(mode->get_keyframe(mwindow, this)->value);
114 if(h - y1 >= mwindow->theme->mode_h)
116 patchbay->add_subwindow(mode = new VModePatch(mwindow,
120 mode->create_objects();
122 y1 += mwindow->theme->mode_h;
128 void VPatchGUI::create_mode()
133 void VPatchGUI::synchronize_fade(float value_change)
135 if(fade && !change_source)
137 fade->update(Units::to_int64(fade->get_value() + value_change));
143 VFadePatch::VFadePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y, int w)
151 (int64_t)get_keyframe(mwindow, patch)->value)
153 this->mwindow = mwindow;
157 float VFadePatch::update_edl()
160 double position = mwindow->edl->local_session->selectionstart;
161 Autos *fade_autos = patch->vtrack->automation->fade_autos;
162 int update_undo = !fade_autos->auto_exists_for_editing(position);
165 mwindow->undo->update_undo_before(_("fade"), LOAD_AUTOMATION);
167 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
169 float result = get_value() - current->value;
170 current->value = get_value();
173 mwindow->undo->update_undo_after();
178 int VFadePatch::handle_event()
183 set_tooltip(get_caption());
186 patch->change_source = 1;
188 float change = update_edl();
190 if(patch->track->gang)
191 patch->patchbay->synchronize_faders(change, TRACK_VIDEO, patch->track);
193 patch->change_source = 0;
196 mwindow->gui->unlock_window();
197 mwindow->restart_brender();
198 mwindow->sync_parameters(CHANGE_PARAMS);
199 mwindow->gui->lock_window();
200 if(mwindow->edl->session->auto_conf->fade)
202 mwindow->gui->canvas->draw_overlays();
203 mwindow->gui->canvas->flash();
208 FloatAuto* VFadePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
210 double unit_position = mwindow->edl->local_session->selectionstart;
211 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
212 unit_position = patch->vtrack->to_units(unit_position, 0);
215 return (FloatAuto*)patch->vtrack->automation->fade_autos->get_prev_auto(
216 (int64_t)unit_position,
224 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
227 patch->patchbay->get_w() - x - 10,
228 mode_to_text(get_keyframe(mwindow, patch)->value),
231 this->mwindow = mwindow;
235 int VModePatch::handle_event()
238 double position = mwindow->edl->local_session->selectionstart;
239 Autos *mode_autos = patch->vtrack->automation->mode_autos;
240 int update_undo = !mode_autos->auto_exists_for_editing(position);
243 mwindow->undo->update_undo_before(_("mode"), LOAD_AUTOMATION);
245 current = (IntAuto*)mode_autos->get_auto_for_editing(position);
246 current->value = text_to_mode(get_text());
249 mwindow->undo->update_undo_after();
251 //printf("VModePatch::handle_event %d\n", text_to_mode(get_text()));
252 mwindow->sync_parameters(CHANGE_PARAMS);
254 if(mwindow->edl->session->auto_conf->mode)
256 mwindow->gui->canvas->draw_overlays();
257 mwindow->gui->canvas->flash();
259 mwindow->session->changes_made = 1;
263 IntAuto* VModePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
266 double unit_position = mwindow->edl->local_session->selectionstart;
267 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
268 unit_position = patch->vtrack->to_units(unit_position, 0);
270 return (IntAuto*)patch->vtrack->automation->mode_autos->get_prev_auto(
271 (int64_t)unit_position,
277 int VModePatch::create_objects()
279 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_NORMAL), TRANSFER_NORMAL));
280 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_ADDITION), TRANSFER_ADDITION));
281 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_SUBTRACT), TRANSFER_SUBTRACT));
282 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_MULTIPLY), TRANSFER_MULTIPLY));
283 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_DIVIDE), TRANSFER_DIVIDE));
284 add_item(new VModePatchItem(this, mode_to_text(TRANSFER_REPLACE), TRANSFER_REPLACE));
288 void VModePatch::update(int mode)
290 set_text(mode_to_text(mode));
293 int VModePatch::text_to_mode(char *text)
295 //printf("%s %s\n", mode_to_text(TRANSFER_MULTIPLY), text);
296 if(!strcasecmp(mode_to_text(TRANSFER_NORMAL), text)) return TRANSFER_NORMAL;
297 if(!strcasecmp(mode_to_text(TRANSFER_ADDITION), text)) return TRANSFER_ADDITION;
298 if(!strcasecmp(mode_to_text(TRANSFER_SUBTRACT), text)) return TRANSFER_SUBTRACT;
299 if(!strcasecmp(mode_to_text(TRANSFER_MULTIPLY), text)) return TRANSFER_MULTIPLY;
300 if(!strcasecmp(mode_to_text(TRANSFER_DIVIDE), text)) return TRANSFER_DIVIDE;
301 if(!strcasecmp(mode_to_text(TRANSFER_REPLACE), text)) return TRANSFER_REPLACE;
302 return TRANSFER_NORMAL;
305 char* VModePatch::mode_to_text(int mode)
309 case TRANSFER_NORMAL:
313 case TRANSFER_REPLACE:
317 case TRANSFER_ADDITION:
318 return _("Addition");
321 case TRANSFER_SUBTRACT:
322 return _("Subtract");
325 case TRANSFER_MULTIPLY:
326 return _("Multiply");
329 case TRANSFER_DIVIDE:
344 VModePatchItem::VModePatchItem(VModePatch *popup, char *text, int mode)
351 int VModePatchItem::handle_event()
353 popup->set_text(get_text());
354 popup->handle_event();