mixer undo fix, new ffmpeg opts, docs
[goodguy/history.git] / cinelerra-5.1 / cinelerra / clippopup.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2012 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 "assetedit.h"
23 #include "clippopup.h"
24 #include "assetremove.h"
25 #include "awindow.h"
26 #include "awindowgui.h"
27 #include "bcsignals.h"
28 #include "clipedit.h"
29 #include "cwindow.h"
30 #include "cwindowgui.h"
31 #include "edl.h"
32 #include "filexml.h"
33 #include "language.h"
34 #include "localsession.h"
35 #include "mainerror.h"
36 #include "mainsession.h"
37 #include "mwindow.h"
38 #include "mwindowgui.h"
39 #include "tracks.h"
40 #include "vwindow.h"
41 #include "vwindowgui.h"
42
43
44
45 ClipPopup::ClipPopup(MWindow *mwindow, AWindowGUI *gui)
46  : BC_PopupMenu(0, 0, 0, "", 0)
47 {
48         this->mwindow = mwindow;
49         this->gui = gui;
50 }
51
52 ClipPopup::~ClipPopup()
53 {
54 }
55
56 void ClipPopup::create_objects()
57 {
58         BC_MenuItem *menu_item;
59         BC_SubMenu *submenu;
60         add_item(info = new ClipPopupInfo(mwindow, this));
61         add_item(format = new AWindowListFormat(mwindow, gui));
62         add_item(new ClipPopupSort(mwindow, this));
63         add_item(view = new ClipPopupView(mwindow, this));
64         add_item(view_window = new ClipPopupViewWindow(mwindow, this));
65         add_item(new ClipPopupCopy(mwindow, this));
66         add_item(new ClipPopupPaste(mwindow, this));
67         add_item(menu_item = new BC_MenuItem(_("Match...")));
68         menu_item->add_submenu(submenu = new BC_SubMenu());
69         submenu->add_submenuitem(new ClipMatchSize(mwindow, this));
70         submenu->add_submenuitem(new ClipMatchRate(mwindow, this));
71         submenu->add_submenuitem(new ClipMatchAll(mwindow, this));
72         add_item(new ClipPopupDelete(mwindow, this));
73 }
74
75 void ClipPopup::paste_assets()
76 {
77 // Collect items into the drag vectors for temporary storage
78         gui->lock_window("ClipPopup::paste_assets");
79         mwindow->gui->lock_window("ClipPopup::paste_assets");
80         mwindow->cwindow->gui->lock_window("ClipPopup::paste_assets");
81
82         gui->collect_assets();
83         mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
84                 mwindow->edl->tracks->first,
85                 0);   // do not overwrite
86
87         gui->unlock_window();
88         mwindow->gui->unlock_window();
89         mwindow->cwindow->gui->unlock_window();
90 }
91
92 void ClipPopup::match_size()
93 {
94 // Collect items into the drag vectors for temporary storage
95         gui->collect_assets();
96         mwindow->gui->lock_window("ClipPopup::match_size");
97         mwindow->asset_to_size();
98         mwindow->gui->unlock_window();
99 }
100
101 void ClipPopup::match_rate()
102 {
103 // Collect items into the drag vectors for temporary storage
104         gui->collect_assets();
105         mwindow->gui->lock_window("ClipPopup::match_rate");
106         mwindow->asset_to_rate();
107         mwindow->gui->unlock_window();
108 }
109
110 void ClipPopup::match_all()
111 {
112 // Collect items into the drag vectors for temporary storage
113         gui->collect_assets();
114         mwindow->gui->lock_window("ClipPopup::match_rate");
115         mwindow->asset_to_all();
116         mwindow->gui->unlock_window();
117 }
118
119 int ClipPopup::update()
120 {
121         format->update();
122         gui->collect_assets();
123         return 0;
124 }
125
126
127 ClipPopupInfo::ClipPopupInfo(MWindow *mwindow, ClipPopup *popup)
128  : BC_MenuItem(_("Info..."))
129 {
130         this->mwindow = mwindow;
131         this->popup = popup;
132 }
133
134 ClipPopupInfo::~ClipPopupInfo()
135 {
136 }
137
138 int ClipPopupInfo::handle_event()
139 {
140         int cur_x, cur_y;
141         popup->gui->get_abs_cursor(cur_x, cur_y, 0);
142
143         if( mwindow->session->drag_assets->total ) {
144                 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
145                 asset_edit->edit_asset(
146                         mwindow->session->drag_assets->values[0], cur_x, cur_y);
147         }
148         else
149         if( mwindow->session->drag_clips->total ) {
150                 popup->gui->awindow->clip_edit->edit_clip(
151                         mwindow->session->drag_clips->values[0], cur_x, cur_y);
152         }
153         return 1;
154 }
155
156
157 ClipPopupSort::ClipPopupSort(MWindow *mwindow, ClipPopup *popup)
158  : BC_MenuItem(_("Sort items"))
159 {
160         this->mwindow = mwindow;
161         this->popup = popup;
162 }
163
164 ClipPopupSort::~ClipPopupSort()
165 {
166 }
167
168 int ClipPopupSort::handle_event()
169 {
170         mwindow->awindow->gui->sort_assets(0);
171         return 1;
172 }
173
174
175 ClipPopupView::ClipPopupView(MWindow *mwindow, ClipPopup *popup)
176  : BC_MenuItem(_("View"))
177 {
178         this->mwindow = mwindow;
179         this->popup = popup;
180 }
181
182 ClipPopupView::~ClipPopupView()
183 {
184 }
185
186 int ClipPopupView::handle_event()
187 {
188         VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
189         vwindow->gui->lock_window("ClipPopupView::handle_event");
190
191         if( mwindow->session->drag_assets->total )
192                 vwindow->change_source(
193                         mwindow->session->drag_assets->values[0]);
194         else
195         if( mwindow->session->drag_clips->total )
196                 vwindow->change_source(
197                         mwindow->session->drag_clips->values[0]);
198
199         vwindow->gui->unlock_window();
200         return 1;
201 }
202
203
204 ClipPopupViewWindow::ClipPopupViewWindow(MWindow *mwindow, ClipPopup *popup)
205  : BC_MenuItem(_("View in new window"))
206 {
207         this->mwindow = mwindow;
208         this->popup = popup;
209 }
210
211 ClipPopupViewWindow::~ClipPopupViewWindow()
212 {
213 }
214
215 int ClipPopupViewWindow::handle_event()
216 {
217 // Find window with nothing
218         VWindow *vwindow = mwindow->get_viewer(1);
219
220 // TODO: create new vwindow or change current vwindow
221         vwindow->gui->lock_window("ClipPopupView::handle_event");
222
223         if( mwindow->session->drag_assets->total )
224                 vwindow->change_source(
225                         mwindow->session->drag_assets->values[0]);
226         else
227         if( mwindow->session->drag_clips->total )
228                 vwindow->change_source(
229                         mwindow->session->drag_clips->values[0]);
230
231         vwindow->gui->unlock_window();
232         return 1;
233 }
234
235
236 ClipPopupCopy::ClipPopupCopy(MWindow *mwindow, ClipPopup *popup)
237  : BC_MenuItem(_("Copy"))
238 {
239         this->mwindow = mwindow;
240         this->popup = popup;
241 }
242 ClipPopupCopy::~ClipPopupCopy()
243 {
244 }
245
246 int ClipPopupCopy::handle_event()
247 {
248         MWindowGUI *gui = mwindow->gui;
249         gui->lock_window("ClipPopupCopy::handle_event");
250         if( mwindow->session->drag_clips->total > 0 ) {
251                 FileXML file;
252                 EDL *edl = mwindow->session->drag_clips->values[0];
253                 double start = 0, end = edl->tracks->total_length();
254                 edl->copy(start, end, 1, 0, 0, &file, "", 1);
255                 const char *file_string = file.string();
256                 long file_length = strlen(file_string);
257                 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
258                 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
259         }
260         gui->unlock_window(); 
261         return 1;
262 }
263
264
265 ClipPopupPaste::ClipPopupPaste(MWindow *mwindow, ClipPopup *popup)
266  : BC_MenuItem(_("Paste"))
267 {
268         this->mwindow = mwindow;
269         this->popup = popup;
270 }
271
272 ClipPopupPaste::~ClipPopupPaste()
273 {
274 }
275
276 int ClipPopupPaste::handle_event()
277 {
278         popup->paste_assets();
279         return 1;
280 }
281
282
283 ClipMatchSize::ClipMatchSize(MWindow *mwindow, ClipPopup *popup)
284  : BC_MenuItem(_("Match project size"))
285 {
286         this->mwindow = mwindow;
287         this->popup = popup;
288 }
289
290 int ClipMatchSize::handle_event()
291 {
292         popup->match_size();
293         return 1;
294 }
295
296
297 ClipMatchRate::ClipMatchRate(MWindow *mwindow, ClipPopup *popup)
298  : BC_MenuItem(_("Match frame rate"))
299 {
300         this->mwindow = mwindow;
301         this->popup = popup;
302 }
303
304 int ClipMatchRate::handle_event()
305 {
306         popup->match_rate();
307         return 1;
308 }
309
310
311 ClipMatchAll::ClipMatchAll(MWindow *mwindow, ClipPopup *popup)
312  : BC_MenuItem(_("Match all"))
313 {
314         this->mwindow = mwindow;
315         this->popup = popup;
316 }
317
318 int ClipMatchAll::handle_event()
319 {
320         popup->match_all();
321         return 1;
322 }
323
324
325 ClipPopupDelete::ClipPopupDelete(MWindow *mwindow, ClipPopup *popup)
326  : BC_MenuItem(_("Delete"))
327 {
328         this->mwindow = mwindow;
329         this->popup = popup;
330 }
331
332
333 ClipPopupDelete::~ClipPopupDelete()
334 {
335 }
336
337 int ClipPopupDelete::handle_event()
338 {
339         mwindow->remove_assets_from_project(1, 1,
340                 mwindow->session->drag_assets,
341                 mwindow->session->drag_clips);
342         return 1;
343 }
344
345
346 ClipPasteToFolder::ClipPasteToFolder(MWindow *mwindow)
347  : BC_MenuItem(_("Paste Clip"))
348 {
349         this->mwindow = mwindow;
350 }
351
352 int ClipPasteToFolder::handle_event()
353 {
354         MWindowGUI *gui = mwindow->gui;
355         gui->lock_window("ClipPasteToFolder::handle_event 1");
356         int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
357         if( len ) {
358                 char *string = new char[len];
359                 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
360                 const char *clip_header = "<EDL VERSION=";
361                 if( !strncmp(clip_header, string, strlen(clip_header)) ) {
362                         FileXML file;
363                         file.read_from_string(string);
364                         EDL *edl = mwindow->edl;
365                         EDL *new_edl = new EDL(mwindow->edl);
366                         new_edl->create_objects();
367                         new_edl->load_xml(&file, LOAD_ALL);
368                         edl->update_assets(new_edl);
369                         mwindow->save_clip(new_edl, _("paste clip: "));
370                 }
371                 else {
372                         char *cp = strchr(string, '\n');
373                         if( cp-string < 32 ) *cp = 0;
374                         else if( len > 32 ) string[32] = 0;
375                         eprintf("paste buffer is not EDL:\n%s", string);
376                 }
377                 delete [] string;
378         }
379         else {
380                 eprintf("paste buffer empty");
381         }
382         gui->unlock_window();
383         return 1;
384 }
385
386
387 ClipListMenu::ClipListMenu(MWindow *mwindow, AWindowGUI *gui)
388  : BC_PopupMenu(0, 0, 0, "", 0)
389 {
390         this->mwindow = mwindow;
391         this->gui = gui;
392 }
393
394 ClipListMenu::~ClipListMenu()
395 {
396 }
397
398 void ClipListMenu::create_objects()
399 {
400         add_item(format = new AWindowListFormat(mwindow, gui));
401         add_item(new AWindowListSort(mwindow, gui));
402         add_item(new ClipPasteToFolder(mwindow));
403         update();
404 }
405
406 void ClipListMenu::update()
407 {
408         format->update();
409 }
410