r1006: configure: Use libx264_pic instead of libx264 if available.
[cinelerra_cv/mob.git] / cinelerra / vpatchgui.C
bloba9c2082c851ff31616479b86f1fa0238ddb3f0d9
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(fade->get_w(),
95                                      value, 
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);
99                 }
100         }
101         else
102         if(h - y1 >= mwindow->theme->fade_h)
103         {
104                 patchbay->add_subwindow(fade = new VFadePatch(mwindow, 
105                         this, 
106                         x1 + x, 
107                         y1 + y, 
108                         patchbay->get_w() - 10));
109         }
110         y1 += mwindow->theme->fade_h;
112         if(mode)
113         {
114                 if(h - y1 < mwindow->theme->mode_h)
115                 {
116                         delete mode;
117                         mode = 0;
118                         delete nudge;
119                         nudge = 0;
120                 }
121                 else
122                 {
123                         mode->update(mode->get_keyframe(mwindow, this)->value);
124                         nudge->update();
125                 }
126         }
127         else
128         if(h - y1 >= mwindow->theme->mode_h)
129         {
130                 patchbay->add_subwindow(mode = new VModePatch(mwindow, 
131                         this, 
132                         x1 + x, 
133                         y1 + y));
134                 mode->create_objects();
135                 x1 += mode->get_w() + 10;
136                 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
137                         this,
138                         x1 + x,
139                         y1 + y,
140                         patchbay->get_w() - x1 - 10));
141         }
147         y1 += mwindow->theme->mode_h;
148         
149         return y1;
154 void VPatchGUI::synchronize_fade(float value_change)
156         if(fade && !change_source) 
157         {
158                 fade->update(Units::to_int64(fade->get_value() + value_change));
159                 fade->update_edl();
160         }
164 VFadePatch::VFadePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y, int w)
165  : BC_ISlider(x, 
166                         y,
167                         0,
168                         w, 
169                         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;
175         this->patch = patch;
178 float VFadePatch::update_edl()
180         FloatAuto *current;
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);
193         return result;
196 int VFadePatch::handle_event()
198         if(shift_down())
199         {
200                 update(100);
201                 set_tooltip(get_caption());
202         }
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])
219         {
220                 mwindow->gui->canvas->draw_overlays();
221                 mwindow->gui->canvas->flash();
222         }
223         return 1;
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);
231         Auto *current = 0;
233         return (FloatAuto*)patch->vtrack->automation->autos[AUTOMATION_FADE]->get_prev_auto(
234                 (int64_t)unit_position, 
235                 PLAY_FORWARD,
236                 current);
242 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
243  : BC_PopupMenu(x, 
244         y,
245         patch->patchbay->mode_icons[0]->get_w() + 20,
246         "",
247         1,
248         mwindow->theme->get_image_set("mode_popup", 0),
249         10)
251         this->mwindow = mwindow;
252         this->patch = patch;
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()
260 // Set menu items
261 //      for(int i = 0; i < total_items(); i++)
262 //      {
263 //              VModePatchItem *item = (VModePatchItem*)get_item(i);
264 //              if(item->mode == mode) 
265 //                      item->set_checked(1);
266 //              else
267 //                      item->set_checked(0);
268 //      }
269         update(mode);
271 // Set keyframe
272         IntAuto *current;
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])
286         {
287                 mwindow->gui->canvas->draw_overlays();
288                 mwindow->gui->canvas->flash();
289         }
290         mwindow->session->changes_made = 1;
291         return 1;
294 IntAuto* VModePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
296         Auto *current = 0;
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, 
303                 PLAY_FORWARD,
304                 current);
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));
317         return 0;
320 void VModePatch::update(int mode)
322         set_icon(patch->patchbay->mode_to_icon(mode));
323         for(int i = 0; i < total_items(); i++)
324         {
325                 VModePatchItem *item = (VModePatchItem*)get_item(i);
326                 item->set_checked(item->mode == mode);
327         }
331 char* VModePatch::mode_to_text(int mode)
333         switch(mode)
334         {
335                 case TRANSFER_NORMAL:
336                         return _("Normal");
337                         break;
339                 case TRANSFER_REPLACE:
340                         return _("Replace");
341                         break;
343                 case TRANSFER_ADDITION:
344                         return _("Addition");
345                         break;
347                 case TRANSFER_SUBTRACT:
348                         return _("Subtract");
349                         break;
351                 case TRANSFER_MULTIPLY:
352                         return _("Multiply");
353                         break;
355                 case TRANSFER_DIVIDE:
356                         return _("Divide");
357                         break;
359                 case TRANSFER_MAX:
360                         return _("Max");
361                         break;
363                 default:
364                         return _("Normal");
365                         break;
366         }
367         return "";
375 VModePatchItem::VModePatchItem(VModePatch *popup, char *text, int mode)
376  : BC_MenuItem(text)
378         this->popup = popup;
379         this->mode = mode;
380         if(this->mode == popup->mode) set_checked(1);
383 int VModePatchItem::handle_event()
385         popup->mode = mode;
386 //      popup->set_icon(popup->patch->patchbay->mode_to_icon(mode));
387         popup->handle_event();
388         return 1;