Andrew fixed Attach Transitions and added english tips
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / editpopup.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "asset.h"
23 #include "assets.h"
24 #include "awindow.h"
25 #include "awindowgui.h"
26 #include "edit.h"
27 #include "edits.h"
28 #include "editpopup.h"
29 #include "edl.h"
30 #include "edlsession.h"
31 #include "file.h"
32 #include "filexml.h"
33 #include "keys.h"
34 #include "language.h"
35 #include "localsession.h"
36 #include "mainerror.h"
37 #include "mainsession.h"
38 #include "mwindow.h"
39 #include "mwindowgui.h"
40 #include "plugindialog.h"
41 #include "resizetrackthread.h"
42 #include "track.h"
43 #include "tracks.h"
44 #include "trackcanvas.h"
45
46 #include <string.h>
47
48 EditPopup::EditPopup(MWindow *mwindow, MWindowGUI *gui)
49  : BC_PopupMenu(0, 0, 0, "", 0)
50 {
51         this->mwindow = mwindow;
52         this->gui = gui;
53
54         track = 0;
55         edit = 0;
56         plugin = 0;
57         pluginset = 0;
58         position = 0;
59         open_edl = 0;
60 }
61
62 EditPopup::~EditPopup()
63 {
64 }
65
66 void EditPopup::create_objects()
67 {
68         add_item(open_edl = new EditPopupOpenEDL(mwindow, this));
69         add_item(new EditPopupClearSelect(mwindow, this));
70         add_item(new EditPopupSelectEdits(mwindow, this));
71         add_item(new EditPopupDeselectEdits(mwindow, this));
72         add_item(new EditPopupCopy(mwindow, this));
73         add_item(new EditPopupCut(mwindow, this));
74         add_item(new EditPopupMute(mwindow, this));
75         add_item(new EditPopupCopyPack(mwindow, this));
76         add_item(new EditPopupCutPack(mwindow, this));
77         add_item(new EditPopupMutePack(mwindow, this));
78         add_item(new EditPopupPaste(mwindow, this));
79         add_item(new EditPopupOverwrite(mwindow, this));
80         add_item(new BC_MenuItem("-"));
81         add_item(new EditPopupOverwritePlugins(mwindow, this));
82         add_item(new EditCollectEffects(mwindow, this));
83         add_item(new EditPasteEffects(mwindow, this));
84         add_item(new EditPopupTimecode(mwindow, this));
85 }
86
87 int EditPopup::activate_menu(Track *track, Edit *edit,
88                 PluginSet *pluginset, Plugin *plugin, double position)
89 {
90         this->track = track;
91         this->edit = edit;
92         this->pluginset = pluginset;
93         this->plugin = plugin;
94         this->position = position;
95         int enable = !edit ? 0 :
96                 edit->nested_edl ? 1 :
97                 !edit->asset ? 0 :
98                 edit->asset->format == FILE_REF ? 1 : 0;
99         open_edl->set_enabled(enable);
100         return BC_PopupMenu::activate_menu();
101 }
102
103 EditPopupOpenEDL::EditPopupOpenEDL(MWindow *mwindow, EditPopup *popup)
104  : BC_MenuItem(_("Open EDL"))
105 {
106         this->mwindow = mwindow;
107         this->popup = popup;
108         set_ctrl(1);
109         set_shift(1);
110 }
111
112 int EditPopupOpenEDL::handle_event()
113 {
114         Edit *edit = popup->edit;
115         if( !edit ) return 1;
116         EDL *edl = 0;
117         Indexable *idxbl = 0;
118         if( edit->asset && edit->asset->format == FILE_REF ) {
119                 FileXML xml_file;
120                 const char *filename = edit->asset->path;
121                 if( xml_file.read_from_file(filename, 1) ) {
122                         eprintf(_("Error: unable to open:\n  %s"), filename);
123                         return 1;
124                 }
125                 edl = new EDL;
126                 edl->create_objects();
127                 if( edl->load_xml(&xml_file, LOAD_ALL) ) {
128                         eprintf(_("Error: unable to load:\n  %s"), filename);
129                         edl->remove_user();
130                         return 1;
131                 }
132                 idxbl = edit->asset;
133         }
134         else if( edit->nested_edl ) {
135                 edl = edit->nested_edl;
136                 edl->add_user();
137                 idxbl = edl;
138         }
139         else {
140                 char edit_title[BCTEXTLEN];
141                 edit->get_title(edit_title);
142                 eprintf(_("Edit is not EDL: %s"), edit_title);
143                 return 1;
144         }
145         mwindow->stack_push(edl, idxbl);
146         return 1;
147 }
148
149 EditPopupClearSelect::EditPopupClearSelect(MWindow *mwindow, EditPopup *popup)
150  : BC_MenuItem(_("Clear Select"),_("Ctrl-Shift-A"),'A')
151 {
152         this->mwindow = mwindow;
153         this->popup = popup;
154         set_ctrl(1);
155         set_shift(1);
156 }
157
158 int EditPopupClearSelect::handle_event()
159 {
160         mwindow->clear_select();
161         return 1;
162 }
163
164 EditPopupSelectEdits::EditPopupSelectEdits(MWindow *mwindow, EditPopup *popup)
165  : BC_MenuItem(_("Select Edits"),_("Ctrl-Alt-'"),'\'')
166 {
167         this->mwindow = mwindow;
168         this->popup = popup;
169         set_ctrl(1);
170         set_alt(1);
171 }
172
173 int EditPopupSelectEdits::handle_event()
174 {
175         mwindow->select_edits(1);
176         return 1;
177 }
178
179 EditPopupDeselectEdits::EditPopupDeselectEdits(MWindow *mwindow, EditPopup *popup)
180  : BC_MenuItem(_("Deselect Edits"))
181 {
182         this->mwindow = mwindow;
183         this->popup = popup;
184 }
185
186 int EditPopupDeselectEdits::handle_event()
187 {
188         mwindow->select_edits(0);
189         return 1;
190 }
191
192 EditPopupCopy::EditPopupCopy(MWindow *mwindow, EditPopup *popup)
193  : BC_MenuItem(_("Copy"),_("Ctrl-c"),'c')
194 {
195         this->mwindow = mwindow;
196         this->popup = popup;
197         set_ctrl(1);
198 }
199
200 int EditPopupCopy::handle_event()
201 {
202         mwindow->selected_edits_to_clipboard(0);
203         return 1;
204 }
205
206 EditPopupCopyPack::EditPopupCopyPack(MWindow *mwindow, EditPopup *popup)
207  : BC_MenuItem(_("Copy pack"),_("Ctrl-Shift-C"),'C')
208 {
209         this->mwindow = mwindow;
210         this->popup = popup;
211         set_ctrl(1);
212         set_shift(1);
213 }
214
215 int EditPopupCopyPack::handle_event()
216 {
217         mwindow->selected_edits_to_clipboard(1);
218         return 1;
219 }
220
221 EditPopupCut::EditPopupCut(MWindow *mwindow, EditPopup *popup)
222  : BC_MenuItem(_("Cut"),_("Ctrl-x"),'x')
223 {
224         this->mwindow = mwindow;
225         this->popup = popup;
226         set_ctrl(1);
227 }
228
229 int EditPopupCut::handle_event()
230 {
231         mwindow->cut_selected_edits(1, 0);
232         return 1;
233 }
234
235 EditPopupCutPack::EditPopupCutPack(MWindow *mwindow, EditPopup *popup)
236  : BC_MenuItem(_("Cut pack"),_("Ctrl-Alt-z"),'z')
237 {
238         this->mwindow = mwindow;
239         this->popup = popup;
240         set_ctrl(1);
241         set_alt();
242 }
243
244 int EditPopupCutPack::handle_event()
245 {
246         mwindow->cut_selected_edits(1, 1);
247         return 1;
248 }
249
250 EditPopupMute::EditPopupMute(MWindow *mwindow, EditPopup *popup)
251  : BC_MenuItem(C_("Mute"),_("Ctrl-m"),'m')
252 {
253         this->mwindow = mwindow;
254         this->popup = popup;
255         set_ctrl(1);
256 }
257
258 int EditPopupMute::handle_event()
259 {
260         mwindow->cut_selected_edits(0, 0);
261         return 1;
262 }
263
264 EditPopupMutePack::EditPopupMutePack(MWindow *mwindow, EditPopup *popup)
265  : BC_MenuItem(_("Mute pack"),_("Ctrl-Shift-M"),'M')
266 {
267         this->mwindow = mwindow;
268         this->popup = popup;
269         set_ctrl(1);
270         set_shift(1);
271 }
272
273 int EditPopupMutePack::handle_event()
274 {
275         mwindow->cut_selected_edits(0, 1);
276         return 1;
277 }
278
279 EditPopupPaste::EditPopupPaste(MWindow *mwindow, EditPopup *popup)
280  : BC_MenuItem(_("Paste"),_("Ctrl-v"),'v')
281 {
282         this->mwindow = mwindow;
283         this->popup = popup;
284         set_ctrl(1);
285 }
286
287 int EditPopupPaste::handle_event()
288 {
289         mwindow->paste(popup->position, popup->track, 0, 0);
290         mwindow->edl->tracks->clear_selected_edits();
291         popup->gui->draw_overlays(1);
292         if( mwindow->session->current_operation == DROP_TARGETING ) {
293                 mwindow->session->current_operation = NO_OPERATION;
294                 popup->gui->update_cursor();
295         }
296         return 1;
297 }
298
299 EditPopupOverwrite::EditPopupOverwrite(MWindow *mwindow, EditPopup *popup)
300  : BC_MenuItem(_("Overwrite"),_("Ctrl-b"),'b')
301 {
302         this->mwindow = mwindow;
303         this->popup = popup;
304         set_ctrl(1);
305 }
306
307 int EditPopupOverwrite::handle_event()
308 {
309         mwindow->paste(popup->position, popup->track, 0, -1);
310         mwindow->edl->tracks->clear_selected_edits();
311         popup->gui->draw_overlays(1);
312         if( mwindow->session->current_operation == DROP_TARGETING ) {
313                 mwindow->session->current_operation = NO_OPERATION;
314                 popup->gui->update_cursor();
315         }
316         return 1;
317 }
318
319 EditPopupOverwritePlugins::EditPopupOverwritePlugins(MWindow *mwindow, EditPopup *popup)
320  : BC_MenuItem(_("Overwrite Plugins"),_("Ctrl-Shift-P"),'P')
321 {
322         this->mwindow = mwindow;
323         this->popup = popup;
324         set_ctrl(1);
325         set_shift(1);
326 }
327
328 int EditPopupOverwritePlugins::handle_event()
329 {
330         mwindow->paste_clipboard(popup->track, popup->position, 1, 0,
331                         mwindow->edl->session->labels_follow_edits,
332                         mwindow->edl->session->autos_follow_edits,
333                         mwindow->edl->session->plugins_follow_edits);
334         mwindow->edl->tracks->clear_selected_edits();
335         if( mwindow->session->current_operation == DROP_TARGETING ) {
336                 mwindow->session->current_operation = NO_OPERATION;
337                 popup->gui->update_cursor();
338         }
339         return 1;
340 }
341
342
343 EditCollectEffects::EditCollectEffects(MWindow *mwindow, EditPopup *popup)
344  : BC_MenuItem(_("Collect Effects"))
345 {
346         this->mwindow = mwindow;
347         this->popup = popup;
348         set_ctrl(1);
349 }
350
351 int EditCollectEffects::handle_event()
352 {
353         if( mwindow->session->current_operation == NO_OPERATION )
354                 mwindow->collect_effects();
355         return 1;
356 }
357
358 EditPasteEffects::EditPasteEffects(MWindow *mwindow, EditPopup *popup)
359  : BC_MenuItem(_("Paste Effects"))
360 {
361         this->mwindow = mwindow;
362         this->popup = popup;
363         set_ctrl(1);
364         set_shift(1);
365 }
366
367 int EditPasteEffects::handle_event()
368 {
369         if( mwindow->session->current_operation == NO_OPERATION )
370                 mwindow->paste_effects();
371         return 1;
372 }
373
374 EditPopupTimecode::EditPopupTimecode(MWindow *mwindow, EditPopup *popup)
375  : BC_MenuItem(_("Timecode"),_("Ctrl-!"),'!')
376 {
377         this->mwindow = mwindow;
378         this->popup = popup;
379         set_ctrl(1);
380 }
381
382 int EditPopupTimecode::handle_event()
383 {
384         if( mwindow->session->current_operation != NO_OPERATION ) return 1;
385         Edit *edit = popup->edit;
386         if( !edit || !edit->asset ) return 1;
387         Asset *asset = edit->asset;
388         double timecode = asset->timecode != -2 ? asset->timecode :
389                 FFMPEG::get_timecode(asset->path,
390                         edit->track->data_type, edit->channel,
391                         mwindow->edl->session->frame_rate);
392         asset->timecode = timecode;
393         if( timecode >= 0 ) {
394                 int64_t pos = edit->startproject + edit->startsource;
395                 double position = edit->track->from_units(pos);
396                 mwindow->set_timecode_offset(timecode - position);
397         }
398         else
399                 mwindow->set_timecode_offset(0);
400         return 1;
401 }
402