ffmpeg seek fixes, asset only pastes, plugin info, remove vocoder, misc fixes
[goodguy/history.git] / cinelerra-5.1 / cinelerra / awindowgui.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 "assets.h"
26 #include "awindowgui.h"
27 #include "awindow.h"
28 #include "bcsignals.h"
29 #include "bchash.h"
30 #include "cache.h"
31 #include "bccmodels.h"
32 #include "clippopup.h"
33 #include "cursors.h"
34 #include "cwindowgui.h"
35 #include "cwindow.h"
36 #include "edl.h"
37 #include "edlsession.h"
38 #include "effectlist.h"
39 #include "file.h"
40 #include "filesystem.h"
41 #include "folderlistmenu.h"
42 #include "indexable.h"
43 #include "keys.h"
44 #include "language.h"
45 #include "labels.h"
46 #include "labelpopup.h"
47 #include "localsession.h"
48 #include "mainmenu.h"
49 #include "mainsession.h"
50 #include "mwindowgui.h"
51 #include "mwindow.h"
52 #include "nestededls.h"
53 #include "newfolder.h"
54 #include "preferences.h"
55 #include "theme.h"
56 #include "vframe.h"
57 #include "vicon.h"
58 #include "vwindowgui.h"
59 #include "vwindow.h"
60
61 #include "data/lad_picon_png.h"
62 #include "data/ff_audio_png.h"
63 #include "data/ff_video_png.h"
64
65 #include<stdio.h>
66 #include<unistd.h>
67 #include<fcntl.h>
68
69
70 const char *AWindowGUI::folder_names[] =
71 {
72         N_("Audio Effects"),
73         N_("Video Effects"),
74         N_("Audio Transitions"),
75         N_("Video Transitions"),
76         N_("Labels"),
77         N_("Clips"),
78         N_("Media"),
79         N_("User")
80 };
81
82
83 AssetVIcon::AssetVIcon(AssetPicon *picon, int w, int h, double framerate, int64_t length)
84  : VIcon(w, h, framerate)
85 {
86         this->picon = picon;
87         this->length = length;
88         temp = 0;
89 }
90
91 AssetVIcon::~AssetVIcon()
92 {
93         delete temp;
94 }
95
96 VFrame *AssetVIcon::frame()
97 {
98         if( seq_no >= images.size() ) {
99                 MWindow *mwindow = picon->mwindow;
100                 Asset *asset = (Asset *)picon->indexable;
101                 File *file = mwindow->video_cache->check_out(asset, mwindow->edl, 1);
102                 if( !file ) return 0;
103                 if( temp && (temp->get_w() != asset->width || temp->get_h() != asset->height) ) {
104                         delete temp;  temp = 0;
105                 }
106                 if( !temp )
107                         temp = new VFrame(asset->width, asset->height, BC_RGB888);
108                 int ww = picon->gui->vicon_thread->view_w;
109                 int hh = picon->gui->vicon_thread->view_h;
110                 while( seq_no >= images.size() ) {
111                         file->set_layer(0);
112                         int64_t pos = images.size() / picon->gui->vicon_thread->refresh_rate * frame_rate;
113                         file->set_video_position(pos,0);
114                         file->read_frame(temp);
115                         add_image(temp, ww, hh, BC_RGB8);
116                 }
117                 mwindow->video_cache->check_in(asset);
118         }
119         return *images[seq_no];
120 }
121
122 int64_t AssetVIcon::set_seq_no(int64_t no)
123 {
124         if( no >= length ) no = 0;
125         return seq_no = no;
126 }
127
128 int AssetVIcon::get_vx()
129 {
130         BC_ListBox *lbox = picon->gui->asset_list;
131         return lbox->get_item_x(picon);
132 }
133 int AssetVIcon::get_vy()
134 {
135         BC_ListBox *lbox = picon->gui->asset_list;
136         return lbox->get_item_y(picon) + lbox->get_title_h();
137 }
138
139 AssetPicon::AssetPicon(MWindow *mwindow,
140         AWindowGUI *gui,
141         Indexable *indexable)
142  : BC_ListBoxItem()
143 {
144         reset();
145         this->mwindow = mwindow;
146         this->gui = gui;
147         this->indexable = indexable;
148         indexable->add_user();
149         this->id = indexable->id;
150 }
151
152 AssetPicon::AssetPicon(MWindow *mwindow,
153         AWindowGUI *gui,
154         EDL *edl)
155  : BC_ListBoxItem()
156 {
157         reset();
158         this->mwindow = mwindow;
159         this->gui = gui;
160         this->edl = edl;
161         edl->add_user();
162         this->id = edl->id;
163 }
164
165 AssetPicon::AssetPicon(MWindow *mwindow,
166         AWindowGUI *gui, int folder)
167  : BC_ListBoxItem(_(AWindowGUI::folder_names[folder]), gui->folder_icon)
168 {
169         reset();
170         foldernum = folder;
171         this->mwindow = mwindow;
172         this->gui = gui;
173 }
174
175 AssetPicon::AssetPicon(MWindow *mwindow,
176         AWindowGUI *gui, const char *folder_name, int folder_num)
177  : BC_ListBoxItem(folder_name, gui->folder_icon)
178 {
179         reset();
180         foldernum = folder_num;
181         this->mwindow = mwindow;
182         this->gui = gui;
183 }
184
185 AssetPicon::AssetPicon(MWindow *mwindow,
186         AWindowGUI *gui,
187         PluginServer *plugin)
188  : BC_ListBoxItem()
189 {
190         reset();
191         this->mwindow = mwindow;
192         this->gui = gui;
193         this->plugin = plugin;
194 }
195
196
197 AssetPicon::AssetPicon(MWindow *mwindow,
198         AWindowGUI *gui,
199         Label *label)
200  : BC_ListBoxItem()
201 {
202         reset();
203         this->mwindow = mwindow;
204         this->gui = gui;
205         this->label = label;
206         indexable = 0;
207         icon = 0;
208         id = 0;
209 }
210
211 AssetPicon::~AssetPicon()
212 {
213         if( vicon )
214                 gui->vicon_thread->del_vicon(vicon);
215         if( indexable ) indexable->remove_user();
216         if( edl ) edl->remove_user();
217         if( icon && !gui->protected_pixmap(icon) ) {
218                 delete icon;
219                 if( !plugin ) delete icon_vframe;
220         }
221 }
222
223 void AssetPicon::reset()
224 {
225         plugin = 0;
226         label = 0;
227         indexable = 0;
228         edl = 0;
229         icon = 0;
230         icon_vframe = 0;
231         vicon = 0;
232         in_use = 1;
233         id = 0;
234         persistent = 0;
235 }
236
237 void AssetPicon::create_objects()
238 {
239         FileSystem fs;
240         char name[BCTEXTLEN];
241         int pixmap_w, pixmap_h;
242         const int debug = 0;
243
244         pixmap_h = 50 * BC_WindowBase::get_resources()->icon_scale;
245
246         if( debug ) printf("AssetPicon::create_objects %d\n", __LINE__);
247         if( indexable ) {
248                 fs.extract_name(name, indexable->path);
249                 set_text(name);
250         }
251
252         if( indexable && indexable->is_asset ) {
253                 if( debug ) printf("AssetPicon::create_objects %d\n", __LINE__);
254                 Asset *asset = (Asset*)indexable;
255                 if( asset->video_data ) {
256                         if( mwindow->preferences->use_thumbnails ) {
257                                 gui->unlock_window();
258                                 if( debug ) printf("AssetPicon::create_objects %d\n", __LINE__);
259                                 File *file = mwindow->video_cache->check_out(asset,
260                                         mwindow->edl,
261                                         1);
262                                 if( debug ) printf("AssetPicon::create_objects %d\n", __LINE__);
263
264                                 if( file ) {
265                                         int height = asset->height > 0 ? asset->height : 1;
266                                         pixmap_w = pixmap_h * asset->width / height;
267
268                                         file->set_layer(0);
269                                         file->set_video_position(0, 0);
270
271                                         if( gui->temp_picon &&
272                                                 (gui->temp_picon->get_w() != asset->width ||
273                                                 gui->temp_picon->get_h() != asset->height) ) {
274                                                 delete gui->temp_picon;
275                                                 gui->temp_picon = 0;
276                                         }
277
278                                         if( !gui->temp_picon ) {
279                                                 gui->temp_picon = new VFrame(0, -1,
280                                                         asset->width, asset->height,
281                                                         BC_RGB888, -1);
282                                         }
283                                         { char string[BCTEXTLEN];
284                                         sprintf(string, _("Reading %s"), name);
285                                         mwindow->gui->lock_window("AssetPicon::create_objects");
286                                         mwindow->gui->show_message(string);
287                                         mwindow->gui->unlock_window(); }
288                                         file->read_frame(gui->temp_picon);
289                                         if( debug ) printf("AssetPicon::create_objects %d\n", __LINE__);
290                                         mwindow->video_cache->check_in(asset);
291
292                                         gui->lock_window("AssetPicon::create_objects 1");
293                                         icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
294                                         icon->draw_vframe(gui->temp_picon,
295                                                 0, 0, pixmap_w, pixmap_h, 0, 0);
296 //printf("%d %d\n", gui->temp_picon->get_w(), gui->temp_picon->get_h());
297                                         icon_vframe = new VFrame(0,
298                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
299                                         icon_vframe->transfer_from(gui->temp_picon);
300 // vicon images
301                                         double framerate = asset->get_frame_rate();
302                                         if( !framerate ) framerate = VICON_RATE;
303                                         int64_t frames = asset->get_video_frames();
304                                         double secs = frames / framerate;
305                                         if( secs > 5 ) secs = 5;
306                                         int64_t length = secs * gui->vicon_thread->refresh_rate;
307                                         vicon = new AssetVIcon(this, pixmap_w, pixmap_h, framerate, length);
308                                         gui->vicon_thread->add_vicon(vicon);
309                                         if( debug ) printf("AssetPicon::create_objects %d\n", __LINE__);
310
311                                 }
312                                 else {
313                                         gui->lock_window("AssetPicon::create_objects 2");
314                                         icon = gui->video_icon;
315                                         icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
316                                 }
317                         }
318                         else {
319                                 icon = gui->video_icon;
320                                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
321                         }
322                 }
323                 else
324                 if( asset->audio_data ) {
325                         icon = gui->audio_icon;
326                         icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_SOUND];
327                 }
328 //printf("AssetPicon::create_objects 2\n");
329
330                 if( debug ) printf("AssetPicon::create_objects %d\n", __LINE__);
331         }
332         else
333         if( indexable && !indexable->is_asset ) {
334                 icon = gui->video_icon;
335                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_FILM];
336         }
337         else
338         if( edl ) {
339 //printf("AssetPicon::create_objects 4 %s\n", edl->local_session->clip_title);
340                 set_text(strcpy(name, edl->local_session->clip_title));
341                 icon = gui->clip_icon;
342                 icon_vframe = mwindow->theme->get_image("clip_icon");
343         }
344         else
345         if( plugin ) {
346                 strcpy(name,  plugin->title);
347                 set_text(name);
348                 icon_vframe = plugin->get_picon();
349                 if( icon_vframe )
350                         icon = gui->create_pixmap(icon_vframe);
351                 else if( plugin->audio ) {
352                         if( plugin->transition ) {
353                                 icon = gui->atransition_icon;
354                                 icon_vframe = gui->atransition_vframe;
355                         }
356                         else if( plugin->is_ffmpeg() ) {
357                                 icon = gui->ff_aud_icon;
358                                 icon_vframe = gui->ff_aud_vframe;
359                         }
360                         else if( plugin->is_ladspa() ) {
361                                 icon = gui->ladspa_icon;
362                                 icon_vframe = gui->ladspa_vframe;
363                         }
364                         else {
365                                 icon = gui->aeffect_icon;
366                                 icon_vframe = gui->aeffect_vframe;
367                         }
368                 }
369                 else if( plugin->video ) {
370                         if( plugin->transition ) {
371                                 icon = gui->vtransition_icon;
372                                 icon_vframe = gui->vtransition_vframe;
373                         }
374                         else if( plugin->is_ffmpeg() ) {
375                                 icon = gui->ff_vid_icon;
376                                 icon_vframe = gui->ff_vid_vframe;
377                         }
378                         else {
379                                 icon = gui->veffect_icon;
380                                 icon_vframe = gui->veffect_vframe;
381                         }
382                 }
383         }
384         else
385         if( label ) {
386                 Units::totext(name,
387                               label->position,
388                               mwindow->edl->session->time_format,
389                               mwindow->edl->session->sample_rate,
390                               mwindow->edl->session->frame_rate,
391                               mwindow->edl->session->frames_per_foot);
392                 set_text(name);
393                 icon = gui->label_icon;
394                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_LABEL];
395                 set_icon(icon);
396                 set_icon_vframe(icon_vframe);
397         }
398         if( !icon ) {
399                 icon = gui->file_icon;
400                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN];
401         }
402         set_icon(icon);
403         set_icon_vframe(icon_vframe);
404
405         if( debug ) printf("AssetPicon::create_objects %d\n", __LINE__);
406 }
407
408
409
410
411
412
413 AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
414  : BC_Window(_(PROGRAM_NAME ": Resources"),
415         mwindow->session->awindow_x, mwindow->session->awindow_y,
416         mwindow->session->awindow_w, mwindow->session->awindow_h,
417         100, 100, 1, 1, 1)
418 {
419 // printf("AWindowGUI::AWindowGUI %d %d %d %d\n",
420 // mwindow->session->awindow_x,
421 // mwindow->session->awindow_y,
422 // mwindow->session->awindow_w,
423 // mwindow->session->awindow_h);
424         this->mwindow = mwindow;
425         this->awindow = awindow;
426         file_icon = 0;
427         audio_icon = 0;
428         video_icon = 0;
429         folder_icon = 0;
430         clip_icon = 0;
431         label_icon = 0;
432         atransition_icon = 0;  atransition_vframe = 0;
433         vtransition_icon = 0;  vtransition_vframe = 0;
434         aeffect_icon = 0;      aeffect_vframe = 0;
435         ladspa_icon = 0;       ladspa_vframe = 0;
436         veffect_icon = 0;      veffect_vframe = 0;
437         ff_aud_icon = 0;       ff_aud_vframe = 0;
438         ff_vid_icon = 0;       ff_vid_vframe = 0;
439         plugin_visibility = ((uint64_t)1<<(8*sizeof(uint64_t)-1))-1;
440         newfolder_thread = 0;
441         asset_menu = 0;
442         effectlist_menu = 0;
443         assetlist_menu = 0;
444         cliplist_menu = 0;
445         labellist_menu = 0;
446         folderlist_menu = 0;
447         temp_picon = 0;
448         allow_iconlisting = 1;
449         remove_plugin = 0;
450         vicon_thread = 0;
451         vicon_drawing = 1;
452 }
453
454 AWindowGUI::~AWindowGUI()
455 {
456         assets.remove_all_objects();
457         folders.remove_all_objects();
458         aeffects.remove_all_objects();
459         veffects.remove_all_objects();
460         atransitions.remove_all_objects();
461         vtransitions.remove_all_objects();
462         labellist.remove_all_objects();
463         displayed_assets[1].remove_all_objects();
464
465         delete vicon_thread;
466         delete file_icon;
467         delete audio_icon;
468         delete video_icon;
469         delete folder_icon;
470         delete clip_icon;
471         delete label_icon;
472         delete atransition_icon;
473         delete vtransition_icon;
474         delete aeffect_icon;
475         delete ladspa_icon;
476         delete ladspa_vframe;
477         delete ff_aud_icon;
478         delete ff_aud_vframe;
479         delete ff_vid_icon;
480         delete ff_vid_vframe;
481         delete veffect_icon;
482         delete newfolder_thread;
483         delete asset_menu;
484         delete clip_menu;
485         delete label_menu;
486         delete effectlist_menu;
487         delete assetlist_menu;
488         delete cliplist_menu;
489         delete labellist_menu;
490         delete folderlist_menu;
491         if( temp_picon ) delete temp_picon;
492         delete remove_plugin;
493 }
494
495 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
496 {
497         return  icon == file_icon ||
498                 icon == folder_icon ||
499                 icon == audio_icon ||
500                 icon == video_icon ||
501                 icon == clip_icon ||
502                 icon == label_icon ||
503                 icon == vtransition_icon ||
504                 icon == atransition_icon ||
505                 icon == veffect_icon ||
506                 icon == aeffect_icon ||
507                 icon == ladspa_icon ||
508                 icon == ff_aud_icon ||
509                 icon == ff_vid_icon;
510 }
511
512 void AWindowGUI::create_objects()
513 {
514         AssetPicon *picon;
515
516         lock_window("AWindowGUI::create_objects");
517 SET_TRACE
518 //printf("AWindowGUI::create_objects 1\n");
519         asset_titles[0] = _("Title");
520         asset_titles[1] = _("Comments");
521
522 SET_TRACE
523
524         set_icon(mwindow->theme->get_image("awindow_icon"));
525         file_icon = new BC_Pixmap(this,
526                 BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN],
527                 PIXMAP_ALPHA);
528
529         folder_icon = new BC_Pixmap(this,
530                 BC_WindowBase::get_resources()->type_to_icon[ICON_FOLDER],
531                 PIXMAP_ALPHA);
532
533         audio_icon = new BC_Pixmap(this,
534                 BC_WindowBase::get_resources()->type_to_icon[ICON_SOUND],
535                 PIXMAP_ALPHA);
536
537         video_icon = new BC_Pixmap(this,
538                 BC_WindowBase::get_resources()->type_to_icon[ICON_FILM],
539                 PIXMAP_ALPHA);
540
541         label_icon = new BC_Pixmap(this,
542                 BC_WindowBase::get_resources()->type_to_icon[ICON_LABEL],
543                 PIXMAP_ALPHA);
544
545 SET_TRACE
546
547         clip_vframe = mwindow->theme->get_image("clip_icon");
548         clip_icon = new BC_Pixmap(this, clip_vframe, PIXMAP_ALPHA);
549         atransition_vframe = mwindow->theme->get_image("atransition_icon");
550         atransition_icon = new BC_Pixmap(this, atransition_vframe, PIXMAP_ALPHA);
551         vtransition_vframe = mwindow->theme->get_image("vtransition_icon");
552         vtransition_icon = new BC_Pixmap(this, vtransition_vframe, PIXMAP_ALPHA);
553         aeffect_vframe = mwindow->theme->get_image("aeffect_icon");
554         aeffect_icon = new BC_Pixmap(this, aeffect_vframe, PIXMAP_ALPHA);
555         ladspa_vframe = new VFramePng(lad_picon_png);
556         ladspa_icon = new BC_Pixmap(this, ladspa_vframe, PIXMAP_ALPHA);
557         ff_aud_vframe = new VFramePng(ff_audio_png);
558         ff_aud_icon = new BC_Pixmap(this, ff_aud_vframe, PIXMAP_ALPHA);
559         ff_vid_vframe = new VFramePng(ff_video_png);
560         ff_vid_icon = new BC_Pixmap(this, ff_vid_vframe, PIXMAP_ALPHA);
561         veffect_vframe = mwindow->theme->get_image("veffect_icon");
562         veffect_icon = new BC_Pixmap(this, veffect_vframe, PIXMAP_ALPHA);
563
564 SET_TRACE
565
566 // Mandatory folders
567         folders.append(picon = new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER));
568         picon->persistent = 1;
569         folders.append(picon = new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER));
570         picon->persistent = 1;
571         folders.append(picon = new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER));
572         picon->persistent = 1;
573         folders.append(picon = new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER));
574         picon->persistent = 1;
575         folders.append(picon = new AssetPicon(mwindow, this, AW_LABEL_FOLDER));
576         picon->persistent = 1;
577         folders.append(picon = new AssetPicon(mwindow, this, AW_CLIP_FOLDER));
578         picon->persistent = 1;
579         folders.append(picon = new AssetPicon(mwindow, this, AW_MEDIA_FOLDER));
580         picon->persistent = 1;
581
582         create_label_folder();
583 SET_TRACE
584
585         mwindow->theme->get_awindow_sizes(this);
586         load_defaults(mwindow->defaults);
587
588 SET_TRACE
589         add_subwindow(asset_list = new AWindowAssets(mwindow,
590                 this,
591                 mwindow->theme->alist_x,
592                 mwindow->theme->alist_y,
593                 mwindow->theme->alist_w,
594                 mwindow->theme->alist_h));
595
596         vicon_thread = new VIconThread(asset_list);
597         vicon_thread->start();
598
599 SET_TRACE
600         add_subwindow(divider = new AWindowDivider(mwindow,
601                 this,
602                 mwindow->theme->adivider_x,
603                 mwindow->theme->adivider_y,
604                 mwindow->theme->adivider_w,
605                 mwindow->theme->adivider_h));
606
607 SET_TRACE
608         divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
609
610 SET_TRACE
611         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
612         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
613         VFrame **images = mwindow->theme->get_image_set("playpatch_data");
614         AVIconDrawing::calculate_geometry(this, images, &avicon_w, &avicon_h);
615         add_subwindow(avicon_drawing = new AVIconDrawing(this, fw-avicon_w, fy, images));
616         add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, _("Visibility")));
617         add_tools->create_objects();
618         fy += add_tools->get_h();  fh -= add_tools->get_h();
619 SET_TRACE
620         add_subwindow(folder_list = new AWindowFolders(mwindow,
621                 this, fx, fy, fw, fh));
622 SET_TRACE
623         update_effects();
624 SET_TRACE
625
626         //int x = mwindow->theme->abuttons_x;
627         //int y = mwindow->theme->abuttons_y;
628
629 SET_TRACE
630
631         newfolder_thread = new NewFolderThread(mwindow, this);
632
633         add_subwindow(asset_menu = new AssetPopup(mwindow, this));
634         asset_menu->create_objects();
635         add_subwindow(clip_menu = new ClipPopup(mwindow, this));
636         clip_menu->create_objects();
637         add_subwindow(label_menu = new LabelPopup(mwindow, this));
638         label_menu->create_objects();
639
640         add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this));
641         effectlist_menu->create_objects();
642         add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
643         assetlist_menu->create_objects();
644         add_subwindow(cliplist_menu = new ClipListMenu(mwindow, this));
645         cliplist_menu->create_objects();
646         add_subwindow(labellist_menu = new LabelListMenu(mwindow, this));
647         labellist_menu->create_objects();
648 SET_TRACE
649
650         add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
651         folderlist_menu->create_objects();
652 SET_TRACE
653 //printf("AWindowGUI::create_objects 2\n");
654
655         create_custom_xatoms();
656         unlock_window();
657 }
658
659 int AWindowGUI::resize_event(int w, int h)
660 {
661         mwindow->session->awindow_x = get_x();
662         mwindow->session->awindow_y = get_y();
663         mwindow->session->awindow_w = w;
664         mwindow->session->awindow_h = h;
665
666         mwindow->theme->get_awindow_sizes(this);
667         mwindow->theme->draw_awindow_bg(this);
668         reposition_objects();
669
670 //      int x = mwindow->theme->abuttons_x;
671 //      int y = mwindow->theme->abuttons_y;
672 //      new_bin->reposition_window(x, y);
673 //      x += new_bin->get_w();
674 //      delete_bin->reposition_window(x, y);
675 //      x += delete_bin->get_w();
676 //      rename_bin->reposition_window(x, y);
677 //      x += rename_bin->get_w();
678 //      delete_disk->reposition_window(x, y);
679 //      x += delete_disk->get_w();
680 //      delete_project->reposition_window(x, y);
681 //      x += delete_project->get_w();
682 //      info->reposition_window(x, y);
683 //      x += info->get_w();
684 //      redraw_index->reposition_window(x, y);
685 //      x += redraw_index->get_w();
686 //      paste->reposition_window(x, y);
687 //      x += paste->get_w();
688 //      append->reposition_window(x, y);
689 //      x += append->get_w();
690 //      view->reposition_window(x, y);
691
692         BC_WindowBase::resize_event(w, h);
693         return 1;
694 }
695
696 int AWindowGUI::translation_event()
697 {
698         mwindow->session->awindow_x = get_x();
699         mwindow->session->awindow_y = get_y();
700         return 0;
701 }
702
703 void AWindowGUI::reposition_objects()
704 {
705         asset_list->reposition_window(
706                 mwindow->theme->alist_x, mwindow->theme->alist_y,
707                 mwindow->theme->alist_w, mwindow->theme->alist_h);
708         divider->reposition_window(
709                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
710                 mwindow->theme->adivider_w, mwindow->theme->adivider_h);
711         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
712         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
713         add_tools->resize_event(fw-avicon_w, add_tools->get_h());
714         avicon_drawing->reposition_window(fw-avicon_w, fy);
715         fy += add_tools->get_h();  fh -= add_tools->get_h();
716         folder_list->reposition_window(fx, fy, fw, fh);
717 }
718
719 int AWindowGUI::save_defaults(BC_Hash *defaults)
720 {
721         defaults->update("PLUGIN_VISIBILTY", plugin_visibility);
722         defaults->update("VICON_DRAWING", vicon_drawing);
723         return 0;
724 }
725
726 int AWindowGUI::load_defaults(BC_Hash *defaults)
727 {
728         plugin_visibility = defaults->get("PLUGIN_VISIBILTY", plugin_visibility);
729         vicon_drawing = defaults->get("VICON_DRAWING", vicon_drawing);
730         return 0;
731 }
732
733 int AWindowGUI::close_event()
734 {
735         hide_window();
736         mwindow->session->show_awindow = 0;
737         unlock_window();
738
739         mwindow->gui->lock_window("AWindowGUI::close_event");
740         mwindow->gui->mainmenu->show_awindow->set_checked(0);
741         mwindow->gui->unlock_window();
742
743         lock_window("AWindowGUI::close_event");
744         save_defaults(mwindow->defaults);
745         mwindow->save_defaults();
746         return 1;
747 }
748
749 void AWindowGUI::start_vicon_drawing()
750 {
751         if( !vicon_drawing ) return;
752         if( mwindow->edl->session->awindow_folder != AW_MEDIA_FOLDER ) return;
753         if( mwindow->edl->session->assetlist_format != ASSETS_ICONS ) return;
754         vicon_thread->start_drawing();
755 }
756
757 void AWindowGUI::stop_vicon_drawing()
758 {
759         vicon_thread->stop_drawing();
760 }
761
762 AWindowRemovePluginGUI::
763 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
764         int x, int y, PluginServer *plugin)
765  : BC_Window(_(PROGRAM_NAME ": Remove plugin"), x,y, 500,200, 50, 50, 1, 0, 1, -1, "", 1)
766 {
767         this->awindow = awindow;
768         this->thread = thread;
769         this->plugin = plugin;
770         VFrame *vframe = plugin->get_picon();
771         icon = vframe ? create_pixmap(vframe) : 0;
772         plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
773 }
774
775 AWindowRemovePluginGUI::
776 ~AWindowRemovePluginGUI()
777 {
778         if( !awindow->gui->protected_pixmap(icon) )
779                 delete icon;
780         plugin_list.remove_all();
781 }
782
783 void AWindowRemovePluginGUI::create_objects()
784 {
785         BC_Button *ok_button = new BC_OKButton(this);
786         add_subwindow(ok_button);
787         BC_Button *cancel_button = new BC_CancelButton(this);
788         add_subwindow(cancel_button);
789         int x = 10, y = 10;
790         BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
791         add_subwindow(title);
792         y += title->get_h() + 5;
793         list = new BC_ListBox(x, y,
794                 get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
795                 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
796         add_subwindow(list);
797         show_window();
798 }
799
800 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
801 {
802         int ret = 0;
803         for( int i=0; i<folder.size(); ) {
804                 AssetPicon *picon = (AssetPicon *)folder[i];
805                 if( picon->plugin == plugin ) {
806                         folder.remove_object_number(i);
807                         ++ret;
808                         continue;
809                 }
810                 ++i;
811         }
812         return ret;
813 }
814
815 void AWindowRemovePlugin::handle_close_event(int result)
816 {
817         if( !result ) {
818                 printf(_("remove %s\n"), plugin->path);
819                 ArrayList<BC_ListBoxItem*> *folder =
820                         plugin->audio ? plugin->transition ?
821                                 &awindow->gui->atransitions :
822                                 &awindow->gui->aeffects :
823                         plugin->video ?  plugin->transition ?
824                                 &awindow->gui->vtransitions :
825                                 &awindow->gui->veffects :
826                         0;
827                 if( folder ) remove_plugin(plugin, *folder);
828                 char plugin_path[BCTEXTLEN];
829                 strcpy(plugin_path, plugin->path);
830                 MWindow *mwindow = awindow->mwindow;
831                 mwindow->plugindb->remove(plugin);
832                 remove(plugin_path);
833                 char index_path[BCTEXTLEN];
834                 snprintf(index_path, sizeof(index_path), "%s/%s",
835                         mwindow->preferences->plugin_dir, PLUGIN_FILE);
836                 remove(index_path);
837                 char png_path[BCTEXTLEN];
838                 if( plugin->get_theme_png_path(png_path, mwindow->preferences->theme) )
839                         remove(png_path);
840                 if( plugin->get_theme_png_path(png_path, "picon") )
841                         remove(png_path);
842                 delete plugin;  plugin = 0;
843                 awindow->gui->async_update_assets();
844         }
845 }
846
847 AWindowRemovePlugin::
848 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
849  : BC_DialogThread()
850 {
851         this->awindow = awindow;
852         this->plugin = plugin;
853 }
854
855 AWindowRemovePlugin::
856 ~AWindowRemovePlugin()
857 {
858         close_window();
859 }
860
861 BC_Window* AWindowRemovePlugin::new_gui()
862 {
863         int x = awindow->gui->get_abs_cursor_x(0);
864         int y = awindow->gui->get_abs_cursor_y(0);
865         AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
866         gui->create_objects();
867         return gui;
868 }
869
870 int AWindowGUI::keypress_event()
871 {
872         switch( get_keypress() ) {
873         case 'w': case 'W':
874                 if( ctrl_down() ) {
875                         close_event();
876                         return 1;
877                 }
878                 break;
879         case DELETE:
880                 if( shift_down() ) {
881                         PluginServer* plugin = selected_plugin();
882                         if( !plugin ) break;
883                         remove_plugin = new AWindowRemovePlugin(awindow, plugin);
884                         unlock_window();
885                         remove_plugin->start();
886                         lock_window();
887                 }
888         }
889         return 0;
890 }
891
892
893
894 int AWindowGUI::create_custom_xatoms()
895 {
896         UpdateAssetsXAtom = create_xatom("CWINDOWGUI_UPDATE_ASSETS");
897         return 0;
898 }
899 int AWindowGUI::recieve_custom_xatoms(xatom_event *event)
900 {
901         if( event->message_type == UpdateAssetsXAtom ) {
902                 update_assets();
903                 return 1;
904         }
905         return 0;
906 }
907
908 void AWindowGUI::async_update_assets()
909 {
910         xatom_event event;
911         event.message_type = UpdateAssetsXAtom;
912         send_custom_xatom(&event);
913 }
914
915
916
917
918
919
920
921 void AWindowGUI::update_folder_list()
922 {
923         stop_vicon_drawing();
924 //printf("AWindowGUI::update_folder_list 1\n");
925         for( int i = 0; i < folders.total; i++ ) {
926                 AssetPicon *picon = (AssetPicon*)folders.values[i];
927                 picon->in_use--;
928         }
929 //printf("AWindowGUI::update_folder_list 1\n");
930
931 // Search assets for folders
932         for( int i = 0; i < mwindow->edl->folders.total; i++ ) {
933                 const char *folder = mwindow->edl->folders.values[i];
934                 int exists = 0;
935 //printf("AWindowGUI::update_folder_list 1.1\n");
936
937                 for( int j = 0; j < folders.total; j++ ) {
938                         AssetPicon *picon = (AssetPicon*)folders.values[j];
939                         if( !strcasecmp(picon->get_text(), folder) ) {
940                                 exists = 1;
941                                 picon->in_use = 1;
942                                 break;
943                         }
944                 }
945
946                 if( !exists ) {
947                         int aw_folder = folder_number(folder);
948                         AssetPicon *picon = aw_folder >= 0 ?
949                                 new AssetPicon(mwindow, this, aw_folder) :
950                                 new AssetPicon(mwindow, this, folder, AW_USER_FOLDER);
951                         picon->create_objects();
952                         folders.append(picon);
953                 }
954 //printf("AWindowGUI::update_folder_list 1.3\n");
955         }
956 //printf("AWindowGUI::update_folder_list 1\n");
957 //for( int i = 0; i < folders.total; i++ )
958 //      printf("AWindowGUI::update_folder_list %s\n", folders.values[i]->get_text());
959
960 // Delete excess
961         for( int i = folders.total - 1; i >= 0; i-- ) {
962                 AssetPicon *picon = (AssetPicon*)folders.values[i];
963                 if( !picon->in_use && !picon->persistent ) {
964                         delete picon;
965                         folders.remove_number(i);
966                 }
967         }
968 //for( int i = 0; i < folders.total; i++ )
969 //      printf("AWindowGUI::update_folder_list %s\n", folders.values[i]->get_text());
970 //printf("AWindowGUI::update_folder_list 2\n");
971         start_vicon_drawing();
972 }
973
974 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
975         int do_audio, int do_video, int is_realtime, int is_transition)
976 {
977         ArrayList<PluginServer*> plugin_list;
978 // Get pointers to plugindb entries
979         mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
980                         0, plugin_list);
981
982         for( int i = 0; i < plugin_list.total; i++ ) {
983                 PluginServer *server = plugin_list.values[i];
984                 int visible = plugin_visibility & (1<<server->dir_idx);
985                 if( !visible ) continue;
986 // Create new listitem
987                 AssetPicon *picon = new AssetPicon(mwindow, this, server);
988                 picon->create_objects();
989                 output->append(picon);
990         }
991 }
992
993 void AWindowGUI::create_label_folder()
994 {
995         Label *current;
996         for( current = mwindow->edl->labels->first; current; current = NEXT ) {
997                 AssetPicon *picon = new AssetPicon(mwindow, this, current);
998                 picon->create_objects();
999                 labellist.append(picon);
1000         }
1001 }
1002
1003
1004 void AWindowGUI::update_asset_list()
1005 {
1006 //printf("AWindowGUI::update_asset_list 1\n");
1007         for( int i = 0; i < assets.total; i++ ) {
1008                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1009                 picon->in_use--;
1010         }
1011
1012
1013
1014
1015
1016 //printf("AWindowGUI::update_asset_list 2\n");
1017
1018
1019 // Synchronize EDL clips
1020         for( int i = 0; i < mwindow->edl->clips.total; i++ ) {
1021                 int exists = 0;
1022
1023 // Look for clip in existing listitems
1024                 for( int j = 0; j < assets.total && !exists; j++ ) {
1025                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1026
1027                         if( picon->id == mwindow->edl->clips.values[i]->id ) {
1028                                 picon->edl = mwindow->edl->clips.values[i];
1029                                 picon->set_text(mwindow->edl->clips.values[i]->local_session->clip_title);
1030                                 exists = 1;
1031                                 picon->in_use = 1;
1032                         }
1033                 }
1034
1035 // Create new listitem
1036                 if( !exists ) {
1037                         AssetPicon *picon = new AssetPicon(mwindow,
1038                                 this,
1039                                 mwindow->edl->clips.values[i]);
1040                         picon->create_objects();
1041                         assets.append(picon);
1042                 }
1043         }
1044
1045
1046
1047
1048
1049 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
1050
1051
1052 // Synchronize EDL assets
1053         for( Asset *current = mwindow->edl->assets->first;
1054                 current;
1055                 current = NEXT ) {
1056                 int exists = 0;
1057
1058 // Look for asset in existing listitems
1059                 for( int j = 0; j < assets.total && !exists; j++ ) {
1060                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1061
1062                         if( picon->id == current->id ) {
1063                                 picon->indexable = current;
1064                                 exists = 1;
1065                                 picon->in_use = 1;
1066                                 break;
1067                         }
1068                 }
1069
1070 // Create new listitem
1071                 if( !exists ) {
1072 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
1073                         AssetPicon *picon = new AssetPicon(mwindow, this, current);
1074 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
1075                         picon->create_objects();
1076 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
1077                         assets.append(picon);
1078                 }
1079         }
1080
1081         mwindow->gui->lock_window("AWindowGUI::update_asset_list");
1082         mwindow->gui->default_message();
1083         mwindow->gui->unlock_window();
1084
1085 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
1086
1087
1088 // Synchronize nested EDLs
1089         for( int i = 0; i < mwindow->edl->nested_edls->size(); i++ ) {
1090                 int exists = 0;
1091                 Indexable *indexable = mwindow->edl->nested_edls->get(i);
1092
1093 // Look for asset in existing listitems
1094                 for( int j = 0; j < assets.total && !exists; j++ ) {
1095                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1096
1097                         if( picon->id == indexable->id ) {
1098                                 picon->indexable = indexable;
1099                                 exists = 1;
1100                                 picon->in_use = 1;
1101                                 break;
1102                         }
1103                 }
1104
1105 // Create new listitem
1106                 if( !exists ) {
1107                         AssetPicon *picon = new AssetPicon(mwindow,
1108                                 this,
1109                                 indexable);
1110                         picon->create_objects();
1111                         assets.append(picon);
1112                 }
1113         }
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123 //printf("AWindowGUI::update_asset_list %d\n", __LINE__);
1124         for( int i = assets.size() - 1; i >= 0; i-- ) {
1125                 AssetPicon *picon = (AssetPicon*)assets.get(i);
1126 //printf("AWindowGUI::update_asset_list %s %d\n", picon->asset->path, picon->in_use);
1127                 if( !picon->in_use ) {
1128                         delete picon;
1129                         assets.remove_number(i);
1130                 }
1131         }
1132 //printf("AWindowGUI::update_asset_list 7 %d\n", assets.total);
1133 }
1134
1135 void AWindowGUI::update_picon(Indexable *indexable)
1136 {
1137 //printf("AWindowGUI::update_asset_list 1\n");
1138         VIcon *vicon = 0;
1139         for( int i = 0; i < assets.total; i++ ) {
1140                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1141                 if( picon->indexable == indexable ||
1142                     picon->edl == (EDL *)indexable ) {
1143                         char name[BCTEXTLEN];
1144                         FileSystem fs;
1145                         fs.extract_name(name, indexable->path);
1146                         picon->set_text(name);
1147                         vicon = picon->vicon;
1148                         break;
1149                 }
1150         }
1151         if( vicon ) {
1152                 stop_vicon_drawing();
1153                 vicon->clear_images();
1154                 vicon->reset(indexable->get_frame_rate());
1155                 start_vicon_drawing();
1156         }
1157 }
1158
1159 void AWindowGUI::sort_assets()
1160 {
1161 //printf("AWindowGUI::sort_assets 1 %s\n", mwindow->edl->session->current_folder);
1162         switch( mwindow->edl->session->awindow_folder ) {
1163         case AW_AEFFECT_FOLDER:
1164                 sort_picons(&aeffects);
1165                 break;
1166         case AW_VEFFECT_FOLDER:
1167                 sort_picons(&veffects);
1168                 break;
1169         case AW_ATRANSITION_FOLDER:
1170                 sort_picons(&atransitions);
1171                 break;
1172         case AW_VTRANSITION_FOLDER:
1173                 sort_picons(&vtransitions);
1174                 break;
1175         case AW_LABEL_FOLDER:
1176                 sort_picons(&labellist);
1177                 break;
1178         default:
1179                 sort_picons(&assets);
1180         }
1181
1182         update_assets();
1183 }
1184
1185 void AWindowGUI::collect_assets()
1186 {
1187         int i = 0;
1188         mwindow->session->drag_assets->remove_all();
1189         mwindow->session->drag_clips->remove_all();
1190         while(1)
1191         {
1192                 AssetPicon *result = (AssetPicon*)asset_list->get_selection(0, i++);
1193                 if( !result ) break;
1194
1195                 if( result->indexable ) mwindow->session->drag_assets->append(result->indexable);
1196                 if( result->edl ) mwindow->session->drag_clips->append(result->edl);
1197         }
1198 }
1199
1200 void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst,
1201         ArrayList<BC_ListBoxItem*> *src, int folder)
1202 {
1203 // Remove current pointers
1204         dst[0].remove_all();
1205         dst[1].remove_all_objects();
1206
1207 // Create new pointers
1208 //if( folder ) printf("AWindowGUI::copy_picons 1 %s\n", folder);
1209         for( int i = 0; i < src->total; i++ ) {
1210                 AssetPicon *picon = (AssetPicon*)src->values[i];
1211 //printf("AWindowGUI::copy_picons 2 %s\n", picon->asset->folder);
1212                 if( folder < 0 ||
1213                     (picon->indexable && picon->indexable->awindow_folder == folder) ||
1214                     (picon->edl && picon->edl->local_session->awindow_folder == folder) ) {
1215                         BC_ListBoxItem *item2, *item1;
1216                         dst[0].append(item1 = picon);
1217                         if( picon->edl )
1218                                 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
1219                         else
1220                         if( picon->label && picon->label->textstr )
1221                                 dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr));
1222                         else
1223                                 dst[1].append(item2 = new BC_ListBoxItem(""));
1224                         item1->set_autoplace_text(1);
1225                         item2->set_autoplace_text(1);
1226 //printf("AWindowGUI::copy_picons 3 %s\n", picon->get_text());
1227                 }
1228         }
1229 }
1230
1231 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src)
1232 {
1233 //printf("AWindowGUI::sort_picons 1\n")
1234         int done = 0;
1235         while(!done)
1236         {
1237                 done = 1;
1238                 for( int i = 0; i < src->total - 1; i++ ) {
1239                         BC_ListBoxItem *item1 = src->values[i];
1240                         BC_ListBoxItem *item2 = src->values[i + 1];
1241                         item1->set_autoplace_icon(1);
1242                         item2->set_autoplace_icon(1);
1243                         item1->set_autoplace_text(1);
1244                         item2->set_autoplace_text(1);
1245                         if( strcmp(item1->get_text(), item2->get_text()) > 0 ) {
1246                                 src->values[i + 1] = item1;
1247                                 src->values[i] = item2;
1248                                 done = 0;
1249                         }
1250                 }
1251         }
1252 }
1253
1254
1255 void AWindowGUI::filter_displayed_assets()
1256 {
1257         //allow_iconlisting = 1;
1258         asset_titles[0] = _("Title");
1259         asset_titles[1] = _("Comments");
1260
1261         switch( mwindow->edl->session->awindow_folder ) {
1262         case AW_AEFFECT_FOLDER:
1263                 copy_picons(displayed_assets, &aeffects, AW_NO_FOLDER);
1264                 break;
1265         case AW_VEFFECT_FOLDER:
1266                 copy_picons(displayed_assets, &veffects, AW_NO_FOLDER);
1267                 break;
1268         case AW_ATRANSITION_FOLDER:
1269                 copy_picons(displayed_assets, &atransitions, AW_NO_FOLDER);
1270                 break;
1271         case AW_VTRANSITION_FOLDER:
1272                 copy_picons(displayed_assets, &vtransitions, AW_NO_FOLDER);
1273                 break;
1274         case AW_LABEL_FOLDER:
1275                 copy_picons(displayed_assets, &labellist, AW_NO_FOLDER);
1276                 asset_titles[0] = _("Time Stamps");
1277                 asset_titles[1] = _("Title");
1278                 //allow_iconlisting = 0;
1279                 break;
1280         default:
1281                 copy_picons(displayed_assets, &assets, mwindow->edl->session->awindow_folder);
1282                 break;
1283         }
1284
1285         // Ensure the current folder icon is highlighted
1286         for( int i = 0; i < folders.total; i++ )
1287                 folders.values[i]->set_selected(0);
1288
1289         folders.values[mwindow->edl->session->awindow_folder]->set_selected(1);
1290 }
1291
1292
1293 void AWindowGUI::update_assets()
1294 {
1295 //printf("AWindowGUI::update_assets 1\n");
1296         update_folder_list();
1297 //printf("AWindowGUI::update_assets 2\n");
1298         update_asset_list();
1299         labellist.remove_all_objects();
1300         create_label_folder();
1301 //printf("AWindowGUI::update_assets 3\n");
1302         filter_displayed_assets();
1303
1304 //for( int i = 0; i < folders.total; i++ )
1305 //printf("AWindowGUI::update_assets 4\n");
1306 //      printf("AWindowGUI::update_assets %s\n", folders.values[i]->get_text());
1307         if( mwindow->edl->session->folderlist_format != folder_list->get_format() )
1308                 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
1309         folder_list->update(&folders, 0, 0, 1,
1310                 folder_list->get_xposition(),
1311                 folder_list->get_yposition(),
1312                 -1);
1313 //printf("AWindowGUI::update_assets 5\n");
1314
1315         if( mwindow->edl->session->assetlist_format != asset_list->get_format() )
1316                 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
1317
1318
1319 //printf("AWindowGUI::update_assets 6 %d\n", displayed_assets[0].total);
1320         asset_list->update(displayed_assets, asset_titles,
1321                 mwindow->edl->session->asset_columns, ASSET_COLUMNS,
1322                 asset_list->get_xposition(),
1323                 asset_list->get_yposition(),
1324                 -1, 0);
1325         asset_list->center_selection();
1326 //printf("AWindowGUI::update_assets 7\n");
1327
1328         flush();
1329 //printf("AWindowGUI::update_assets 8\n");
1330         return;
1331 }
1332
1333 void AWindowGUI::update_effects()
1334 {
1335         aeffects.remove_all_objects();
1336         create_persistent_folder(&aeffects, 1, 0, 1, 0);
1337         veffects.remove_all_objects();
1338         create_persistent_folder(&veffects, 0, 1, 1, 0);
1339         atransitions.remove_all_objects();
1340         create_persistent_folder(&atransitions, 1, 0, 0, 1);
1341         vtransitions.remove_all_objects();
1342         create_persistent_folder(&vtransitions, 0, 1, 0, 1);
1343 }
1344
1345 int AWindowGUI::folder_number(const char *name)
1346 {
1347         for( int i = 0; i < AWINDOW_FOLDERS; i++ ) {
1348                 if( !strcasecmp(name, folder_names[i]) ) return i;
1349         }
1350         return AW_NO_FOLDER;
1351 }
1352
1353 int AWindowGUI::drag_motion()
1354 {
1355         if( get_hidden() ) return 0;
1356
1357         int result = 0;
1358         return result;
1359 }
1360
1361 int AWindowGUI::drag_stop()
1362 {
1363         if( get_hidden() ) return 0;
1364
1365         return 0;
1366 }
1367
1368 Indexable* AWindowGUI::selected_asset()
1369 {
1370         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1371         return picon ? picon->indexable : 0;
1372 }
1373
1374 PluginServer* AWindowGUI::selected_plugin()
1375 {
1376         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1377         return picon ? picon->plugin : 0;
1378 }
1379
1380 AssetPicon* AWindowGUI::selected_folder()
1381 {
1382         AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
1383         return picon;
1384 }
1385
1386
1387
1388
1389
1390
1391
1392
1393 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1394  : BC_SubWindow(x, y, w, h)
1395 {
1396         this->mwindow = mwindow;
1397         this->gui = gui;
1398 }
1399 AWindowDivider::~AWindowDivider()
1400 {
1401 }
1402
1403 int AWindowDivider::button_press_event()
1404 {
1405         if( is_event_win() && cursor_inside() ) {
1406                 mwindow->session->current_operation = DRAG_PARTITION;
1407                 return 1;
1408         }
1409         return 0;
1410 }
1411
1412 int AWindowDivider::cursor_motion_event()
1413 {
1414         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1415                 int wmin = 25;
1416                 int wmax = mwindow->session->awindow_w - mwindow->theme->adivider_w - wmin;
1417                 int fw = gui->get_relative_cursor_x();
1418                 if( fw > wmax ) fw = wmax;
1419                 if( fw < wmin ) fw = wmin;
1420                 mwindow->session->afolders_w = fw;
1421                 mwindow->theme->get_awindow_sizes(gui);
1422                 gui->reposition_objects();
1423                 gui->flush();
1424         }
1425         return 0;
1426 }
1427
1428 int AWindowDivider::button_release_event()
1429 {
1430         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1431                 mwindow->session->current_operation = NO_OPERATION;
1432                 return 1;
1433         }
1434         return 0;
1435 }
1436
1437
1438
1439
1440
1441
1442 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1443  : BC_ListBox(x,
1444                 y,
1445                 w,
1446                 h,
1447                 mwindow->edl->session->folderlist_format == ASSETS_ICONS ?
1448                         LISTBOX_ICONS : LISTBOX_TEXT,
1449                 &gui->folders, // Each column has an ArrayList of BC_ListBoxItems.
1450                 0,             // Titles for columns.  Set to 0 for no titles
1451                 0,                // width of each column
1452                 1,                      // Total columns.
1453                 0,                    // Pixel of top of window.
1454                 0,                        // If this listbox is a popup window
1455                 LISTBOX_SINGLE,  // Select one item or multiple items
1456                 ICON_TOP,        // Position of icon relative to text of each item
1457                 1)               // Allow drags
1458 {
1459         this->mwindow = mwindow;
1460         this->gui = gui;
1461         set_drag_scroll(0);
1462 }
1463
1464 AWindowFolders::~AWindowFolders()
1465 {
1466 }
1467
1468 int AWindowFolders::selection_changed()
1469 {
1470         AssetPicon *picon = (AssetPicon*)get_selection(0, 0);
1471         if( picon ) {
1472                 gui->stop_vicon_drawing();
1473
1474                 if( get_button_down() && get_buttonpress() == 3 ) {
1475                         gui->folderlist_menu->update_titles();
1476                         gui->folderlist_menu->activate_menu();
1477                 }
1478
1479                 mwindow->edl->session->awindow_folder =  picon->foldernum;
1480 //printf("AWindowFolders::selection_changed 1\n");
1481                 gui->asset_list->draw_background();
1482                 gui->async_update_assets();
1483
1484                 gui->start_vicon_drawing();
1485         }
1486         return 1;
1487 }
1488
1489 int AWindowFolders::button_press_event()
1490 {
1491         int result = 0;
1492
1493         result = BC_ListBox::button_press_event();
1494
1495         if( !result ) {
1496                 if( get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1497                         gui->folderlist_menu->update_titles();
1498                         gui->folderlist_menu->activate_menu();
1499                         result = 1;
1500                 }
1501         }
1502
1503
1504         return result;
1505 }
1506
1507
1508
1509
1510
1511
1512
1513 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1514  : BC_ListBox(x, y, w, h,
1515                 (mwindow->edl->session->assetlist_format == ASSETS_ICONS && gui->allow_iconlisting ) ?
1516                         LISTBOX_ICONS : LISTBOX_TEXT,
1517                 &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
1518                 gui->asset_titles,             // Titles for columns.  Set to 0 for no titles
1519                 mwindow->edl->session->asset_columns,                // width of each column
1520                 1,                      // Total columns.
1521                 0,                    // Pixel of top of window.
1522                 0,                        // If this listbox is a popup window
1523                 LISTBOX_MULTIPLE,  // Select one item or multiple items
1524                 ICON_TOP,        // Position of icon relative to text of each item
1525                 1)               // Allow drag
1526 {
1527         this->mwindow = mwindow;
1528         this->gui = gui;
1529         set_drag_scroll(0);
1530 }
1531
1532 AWindowAssets::~AWindowAssets()
1533 {
1534 }
1535
1536 int AWindowAssets::button_press_event()
1537 {
1538         int result = 0;
1539
1540         result = BC_ListBox::button_press_event();
1541
1542         if( !result && get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1543                 BC_ListBox::deactivate_selection();
1544                 int folder = mwindow->edl->session->awindow_folder;
1545                 switch( folder ) {
1546                 case AW_AEFFECT_FOLDER:
1547                 case AW_VEFFECT_FOLDER:
1548                 case AW_ATRANSITION_FOLDER:
1549                 case AW_VTRANSITION_FOLDER:
1550                         gui->effectlist_menu->update();
1551                         gui->effectlist_menu->activate_menu();
1552                         break;
1553                 case AW_LABEL_FOLDER:
1554                         gui->labellist_menu->update();
1555                         gui->labellist_menu->activate_menu();
1556                         break;
1557                 case AW_CLIP_FOLDER:
1558                         gui->cliplist_menu->update();
1559                         gui->cliplist_menu->activate_menu();
1560                         break;
1561                 case AW_MEDIA_FOLDER:
1562                         gui->assetlist_menu->update_titles();
1563                         gui->assetlist_menu->activate_menu();
1564                         break;
1565                 }
1566                 result = 1;
1567         }
1568
1569
1570         return result;
1571 }
1572
1573
1574 int AWindowAssets::handle_event()
1575 {
1576 //printf("AWindowAssets::handle_event 1 %d %d\n", get_buttonpress(), get_selection(0, 0));
1577         AssetPicon *asset_picon = (AssetPicon *)get_selection(0, 0);
1578         if( !asset_picon ) return 0;
1579         switch( mwindow->edl->session->awindow_folder ) {
1580         case AW_AEFFECT_FOLDER:
1581         case AW_VEFFECT_FOLDER:
1582         case AW_ATRANSITION_FOLDER:
1583         case AW_VTRANSITION_FOLDER: return 1;
1584         }
1585         VWindow *vwindow = mwindow->vwindows.size() > DEFAULT_VWINDOW ?
1586                 mwindow->vwindows.get(DEFAULT_VWINDOW) : 0;
1587         if( !vwindow || !vwindow->is_running() ) return 1;
1588 //printf("AWindowAssets::handle_event 2 %d %d\n", get_buttonpress(), get_selection(0, 0));
1589
1590         vwindow->gui->lock_window("AWindowAssets::handle_event");
1591         if( asset_picon->indexable )
1592                 vwindow->change_source(asset_picon->indexable);
1593         else if( asset_picon->edl )
1594                 vwindow->change_source(asset_picon->edl);
1595         vwindow->gui->unlock_window();
1596         return 1;
1597 }
1598
1599 int AWindowAssets::selection_changed()
1600 {
1601 // Show popup window
1602         AssetPicon *item;
1603         if( get_button_down() && get_buttonpress() == 3 &&
1604             (item = (AssetPicon*)get_selection(0, 0)) ) {
1605                 int folder = mwindow->edl->session->awindow_folder;
1606                 switch( folder ) {
1607                 case AW_AEFFECT_FOLDER:
1608                 case AW_VEFFECT_FOLDER:
1609                 case AW_ATRANSITION_FOLDER:
1610                 case AW_VTRANSITION_FOLDER:
1611                         gui->effectlist_menu->update();
1612                         gui->effectlist_menu->activate_menu();
1613                         break;
1614                 case AW_LABEL_FOLDER:
1615                         if( !item->label ) break;
1616                         gui->label_menu->activate_menu();
1617                         break;
1618                 case AW_CLIP_FOLDER:
1619                         if( !item->indexable && !item->edl ) break;
1620                         gui->clip_menu->update();
1621                         gui->clip_menu->activate_menu();
1622                         break;
1623                 default:
1624                         if( !item->indexable && !item->edl ) break;
1625                         gui->asset_menu->update();
1626                         gui->asset_menu->activate_menu();
1627                         break;
1628                 }
1629
1630                 BC_ListBox::deactivate_selection();
1631                 return 1;
1632         }
1633         else if( get_button_down() && get_buttonpress() == 1 &&
1634                  (item = (AssetPicon*)get_selection(0, 0)) ) {
1635                 VIcon *vicon = 0;
1636                 if( !gui->vicon_thread->viewing ) {
1637                         vicon = item->vicon;
1638                 }
1639                 gui->vicon_thread->set_view_popup(vicon);
1640
1641         }
1642         return 0;
1643 }
1644
1645 void AWindowAssets::draw_background()
1646 {
1647         clear_box(0,0,get_w(),get_h(),get_bg_surface());
1648         set_color(BC_WindowBase::get_resources()->audiovideo_color);
1649         set_font(LARGEFONT);
1650         int aw_folder = mwindow->edl->session->awindow_folder;
1651         if( aw_folder < 0 ) return;
1652         const char *aw_name = _(AWindowGUI::folder_names[aw_folder]);
1653         draw_text(get_w() - get_text_width(LARGEFONT, aw_name) - 4, 30,
1654                 aw_name, -1, get_bg_surface());
1655 }
1656
1657 int AWindowAssets::drag_start_event()
1658 {
1659         int collect_pluginservers = 0;
1660         int collect_assets = 0;
1661
1662         if( BC_ListBox::drag_start_event() ) {
1663                 switch( mwindow->edl->session->awindow_folder ) {
1664                 case AW_AEFFECT_FOLDER:
1665                         mwindow->session->current_operation = DRAG_AEFFECT;
1666                         collect_pluginservers = 1;
1667                         break;
1668                 case AW_VEFFECT_FOLDER:
1669                         mwindow->session->current_operation = DRAG_VEFFECT;
1670                         collect_pluginservers = 1;
1671                         break;
1672                 case AW_ATRANSITION_FOLDER:
1673                         mwindow->session->current_operation = DRAG_ATRANSITION;
1674                         collect_pluginservers = 1;
1675                         break;
1676                 case AW_VTRANSITION_FOLDER:
1677                         mwindow->session->current_operation = DRAG_VTRANSITION;
1678                         collect_pluginservers = 1;
1679                         break;
1680                 case AW_LABEL_FOLDER:
1681                         // do nothing!
1682                         break;
1683                 default:
1684                         mwindow->session->current_operation = DRAG_ASSET;
1685                         collect_assets = 1;
1686                         break;
1687                 }
1688
1689                 if( collect_pluginservers ) {
1690                         int i = 0;
1691                         mwindow->session->drag_pluginservers->remove_all();
1692                         while(1)
1693                         {
1694                                 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
1695                                 if( !result ) break;
1696
1697                                 mwindow->session->drag_pluginservers->append(result->plugin);
1698                         }
1699                 }
1700
1701                 if( collect_assets ) {
1702                         gui->collect_assets();
1703                 }
1704
1705                 return 1;
1706         }
1707         return 0;
1708 }
1709
1710 int AWindowAssets::drag_motion_event()
1711 {
1712         BC_ListBox::drag_motion_event();
1713         unlock_window();
1714
1715         mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1716         mwindow->gui->drag_motion();
1717         mwindow->gui->unlock_window();
1718
1719         for( int i = 0; i < mwindow->vwindows.size(); i++ ) {
1720                 VWindow *vwindow = mwindow->vwindows.get(i);
1721                 if( !vwindow->is_running() ) continue;
1722                 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1723                 vwindow->gui->drag_motion();
1724                 vwindow->gui->unlock_window();
1725         }
1726
1727         mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
1728         mwindow->cwindow->gui->drag_motion();
1729         mwindow->cwindow->gui->unlock_window();
1730
1731         lock_window("AWindowAssets::drag_motion_event");
1732         return 0;
1733 }
1734
1735 int AWindowAssets::drag_stop_event()
1736 {
1737         int result = 0;
1738
1739         result = gui->drag_stop();
1740
1741         unlock_window();
1742
1743         if( !result ) {
1744                 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1745                 result = mwindow->gui->drag_stop();
1746                 mwindow->gui->unlock_window();
1747         }
1748
1749         if( !result ) {
1750                 for( int i = 0; !result && i < mwindow->vwindows.size(); i++ ) {
1751                         VWindow *vwindow = mwindow->vwindows.get(i);
1752                         if( !vwindow ) continue;
1753                         if( !vwindow->is_running() ) continue;
1754                         if( vwindow->gui->is_hidden() ) continue;
1755                         vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1756                         if( vwindow->gui->cursor_above() &&
1757                             vwindow->gui->get_cursor_over_window() ) {
1758                                 result = vwindow->gui->drag_stop();
1759                         }
1760                         vwindow->gui->unlock_window();
1761                 }
1762         }
1763
1764         if( !result ) {
1765                 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
1766                 result = mwindow->cwindow->gui->drag_stop();
1767                 mwindow->cwindow->gui->unlock_window();
1768         }
1769
1770         lock_window("AWindowAssets::drag_stop_event");
1771
1772         if( result ) get_drag_popup()->set_animation(0);
1773
1774         BC_ListBox::drag_stop_event();
1775         mwindow->session->current_operation = ::NO_OPERATION; // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
1776         return 0;
1777 }
1778
1779 int AWindowAssets::column_resize_event()
1780 {
1781         mwindow->edl->session->asset_columns[0] = get_column_width(0);
1782         mwindow->edl->session->asset_columns[1] = get_column_width(1);
1783         return 1;
1784 }
1785
1786 int AWindowAssets::focus_in_event()
1787 {
1788         gui->start_vicon_drawing();
1789         return 0;
1790 }
1791
1792 int AWindowAssets::focus_out_event()
1793 {
1794         gui->stop_vicon_drawing();
1795         return BC_ListBox::focus_out_event();
1796 }
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809 AWindowNewFolder::AWindowNewFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1810  : BC_Button(x, y, mwindow->theme->newbin_data)
1811 {
1812         this->mwindow = mwindow;
1813         this->gui = gui;
1814         set_tooltip(_("New bin"));
1815 }
1816
1817 int AWindowNewFolder::handle_event()
1818 {
1819         gui->newfolder_thread->start_new_folder();
1820         return 1;
1821 }
1822
1823 AWindowDeleteFolder::AWindowDeleteFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1824  : BC_Button(x, y, mwindow->theme->deletebin_data)
1825 {
1826         this->mwindow = mwindow;
1827         this->gui = gui;
1828         set_tooltip(_("Delete bin"));
1829 }
1830
1831 int AWindowDeleteFolder::handle_event()
1832 {
1833         if( gui->folder_list->get_selection(0, 0) ) {
1834                 BC_ListBoxItem *folder = gui->folder_list->get_selection(0, 0);
1835                 mwindow->delete_folder(folder->get_text());
1836         }
1837         return 1;
1838 }
1839
1840 AWindowRenameFolder::AWindowRenameFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1841  : BC_Button(x, y, mwindow->theme->renamebin_data)
1842 {
1843         this->mwindow = mwindow;
1844         this->gui = gui;
1845         set_tooltip(_("Rename bin"));
1846 }
1847
1848 int AWindowRenameFolder::handle_event()
1849 {
1850         return 1;
1851 }
1852
1853 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1854  : BC_Button(x, y, mwindow->theme->deletedisk_data)
1855 {
1856         this->mwindow = mwindow;
1857         this->gui = gui;
1858         set_tooltip(_("Delete asset from disk"));
1859 }
1860
1861 int AWindowDeleteDisk::handle_event()
1862 {
1863         return 1;
1864 }
1865
1866 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1867  : BC_Button(x, y, mwindow->theme->deleteproject_data)
1868 {
1869         this->mwindow = mwindow;
1870         this->gui = gui;
1871         set_tooltip(_("Delete asset from project"));
1872 }
1873
1874 int AWindowDeleteProject::handle_event()
1875 {
1876         return 1;
1877 }
1878
1879 AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1880  : BC_Button(x, y, mwindow->theme->infoasset_data)
1881 {
1882         this->mwindow = mwindow;
1883         this->gui = gui;
1884         set_tooltip(_("Edit information on asset"));
1885 }
1886
1887 int AWindowInfo::handle_event()
1888 {
1889         int cur_x, cur_y;
1890         gui->get_abs_cursor_xy(cur_x, cur_y, 0);
1891         gui->awindow->asset_edit->edit_asset(gui->selected_asset(), cur_x, cur_y);
1892         return 1;
1893 }
1894
1895 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1896  : BC_Button(x, y, mwindow->theme->redrawindex_data)
1897 {
1898         this->mwindow = mwindow;
1899         this->gui = gui;
1900         set_tooltip(_("Redraw index"));
1901 }
1902
1903 int AWindowRedrawIndex::handle_event()
1904 {
1905         return 1;
1906 }
1907
1908 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1909  : BC_Button(x, y, mwindow->theme->pasteasset_data)
1910 {
1911         this->mwindow = mwindow;
1912         this->gui = gui;
1913         set_tooltip(_("Paste asset on recordable tracks"));
1914 }
1915
1916 int AWindowPaste::handle_event()
1917 {
1918         return 1;
1919 }
1920
1921 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1922  : BC_Button(x, y, mwindow->theme->appendasset_data)
1923 {
1924         this->mwindow = mwindow;
1925         this->gui = gui;
1926         set_tooltip(_("Append asset in new tracks"));
1927 }
1928
1929 int AWindowAppend::handle_event()
1930 {
1931         return 1;
1932 }
1933
1934 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
1935  : BC_Button(x, y, mwindow->theme->viewasset_data)
1936 {
1937         this->mwindow = mwindow;
1938         this->gui = gui;
1939         set_tooltip(_("View asset"));
1940 }
1941
1942 int AWindowView::handle_event()
1943 {
1944         return 1;
1945 }
1946
1947 AddTools::AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, const char *title)
1948  : BC_PopupMenu(x, y, BC_Title::calculate_w(gui, title, MEDIUMFONT)+8, title, -1, 0, 4)
1949 {
1950         this->mwindow = mwindow;
1951         this->gui = gui;
1952 }
1953
1954 void AddTools::create_objects()
1955 {
1956         uint64_t vis = 0;
1957         add_item(new AddPluginItem(this, "ladspa", PLUGIN_LADSPA_ID));
1958         vis |= 1 << PLUGIN_LADSPA_ID;
1959         add_item(new AddPluginItem(this, "ffmpeg", PLUGIN_FFMPEG_ID));
1960         vis |= 1 << PLUGIN_FFMPEG_ID;
1961         for( int i=0; i<MWindow::plugindb->size(); ++i ) {
1962                 PluginServer *plugin = MWindow::plugindb->get(i);
1963                 if( !plugin->audio && !plugin->video ) continue;
1964                 int idx = plugin->dir_idx;
1965                 uint32_t msk = 1 << idx;
1966                 if( (msk & vis) != 0 ) continue;
1967                 vis |= msk;
1968                 char parent[BCTEXTLEN];
1969                 strcpy(parent, plugin->path);
1970                 char *bp = strrchr(parent, '/');
1971                 if( bp ) { *bp = 0;  bp = strrchr(parent, '/'); }
1972                 if( !bp ) bp = parent; else ++bp;
1973                 add_item(new AddPluginItem(this, bp, idx));
1974         }
1975 }
1976
1977 #if 0
1978 // plugin_dirs list from toplevel makefile include plugin_defs
1979 N_("ladspa")
1980 N_("ffmpeg")
1981 N_("audio_tools")
1982 N_("audio_transitions")
1983 N_("blending")
1984 N_("colors")
1985 N_("exotic")
1986 N_("transforms")
1987 N_("tv_effects")
1988 N_("video_tools")
1989 N_("video_transitions")
1990 #endif
1991
1992 AddPluginItem::AddPluginItem(AddTools *menu, char const *text, int idx)
1993  : BC_MenuItem(_(text))
1994 {
1995         this->menu = menu;
1996         this->idx = idx;
1997         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
1998         int chk = (msk & vis) ? 1 : 0;
1999         set_checked(chk);
2000 }
2001
2002 int AddPluginItem::handle_event()
2003 {
2004         int chk = get_checked() ^ 1;
2005         set_checked(chk);
2006         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2007         menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
2008         menu->gui->update_effects();
2009         menu->gui->save_defaults(menu->mwindow->defaults);
2010         menu->gui->async_update_assets();
2011         return 1;
2012 }
2013
2014 AVIconDrawing::AVIconDrawing(AWindowGUI *agui, int x, int y, VFrame **images)
2015  : BC_Toggle(x, y, images, agui->vicon_drawing)
2016 {
2017         this->agui = agui;
2018         set_tooltip(_("draw vicons"));
2019 }
2020
2021 void AVIconDrawing::calculate_geometry(AWindowGUI *agui, VFrame **images, int *ww, int *hh)
2022 {
2023         int text_line = -1, toggle_x = -1, toggle_y = -1;
2024         int text_x = -1, text_y = -1, text_w = -1, text_h = -1;
2025         BC_Toggle::calculate_extents(agui, images, 1,
2026                 &text_line, ww, hh, &toggle_x, &toggle_y,
2027                 &text_x, &text_y, &text_w, &text_h, "", MEDIUMFONT);
2028 }
2029
2030 AVIconDrawing::~AVIconDrawing()
2031 {
2032 }
2033
2034 int AVIconDrawing::handle_event()
2035 {
2036         agui->vicon_drawing = get_value();
2037         if( agui->vicon_drawing )
2038                 agui->start_vicon_drawing();
2039         else
2040                 agui->stop_vicon_drawing();
2041         return 1;
2042 }
2043
2044
2045 AWindowListFormat::AWindowListFormat(MWindow *mwindow, AWindowGUI *gui)
2046  : BC_MenuItem("")
2047 {
2048         this->mwindow = mwindow;
2049         this->gui = gui;
2050 }
2051
2052 int AWindowListFormat::handle_event()
2053 {
2054         gui->stop_vicon_drawing();
2055
2056         EDLSession *session = mwindow->edl->session;
2057         switch( session->assetlist_format ) {
2058         case ASSETS_TEXT:
2059                 session->assetlist_format = ASSETS_ICONS;
2060                 break;
2061         case ASSETS_ICONS:
2062                 session->assetlist_format = ASSETS_TEXT;
2063                 break;
2064         }
2065
2066         gui->asset_list->update_format(session->assetlist_format, 1);
2067         if( !mwindow->awindow->gui->allow_iconlisting ) {
2068                 mwindow->edl->session->assetlist_format = ASSETS_TEXT;
2069         }
2070
2071         gui->start_vicon_drawing();
2072         return 1;
2073 }
2074
2075 void AWindowListFormat::update()
2076 {
2077         set_text(mwindow->edl->session->assetlist_format == ASSETS_TEXT ?
2078                 (char*)_("Display icons") : (char*)_("Display text"));
2079 }
2080
2081 AWindowListSort::AWindowListSort(MWindow *mwindow, AWindowGUI *gui)
2082  : BC_MenuItem(_("Sort items"))
2083 {
2084         this->mwindow = mwindow;
2085         this->gui = gui;
2086 }
2087
2088 int AWindowListSort::handle_event()
2089 {
2090         gui->sort_assets();
2091         return 1;
2092 }
2093
2094