r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / vpatchgui.C
blob35978b23da0161558ab6b6d301e78716a023049a
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->selectionstart;
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->fade_autos)->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->selectionstart;
179         Autos *fade_autos = patch->vtrack->automation->fade_autos;
180         int update_undo = !fade_autos->auto_exists_for_editing(position);
182         if(update_undo)
183                 mwindow->undo->update_undo_before(_("fade"), LOAD_AUTOMATION);
185         current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
187         float result = get_value() - current->value;
188         current->value = get_value();
190         if(update_undo)
191                 mwindow->undo->update_undo_after();
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->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->selectionstart;
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->fade_autos->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() + 40,
246         "",
247         1)
249         this->mwindow = mwindow;
250         this->patch = patch;
251         this->mode = get_keyframe(mwindow, patch)->value;
252         set_icon(patch->patchbay->mode_to_icon(this->mode));
253         set_tooltip("Overlay mode");
256 int VModePatch::handle_event()
258 // Set menu items
259         update(mode);
261 // Set keyframe
262         IntAuto *current;
263         double position = mwindow->edl->local_session->selectionstart;
264         Autos *mode_autos = patch->vtrack->automation->mode_autos;
265         int update_undo = !mode_autos->auto_exists_for_editing(position);
267         if(update_undo)
268                 mwindow->undo->update_undo_before(_("mode"), LOAD_AUTOMATION);
270         current = (IntAuto*)mode_autos->get_auto_for_editing(position);
271         current->value = mode;
273         if(update_undo)
274                 mwindow->undo->update_undo_after();
276         mwindow->sync_parameters(CHANGE_PARAMS);
278         if(mwindow->edl->session->auto_conf->mode)
279         {
280                 mwindow->gui->canvas->draw_overlays();
281                 mwindow->gui->canvas->flash();
282         }
283         mwindow->session->changes_made = 1;
284         return 1;
287 IntAuto* VModePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
289         Auto *current = 0;
290         double unit_position = mwindow->edl->local_session->selectionstart;
291         unit_position = mwindow->edl->align_to_frame(unit_position, 0);
292         unit_position = patch->vtrack->to_units(unit_position, 0);
294         return (IntAuto*)patch->vtrack->automation->mode_autos->get_prev_auto(
295                 (int64_t)unit_position, 
296                 PLAY_FORWARD,
297                 current);
301 int VModePatch::create_objects()
303         add_item(new VModePatchItem(this, mode_to_text(TRANSFER_NORMAL), TRANSFER_NORMAL));
304         add_item(new VModePatchItem(this, mode_to_text(TRANSFER_ADDITION), TRANSFER_ADDITION));
305         add_item(new VModePatchItem(this, mode_to_text(TRANSFER_SUBTRACT), TRANSFER_SUBTRACT));
306         add_item(new VModePatchItem(this, mode_to_text(TRANSFER_MULTIPLY), TRANSFER_MULTIPLY));
307         add_item(new VModePatchItem(this, mode_to_text(TRANSFER_DIVIDE), TRANSFER_DIVIDE));
308         add_item(new VModePatchItem(this, mode_to_text(TRANSFER_REPLACE), TRANSFER_REPLACE));
309         return 0;
312 void VModePatch::update(int mode)
314         set_icon(patch->patchbay->mode_to_icon(mode));
316         for(int i = 0; i < total_items(); i++)
317         {
318                 VModePatchItem *item = (VModePatchItem*)get_item(i);
319                 item->set_checked(item->mode == mode);
320         }
324 char* VModePatch::mode_to_text(int mode)
326         switch(mode)
327         {
328                 case TRANSFER_NORMAL:
329                         return _("Normal");
330                         break;
332                 case TRANSFER_REPLACE:
333                         return _("Replace");
334                         break;
336                 case TRANSFER_ADDITION:
337                         return _("Addition");
338                         break;
340                 case TRANSFER_SUBTRACT:
341                         return _("Subtract");
342                         break;
344                 case TRANSFER_MULTIPLY:
345                         return _("Multiply");
346                         break;
348                 case TRANSFER_DIVIDE:
349                         return _("Divide");
350                         break;
352                 default:
353                         return _("Normal");
354                         break;
355         }
356         return "";
364 VModePatchItem::VModePatchItem(VModePatch *popup, char *text, int mode)
365  : BC_MenuItem(text)
367         this->popup = popup;
368         this->mode = mode;
369         if(this->mode == popup->mode) set_checked(1);
372 int VModePatchItem::handle_event()
374         popup->mode = mode;
375         popup->handle_event();
376         return 1;