switch move/swap tracks, add mv trk shortcut, update msg
[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 EditPopupCopy(mwindow, this));
72         add_item(new EditPopupCut(mwindow, this));
73         add_item(new EditPopupMute(mwindow, this));
74         add_item(new EditPopupCopyPack(mwindow, this));
75         add_item(new EditPopupCutPack(mwindow, this));
76         add_item(new EditPopupMutePack(mwindow, this));
77         add_item(new EditPopupPaste(mwindow, this));
78         add_item(new EditPopupOverwrite(mwindow, this));
79         add_item(new BC_MenuItem("-"));
80         add_item(new EditPopupOverwritePlugins(mwindow, this));
81         add_item(new EditCollectEffects(mwindow, this));
82         add_item(new EditPasteEffects(mwindow, this));
83         add_item(new EditPopupTimecode(mwindow, this));
84 }
85
86 int EditPopup::activate_menu(Track *track, Edit *edit,
87                 PluginSet *pluginset, Plugin *plugin, double position)
88 {
89         this->track = track;
90         this->edit = edit;
91         this->pluginset = pluginset;
92         this->plugin = plugin;
93         this->position = position;
94         int enable = !edit ? 0 :
95                 edit->nested_edl ? 1 :
96                 !edit->asset ? 0 :
97                 edit->asset->format == FILE_REF ? 1 : 0;
98         open_edl->set_enabled(enable);
99         return BC_PopupMenu::activate_menu();
100 }
101
102 EditPopupOpenEDL::EditPopupOpenEDL(MWindow *mwindow, EditPopup *popup)
103  : BC_MenuItem(_("Open EDL"))
104 {
105         this->mwindow = mwindow;
106         this->popup = popup;
107         set_ctrl(1);
108         set_shift(1);
109 }
110
111 int EditPopupOpenEDL::handle_event()
112 {
113         Edit *edit = popup->edit;
114         if( !edit ) return 1;
115         EDL *edl = 0;
116         Indexable *idxbl = 0;
117         if( edit->asset && edit->asset->format == FILE_REF ) {
118                 FileXML xml_file;
119                 const char *filename = edit->asset->path;
120                 if( xml_file.read_from_file(filename, 1) ) {
121                         eprintf(_("Error: unable to open:\n  %s"), filename);
122                         return 1;
123                 }
124                 edl = new EDL;
125                 edl->create_objects();
126                 if( edl->load_xml(&xml_file, LOAD_ALL) ) {
127                         eprintf(_("Error: unable to load:\n  %s"), filename);
128                         edl->remove_user();
129                         return 1;
130                 }
131                 idxbl = edit->asset;
132         }
133         else if( edit->nested_edl ) {
134                 edl = edit->nested_edl;
135                 edl->add_user();
136                 idxbl = edl;
137         }
138         else {
139                 char edit_title[BCTEXTLEN];
140                 edit->get_title(edit_title);
141                 eprintf(_("Edit is not EDL: %s"), edit_title);
142                 return 1;
143         }
144         mwindow->stack_push(edl, idxbl);
145         return 1;
146 }
147
148 EditPopupClearSelect::EditPopupClearSelect(MWindow *mwindow, EditPopup *popup)
149  : BC_MenuItem(_("Clear Select"),_("Ctrl-Shift-A"),'A')
150 {
151         this->mwindow = mwindow;
152         this->popup = popup;
153         set_ctrl(1);
154         set_shift(1);
155 }
156
157 int EditPopupClearSelect::handle_event()
158 {
159         mwindow->clear_select();
160         return 1;
161 }
162
163 EditPopupSelectEdits::EditPopupSelectEdits(MWindow *mwindow, EditPopup *popup)
164  : BC_MenuItem(_("Select Edits"),_("Ctrl-Alt-a"),'a')
165 {
166         this->mwindow = mwindow;
167         this->popup = popup;
168         set_ctrl(1);
169         set_alt(1);
170 }
171
172 int EditPopupSelectEdits::handle_event()
173 {
174         mwindow->select_edits();
175         return 1;
176 }
177
178 EditPopupCopy::EditPopupCopy(MWindow *mwindow, EditPopup *popup)
179  : BC_MenuItem(_("Copy"),_("Ctrl-c"),'c')
180 {
181         this->mwindow = mwindow;
182         this->popup = popup;
183         set_ctrl(1);
184 }
185
186 int EditPopupCopy::handle_event()
187 {
188         mwindow->selected_edits_to_clipboard(0);
189         return 1;
190 }
191
192 EditPopupCopyPack::EditPopupCopyPack(MWindow *mwindow, EditPopup *popup)
193  : BC_MenuItem(_("Copy pack"),_("Ctrl-Shift-C"),'C')
194 {
195         this->mwindow = mwindow;
196         this->popup = popup;
197         set_ctrl(1);
198         set_shift(1);
199 }
200
201 int EditPopupCopyPack::handle_event()
202 {
203         mwindow->selected_edits_to_clipboard(1);
204         return 1;
205 }
206
207 EditPopupCut::EditPopupCut(MWindow *mwindow, EditPopup *popup)
208  : BC_MenuItem(_("Cut"),_("Ctrl-x"),'x')
209 {
210         this->mwindow = mwindow;
211         this->popup = popup;
212         set_ctrl(1);
213 }
214
215 int EditPopupCut::handle_event()
216 {
217         mwindow->cut_selected_edits(1, 0);
218         return 1;
219 }
220
221 EditPopupCutPack::EditPopupCutPack(MWindow *mwindow, EditPopup *popup)
222  : BC_MenuItem(_("Cut pack"),_("Ctrl-Alt-z"),'z')
223 {
224         this->mwindow = mwindow;
225         this->popup = popup;
226         set_ctrl(1);
227         set_alt();
228 }
229
230 int EditPopupCutPack::handle_event()
231 {
232         mwindow->cut_selected_edits(1, 1);
233         return 1;
234 }
235
236 EditPopupMute::EditPopupMute(MWindow *mwindow, EditPopup *popup)
237  : BC_MenuItem(C_("Mute"),_("Ctrl-m"),'m')
238 {
239         this->mwindow = mwindow;
240         this->popup = popup;
241         set_ctrl(1);
242 }
243
244 int EditPopupMute::handle_event()
245 {
246         mwindow->cut_selected_edits(0, 0);
247         return 1;
248 }
249
250 EditPopupMutePack::EditPopupMutePack(MWindow *mwindow, EditPopup *popup)
251  : BC_MenuItem(_("Mute pack"),_("Ctrl-Shift-M"),'M')
252 {
253         this->mwindow = mwindow;
254         this->popup = popup;
255         set_ctrl(1);
256         set_shift(1);
257 }
258
259 int EditPopupMutePack::handle_event()
260 {
261         mwindow->cut_selected_edits(0, 1);
262         return 1;
263 }
264
265 EditPopupPaste::EditPopupPaste(MWindow *mwindow, EditPopup *popup)
266  : BC_MenuItem(_("Paste"),_("Ctrl-v"),'v')
267 {
268         this->mwindow = mwindow;
269         this->popup = popup;
270         set_ctrl(1);
271 }
272
273 int EditPopupPaste::handle_event()
274 {
275         mwindow->paste(popup->position, popup->track, 0, 0);
276         mwindow->edl->tracks->clear_selected_edits();
277         popup->gui->draw_overlays(1);
278         if( mwindow->session->current_operation == DROP_TARGETING ) {
279                 mwindow->session->current_operation = NO_OPERATION;
280                 popup->gui->update_cursor();
281         }
282         return 1;
283 }
284
285 EditPopupOverwrite::EditPopupOverwrite(MWindow *mwindow, EditPopup *popup)
286  : BC_MenuItem(_("Overwrite"),_("Ctrl-b"),'b')
287 {
288         this->mwindow = mwindow;
289         this->popup = popup;
290         set_ctrl(1);
291 }
292
293 int EditPopupOverwrite::handle_event()
294 {
295         mwindow->paste(popup->position, popup->track, 0, -1);
296         mwindow->edl->tracks->clear_selected_edits();
297         popup->gui->draw_overlays(1);
298         if( mwindow->session->current_operation == DROP_TARGETING ) {
299                 mwindow->session->current_operation = NO_OPERATION;
300                 popup->gui->update_cursor();
301         }
302         return 1;
303 }
304
305 EditPopupOverwritePlugins::EditPopupOverwritePlugins(MWindow *mwindow, EditPopup *popup)
306  : BC_MenuItem(_("Overwrite Plugins"),_("Ctrl-Shift-P"),'P')
307 {
308         this->mwindow = mwindow;
309         this->popup = popup;
310         set_ctrl(1);
311         set_shift(1);
312 }
313
314 int EditPopupOverwritePlugins::handle_event()
315 {
316         mwindow->paste_clipboard(popup->track, popup->position, 1, 0,
317                         mwindow->edl->session->labels_follow_edits,
318                         mwindow->edl->session->autos_follow_edits,
319                         mwindow->edl->session->plugins_follow_edits);
320         mwindow->edl->tracks->clear_selected_edits();
321         if( mwindow->session->current_operation == DROP_TARGETING ) {
322                 mwindow->session->current_operation = NO_OPERATION;
323                 popup->gui->update_cursor();
324         }
325         return 1;
326 }
327
328
329 EditCollectEffects::EditCollectEffects(MWindow *mwindow, EditPopup *popup)
330  : BC_MenuItem(_("Collect Effects"))
331 {
332         this->mwindow = mwindow;
333         this->popup = popup;
334         set_ctrl(1);
335 }
336
337 int EditCollectEffects::handle_event()
338 {
339         if( mwindow->session->current_operation == NO_OPERATION )
340                 mwindow->collect_effects();
341         return 1;
342 }
343
344 EditPasteEffects::EditPasteEffects(MWindow *mwindow, EditPopup *popup)
345  : BC_MenuItem(_("Paste Effects"))
346 {
347         this->mwindow = mwindow;
348         this->popup = popup;
349         set_ctrl(1);
350         set_shift(1);
351 }
352
353 int EditPasteEffects::handle_event()
354 {
355         if( mwindow->session->current_operation == NO_OPERATION )
356                 mwindow->paste_effects();
357         return 1;
358 }
359
360 EditPopupTimecode::EditPopupTimecode(MWindow *mwindow, EditPopup *popup)
361  : BC_MenuItem(_("Timecode"),_("Ctrl-!"),'!')
362 {
363         this->mwindow = mwindow;
364         this->popup = popup;
365         set_ctrl(1);
366 }
367
368 int EditPopupTimecode::handle_event()
369 {
370         if( mwindow->session->current_operation != NO_OPERATION ) return 1;
371         Edit *edit = popup->edit;
372         if( !edit || !edit->asset ) return 1;
373         Asset *asset = edit->asset;
374         double timecode = asset->timecode != -2 ? asset->timecode :
375                 FFMPEG::get_timecode(asset->path,
376                         edit->track->data_type, edit->channel,
377                         mwindow->edl->session->frame_rate);
378         asset->timecode = timecode;
379         if( timecode >= 0 ) {
380                 int64_t pos = edit->startproject + edit->startsource;
381                 double position = edit->track->from_units(pos);
382                 mwindow->set_timecode_offset(timecode - position);
383         }
384         else
385                 mwindow->set_timecode_offset(0);
386         return 1;
387 }
388