es.po update by rafa, add ms win10 cygwin port, add pulseaudio, new config flags...
[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 EditPopupCopy(mwindow, this));
71         add_item(new EditPopupCut(mwindow, this));
72         add_item(new EditPopupMute(mwindow, this));
73         add_item(new EditPopupCopyPack(mwindow, this));
74         add_item(new EditPopupCutPack(mwindow, this));
75         add_item(new EditPopupMutePack(mwindow, this));
76         add_item(new EditPopupPaste(mwindow, this));
77         add_item(new EditPopupOverwrite(mwindow, this));
78         add_item(new EditPopupOverwritePlugins(mwindow, this));
79 }
80
81 int EditPopup::activate_menu(Track *track, Edit *edit,
82                 PluginSet *pluginset, Plugin *plugin, double position)
83 {
84         this->track = track;
85         this->edit = edit;
86         this->pluginset = pluginset;
87         this->plugin = plugin;
88         this->position = position;
89         int enable = !edit ? 0 :
90                 edit->nested_edl ? 1 :
91                 !edit->asset ? 0 :
92                 edit->asset->format == FILE_REF ? 1 : 0;
93         open_edl->set_enabled(enable);
94         return BC_PopupMenu::activate_menu();
95 }
96
97 EditPopupOpenEDL::EditPopupOpenEDL(MWindow *mwindow, EditPopup *popup)
98  : BC_MenuItem(_("Open EDL"))
99 {
100         this->mwindow = mwindow;
101         this->popup = popup;
102         set_ctrl(1);
103         set_shift(1);
104 }
105
106 int EditPopupOpenEDL::handle_event()
107 {
108         Edit *edit = popup->edit;
109         if( !edit ) return 1;
110         EDL *edl = 0;
111         Indexable *idxbl = 0;
112         if( edit->asset && edit->asset->format == FILE_REF ) {
113                 FileXML xml_file;
114                 const char *filename = edit->asset->path;
115                 if( xml_file.read_from_file(filename, 1) ) {
116                         eprintf(_("Error: unable to open:\n  %s"), filename);
117                         return 1;
118                 }
119                 edl = new EDL;
120                 edl->create_objects();
121                 if( edl->load_xml(&xml_file, LOAD_ALL) ) {
122                         eprintf(_("Error: unable to load:\n  %s"), filename);
123                         edl->remove_user();
124                         return 1;
125                 }
126                 idxbl = edit->asset;
127         }
128         else if( edit->nested_edl ) {
129                 edl = edit->nested_edl;
130                 edl->add_user();
131                 idxbl = edl;
132         }
133         else {
134                 char edit_title[BCTEXTLEN];
135                 edit->get_title(edit_title);
136                 eprintf(_("Edit is not EDL: %s"), edit_title);
137                 return 1;
138         }
139         mwindow->stack_push(edl, idxbl);
140         return 1;
141 }
142
143 EditPopupClearSelect::EditPopupClearSelect(MWindow *mwindow, EditPopup *popup)
144  : BC_MenuItem(_("Clear Select"),_("Ctrl-Shift-A"),'A')
145 {
146         this->mwindow = mwindow;
147         this->popup = popup;
148         set_ctrl(1);
149         set_shift(1);
150 }
151
152 int EditPopupClearSelect::handle_event()
153 {
154         mwindow->clear_select();
155         return 1;
156 }
157
158 EditPopupCopy::EditPopupCopy(MWindow *mwindow, EditPopup *popup)
159  : BC_MenuItem(_("Copy"),_("Ctrl-c"),'c')
160 {
161         this->mwindow = mwindow;
162         this->popup = popup;
163         set_ctrl(1);
164 }
165
166 int EditPopupCopy::handle_event()
167 {
168         mwindow->selected_edits_to_clipboard(0);
169         return 1;
170 }
171
172 EditPopupCopyPack::EditPopupCopyPack(MWindow *mwindow, EditPopup *popup)
173  : BC_MenuItem(_("Copy pack"),_("Ctrl-Shift-C"),'C')
174 {
175         this->mwindow = mwindow;
176         this->popup = popup;
177         set_ctrl(1);
178         set_shift(1);
179 }
180
181 int EditPopupCopyPack::handle_event()
182 {
183         mwindow->selected_edits_to_clipboard(1);
184         return 1;
185 }
186
187 EditPopupCut::EditPopupCut(MWindow *mwindow, EditPopup *popup)
188  : BC_MenuItem(_("Cut"),_("Ctrl-x"),'x')
189 {
190         this->mwindow = mwindow;
191         this->popup = popup;
192         set_ctrl(1);
193 }
194
195 int EditPopupCut::handle_event()
196 {
197         mwindow->cut_selected_edits(1, 0);
198         return 1;
199 }
200
201 EditPopupCutPack::EditPopupCutPack(MWindow *mwindow, EditPopup *popup)
202  : BC_MenuItem(_("Cut pack"),_("Ctrl-z"),'z')
203 {
204         this->mwindow = mwindow;
205         this->popup = popup;
206         set_ctrl(1);
207 }
208
209 int EditPopupCutPack::handle_event()
210 {
211         mwindow->cut_selected_edits(1, 1);
212         return 1;
213 }
214
215 EditPopupMute::EditPopupMute(MWindow *mwindow, EditPopup *popup)
216  : BC_MenuItem(C_("Mute"),_("Ctrl-m"),'m')
217 {
218         this->mwindow = mwindow;
219         this->popup = popup;
220         set_ctrl(1);
221 }
222
223 int EditPopupMute::handle_event()
224 {
225         mwindow->cut_selected_edits(0, 0);
226         return 1;
227 }
228
229 EditPopupMutePack::EditPopupMutePack(MWindow *mwindow, EditPopup *popup)
230  : BC_MenuItem(_("Mute pack"),_("Ctrl-Shift-M"),'M')
231 {
232         this->mwindow = mwindow;
233         this->popup = popup;
234         set_ctrl(1);
235         set_shift(1);
236 }
237
238 int EditPopupMutePack::handle_event()
239 {
240         mwindow->cut_selected_edits(0, 1);
241         return 1;
242 }
243
244 EditPopupPaste::EditPopupPaste(MWindow *mwindow, EditPopup *popup)
245  : BC_MenuItem(_("Paste"),_("Ctrl-v"),'v')
246 {
247         this->mwindow = mwindow;
248         this->popup = popup;
249         set_ctrl(1);
250 }
251
252 int EditPopupPaste::handle_event()
253 {
254         mwindow->paste(popup->position, popup->track, 0, 0);
255         mwindow->edl->tracks->clear_selected_edits();
256         popup->gui->draw_overlays(1);
257         if( mwindow->session->current_operation == DROP_TARGETING ) {
258                 mwindow->session->current_operation = NO_OPERATION;
259                 popup->gui->update_cursor();
260         }
261         return 1;
262 }
263
264 EditPopupOverwrite::EditPopupOverwrite(MWindow *mwindow, EditPopup *popup)
265  : BC_MenuItem(_("Overwrite"),_("Ctrl-b"),'b')
266 {
267         this->mwindow = mwindow;
268         this->popup = popup;
269         set_ctrl(1);
270 }
271
272 int EditPopupOverwrite::handle_event()
273 {
274         mwindow->paste(popup->position, popup->track, 0, -1);
275         mwindow->edl->tracks->clear_selected_edits();
276         popup->gui->draw_overlays(1);
277         if( mwindow->session->current_operation == DROP_TARGETING ) {
278                 mwindow->session->current_operation = NO_OPERATION;
279                 popup->gui->update_cursor();
280         }
281         return 1;
282 }
283
284 EditPopupOverwritePlugins::EditPopupOverwritePlugins(MWindow *mwindow, EditPopup *popup)
285  : BC_MenuItem(_("Overwrite Plugins"),_("Ctrl-Shift-P"),'P')
286 {
287         this->mwindow = mwindow;
288         this->popup = popup;
289         set_ctrl(1);
290         set_shift(1);
291 }
292
293 int EditPopupOverwritePlugins::handle_event()
294 {
295         mwindow->paste_clipboard(popup->track, popup->position, 1, 0,
296                         mwindow->edl->session->labels_follow_edits,
297                         mwindow->edl->session->autos_follow_edits,
298                         mwindow->edl->session->plugins_follow_edits);
299         mwindow->edl->tracks->clear_selected_edits();
300         if( mwindow->session->current_operation == DROP_TARGETING ) {
301                 mwindow->session->current_operation = NO_OPERATION;
302                 popup->gui->update_cursor();
303         }
304         return 1;
305 }
306