sams last ladspa icons, libopus/vp9, mixer fixer, plugin resets, fmt frmsz, shm fixes
[goodguy/history.git] / cinelerra-5.1 / cinelerra / assetpopup.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 "asset.h"
23 #include "assetedit.h"
24 #include "assetpopup.h"
25 #include "assetremove.h"
26 #include "awindow.h"
27 #include "awindowgui.h"
28 #include "bcdisplayinfo.h"
29 #include "bcsignals.h"
30 #include "clipedit.h"
31 #include "cstrdup.h"
32 #include "cwindow.h"
33 #include "cwindowgui.h"
34 #include "edl.h"
35 #include "edlsession.h"
36 #include "filexml.h"
37 #include "language.h"
38 #include "localsession.h"
39 #include "mainerror.h"
40 #include "mainindexes.h"
41 #include "mainsession.h"
42 #include "mwindow.h"
43 #include "mwindowgui.h"
44 #include "tracks.h"
45 #include "vwindow.h"
46 #include "vwindowgui.h"
47 #include "zwindow.h"
48
49
50 AssetPopup::AssetPopup(MWindow *mwindow, AWindowGUI *gui)
51  : BC_PopupMenu(0, 0, 0, "", 0)
52 {
53         this->mwindow = mwindow;
54         this->gui = gui;
55 }
56
57 AssetPopup::~AssetPopup()
58 {
59 }
60
61 void AssetPopup::create_objects()
62 {
63         BC_MenuItem *menu_item;
64         BC_SubMenu *submenu;
65         add_item(info = new AssetPopupInfo(mwindow, this));
66         add_item(format = new AWindowListFormat(mwindow, gui));
67         add_item(new AssetPopupSort(mwindow, this));
68         add_item(index = new AssetPopupBuildIndex(mwindow, this));
69         add_item(view = new AssetPopupView(mwindow, this));
70         add_item(view_window = new AssetPopupViewWindow(mwindow, this));
71         add_item(mixer = new AssetPopupMixer(mwindow, this));
72         add_item(new AssetPopupPaste(mwindow, this));
73         add_item(menu_item = new BC_MenuItem(_("Match...")));
74         menu_item->add_submenu(submenu = new BC_SubMenu());
75         submenu->add_submenuitem(new AssetMatchSize(mwindow, this));
76         submenu->add_submenuitem(new AssetMatchRate(mwindow, this));
77         submenu->add_submenuitem(new AssetMatchAll(mwindow, this));
78         add_item(menu_item = new BC_MenuItem(_("Remove...")));
79         menu_item->add_submenu(submenu = new BC_SubMenu());
80         submenu->add_submenuitem(new AssetPopupProjectRemove(mwindow, this));
81         submenu->add_submenuitem(new AssetPopupDiskRemove(mwindow, this));
82 }
83
84 void AssetPopup::paste_assets()
85 {
86 // Collect items into the drag vectors for temporary storage
87         gui->lock_window("AssetPopup::paste_assets");
88         mwindow->gui->lock_window("AssetPopup::paste_assets");
89         mwindow->cwindow->gui->lock_window("AssetPopup::paste_assets");
90
91         gui->collect_assets();
92         mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
93                 mwindow->edl->tracks->first,
94                 0);   // do not overwrite
95
96         gui->unlock_window();
97         mwindow->gui->unlock_window();
98         mwindow->cwindow->gui->unlock_window();
99 }
100
101 void AssetPopup::match_size()
102 {
103 // Collect items into the drag vectors for temporary storage
104         gui->collect_assets();
105         mwindow->gui->lock_window("AssetPopup::match_size");
106         mwindow->asset_to_size();
107         mwindow->gui->unlock_window();
108 }
109
110 void AssetPopup::match_rate()
111 {
112 // Collect items into the drag vectors for temporary storage
113         gui->collect_assets();
114         mwindow->gui->lock_window("AssetPopup::match_rate");
115         mwindow->asset_to_rate();
116         mwindow->gui->unlock_window();
117 }
118
119 void AssetPopup::match_all()
120 {
121 // Collect items into the drag vectors for temporary storage
122         gui->collect_assets();
123         mwindow->gui->lock_window("AssetPopup::match_rate");
124         mwindow->asset_to_all();
125         mwindow->gui->unlock_window();
126 }
127
128 int AssetPopup::update()
129 {
130         format->update();
131         gui->collect_assets();
132         return 0;
133 }
134
135
136 AssetPopupInfo::AssetPopupInfo(MWindow *mwindow, AssetPopup *popup)
137  : BC_MenuItem(_("Info..."))
138 {
139         this->mwindow = mwindow;
140         this->popup = popup;
141 }
142
143 AssetPopupInfo::~AssetPopupInfo()
144 {
145 }
146
147 int AssetPopupInfo::handle_event()
148 {
149         int cur_x, cur_y;
150         popup->gui->get_abs_cursor(cur_x, cur_y);
151         if( mwindow->session->drag_assets->size() ) {
152                 AssetEdit *asset_edit = mwindow->awindow->get_asset_editor();
153                 asset_edit->edit_asset(
154                         mwindow->session->drag_assets->values[0], cur_x, cur_y);
155         }
156         else if( mwindow->session->drag_clips->size() ) {
157                 popup->gui->awindow->clip_edit->edit_clip(
158                         mwindow->session->drag_clips->values[0], cur_x, cur_y);
159         }
160         return 1;
161 }
162
163
164 AssetPopupBuildIndex::AssetPopupBuildIndex(MWindow *mwindow, AssetPopup *popup)
165  : BC_MenuItem(_("Rebuild index"))
166 {
167         this->mwindow = mwindow;
168         this->popup = popup;
169 }
170
171 AssetPopupBuildIndex::~AssetPopupBuildIndex()
172 {
173 }
174
175 int AssetPopupBuildIndex::handle_event()
176 {
177 //printf("AssetPopupBuildIndex::handle_event 1\n");
178         mwindow->rebuild_indices();
179         return 1;
180 }
181
182
183 AssetPopupSort::AssetPopupSort(MWindow *mwindow, AssetPopup *popup)
184  : BC_MenuItem(_("Sort items"))
185 {
186         this->mwindow = mwindow;
187         this->popup = popup;
188 }
189
190 AssetPopupSort::~AssetPopupSort()
191 {
192 }
193
194 int AssetPopupSort::handle_event()
195 {
196         mwindow->awindow->gui->sort_assets();
197         return 1;
198 }
199
200
201 AssetPopupView::AssetPopupView(MWindow *mwindow, AssetPopup *popup)
202  : BC_MenuItem(_("View"))
203 {
204         this->mwindow = mwindow;
205         this->popup = popup;
206 }
207
208 AssetPopupView::~AssetPopupView()
209 {
210 }
211
212 int AssetPopupView::handle_event()
213 {
214         VWindow *vwindow = mwindow->get_viewer(1, DEFAULT_VWINDOW);
215         vwindow->gui->lock_window("AssetPopupView::handle_event");
216
217         if( mwindow->session->drag_assets->total )
218                 vwindow->change_source(
219                         mwindow->session->drag_assets->values[0]);
220         else
221         if( mwindow->session->drag_clips->total )
222                 vwindow->change_source(
223                         mwindow->session->drag_clips->values[0]);
224
225         vwindow->gui->unlock_window();
226         return 1;
227 }
228
229
230 AssetPopupViewWindow::AssetPopupViewWindow(MWindow *mwindow, AssetPopup *popup)
231  : BC_MenuItem(_("View in new window"))
232 {
233         this->mwindow = mwindow;
234         this->popup = popup;
235 }
236
237 AssetPopupViewWindow::~AssetPopupViewWindow()
238 {
239 }
240
241 int AssetPopupViewWindow::handle_event()
242 {
243 // Find window with nothing
244         VWindow *vwindow = mwindow->get_viewer(1);
245
246 // TODO: create new vwindow or change current vwindow
247         vwindow->gui->lock_window("AssetPopupView::handle_event");
248
249         if( mwindow->session->drag_assets->total )
250                 vwindow->change_source(
251                         mwindow->session->drag_assets->values[0]);
252         else
253         if( mwindow->session->drag_clips->total )
254                 vwindow->change_source(
255                         mwindow->session->drag_clips->values[0]);
256
257         vwindow->gui->unlock_window();
258         return 1;
259 }
260
261 AssetPopupMixer::AssetPopupMixer(MWindow *mwindow, AssetPopup *popup)
262  : BC_MenuItem(_("Open Mixers"))
263 {
264         this->mwindow = mwindow;
265         this->popup = popup;
266 }
267
268 AssetPopupMixer::~AssetPopupMixer()
269 {
270 }
271
272 int AssetPopupMixer::handle_event()
273 {
274         ArrayList<ZWindow *>new_mixers;
275
276         mwindow->select_zwindow(0);
277         for( int i=0; i<mwindow->session->drag_assets->total; ++i ) {
278                 Indexable *indexable = mwindow->session->drag_assets->values[i];
279                 ArrayList<Indexable*> new_assets;
280                 new_assets.append(indexable);
281                 Track *track = mwindow->edl->tracks->last;
282                 mwindow->load_assets(&new_assets, -1, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
283                 track = !track ? mwindow->edl->tracks->first : track->next;
284                 Mixer *mixer = 0;
285                 ZWindow *zwindow = mwindow->get_mixer(mixer);
286                 while( track ) {
287                         track->play = track->record = 0;
288                         if( track->data_type == TRACK_VIDEO ) {
289                                 sprintf(track->title, _("Mixer %d"), zwindow->idx);
290                         }
291                         mixer->mixer_ids.append(track->get_mixer_id());
292                         track = track->next;
293                 }
294                 char *path = indexable->path;
295                 char *tp = strrchr(path, '/');
296                 if( !tp ) tp = path; else ++tp;
297                 zwindow->set_title(tp);
298                 new_mixers.append(zwindow);
299         }
300
301         mwindow->tile_mixers();
302         for( int i=0; i<new_mixers.size(); ++i )
303                 new_mixers[i]->start();
304
305         mwindow->refresh_mixers();
306         mwindow->resync_guis();
307         return 1;
308 }
309
310 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
311  : BC_MenuItem(_("Paste"))
312 {
313         this->mwindow = mwindow;
314         this->popup = popup;
315 }
316
317 AssetPopupPaste::~AssetPopupPaste()
318 {
319 }
320
321 int AssetPopupPaste::handle_event()
322 {
323         popup->paste_assets();
324         return 1;
325 }
326
327
328 AssetMatchSize::AssetMatchSize(MWindow *mwindow, AssetPopup *popup)
329  : BC_MenuItem(_("Match project size"))
330 {
331         this->mwindow = mwindow;
332         this->popup = popup;
333 }
334
335 int AssetMatchSize::handle_event()
336 {
337         popup->match_size();
338         return 1;
339 }
340
341 AssetMatchRate::AssetMatchRate(MWindow *mwindow, AssetPopup *popup)
342  : BC_MenuItem(_("Match frame rate"))
343 {
344         this->mwindow = mwindow;
345         this->popup = popup;
346 }
347
348 int AssetMatchRate::handle_event()
349 {
350         popup->match_rate();
351         return 1;
352 }
353
354 AssetMatchAll::AssetMatchAll(MWindow *mwindow, AssetPopup *popup)
355  : BC_MenuItem(_("Match all"))
356 {
357         this->mwindow = mwindow;
358         this->popup = popup;
359 }
360
361 int AssetMatchAll::handle_event()
362 {
363         popup->match_all();
364         return 1;
365 }
366
367
368 AssetPopupProjectRemove::AssetPopupProjectRemove(MWindow *mwindow, AssetPopup *popup)
369  : BC_MenuItem(_("Remove from project"))
370 {
371         this->mwindow = mwindow;
372         this->popup = popup;
373 }
374
375 AssetPopupProjectRemove::~AssetPopupProjectRemove()
376 {
377 }
378
379 int AssetPopupProjectRemove::handle_event()
380 {
381         mwindow->remove_assets_from_project(1, 1,
382                 mwindow->session->drag_assets,
383                 mwindow->session->drag_clips);
384         return 1;
385 }
386
387
388 AssetPopupDiskRemove::AssetPopupDiskRemove(MWindow *mwindow, AssetPopup *popup)
389  : BC_MenuItem(_("Remove from disk"))
390 {
391         this->mwindow = mwindow;
392         this->popup = popup;
393 }
394
395
396 AssetPopupDiskRemove::~AssetPopupDiskRemove()
397 {
398 }
399
400 int AssetPopupDiskRemove::handle_event()
401 {
402         mwindow->awindow->asset_remove->start();
403         return 1;
404 }
405
406
407 AssetListMenu::AssetListMenu(MWindow *mwindow, AWindowGUI *gui)
408  : BC_PopupMenu(0, 0, 0, "", 0)
409 {
410         this->mwindow = mwindow;
411         this->gui = gui;
412 }
413
414 AssetListMenu::~AssetListMenu()
415 {
416 }
417
418 void AssetListMenu::create_objects()
419 {
420         add_item(format = new AWindowListFormat(mwindow, gui));
421         add_item(new AWindowListSort(mwindow, gui));
422         add_item(new AssetListCopy(mwindow, gui));
423         add_item(new AssetListPaste(mwindow, gui));
424         update_titles();
425 }
426
427 void AssetListMenu::update_titles()
428 {
429         format->update();
430 }
431
432 AssetListCopy::AssetListCopy(MWindow *mwindow, AWindowGUI *gui)
433  : BC_MenuItem(_("Copy file list"))
434 {
435         this->mwindow = mwindow;
436         this->gui = gui;
437         copy_dialog = 0;
438 }
439 AssetListCopy::~AssetListCopy()
440 {
441         delete copy_dialog;
442 }
443
444 int AssetListCopy::handle_event()
445 {
446         int len = 0;
447         MWindowGUI *gui = mwindow->gui;
448         gui->lock_window("AssetListCopy::handle_event");
449         mwindow->awindow->gui->collect_assets();
450         int n = mwindow->session->drag_assets->total;
451         for( int i=0; i<n; ++i ) {
452                 Indexable *indexable = mwindow->session->drag_assets->values[i];
453                 const char *path = indexable->path;
454                 if( !*path ) continue;
455                 len += strlen(path) + 1;
456         }
457         char *text = new char[len+1], *cp = text;
458         for( int i=0; i<n; ++i ) {
459                 Indexable *indexable = mwindow->session->drag_assets->values[i];
460                 const char *path = indexable->path;
461                 if( !*path ) continue;
462                 cp += sprintf(cp, "%s\n", path);
463         }
464         *cp = 0;
465         int cur_x, cur_y;
466         gui->get_abs_cursor(cur_x, cur_y, 0);
467         gui->unlock_window(); 
468
469         if( n ) {
470                 if( !copy_dialog )
471                         copy_dialog = new AssetCopyDialog(this);
472                 copy_dialog->start(text, cur_x, cur_y);
473         }
474         else {
475                 eprintf(_("Nothing selected"));
476                 delete [] text;
477         }
478         return 1;
479 }
480
481 AssetCopyDialog::AssetCopyDialog(AssetListCopy *copy)
482  : BC_DialogThread()
483 {
484         this->copy = copy;
485         copy_window = 0;
486 }
487
488 void AssetCopyDialog::start(char *text, int x, int y)
489 {
490         close_window();
491         this->text = text;
492         this->x = x;  this->y = y;
493         BC_DialogThread::start();
494 }
495
496 AssetCopyDialog::~AssetCopyDialog()
497 {
498         close_window();
499 }
500
501 BC_Window* AssetCopyDialog::new_gui()
502 {
503         BC_DisplayInfo display_info;
504
505         copy_window = new AssetCopyWindow(this);
506         copy_window->create_objects();
507         return copy_window;
508 }
509
510 void AssetCopyDialog::handle_done_event(int result)
511 {
512         delete [] text;  text = 0;
513 }
514
515 void AssetCopyDialog::handle_close_event(int result)
516 {
517         copy_window = 0;
518 }
519
520
521 AssetCopyWindow::AssetCopyWindow(AssetCopyDialog *copy_dialog)
522  : BC_Window(_(PROGRAM_NAME ": Copy File List"),
523         copy_dialog->x - 500/2, copy_dialog->y - 200/2,
524         500, 200, 500, 200, 1, 0, 1)
525 {
526         this->copy_dialog = copy_dialog;
527 }
528
529 AssetCopyWindow::~AssetCopyWindow()
530 {
531 }
532
533 void AssetCopyWindow::create_objects()
534 {
535         BC_Title *title;
536         int x = 10, y = 10, pad = 5;
537         add_subwindow(title = new BC_Title(x, y, _("List of asset paths:")));
538         y += title->get_h() + pad;
539         int text_w = get_w() - x - 10;
540         int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
541         int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
542         char *text = copy_dialog->text;
543         int len = strlen(text) + BCTEXTLEN;
544         file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, text, len);
545         file_list->create_objects();
546
547         add_subwindow(new BC_OKButton(this));
548         show_window();
549 }
550
551 int AssetCopyWindow::resize_event(int w, int h)
552 {
553         int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
554         int text_w = w - fx - 10;
555         int text_h = h - fy - BC_OKButton::calculate_h() - pad;
556         int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
557         file_list->reposition_window(fx, fy, text_w, text_rows);
558         return 0;
559 }
560
561 AssetListPaste::AssetListPaste(MWindow *mwindow, AWindowGUI *gui)
562  : BC_MenuItem(_("Paste file list"))
563 {
564         this->mwindow = mwindow;
565         this->gui = gui;
566         paste_dialog = 0;
567 }
568 AssetListPaste::~AssetListPaste()
569 {
570         delete paste_dialog;
571 }
572
573 int AssetListPaste::handle_event()
574 {
575         if( !paste_dialog )
576                 paste_dialog = new AssetPasteDialog(this);
577         else
578                 paste_dialog->close_window();
579         int cur_x, cur_y;
580         gui->get_abs_cursor(cur_x, cur_y, 0);
581         paste_dialog->start(cur_x, cur_y);
582         return 1;
583 }
584
585 AssetPasteDialog::AssetPasteDialog(AssetListPaste *paste)
586  : BC_DialogThread()
587 {
588         this->paste = paste;
589         paste_window = 0;
590 }
591
592 AssetPasteDialog::~AssetPasteDialog()
593 {
594         close_window();
595 }
596
597 BC_Window* AssetPasteDialog::new_gui()
598 {
599         paste_window = new AssetPasteWindow(this);
600         paste_window->create_objects();
601         return paste_window;
602 }
603
604 void AssetPasteDialog::handle_done_event(int result)
605 {
606         if( result ) return;
607         const char *bp = paste_window->file_list->get_text(), *ep = bp+strlen(bp);
608         ArrayList<char*> path_list;
609         path_list.set_array_delete();
610
611         for( const char *cp=bp; cp<ep && *cp; ) {
612                 const char *dp = strchr(cp, '\n');
613                 if( !dp ) dp = ep;
614                 char path[BCTEXTLEN], *pp = path;
615                 int len = sizeof(path)-1;
616                 while( --len>0 && cp<dp ) *pp++ = *cp++;
617                 if( *cp ) ++cp;
618                 *pp = 0;
619                 if( !strlen(path) ) continue;
620                 path_list.append(cstrdup(path));
621         }
622         if( !path_list.size() ) return;
623
624         MWindow *mwindow = paste->mwindow;
625         mwindow->interrupt_indexes();
626         mwindow->gui->lock_window("AssetPasteDialog::handle_done_event");
627         result = mwindow->load_filenames(&path_list, LOADMODE_RESOURCESONLY, 0);
628         mwindow->gui->unlock_window();
629         path_list.remove_all_objects();
630         mwindow->save_backup();
631         mwindow->restart_brender();
632         mwindow->session->changes_made = 1;
633 }
634
635 void AssetPasteDialog::handle_close_event(int result)
636 {
637         paste_window = 0;
638 }
639
640 void AssetPasteDialog::start(int x, int y)
641 {
642         this->x = x;  this->y = y;
643         BC_DialogThread::start();
644 }
645
646 AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog)
647  : BC_Window(_(PROGRAM_NAME ": Paste File List"),
648         paste_dialog->x - 500/2, paste_dialog->y - 200/2,
649         500, 200, 500, 200, 1, 0, 1)
650 {
651         this->paste_dialog = paste_dialog;
652 }
653
654 AssetPasteWindow::~AssetPasteWindow()
655 {
656 }
657
658 void AssetPasteWindow::create_objects()
659 {
660         BC_Title *title;
661         int x = 10, y = 10, pad = 5;
662         add_subwindow(title = new BC_Title(x, y, _("Enter list of asset paths:")));
663         y += title->get_h() + pad;
664         int text_w = get_w() - x - 10;
665         int text_h = get_h() - y - BC_OKButton::calculate_h() - pad;
666         int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
667         file_list = new BC_ScrollTextBox(this, x, y, text_w, text_rows, (char*)0, 65536);
668         file_list->create_objects();
669         add_subwindow(new BC_OKButton(this));
670         add_subwindow(new BC_CancelButton(this));
671         show_window();
672 }
673
674 int AssetPasteWindow::resize_event(int w, int h)
675 {
676         int fx = file_list->get_x(), fy = file_list->get_y(), pad = 5;
677         int text_w = w - fx - 10;
678         int text_h = h - fy - BC_OKButton::calculate_h() - pad;
679         int text_rows = BC_TextBox::pixels_to_rows(this, MEDIUMFONT, text_h);
680         file_list->reposition_window(fx, fy, text_w, text_rows);
681         return 0;
682 }
683