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