r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / vpatchgui.C
blob1895b2575a8dc57d712c2702845252175f1f1ba7
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 "localsession.h"
10 #include "mainsession.h"
11 #include "mainundo.h"
12 #include "mwindow.h"
13 #include "mwindowgui.h"
14 #include "overlayframe.inc"
15 #include "patchbay.h"
16 #include "theme.h"
17 #include "trackcanvas.h"
18 #include "vpatchgui.h"
19 #include "vtrack.h"
21 #include <string.h>
23 #include <libintl.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;
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(x1 + x, 
54                 y1 + y);
55         y1 += mwindow->theme->fade_h;
56         if(mode) mode->reposition_window(x1 + x,
57                 y1 + y);
58         y1 += mwindow->theme->mode_h;
59         return y1;
62 int VPatchGUI::update(int x, int y)
64         int h = track->vertical_span(mwindow->theme);
65         int x1 = 0;
66         int y1 = PatchGUI::update(x, y);
68         if(fade)
69         {
70                 if(h - y1 < mwindow->theme->fade_h)
71                 {
72                         delete fade;
73                         fade = 0;
74                 }
75                 else
76                 {
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,
83                                 PLAY_FORWARD, 
84                                 previous, 
85                                 next);
86                         fade->update(value);
87 //                      fade->update((int)fade->get_keyframe(mwindow, this)->value);
88                 }
89         }
90         else
91         if(h - y1 >= mwindow->theme->fade_h)
92         {
93                 patchbay->add_subwindow(fade = new VFadePatch(mwindow, 
94                         this, 
95                         x1 + x, 
96                         y1 + y, 
97                         patchbay->get_w() - 10));
98         }
99         y1 += mwindow->theme->fade_h;
101         if(mode)
102         {
103                 if(h - y1 < mwindow->theme->mode_h)
104                 {
105                         delete mode;
106                         mode = 0;
107                 }
108                 else
109                 {
110                         mode->update(mode->get_keyframe(mwindow, this)->value);
111                 }
112         }
113         else
114         if(h - y1 >= mwindow->theme->mode_h)
115         {
116                 patchbay->add_subwindow(mode = new VModePatch(mwindow, 
117                         this, 
118                         x1 + x, 
119                         y1 + y));
120                 mode->create_objects();
121         }
122         y1 += mwindow->theme->mode_h;
123         
124         return y1;
128 void VPatchGUI::create_mode()
133 void VPatchGUI::synchronize_fade(float value_change)
135         if(fade && !change_source) 
136         {
137                 fade->update(Units::to_int64(fade->get_value() + value_change));
138                 fade->update_edl();
139         }
143 VFadePatch::VFadePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y, int w)
144  : BC_ISlider(x, 
145                         y,
146                         0,
147                         w, 
148                         w, 
149                         0, 
150                         MAX_VIDEO_FADE, 
151                         (int64_t)get_keyframe(mwindow, patch)->value)
153         this->mwindow = mwindow;
154         this->patch = patch;
157 float VFadePatch::update_edl()
159         FloatAuto *current;
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);
164         if(update_undo)
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();
172         if(update_undo)
173                 mwindow->undo->update_undo_after();
175         return result;
178 int VFadePatch::handle_event()
180         if(shift_down())
181         {
182                 update(100);
183                 set_tooltip(get_caption());
184         }
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)
201         {
202                 mwindow->gui->canvas->draw_overlays();
203                 mwindow->gui->canvas->flash();
204         }
205         return 1;
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);
213         Auto *current = 0;
214         
215         return (FloatAuto*)patch->vtrack->automation->fade_autos->get_prev_auto(
216                 (int64_t)unit_position, 
217                 PLAY_FORWARD,
218                 current);
224 VModePatch::VModePatch(MWindow *mwindow, VPatchGUI *patch, int x, int y)
225  : BC_PopupMenu(x, 
226         y,
227         patch->patchbay->get_w() - x - 10,
228         mode_to_text(get_keyframe(mwindow, patch)->value),
229         1)
231         this->mwindow = mwindow;
232         this->patch = patch;
235 int VModePatch::handle_event()
237         IntAuto *current;
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);
242         if(update_undo)
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());
248         if(update_undo)
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)
255         {
256                 mwindow->gui->canvas->draw_overlays();
257                 mwindow->gui->canvas->flash();
258         }
259         mwindow->session->changes_made = 1;
260         return 1;
263 IntAuto* VModePatch::get_keyframe(MWindow *mwindow, VPatchGUI *patch)
265         Auto *current = 0;
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, 
272                 PLAY_FORWARD,
273                 current);
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));
285         return 0;
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)
307         switch(mode)
308         {
309                 case TRANSFER_NORMAL:
310                         return _("Normal");
311                         break;
312                 
313                 case TRANSFER_REPLACE:
314                         return _("Replace");
315                         break;
316                 
317                 case TRANSFER_ADDITION:
318                         return _("Addition");
319                         break;
320                 
321                 case TRANSFER_SUBTRACT:
322                         return _("Subtract");
323                         break;
324                 
325                 case TRANSFER_MULTIPLY:
326                         return _("Multiply");
327                         break;
328                 
329                 case TRANSFER_DIVIDE:
330                         return _("Divide");
331                         break;
332                 
333                 default:
334                         return _("Normal");
335                         break;
336         }
337         return "";
344 VModePatchItem::VModePatchItem(VModePatch *popup, char *text, int mode)
345  : BC_MenuItem(text)
347         this->popup = popup;
348         this->mode = mode;
351 int VModePatchItem::handle_event()
353         popup->set_text(get_text());
354         popup->handle_event();
355         return 1;