r668: Configure.in and autogen.sh cleanup based on ideas by giskard.
[cinelerra_cv.git] / cinelerra / vpatchgui.C
blob3216ece867b7bda3646031293644b7ce51bfa12d
1 #include "autoconf.h"
2 #include "automation.h"
3 #include "edl.h"
4 #include "edlsession.h"
5 #include "floatauto.h"
6 #include "floatautos.h"
7 #include "intauto.h"
8 #include "intautos.h"
9 #include "language.h"
10 #include "localsession.h"
11 #include "mainsession.h"
12 #include "mainundo.h"
13 #include "mwindow.h"
14 #include "mwindowgui.h"
15 #include "overlayframe.inc"
16 #include "patchbay.h"
17 #include "theme.h"
18 #include "trackcanvas.h"
19 #include "vpatchgui.h"
20 #include "vtrack.h"
22 #include <string.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;
32         this->vtrack = track;
33         mode = 0;
34         fade = 0;
37 VPatchGUI::~VPatchGUI()
39         if(fade) delete fade;
40         if(mode) delete mode;
43 int VPatchGUI::create_objects()
45         return update(x, y);
48 int VPatchGUI::reposition(int x, int y)
50         int x1 = 0;
51         int y1 = PatchGUI::reposition(x, y);
53         if(fade) fade->reposition_window(fade->get_x(), 
54                 y1 + y);
56         y1 += mwindow->theme->fade_h;
58         if(mode) mode->reposition_window(mode->get_x(),
59                 y1 + y);
61         if(nudge) nudge->reposition_window(nudge->get_x(), 
62                 y1 + y);
65         y1 += mwindow->theme->mode_h;
67         return y1;
70 int VPatchGUI::update(int x, int y)
72         int h = track->vertical_span(mwindow->theme);
73         int x1 = 0;
74         int y1 = PatchGUI::update(x, y);
76         if(fade)
77         {
78                 if(h - y1 < mwindow->theme->fade_h)
79                 {
80                         delete fade;
81                         fade = 0;
82                 }
83                 else
84                 {
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,
91                                 PLAY_FORWARD, 
92                                 previous, 
93                                 next);
94                         fade->update(value);
95 //                      fade->update((int)fade->get_keyframe(mwindow, this)->value);
96                 }
97         }
98         else
99         if(h - y1 >= mwindow->theme->fade_h)
100         {
101                 patchbay->add_subwindow(fade = new VFadePatch(mwindow, 
102                         this, 
103                         x1 + x, 
104                         y1 + y, 
105                         patchbay->get_w() - 10));
106         }
107         y1 += mwindow->theme->fade_h;
109         if(mode)
110         {
111                 if(h - y1 < mwindow->theme->mode_h)
112                 {
113                         delete mode;
114                         mode = 0;
115                         delete nudge;
116                         nudge = 0;
117                 }
118                 else
119                 {
120                         mode->update(mode->get_keyframe(mwindow, this)->value);
121                         nudge->update();
122                 }
123         }
124         else
125         if(h - y1 >= mwindow->theme->mode_h)
126         {
127                 patchbay->add_subwindow(mode = new VModePatch(mwindow, 
128                         this, 
129                         x1 + x, 
130                         y1 + y));
131                 mode->create_objects();
132                 x1 += mode->get_w() + 10;
133                 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
134                         this,
135                         x1 + x,
136                         y1 + y,
137                         patchbay->get_w() - x1 - 10));
138         }
144         y1 += mwindow->theme->mode_h;
145         
146         return y1;
151 void VPatchGUI::synchronize_fade(float value_change)
153         if(fade && !change_source) 
154         {
155                 fade->update(Units::to_int64(fade->get_value() + value_change));
156                 fade->update_edl();
157         }
161 VFadePatch::VFadePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y, int w)
162  : BC_ISlider(x, 
163                         y,
164                         0,
165                         w, 
166                         w, 
167                         0, 
168                         MAX_VIDEO_FADE, 
169                         (int64_t)get_keyframe(mwindow, patch)->value)
171         this->mwindow = mwindow;
172         this->patch = patch;
175 float VFadePatch::update_edl()
177         FloatAuto *current;
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);
190         return result;
193 int VFadePatch::handle_event()
195         if(shift_down())
196         {
197                 update(100);
198                 set_tooltip(get_caption());
199         }
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])
216         {
217                 mwindow->gui->canvas->draw_overlays();
218                 mwindow->gui->canvas->flash();
219         }
220         return 1;
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);
228         Auto *current = 0;
230         return (FloatAuto*)patch->vtrack->automation->autos[AUTOMATION_FADE]->get_prev_auto(
231                 (int64_t)unit_position, 
232                 PLAY_FORWARD,
233                 current);
239 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
240  : BC_PopupMenu(x, 
241         y,
242         patch->patchbay->mode_icons[0]->get_w() + 20,
243         "",
244         1,
245         mwindow->theme->get_image_set("mode_popup", 0),
246         10)
248         this->mwindow = mwindow;
249         this->patch = patch;
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()
257 // Set menu items
258 //      for(int i = 0; i < total_items(); i++)
259 //      {
260 //              VModePatchItem *item = (VModePatchItem*)get_item(i);
261 //              if(item->mode == mode) 
262 //                      item->set_checked(1);
263 //              else
264 //                      item->set_checked(0);
265 //      }
266         update(mode);
268 // Set keyframe
269         IntAuto *current;
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])
283         {
284                 mwindow->gui->canvas->draw_overlays();
285                 mwindow->gui->canvas->flash();
286         }
287         mwindow->session->changes_made = 1;
288         return 1;
291 IntAuto* VModePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
293         Auto *current = 0;
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, 
300                 PLAY_FORWARD,
301                 current);
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));
313         return 0;
316 void VModePatch::update(int mode)
318         set_icon(patch->patchbay->mode_to_icon(mode));
319         for(int i = 0; i < total_items(); i++)
320         {
321                 VModePatchItem *item = (VModePatchItem*)get_item(i);
322                 item->set_checked(item->mode == mode);
323         }
327 char* VModePatch::mode_to_text(int mode)
329         switch(mode)
330         {
331                 case TRANSFER_NORMAL:
332                         return _("Normal");
333                         break;
335                 case TRANSFER_REPLACE:
336                         return _("Replace");
337                         break;
339                 case TRANSFER_ADDITION:
340                         return _("Addition");
341                         break;
343                 case TRANSFER_SUBTRACT:
344                         return _("Subtract");
345                         break;
347                 case TRANSFER_MULTIPLY:
348                         return _("Multiply");
349                         break;
351                 case TRANSFER_DIVIDE:
352                         return _("Divide");
353                         break;
355                 default:
356                         return _("Normal");
357                         break;
358         }
359         return "";
367 VModePatchItem::VModePatchItem(VModePatch *popup, char *text, int mode)
368  : BC_MenuItem(text)
370         this->popup = popup;
371         this->mode = mode;
372         if(this->mode == popup->mode) set_checked(1);
375 int VModePatchItem::handle_event()
377         popup->mode = mode;
378 //      popup->set_icon(popup->patch->patchbay->mode_to_icon(mode));
379         popup->handle_event();
380         return 1;