label edit deadlock, build openexr cfg option, code cleanup
[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_xy(cur_x, cur_y, 0);
142
143         if( mwindow->session->drag_assets->total ) {
144                 mwindow->awindow->asset_edit->edit_asset(
145                         mwindow->session->drag_assets->values[0], cur_x, cur_y);
146         }
147         else
148         if( mwindow->session->drag_clips->total ) {
149                 popup->gui->awindow->clip_edit->edit_clip(
150                         mwindow->session->drag_clips->values[0], cur_x, cur_y);
151         }
152         return 1;
153 }
154
155
156 ClipPopupSort::ClipPopupSort(MWindow *mwindow, ClipPopup *popup)
157  : BC_MenuItem(_("Sort items"))
158 {
159         this->mwindow = mwindow;
160         this->popup = popup;
161 }
162
163 ClipPopupSort::~ClipPopupSort()
164 {
165 }
166
167 int ClipPopupSort::handle_event()
168 {
169         mwindow->awindow->gui->sort_assets();
170         return 1;
171 }
172
173
174 ClipPopupView::ClipPopupView(MWindow *mwindow, ClipPopup *popup)
175  : BC_MenuItem(_("View"))
176 {
177         this->mwindow = mwindow;
178         this->popup = popup;
179 }
180
181 ClipPopupView::~ClipPopupView()
182 {
183 }
184
185 int ClipPopupView::handle_event()
186 {
187         VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
188         vwindow->gui->lock_window("ClipPopupView::handle_event");
189
190         if( mwindow->session->drag_assets->total )
191                 vwindow->change_source(
192                         mwindow->session->drag_assets->values[0]);
193         else
194         if( mwindow->session->drag_clips->total )
195                 vwindow->change_source(
196                         mwindow->session->drag_clips->values[0]);
197
198         vwindow->gui->unlock_window();
199         return 1;
200 }
201
202
203 ClipPopupViewWindow::ClipPopupViewWindow(MWindow *mwindow, ClipPopup *popup)
204  : BC_MenuItem(_("View in new window"))
205 {
206         this->mwindow = mwindow;
207         this->popup = popup;
208 }
209
210 ClipPopupViewWindow::~ClipPopupViewWindow()
211 {
212 }
213
214 int ClipPopupViewWindow::handle_event()
215 {
216 // Find window with nothing
217         VWindow *vwindow = mwindow->get_viewer(1);
218
219 // TODO: create new vwindow or change current vwindow
220         vwindow->gui->lock_window("ClipPopupView::handle_event");
221
222         if( mwindow->session->drag_assets->total )
223                 vwindow->change_source(
224                         mwindow->session->drag_assets->values[0]);
225         else
226         if( mwindow->session->drag_clips->total )
227                 vwindow->change_source(
228                         mwindow->session->drag_clips->values[0]);
229
230         vwindow->gui->unlock_window();
231         return 1;
232 }
233
234
235 ClipPopupCopy::ClipPopupCopy(MWindow *mwindow, ClipPopup *popup)
236  : BC_MenuItem(_("Copy"))
237 {
238         this->mwindow = mwindow;
239         this->popup = popup;
240 }
241 ClipPopupCopy::~ClipPopupCopy()
242 {
243 }
244
245 int ClipPopupCopy::handle_event()
246 {
247         MWindowGUI *gui = mwindow->gui;
248         gui->lock_window("ClipPopupCopy::handle_event");
249         if( mwindow->session->drag_clips->total > 0 ) {
250                 FileXML file;
251                 EDL *edl = mwindow->session->drag_clips->values[0];
252                 double start = 0, end = edl->tracks->total_length();
253                 edl->copy(start, end, 1, 0, 0, &file, "", 1);
254                 const char *file_string = file.string();
255                 long file_length = strlen(file_string);
256                 gui->get_clipboard()->to_clipboard(file_string, file_length,
257                         SECONDARY_SELECTION);
258                 gui->get_clipboard()->to_clipboard(file_string, file_length,
259                         BC_PRIMARY_SELECTION);
260         }
261         gui->unlock_window(); 
262         return 1;
263 }
264
265
266 ClipPopupPaste::ClipPopupPaste(MWindow *mwindow, ClipPopup *popup)
267  : BC_MenuItem(_("Paste"))
268 {
269         this->mwindow = mwindow;
270         this->popup = popup;
271 }
272
273 ClipPopupPaste::~ClipPopupPaste()
274 {
275 }
276
277 int ClipPopupPaste::handle_event()
278 {
279         popup->paste_assets();
280         return 1;
281 }
282
283
284 ClipMatchSize::ClipMatchSize(MWindow *mwindow, ClipPopup *popup)
285  : BC_MenuItem(_("Match project size"))
286 {
287         this->mwindow = mwindow;
288         this->popup = popup;
289 }
290
291 int ClipMatchSize::handle_event()
292 {
293         popup->match_size();
294         return 1;
295 }
296
297
298 ClipMatchRate::ClipMatchRate(MWindow *mwindow, ClipPopup *popup)
299  : BC_MenuItem(_("Match frame rate"))
300 {
301         this->mwindow = mwindow;
302         this->popup = popup;
303 }
304
305 int ClipMatchRate::handle_event()
306 {
307         popup->match_rate();
308         return 1;
309 }
310
311
312 ClipMatchAll::ClipMatchAll(MWindow *mwindow, ClipPopup *popup)
313  : BC_MenuItem(_("Match all"))
314 {
315         this->mwindow = mwindow;
316         this->popup = popup;
317 }
318
319 int ClipMatchAll::handle_event()
320 {
321         popup->match_all();
322         return 1;
323 }
324
325
326 ClipPopupDelete::ClipPopupDelete(MWindow *mwindow, ClipPopup *popup)
327  : BC_MenuItem(_("Delete"))
328 {
329         this->mwindow = mwindow;
330         this->popup = popup;
331 }
332
333
334 ClipPopupDelete::~ClipPopupDelete()
335 {
336 }
337
338 int ClipPopupDelete::handle_event()
339 {
340         mwindow->remove_assets_from_project(1, 1,
341                 mwindow->session->drag_assets,
342                 mwindow->session->drag_clips);
343         return 1;
344 }
345
346
347 ClipPasteToFolder::ClipPasteToFolder(MWindow *mwindow)
348  : BC_MenuItem(_("Paste Clip"))
349 {
350         this->mwindow = mwindow;
351 }
352
353 int ClipPasteToFolder::handle_event()
354 {
355         MWindowGUI *gui = mwindow->gui;
356         gui->lock_window("ClipPasteToFolder::handle_event 1");
357         int64_t len = gui->get_clipboard()->clipboard_len(SECONDARY_SELECTION);
358         if( len ) {
359                 char *string = new char[len + 1];
360                 gui->get_clipboard()->from_clipboard(string, len, BC_PRIMARY_SELECTION);
361                 const char *clip_header = "<EDL VERSION=";
362                 if( !strncmp(clip_header, string, strlen(clip_header)) ) {
363                         FileXML file;
364                         file.read_from_string(string);
365                         EDL *edl = mwindow->edl;
366                         EDL *new_edl = new EDL(mwindow->edl);
367                         new_edl->create_objects();
368                         new_edl->load_xml(&file, LOAD_ALL);
369                         edl->update_assets(new_edl);
370                         mwindow->save_clip(new_edl, _("paste clip: "));
371                 }
372                 else {
373                         char *cp = strchr(string, '\n');
374                         if( cp-string < 32 ) *cp = 0;
375                         else if( len > 32 ) string[32] = 0;
376                         eprintf("paste buffer is not EDL:\n%s", string);
377                 }
378                 delete [] string;
379         }
380         else {
381                 eprintf("paste buffer empty");
382         }
383         gui->unlock_window();
384         return 1;
385 }
386
387
388 ClipListMenu::ClipListMenu(MWindow *mwindow, AWindowGUI *gui)
389  : BC_PopupMenu(0, 0, 0, "", 0)
390 {
391         this->mwindow = mwindow;
392         this->gui = gui;
393 }
394
395 ClipListMenu::~ClipListMenu()
396 {
397 }
398
399 void ClipListMenu::create_objects()
400 {
401         add_item(format = new AWindowListFormat(mwindow, gui));
402         add_item(new AWindowListSort(mwindow, gui));
403         add_item(new ClipPasteToFolder(mwindow));
404         update();
405 }
406
407 void ClipListMenu::update()
408 {
409         format->update();
410 }
411