Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / keyframepopup.C
blob6486f16dc006b557d539024f5660dd6c9314c38d
1 #include "cwindow.h"
2 #include "edl.h"
3 #include "keyframe.h"
4 #include "keyframepopup.h"
5 #include "language.h"
6 #include "mainundo.h"
7 #include "mwindow.h"
8 #include "mwindowgui.h"
9 #include "localsession.h"
10 #include "cwindowgui.h" 
11 #include "cpanel.h"
12 #include "patchbay.h"
13 #include "patchgui.h" 
14 #include "apatchgui.h"
15 #include "vpatchgui.h"
16 #include "track.h"
17 #include "maincursor.h"
18 #include "bcwindowbase.h"
19 #include "filexml.h"
20 #include "edlsession.h"
21 #include "autoconf.h"
23 KeyframePopup::KeyframePopup(MWindow *mwindow, MWindowGUI *gui)
24  : BC_PopupMenu(0, 
25                 0, 
26                 0, 
27                 "", 
28                 0)
30         this->mwindow = mwindow;
31         this->gui = gui;
32         key_show = 0;
33         key_delete = 0;
34         key_copy = 0;
37 KeyframePopup::~KeyframePopup()
41 void KeyframePopup::create_objects()
43 //      add_item(key_show = new KeyframePopupShow(mwindow, this));
44         add_item(key_delete = new KeyframePopupDelete(mwindow, this));
45         add_item(key_copy = new KeyframePopupCopy(mwindow, this));
48 int KeyframePopup::update(Plugin *plugin, KeyFrame *keyframe)
50         this->keyframe_plugin = plugin;
51         this->keyframe_auto = keyframe;
52         this->keyframe_autos = 0;
53         this->keyframe_automation = 0;
54         return 0;
57 int KeyframePopup::update(Automation *automation, Autos *autos, Auto *auto_keyframe)
59         this->keyframe_plugin = 0;
60         this->keyframe_automation = automation;
61         this->keyframe_autos = autos;
62         this->keyframe_auto = auto_keyframe;
64         /* snap to cursor */
65         double current_position = mwindow->edl->local_session->get_selectionstart(1);
66         double new_position = keyframe_automation->track->from_units(keyframe_auto->position);
67         mwindow->edl->local_session->set_selectionstart(new_position);
68         mwindow->edl->local_session->set_selectionend(new_position);
69         if (current_position != new_position)
70         {
71                 mwindow->edl->local_session->set_selectionstart(new_position);
72                 mwindow->edl->local_session->set_selectionend(new_position);
73                 mwindow->gui->lock_window();
74                 mwindow->gui->update(1, 1, 1, 1, 1, 1, 0);      
75                 mwindow->gui->unlock_window();
76         }
77         return 0;
80 KeyframePopupDelete::KeyframePopupDelete(MWindow *mwindow, KeyframePopup *popup)
81  : BC_MenuItem(_("Delete keyframe"))
83         this->mwindow = mwindow;
84         this->popup = popup;
87 KeyframePopupDelete::~KeyframePopupDelete()
91 int KeyframePopupDelete::handle_event()
93         delete popup->keyframe_auto;
94         mwindow->save_backup();
95         mwindow->undo->update_undo(_("delete keyframe"), LOAD_ALL);
97         mwindow->gui->update(0,
98                 1,      // 1 for incremental drawing.  2 for full refresh
99                 0,
100                 0,
101                 0,
102             0,   
103             0);
104         mwindow->update_plugin_guis();
105         mwindow->restart_brender();
106         mwindow->sync_parameters(CHANGE_EDL);
108         return 1;
111 KeyframePopupShow::KeyframePopupShow(MWindow *mwindow, KeyframePopup *popup)
112  : BC_MenuItem(_("Show keyframe settings"))
114         this->mwindow = mwindow;
115         this->popup = popup;
118 KeyframePopupShow::~KeyframePopupShow()
122 int KeyframePopupShow::handle_event()
124         if (popup->keyframe_plugin)
125         {
126                 mwindow->update_plugin_guis();
127                 mwindow->show_plugin(popup->keyframe_plugin);
128         } else
129         if (popup->keyframe_automation)
130         {
133                 mwindow->cwindow->gui->lock_window();
134                 int show_window = 1;
135                 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->projector_autos ||
136                    popup->keyframe_autos == (Autos *)popup->keyframe_automation->pzoom_autos)
137                    
138                 {
139                         mwindow->cwindow->gui->set_operation(CWINDOW_PROJECTOR);        
140                 } else
141                 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->camera_autos ||
142                    popup->keyframe_autos == (Autos *)popup->keyframe_automation->czoom_autos)
143                    
144                 {
145                         mwindow->cwindow->gui->set_operation(CWINDOW_CAMERA);   
146                 } else
147                 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mode_autos)
148                    
149                 {
150                         // no window to be shown
151                         show_window = 0;
152                         // first find the appropriate patchgui
153                         PatchBay *patchbay = mwindow->gui->patchbay;
154                         PatchGUI *patchgui = 0;
155                         for (int i = 0; i < patchbay->patches.total; i++)
156                                 if (patchbay->patches.values[i]->track == popup->keyframe_automation->track)
157                                         patchgui = patchbay->patches.values[i];         
158                         if (patchgui != 0)
159                         {
160 // FIXME: repositioning of the listbox needs support in guicast
161 //                              int cursor_x = popup->get_relative_cursor_x();
162 //                              int cursor_y = popup->get_relative_cursor_y();
163 //                              vpatchgui->mode->reposition_window(cursor_x, cursor_y);
166 // Open the popup menu
167                                 VPatchGUI *vpatchgui = (VPatchGUI *)patchgui;
168                                 vpatchgui->mode->activate_menu();
169                         }
170                 } else
171                 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mask_autos)
172                    
173                 {
174                         mwindow->cwindow->gui->set_operation(CWINDOW_MASK);     
175                 } else
176                 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->pan_autos)
177                    
178                 {
179                         // no window to be shown
180                         show_window = 0;
181                         // first find the appropriate patchgui
182                         PatchBay *patchbay = mwindow->gui->patchbay;
183                         PatchGUI *patchgui = 0;
184                         for (int i = 0; i < patchbay->patches.total; i++)
185                                 if (patchbay->patches.values[i]->track == popup->keyframe_automation->track)
186                                         patchgui = patchbay->patches.values[i];         
187                         if (patchgui != 0)
188                         {
189 // Open the popup menu at current mouse position
190                                 APatchGUI *apatchgui = (APatchGUI *)patchgui;
191                                 int cursor_x = popup->get_relative_cursor_x();
192                                 int cursor_y = popup->get_relative_cursor_y();
193                                 apatchgui->pan->activate(cursor_x, cursor_y);
194                         }
195                         
197                 } else
198                 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->fade_autos)
199                    
200                 {
201                         // no window to be shown, so do nothing
202                         // IDEA: open window for fading
203                         show_window = 0;
204                 } else
205                 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mute_autos)
206                    
207                 {
208                         // no window to be shown, so do nothing
209                         // IDEA: directly switch
210                         show_window = 0;
211                 } else;
212                 
214 // ensure bringing to front
215                 if (show_window)
216                 {
217                         ((CPanelToolWindow *)(mwindow->cwindow->gui->composite_panel->operation[CWINDOW_TOOL_WINDOW]))->set_shown(0);
218                         ((CPanelToolWindow *)(mwindow->cwindow->gui->composite_panel->operation[CWINDOW_TOOL_WINDOW]))->set_shown(1);
219                 }
220                 mwindow->cwindow->gui->unlock_window();
224         }
225         return 1;
230 KeyframePopupCopy::KeyframePopupCopy(MWindow *mwindow, KeyframePopup *popup)
231  : BC_MenuItem(_("Copy keyframe"))
233         this->mwindow = mwindow;
234         this->popup = popup;
237 KeyframePopupCopy::~KeyframePopupCopy()
241 int KeyframePopupCopy::handle_event()
244         FIXME:
245         we want to copy just keyframe under cursor, NOT all keyframes at this frame
246         - very hard to do, so this is good approximation for now...
248         
249 #if 0
250         if (popup->keyframe_automation)
251         {
252                 FileXML file;
253                 EDL *edl = mwindow->edl;
254                 Track *track = popup->keyframe_automation->track;
255                 int64_t position = popup->keyframe_auto->position;
256                 AutoConf autoconf;
257 // first find out type of our auto
258                 autoconf.set_all(0);
259                 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->projector_autos)
260                         autoconf.projector = 1;
261                 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->pzoom_autos)
262                         autoconf.pzoom = 1;
263                 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->camera_autos)
264                         autoconf.camera = 1;
265                 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->czoom_autos)
266                         autoconf.czoom = 1;             
267                 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mode_autos)
268                         autoconf.mode = 1;
269                 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mask_autos)
270                         autoconf.mask = 1;
271                 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->pan_autos)
272                         autoconf.pan = 1;                  
273                 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->fade_autos)
274                         autoconf.fade = 1;
275                 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mute_autos)
276                         autoconf.mute = 1;              
279 // now create a clipboard
280                 file.tag.set_title("AUTO_CLIPBOARD");
281                 file.tag.set_property("LENGTH", 0);
282                 file.tag.set_property("FRAMERATE", edl->session->frame_rate);
283                 file.tag.set_property("SAMPLERATE", edl->session->sample_rate);
284                 file.append_tag();
285                 file.append_newline();
286                 file.append_newline();
288 /*              track->copy_automation(position, 
289                         position, 
290                         &file,
291                         0,
292                         0);
293                         */
294                 file.tag.set_title("TRACK");
295 // Video or audio
296                 track->save_header(&file);
297                 file.append_tag();
298                 file.append_newline();
300                 track->automation->copy(position, 
301                         position, 
302                         &file,
303                         0,
304                         0,
305                         &autoconf);
306                 
307                 
308                 
309                 file.tag.set_title("/TRACK");
310                 file.append_tag();
311                 file.append_newline();
312                 file.append_newline();
313                 file.append_newline();
314                 file.append_newline();
318                 file.tag.set_title("/AUTO_CLIPBOARD");
319                 file.append_tag();
320                 file.append_newline();
321                 file.terminate_string();
323                 mwindow->gui->lock_window();
324                 mwindow->gui->get_clipboard()->to_clipboard(file.string, 
325                         strlen(file.string), 
326                         SECONDARY_SELECTION);
327                 mwindow->gui->unlock_window();
329         } else
330 #endif
331                 mwindow->copy_automation();
332         return 1;
338 //      Local Variables:
339 //      mode: C++
340 //      c-file-style: "linux"
341 //      End: