add audio to proxy, and minor bug 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 "arender.h"
23 #include "asset.h"
24 #include "assetedit.h"
25 #include "assetpopup.h"
26 #include "assets.h"
27 #include "audiodevice.h"
28 #include "awindowgui.h"
29 #include "awindow.h"
30 #include "bccmodels.h"
31 #include "bcsignals.h"
32 #include "bchash.h"
33 #include "cache.h"
34 #include "cstrdup.h"
35 #include "clip.h"
36 #include "clipedls.h"
37 #include "clippopup.h"
38 #include "cursors.h"
39 #include "cwindowgui.h"
40 #include "cwindow.h"
41 #include "edl.h"
42 #include "edlsession.h"
43 #include "effectlist.h"
44 #include "file.h"
45 #include "filesystem.h"
46 #include "folderlistmenu.h"
47 #include "indexable.h"
48 #include "keys.h"
49 #include "language.h"
50 #include "labels.h"
51 #include "labelpopup.h"
52 #include "localsession.h"
53 #include "mainmenu.h"
54 #include "mainsession.h"
55 #include "mwindowgui.h"
56 #include "mwindow.h"
57 #include "newfolder.h"
58 #include "preferences.h"
59 #include "proxy.h"
60 #include "renderengine.h"
61 #include "samples.h"
62 #include "theme.h"
63 #include "tracks.h"
64 #include "transportque.h"
65 #include "vframe.h"
66 #include "vicon.h"
67 #include "vrender.h"
68 #include "vwindowgui.h"
69 #include "vwindow.h"
70
71 #include "data/lad_picon_png.h"
72 #include "data/ff_audio_png.h"
73 #include "data/ff_video_png.h"
74
75 #include<stdio.h>
76 #include<unistd.h>
77 #include<fcntl.h>
78
79
80 const char *AWindowGUI::folder_names[] =
81 {
82         N_("Audio Effects"),
83         N_("Video Effects"),
84         N_("Audio Transitions"),
85         N_("Video Transitions"),
86         N_("Labels"),
87         N_("Clips"),
88         N_("Media"),
89         N_("Proxy"),
90 };
91
92
93 AssetVIcon::AssetVIcon(AssetPicon *picon, int w, int h, double framerate, int64_t length)
94  : VIcon(w, h, framerate)
95 {
96         this->picon = picon;
97         this->length = length;
98         temp = 0;
99 }
100
101 AssetVIcon::~AssetVIcon()
102 {
103         delete temp;
104 }
105
106 VFrame *AssetVIcon::frame()
107 {
108         Asset *asset = (Asset *)picon->indexable;
109         if( !asset->video_data && audio_data && audio_size && length > 0 ) {
110                 if( !temp ) temp = new VFrame(0, -1, vw, vh, BC_RGB888, -1);
111                 temp->clear_frame();
112                 int sample_rate = asset->get_sample_rate();
113                 int64_t audio_samples = asset->get_audio_samples();
114                 double duration = (double)audio_samples / sample_rate;
115                 picon->draw_hue_bar(temp, duration);
116                 int secs = length / frame_rate + 0.5;
117                 if( !secs ) secs = 1;
118                 int bfrsz = VICON_SAMPLE_RATE;
119                 int samples = audio_size/sizeof(vicon_audio_t);
120                 double line_pos = (double)seq_no/(length-1);
121                 int audio_pos = samples * line_pos * (secs-1)/secs;
122                 vicon_audio_t *audio_data = ((vicon_audio_t *)this->audio_data) + audio_pos;
123                 static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
124                 double data[bfrsz], sample_scale = 1./mx;
125                 int len = samples - audio_pos;
126                 if( len > bfrsz ) len = bfrsz;
127                 int i = 0;
128                 while( i < len ) data[i++] = *audio_data++ * sample_scale;
129                 while( i < bfrsz ) data[i++] = 0;
130                 picon->draw_wave(temp, data, bfrsz, RED, GREEN);
131                 int x = (vw-1) * line_pos;
132                 temp->pixel_rgb = RED;
133                 temp->draw_line(x,0, x,vh);
134                 return temp;
135         }
136         if( seq_no >= images.size() ) {
137                 MWindow *mwindow = picon->mwindow;
138                 File *file = mwindow->video_cache->check_out(asset, mwindow->edl, 1);
139                 if( !file ) return 0;
140                 if( temp && (temp->get_w() != asset->width || temp->get_h() != asset->height) ) {
141                         delete temp;  temp = 0;
142                 }
143                 if( !temp )
144                         temp = new VFrame(0, -1, asset->width, asset->height, BC_RGB888, -1);
145                 int ww = picon->gui->vicon_thread->view_w;
146                 int hh = picon->gui->vicon_thread->view_h;
147                 while( seq_no >= images.size() ) {
148                         file->set_layer(0);
149                         int64_t pos = images.size() / picon->gui->vicon_thread->refresh_rate * frame_rate;
150                         file->set_video_position(pos,0);
151                         if( file->read_frame(temp) ) temp->clear_frame();
152                         add_image(temp, ww, hh, BC_RGB8);
153                 }
154                 mwindow->video_cache->check_in(asset);
155         }
156         return *images[seq_no];
157 }
158
159 int64_t AssetVIcon::set_seq_no(int64_t no)
160 {
161         if( no >= length ) no = 0;
162         return seq_no = no;
163 }
164
165 int AssetVIcon::get_vx()
166 {
167         BC_ListBox *lbox = picon->gui->asset_list;
168         return lbox->get_item_x(picon);
169 }
170 int AssetVIcon::get_vy()
171 {
172         BC_ListBox *lbox = picon->gui->asset_list;
173         return lbox->get_item_y(picon) + lbox->get_title_h();
174 }
175
176 void AssetVIcon::load_audio()
177 {
178         MWindow *mwindow = picon->mwindow;
179         Asset *asset = (Asset *)picon->indexable;
180         File *file = mwindow->audio_cache->check_out(asset, mwindow->edl, 1);
181         int channels = asset->get_audio_channels();
182         if( channels > 2 ) channels = 2;
183         int sample_rate = asset->get_sample_rate();
184         int bfrsz = sample_rate;
185         Samples samples(bfrsz);
186         double time_scale = (double)sample_rate / VICON_SAMPLE_RATE;
187         vicon_audio_t *audio_data = (vicon_audio_t *)this->audio_data;
188         static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
189         double sample_scale = (double)mx / channels;
190         int audio_pos = 0, audio_len = audio_size/sizeof(vicon_audio_t);
191         while( audio_pos < audio_len ) {
192                 int64_t pos = audio_pos * time_scale;
193                 for( int ch=0; ch<channels; ++ch ) {
194                         file->set_channel(ch);
195                         file->set_audio_position(pos);
196                         file->read_samples(&samples, bfrsz);
197                         double *data = samples.get_data();
198                         for( int64_t k=audio_pos; k<audio_len; ++k ) {
199                                 int i = k * time_scale - pos;
200                                 if( i >= bfrsz ) break;
201                                 int v = audio_data[k] + data[i] * sample_scale;
202                                 audio_data[k] = CLIP(v, -mx,mx);
203                         }
204                 }
205                 audio_pos = (pos + bfrsz) / time_scale;
206         }
207         mwindow->audio_cache->check_in(asset);
208 }
209
210
211 AssetVIconAudio::AssetVIconAudio(AWindowGUI *gui)
212  : Thread(1, 0, 0)
213 {
214         this->gui = gui;
215         audio = new AudioDevice(gui->mwindow);
216         interrupted = 0;
217         vicon = 0;
218 }
219 AssetVIconAudio::~AssetVIconAudio()
220 {
221         delete audio;
222 }
223
224 void AssetVIconAudio::run()
225 {
226         int channels = 2;
227         int64_t bfrsz = VICON_SAMPLE_RATE;
228         MWindow *mwindow = gui->mwindow;
229         EDL *edl = mwindow->edl;
230         EDLSession *session = edl->session;
231         AudioOutConfig *aconfig = session->playback_config->aconfig;
232         audio->open_output(aconfig, VICON_SAMPLE_RATE, bfrsz, channels, 0);
233         audio->start_playback();
234         double out0[bfrsz], out1[bfrsz], *out[2] = { out0, out1 };
235         vicon_audio_t *audio_data = (vicon_audio_t *)vicon->audio_data;
236         static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
237
238         int audio_len = vicon->audio_size/sizeof(vicon_audio_t);
239         while( !interrupted ) {
240                 int len = audio_len - audio_pos;
241                 if( len <= 0 ) break;
242                 if( len > bfrsz ) len = bfrsz;
243                 int k = audio_pos;
244                 for( int i=0; i<len; ++i,++k )
245                         out0[i] = out1[i] = (double)audio_data[k] / mx;
246                 audio_pos = k;
247                 audio->write_buffer(out, channels, len);
248         }
249
250         if( !interrupted )
251                 audio->set_last_buffer();
252         audio->stop_audio(interrupted ? 0 : 1);
253         audio->close_all();
254 }
255
256 void AssetVIconAudio::start(AssetVIcon *vicon)
257 {
258         if( running() ) return;
259         interrupted = 0;
260         audio_pos = 0;
261         this->vicon = vicon;
262         Thread::start();
263 }
264
265 void AssetVIconAudio::stop(int wait)
266 {
267         if( running() && !interrupted ) {
268                 interrupted = 1;
269                 audio->stop_audio(wait);
270         }
271         Thread::join();
272         if( vicon ) {
273                 vicon->playing_audio = 0;
274                 vicon = 0;
275         }
276 }
277
278 void AssetVIcon::start_audio()
279 {
280         picon->gui->vicon_audio->stop(0);
281         playing_audio = 1;
282         picon->gui->vicon_audio->start(this);
283 }
284
285 void AssetVIcon::stop_audio()
286 {
287         picon->gui->vicon_audio->stop(0);
288         playing_audio = 0;
289 }
290
291 AssetPicon::AssetPicon(MWindow *mwindow,
292         AWindowGUI *gui, Indexable *indexable)
293  : BC_ListBoxItem()
294 {
295         reset();
296         this->mwindow = mwindow;
297         this->gui = gui;
298         this->indexable = indexable;
299         indexable->add_user();
300         this->id = indexable->id;
301 }
302
303 AssetPicon::AssetPicon(MWindow *mwindow,
304         AWindowGUI *gui, EDL *edl)
305  : BC_ListBoxItem()
306 {
307         reset();
308         this->mwindow = mwindow;
309         this->gui = gui;
310         this->edl = edl;
311         edl->add_user();
312         this->id = edl->id;
313 }
314
315 AssetPicon::AssetPicon(MWindow *mwindow,
316         AWindowGUI *gui, int folder, int persist)
317  : BC_ListBoxItem(_(AWindowGUI::folder_names[folder]),
318         folder>=0 && folder<AWINDOW_FOLDERS ?
319                 gui->folder_icons[folder]: gui->folder_icon)
320 {
321         reset();
322         foldernum = folder;
323         this->mwindow = mwindow;
324         this->gui = gui;
325         persistent = persist;
326 }
327
328 AssetPicon::AssetPicon(MWindow *mwindow,
329         AWindowGUI *gui, PluginServer *plugin)
330  : BC_ListBoxItem()
331 {
332         reset();
333         this->mwindow = mwindow;
334         this->gui = gui;
335         this->plugin = plugin;
336 }
337
338 AssetPicon::AssetPicon(MWindow *mwindow,
339         AWindowGUI *gui, Label *label)
340  : BC_ListBoxItem()
341 {
342         reset();
343         this->mwindow = mwindow;
344         this->gui = gui;
345         this->label = label;
346         indexable = 0;
347         icon = 0;
348         id = 0;
349 }
350
351 AssetPicon::~AssetPicon()
352 {
353         if( vicon )
354                 gui->vicon_thread->del_vicon(vicon);
355         if( indexable ) indexable->remove_user();
356         if( edl ) edl->remove_user();
357         if( icon && !gui->protected_pixmap(icon) ) {
358                 delete icon;
359                 if( !plugin ) delete icon_vframe;
360         }
361 }
362
363 void AssetPicon::draw_hue_bar(VFrame *frame, double duration)
364 {
365         float t = duration > 1 ? (log(duration) / log(3600.f)) : 0;
366         if( t > 1 ) t = 1;
367         float h = 300 * t, s = 1., v = 1.;
368         float r, g, b; // duration, 0..1hr == hue red..magenta
369         HSV::hsv_to_rgb(r,g,b, h,s,v);
370         int ih = frame->get_h()/8, iw = frame->get_w();
371         int ir = r * 256;  CLAMP(ir, 0,255);
372         int ig = g * 256;  CLAMP(ig, 0,255);
373         int ib = b * 256;  CLAMP(ib, 0,255);
374         unsigned char **rows = frame->get_rows();
375         for( int y=0; y<ih; ++y ) {
376                 unsigned char *rp = rows[y];
377                 for( int x=0; x<iw; rp+=3,++x ) {
378                         rp[0] = ir;  rp[1] = ig;  rp[2] = ib;
379                 }
380         }
381 }
382
383 void AssetPicon::draw_wave(VFrame *frame, double *dp, int len, int base_color, int line_color)
384 {
385         int w = frame->get_w(), h = frame->get_h();
386         int h1 = h-1, h2 = h/2, y = h2;
387         int rgb_color = frame->pixel_rgb;
388         for( int x=0,x1=0,x2=0; x<w; ++x,x1=x2 ) {
389                 double min = *dp, max = min;
390                 x2 = (len * (x+1))/w;
391                 for( int i=x1; i<x2; ++i ) {
392                         double value = *dp++;
393                         if( value < min ) min = value;
394                         if( value > max ) max = value;
395                 }
396                 int ctr = (min + max) / 2;
397                 int y0 = (int)(h2 - ctr*h2);  CLAMP(y0, 0,h1);
398                 int y1 = (int)(h2 - min*h2);  CLAMP(y1, 0,h1);
399                 int y2 = (int)(h2 - max*h2);  CLAMP(y2, 0,h1);
400                 frame->pixel_rgb = line_color;
401                 frame->draw_line(x,y1, x,y2);
402                 frame->pixel_rgb = base_color;
403                 frame->draw_line(x,y, x,y0);
404                 y = y0;
405         }
406         frame->pixel_rgb = rgb_color;
407 }
408
409 void AssetPicon::reset()
410 {
411         plugin = 0;
412         label = 0;
413         indexable = 0;
414         edl = 0;
415         foldernum = AW_NO_FOLDER;
416         icon = 0;
417         icon_vframe = 0;
418         vicon = 0;
419         in_use = 1;
420         mtime = 0;
421         id = 0;
422         persistent = 0;
423 }
424
425 void AssetPicon::open_render_engine(EDL *edl, int is_audio)
426 {
427         TransportCommand command;
428         command.command = is_audio ? NORMAL_FWD : CURRENT_FRAME;
429         command.get_edl()->copy_all(edl);
430         command.change_type = CHANGE_ALL;
431         command.realtime = 0;
432         render_engine = new RenderEngine(0, mwindow->preferences, 0, 0);
433         render_engine->set_vcache(mwindow->video_cache);
434         render_engine->set_acache(mwindow->audio_cache);
435         render_engine->arm_command(&command);
436 }
437 void AssetPicon::close_render_engine()
438 {
439         delete render_engine;  render_engine = 0;
440 }
441 void AssetPicon::render_video(int64_t pos, VFrame *vfrm)
442 {
443         if( !render_engine || !render_engine->vrender ) return;
444         render_engine->vrender->process_buffer(vfrm, pos, 0);
445 }
446 void AssetPicon::render_audio(int64_t pos, Samples **samples, int len)
447 {
448         if( !render_engine || !render_engine->arender ) return;
449         render_engine->arender->process_buffer(samples, len, pos);
450 }
451
452 void AssetPicon::create_objects()
453 {
454         FileSystem fs;
455         char name[BCTEXTLEN];
456         int pixmap_w, pixmap_h;
457
458         pixmap_h = 50 * BC_WindowBase::get_resources()->icon_scale;
459
460         if( indexable ) {
461                 fs.extract_name(name, indexable->path);
462                 set_text(name);
463         }
464         else if( edl ) {
465                 set_text(strcpy(name, edl->local_session->clip_title));
466                 set_text(name);
467         }
468
469         if( indexable && indexable->is_asset ) {
470                 Asset *asset = (Asset*)indexable;
471                 if( asset->video_data ) {
472                         if( mwindow->preferences->use_thumbnails ) {
473                                 gui->unlock_window();
474                                 File *file = mwindow->video_cache->check_out(asset,
475                                         mwindow->edl,
476                                         1);
477
478                                 if( file ) {
479                                         int height = asset->height > 0 ? asset->height : 1;
480                                         pixmap_w = pixmap_h * asset->width / height;
481
482                                         file->set_layer(0);
483                                         file->set_video_position(0, 0);
484
485                                         if( gui->temp_picon &&
486                                                 (gui->temp_picon->get_w() != asset->width ||
487                                                 gui->temp_picon->get_h() != asset->height) ) {
488                                                 delete gui->temp_picon;
489                                                 gui->temp_picon = 0;
490                                         }
491
492                                         if( !gui->temp_picon ) {
493                                                 gui->temp_picon = new VFrame(0, -1,
494                                                         asset->width, asset->height,
495                                                         BC_RGB888, -1);
496                                         }
497                                         { char string[BCTEXTLEN];
498                                         sprintf(string, _("Reading %s"), name);
499                                         mwindow->gui->lock_window("AssetPicon::create_objects");
500                                         mwindow->gui->show_message(string);
501                                         mwindow->gui->unlock_window(); }
502                                         file->read_frame(gui->temp_picon);
503                                         mwindow->video_cache->check_in(asset);
504
505                                         gui->lock_window("AssetPicon::create_objects 0");
506                                         icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
507                                         icon->draw_vframe(gui->temp_picon,
508                                                 0, 0, pixmap_w, pixmap_h, 0, 0);
509                                         icon_vframe = new VFrame(0,
510                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
511                                         icon_vframe->transfer_from(gui->temp_picon);
512                                         if( asset->awindow_folder == AW_MEDIA_FOLDER ) {
513 // vicon images
514                                                 double framerate = asset->get_frame_rate();
515                                                 if( !framerate ) framerate = VICON_RATE;
516                                                 int64_t frames = asset->get_video_frames();
517                                                 double secs = frames / framerate;
518                                                 if( secs > 5 ) secs = 5;
519                                                 int64_t length = secs * gui->vicon_thread->refresh_rate;
520                                                 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, framerate, length);
521                                                 if( asset->audio_data && secs > 0 ) {
522                                                         gui->unlock_window();
523                                                         int audio_len = VICON_SAMPLE_RATE*secs+0.5;
524                                                         vicon->init_audio(audio_len*sizeof(vicon_audio_t));
525                                                         vicon->load_audio();
526                                                         gui->lock_window("AssetPicon::create_objects 1");
527                                                 }
528                                                 gui->vicon_thread->add_vicon(vicon);
529                                         }
530
531                                 }
532                                 else {
533                                         gui->lock_window("AssetPicon::create_objects 2");
534                                         icon = gui->video_icon;
535                                         icon_vframe = gui->video_vframe;
536                                 }
537                         }
538                         else {
539                                 icon = gui->video_icon;
540                                 icon_vframe = gui->video_vframe;
541                         }
542                 }
543                 else
544                 if( asset->audio_data ) {
545                         if( mwindow->preferences->use_thumbnails ) {
546                                 gui->unlock_window();
547                                 File *file = mwindow->audio_cache->check_out(asset,
548                                         mwindow->edl,
549                                         1);
550                                 if( file ) {
551                                         pixmap_w = pixmap_h * 16/9;
552                                         icon_vframe = new VFrame(0,
553                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
554                                         { char string[BCTEXTLEN];
555                                         sprintf(string, _("Reading %s"), name);
556                                         mwindow->gui->lock_window("AssetPicon::create_objects 3");
557                                         mwindow->gui->show_message(string);
558                                         mwindow->gui->unlock_window(); }
559                                         int sample_rate = asset->get_sample_rate();
560                                         int channels = asset->get_audio_channels();
561                                         if( channels > 2 ) channels = 2;
562                                         int64_t audio_samples = asset->get_audio_samples();
563                                         double duration = (double)audio_samples / sample_rate;
564                                         draw_hue_bar(icon_vframe, duration);
565                                         int bfrsz = sample_rate;
566                                         Samples samples(bfrsz);
567                                         static int line_colors[2] = { GREEN, YELLOW };
568                                         static int base_colors[2] = { RED, PINK };
569                                         for( int i=channels; --i>=0; ) {
570                                                 file->set_channel(i);
571                                                 file->set_audio_position(0);
572                                                 file->read_samples(&samples, bfrsz);
573                                                 draw_wave(icon_vframe, samples.get_data(), bfrsz,
574                                                         base_colors[i], line_colors[i]);
575                                         }
576                                         mwindow->audio_cache->check_in(asset);
577                                         if( asset->awindow_folder == AW_MEDIA_FOLDER ) {
578                                                 double secs = duration;
579                                                 if( secs > 5 ) secs = 5;
580                                                 double refresh_rate = gui->vicon_thread->refresh_rate;
581                                                 int64_t length = secs * refresh_rate;
582                                                 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, refresh_rate, length);
583                                                 int audio_len = VICON_SAMPLE_RATE*secs+0.5;
584                                                 vicon->init_audio(audio_len*sizeof(vicon_audio_t));
585                                                 vicon->load_audio();
586                                                 gui->vicon_thread->add_vicon(vicon);
587                                         }
588                                         gui->lock_window("AssetPicon::create_objects 4");
589                                         icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
590                                         icon->draw_vframe(icon_vframe,
591                                                 0, 0, pixmap_w, pixmap_h, 0, 0);
592                                 }
593                                 else {
594                                         gui->lock_window("AssetPicon::create_objects 5");
595                                         icon = gui->audio_icon;
596                                         icon_vframe = gui->audio_vframe;
597                                 }
598                         }
599                         else {
600                                 icon = gui->audio_icon;
601                                 icon_vframe = gui->audio_vframe;
602                         }
603
604                 }
605                 struct stat st;
606                 mtime = !stat(asset->path, &st) ? st.st_mtime : 0;
607         }
608         else
609         if( indexable && !indexable->is_asset ) {
610                 icon = gui->video_icon;
611                 icon_vframe = gui->video_vframe;
612         }
613         else
614         if( edl ) {
615                 if( edl->tracks->playable_video_tracks() ) {
616                         if( mwindow->preferences->use_thumbnails ) {
617                                 gui->unlock_window();
618                                 char clip_icon_path[BCTEXTLEN];
619                                 char *clip_icon = edl->local_session->clip_icon;
620                                 if( clip_icon[0] ) {
621                                         snprintf(clip_icon_path, sizeof(clip_icon_path),
622                                                 "%s/%s", File::get_config_path(), clip_icon);
623                                         icon_vframe = VFramePng::vframe_png(clip_icon_path);
624                                 }
625                                 if( !icon_vframe ) {
626 //printf("render clip: %s\n", name);
627                                         int edl_h = edl->get_h(), edl_w = edl->get_w();
628                                         int height = edl_h > 0 ? edl_h : 1;
629                                         int width = edl_w > 0 ? edl_w : 1;
630                                         int color_model = edl->session->color_model;
631                                         pixmap_w = pixmap_h * width / height;
632
633                                         if( gui->temp_picon &&
634                                             (gui->temp_picon->get_color_model() != color_model ||
635                                              gui->temp_picon->get_w() != width ||
636                                              gui->temp_picon->get_h() != height) ) {
637                                                 delete gui->temp_picon;  gui->temp_picon = 0;
638                                         }
639
640                                         if( !gui->temp_picon ) {
641                                                 gui->temp_picon = new VFrame(0, -1,
642                                                         width, height, color_model, -1);
643                                         }
644                                         char string[BCTEXTLEN];
645                                         sprintf(string, _("Rendering %s"), name);
646                                         mwindow->gui->lock_window("AssetPicon::create_objects");
647                                         mwindow->gui->show_message(string);
648                                         mwindow->gui->unlock_window();
649                                         open_render_engine(edl, 0);
650                                         render_video(0, gui->temp_picon);
651                                         close_render_engine();
652                                         gui->lock_window("AssetPicon::create_objects 0");
653                                         icon_vframe = new VFrame(0,
654                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
655                                         icon_vframe->transfer_from(gui->temp_picon);
656                                         if( clip_icon[0] ) icon_vframe->write_png(clip_icon_path);
657                                 }
658                                 else {
659                                         pixmap_w = icon_vframe->get_w();
660                                         pixmap_h = icon_vframe->get_h();
661                                 }
662                                 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
663                                 icon->draw_vframe(icon_vframe,
664                                         0, 0, pixmap_w, pixmap_h, 0, 0);
665                         }
666                         else {
667                                 icon = gui->clip_icon;
668                                 icon_vframe = gui->clip_vframe;
669                         }
670                 }
671                 else
672                 if( edl->tracks->playable_audio_tracks() ) {
673                         if( mwindow->preferences->use_thumbnails ) {
674                                 gui->unlock_window();
675                                 char clip_icon_path[BCTEXTLEN];
676                                 char *clip_icon = edl->local_session->clip_icon;
677                                 if( clip_icon[0] ) {
678                                         snprintf(clip_icon_path, sizeof(clip_icon_path),
679                                                 "%s/%s", File::get_config_path(), clip_icon);
680                                         icon_vframe = VFramePng::vframe_png(clip_icon_path);
681                                 }
682                                 if( !icon_vframe ) {
683                                         pixmap_w = pixmap_h * 16/9;
684                                         icon_vframe = new VFrame(0,
685                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
686                                         char string[BCTEXTLEN];
687                                         sprintf(string, _("Rendering %s"), name);
688                                         mwindow->gui->lock_window("AssetPicon::create_objects 3");
689                                         mwindow->gui->show_message(string);
690                                         mwindow->gui->unlock_window();
691                                         int sample_rate = edl->get_sample_rate();
692                                         int channels = edl->get_audio_channels();
693                                         if( channels > 2 ) channels = 2;
694                                         int64_t audio_samples = edl->get_audio_samples();
695                                         double duration = (double)audio_samples / sample_rate;
696                                         draw_hue_bar(icon_vframe, duration);
697                                         Samples *samples[MAX_CHANNELS];
698                                         int bfrsz = sample_rate;
699                                         for( int i=0; i<MAX_CHANNELS; ++i )
700                                                 samples[i] = i<channels ? new Samples(bfrsz) : 0;
701                                         open_render_engine(edl, 1);
702                                         render_audio(0, samples, bfrsz);
703                                         close_render_engine();
704                                         gui->lock_window("AssetPicon::create_objects 4");
705                                         static int line_colors[2] = { GREEN, YELLOW };
706                                         static int base_colors[2] = { RED, PINK };
707                                         for( int i=channels; --i>=0; ) {
708                                                 draw_wave(icon_vframe, samples[i]->get_data(), bfrsz,
709                                                         base_colors[i], line_colors[i]);
710                                         }
711                                         for( int i=0; i<channels; ++i ) delete samples[i];
712                                         if( clip_icon[0] ) icon_vframe->write_png(clip_icon_path);
713                                 }
714                                 else {
715                                         pixmap_w = icon_vframe->get_w();
716                                         pixmap_h = icon_vframe->get_h();
717                                 }
718                                 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
719                                 icon->draw_vframe(icon_vframe,
720                                         0, 0, pixmap_w, pixmap_h, 0, 0);
721                         }
722                         else {
723                                 icon = gui->clip_icon;
724                                 icon_vframe = gui->clip_vframe;
725                         }
726                 }
727         }
728         else
729         if( plugin ) {
730                 strcpy(name, _(plugin->title));
731                 set_text(name);
732                 icon_vframe = plugin->get_picon();
733                 if( icon_vframe )
734                         icon = gui->create_pixmap(icon_vframe);
735                 else if( plugin->audio ) {
736                         if( plugin->transition ) {
737                                 icon = gui->atransition_icon;
738                                 icon_vframe = gui->atransition_vframe;
739                         }
740                         else if( plugin->is_ffmpeg() ) {
741                                 icon = gui->ff_aud_icon;
742                                 icon_vframe = gui->ff_aud_vframe;
743                         }
744                         else if( plugin->is_ladspa() ) {
745                                 icon = gui->ladspa_icon;
746                                 icon_vframe = gui->ladspa_vframe;
747                         }
748                         else {
749                                 icon = gui->aeffect_icon;
750                                 icon_vframe = gui->aeffect_vframe;
751                         }
752                 }
753                 else if( plugin->video ) {
754                         if( plugin->transition ) {
755                                 icon = gui->vtransition_icon;
756                                 icon_vframe = gui->vtransition_vframe;
757                         }
758                         else if( plugin->is_ffmpeg() ) {
759                                 icon = gui->ff_vid_icon;
760                                 icon_vframe = gui->ff_vid_vframe;
761                         }
762                         else {
763                                 icon = gui->veffect_icon;
764                                 icon_vframe = gui->veffect_vframe;
765                         }
766                 }
767         }
768         else
769         if( label ) {
770                 Units::totext(name,
771                               label->position,
772                               mwindow->edl->session->time_format,
773                               mwindow->edl->session->sample_rate,
774                               mwindow->edl->session->frame_rate,
775                               mwindow->edl->session->frames_per_foot);
776                 set_text(name);
777                 icon = gui->label_icon;
778                 icon_vframe = gui->label_vframe;
779         }
780         if( !icon ) {
781                 icon = gui->file_icon;
782                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN];
783         }
784         set_icon(icon);
785         set_icon_vframe(icon_vframe);
786 }
787
788 AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
789  : BC_Window(_(PROGRAM_NAME ": Resources"),
790         mwindow->session->awindow_x, mwindow->session->awindow_y,
791         mwindow->session->awindow_w, mwindow->session->awindow_h,
792         100, 100, 1, 1, 1)
793 {
794         this->mwindow = mwindow;
795         this->awindow = awindow;
796
797         file_vframe = 0;                file_icon = 0;
798         folder_vframe = 0;              folder_icon = 0;
799         audio_vframe = 0;               audio_icon = 0;
800         video_vframe = 0;               video_icon = 0;
801         label_vframe = 0;               label_icon = 0;
802
803         atransition_vframe = 0;         atransition_icon = 0;
804         vtransition_vframe = 0;         vtransition_icon = 0;
805         aeffect_vframe = 0;             aeffect_icon = 0;
806         ladspa_vframe = 0;              ladspa_icon = 0;
807         veffect_vframe = 0;             veffect_icon = 0;
808         ff_aud_vframe = 0;              ff_aud_icon = 0;
809         ff_vid_vframe = 0;              ff_vid_icon = 0;
810
811         aeffect_folder_vframe = 0;      aeffect_folder_icon = 0;
812         atransition_folder_vframe = 0;  atransition_folder_icon = 0;
813         clip_folder_vframe = 0;         clip_folder_icon = 0;
814         label_folder_vframe = 0;        label_folder_icon = 0;
815         media_folder_vframe = 0;        media_folder_icon = 0;
816         proxy_folder_vframe = 0;        proxy_folder_icon = 0;
817         veffect_folder_vframe = 0;      veffect_folder_icon = 0;
818         vtransition_folder_vframe = 0;  vtransition_folder_icon = 0;
819
820         ladspa_vframe = 0;              ladspa_icon = 0;
821         ff_aud_vframe = 0;              ff_aud_icon = 0;
822         ff_vid_vframe = 0;              ff_vid_icon = 0;
823
824         clip_vframe = 0;                clip_icon = 0;
825         atransition_vframe = 0;         atransition_icon = 0;
826         vtransition_vframe = 0;         vtransition_icon = 0;
827         aeffect_vframe = 0;             aeffect_icon = 0;
828         veffect_vframe = 0;             veffect_icon = 0;
829
830         plugin_visibility = ((uint64_t)1<<(8*sizeof(uint64_t)-1))-1;
831         newfolder_thread = 0;
832         asset_menu = 0;
833         effectlist_menu = 0;
834         assetlist_menu = 0;
835         cliplist_menu = 0;
836         labellist_menu = 0;
837         folderlist_menu = 0;
838         temp_picon = 0;
839         search_text = 0;
840         allow_iconlisting = 1;
841         remove_plugin = 0;
842         vicon_thread = 0;
843         vicon_audio = 0;
844         vicon_drawing = 1;
845         displayed_folder = AW_NO_FOLDER;
846 }
847
848 AWindowGUI::~AWindowGUI()
849 {
850         assets.remove_all_objects();
851         folders.remove_all_objects();
852         aeffects.remove_all_objects();
853         veffects.remove_all_objects();
854         atransitions.remove_all_objects();
855         vtransitions.remove_all_objects();
856         labellist.remove_all_objects();
857         displayed_assets[1].remove_all_objects();
858
859         delete vicon_thread;
860         delete vicon_audio;
861         delete newfolder_thread;
862
863         delete asset_menu;
864         delete clip_menu;
865         delete label_menu;
866         delete effectlist_menu;
867         delete assetlist_menu;
868         delete cliplist_menu;
869         delete labellist_menu;
870         delete folderlist_menu;
871         delete search_text;
872         delete temp_picon;
873         delete remove_plugin;
874
875         delete file_vframe;             delete file_icon;
876         delete folder_vframe;           delete folder_icon;
877         delete audio_vframe;            delete audio_icon;
878         delete video_vframe;            delete video_icon;
879         delete label_vframe;            delete label_icon;
880         delete clip_vframe;             delete clip_icon;
881         delete aeffect_folder_vframe;   delete aeffect_folder_icon;
882         delete atransition_folder_vframe; delete atransition_folder_icon;
883         delete veffect_folder_vframe;   delete veffect_folder_icon;
884         delete vtransition_folder_vframe; delete vtransition_folder_icon;
885         delete clip_folder_vframe;      delete clip_folder_icon;
886         delete label_folder_vframe;     delete label_folder_icon;
887         delete media_folder_vframe;     delete media_folder_icon;
888         delete proxy_folder_vframe;     delete proxy_folder_icon;
889         delete ladspa_vframe;           delete ladspa_icon;
890         delete ff_aud_vframe;           delete ff_aud_icon;
891         delete ff_vid_vframe;           delete ff_vid_icon;
892         delete atransition_vframe;      delete atransition_icon;
893         delete vtransition_vframe;      delete vtransition_icon;
894         delete aeffect_vframe;          delete aeffect_icon;
895         delete veffect_vframe;          delete veffect_icon;
896 }
897
898 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
899 {
900         return  icon == file_icon ||
901                 icon == folder_icon ||
902                 icon == audio_icon ||
903                 icon == video_icon ||
904                 icon == clip_icon ||
905                 icon == label_icon ||
906                 icon == vtransition_icon ||
907                 icon == atransition_icon ||
908                 icon == veffect_icon ||
909                 icon == aeffect_icon ||
910                 icon == ladspa_icon ||
911                 icon == ff_aud_icon ||
912                 icon == ff_vid_icon ||
913                 icon == aeffect_folder_icon ||
914                 icon == veffect_folder_icon ||
915                 icon == atransition_folder_icon ||
916                 icon == vtransition_folder_icon ||
917                 icon == label_folder_icon ||
918                 icon == clip_folder_icon ||
919                 icon == media_folder_icon ||
920                 icon == proxy_folder_icon;
921 }
922
923 VFrame *AWindowGUI::get_picon(const char *name, const char *plugin_icons)
924 {
925         char png_path[BCTEXTLEN];
926         char *pp = png_path, *ep = pp + sizeof(png_path)-1;
927         snprintf(pp, ep-pp, "%s/picon/%s/%s.png",
928                 File::get_plugin_path(), plugin_icons, name);
929         if( access(png_path, R_OK) ) return 0;
930         return VFramePng::vframe_png(png_path,0,0);
931 }
932
933 VFrame *AWindowGUI::get_picon(const char *name)
934 {
935         VFrame *vframe = get_picon(name, mwindow->preferences->plugin_icons);
936         if( !vframe ) {
937                 char png_name[BCSTRLEN], *pp = png_name, *ep = pp + sizeof(png_name)-1;
938                 snprintf(pp, ep-pp, "%s.png", name);
939                 unsigned char *data = mwindow->theme->get_image_data(png_name);
940                 if( data ) vframe = new VFramePng(data, 0.);
941         }
942         return vframe;
943 }
944
945 void AWindowGUI::resource_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, int idx)
946 {
947         vfrm = get_picon(fn);
948         if( !vfrm ) vfrm = BC_WindowBase::get_resources()->type_to_icon[idx];
949         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
950 }
951 void AWindowGUI::theme_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn)
952 {
953         vfrm = get_picon(fn);
954         if( !vfrm ) vfrm = mwindow->theme->get_image(fn);
955         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
956 }
957 void AWindowGUI::plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, unsigned char *png)
958 {
959         vfrm = get_picon(fn);
960         if( !vfrm ) vfrm = new VFramePng(png);
961         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
962 }
963
964 void AWindowGUI::create_objects()
965 {
966         lock_window("AWindowGUI::create_objects");
967         asset_titles[0] = C_("Title");
968         asset_titles[1] = _("Comments");
969
970         set_icon(mwindow->theme->get_image("awindow_icon"));
971
972         resource_icon(file_vframe,   file_icon,   "film_icon",   ICON_UNKNOWN);
973         resource_icon(folder_vframe, folder_icon, "folder_icon", ICON_FOLDER);
974         resource_icon(audio_vframe,  audio_icon,  "audio_icon",  ICON_SOUND);
975         resource_icon(video_vframe,  video_icon,  "video_icon",  ICON_FILM);
976         resource_icon(label_vframe,  label_icon,  "label_icon",  ICON_LABEL);
977
978         theme_icon(aeffect_folder_vframe,      aeffect_folder_icon,     "aeffect_folder");
979         theme_icon(atransition_folder_vframe,  atransition_folder_icon, "atransition_folder");
980         theme_icon(clip_folder_vframe,         clip_folder_icon,        "clip_folder");
981         theme_icon(label_folder_vframe,        label_folder_icon,       "label_folder");
982         theme_icon(media_folder_vframe,        media_folder_icon,       "media_folder");
983         theme_icon(proxy_folder_vframe,        proxy_folder_icon,       "proxy_folder");
984         theme_icon(veffect_folder_vframe,      veffect_folder_icon,     "veffect_folder");
985         theme_icon(vtransition_folder_vframe,  vtransition_folder_icon, "vtransition_folder");
986
987         folder_icons[AW_AEFFECT_FOLDER] = aeffect_folder_icon;
988         folder_icons[AW_VEFFECT_FOLDER] = veffect_folder_icon;
989         folder_icons[AW_ATRANSITION_FOLDER] = atransition_folder_icon;
990         folder_icons[AW_VTRANSITION_FOLDER] = vtransition_folder_icon;
991         folder_icons[AW_LABEL_FOLDER] = label_folder_icon;
992         folder_icons[AW_CLIP_FOLDER] = clip_folder_icon;
993         folder_icons[AW_MEDIA_FOLDER] = media_folder_icon;
994         folder_icons[AW_PROXY_FOLDER] = proxy_folder_icon;
995
996         theme_icon(clip_vframe,        clip_icon,        "clip_icon");
997         theme_icon(atransition_vframe, atransition_icon, "atransition_icon");
998         theme_icon(vtransition_vframe, vtransition_icon, "vtransition_icon");
999         theme_icon(aeffect_vframe,     aeffect_icon,     "aeffect_icon");
1000         theme_icon(veffect_vframe,     veffect_icon,     "veffect_icon");
1001
1002         plugin_icon(ladspa_vframe, ladspa_icon, "lad_picon", lad_picon_png);
1003         plugin_icon(ff_aud_vframe, ff_aud_icon, "ff_audio",  ff_audio_png);
1004         plugin_icon(ff_vid_vframe, ff_vid_icon, "ff_video",  ff_video_png);
1005
1006 // Mandatory folders
1007         folders.append(new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER, 1));
1008         folders.append(new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER, 1));
1009         folders.append(new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER, 1));
1010         folders.append(new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER, 1));
1011         folders.append(new AssetPicon(mwindow, this, AW_LABEL_FOLDER, 1));
1012         folders.append(new AssetPicon(mwindow, this, AW_CLIP_FOLDER, 1));
1013         folders.append(new AssetPicon(mwindow, this, AW_PROXY_FOLDER, 1));
1014         folders.append(new AssetPicon(mwindow, this, AW_MEDIA_FOLDER, 1));
1015
1016         create_label_folder();
1017
1018         mwindow->theme->get_awindow_sizes(this);
1019         load_defaults(mwindow->defaults);
1020
1021         int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1022         int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1023         search_text = new AWindowSearchText(mwindow, this, x1, y1+5);
1024         search_text->create_objects();
1025         int dy = search_text->get_h() + 10;
1026         y1 += dy;  h1 -= dy;
1027         add_subwindow(asset_list = new AWindowAssets(mwindow, this, x1, y1, w1, h1));
1028
1029         vicon_thread = new VIconThread(asset_list);
1030         vicon_thread->start();
1031         vicon_audio = new AssetVIconAudio(this);
1032
1033         add_subwindow(divider = new AWindowDivider(mwindow, this,
1034                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1035                 mwindow->theme->adivider_w, mwindow->theme->adivider_h));
1036
1037         divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
1038
1039         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1040         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1041         VFrame **images = mwindow->theme->get_image_set("playpatch_data");
1042         AVIconDrawing::calculate_geometry(this, images, &avicon_w, &avicon_h);
1043         add_subwindow(avicon_drawing = new AVIconDrawing(this, fw-avicon_w, fy, images));
1044         add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, _("Visibility")));
1045         add_tools->create_objects();
1046         fy += add_tools->get_h();  fh -= add_tools->get_h();
1047         add_subwindow(folder_list = new AWindowFolders(mwindow,
1048                 this, fx, fy, fw, fh));
1049         update_effects();
1050
1051         //int x = mwindow->theme->abuttons_x;
1052         //int y = mwindow->theme->abuttons_y;
1053
1054
1055         newfolder_thread = new NewFolderThread(mwindow, this);
1056
1057         add_subwindow(asset_menu = new AssetPopup(mwindow, this));
1058         asset_menu->create_objects();
1059         add_subwindow(clip_menu = new ClipPopup(mwindow, this));
1060         clip_menu->create_objects();
1061         add_subwindow(label_menu = new LabelPopup(mwindow, this));
1062         label_menu->create_objects();
1063
1064         add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this));
1065         effectlist_menu->create_objects();
1066         add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
1067         assetlist_menu->create_objects();
1068         add_subwindow(cliplist_menu = new ClipListMenu(mwindow, this));
1069         cliplist_menu->create_objects();
1070         add_subwindow(labellist_menu = new LabelListMenu(mwindow, this));
1071         labellist_menu->create_objects();
1072
1073         add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
1074         folderlist_menu->create_objects();
1075
1076         create_custom_xatoms();
1077         unlock_window();
1078 }
1079
1080 int AWindowGUI::resize_event(int w, int h)
1081 {
1082         mwindow->session->awindow_x = get_x();
1083         mwindow->session->awindow_y = get_y();
1084         mwindow->session->awindow_w = w;
1085         mwindow->session->awindow_h = h;
1086
1087         mwindow->theme->get_awindow_sizes(this);
1088         mwindow->theme->draw_awindow_bg(this);
1089         reposition_objects();
1090
1091 //      int x = mwindow->theme->abuttons_x;
1092 //      int y = mwindow->theme->abuttons_y;
1093 //      new_bin->reposition_window(x, y);
1094 //      x += new_bin->get_w();
1095 //      delete_bin->reposition_window(x, y);
1096 //      x += delete_bin->get_w();
1097 //      rename_bin->reposition_window(x, y);
1098 //      x += rename_bin->get_w();
1099 //      delete_disk->reposition_window(x, y);
1100 //      x += delete_disk->get_w();
1101 //      delete_project->reposition_window(x, y);
1102 //      x += delete_project->get_w();
1103 //      info->reposition_window(x, y);
1104 //      x += info->get_w();
1105 //      redraw_index->reposition_window(x, y);
1106 //      x += redraw_index->get_w();
1107 //      paste->reposition_window(x, y);
1108 //      x += paste->get_w();
1109 //      append->reposition_window(x, y);
1110 //      x += append->get_w();
1111 //      view->reposition_window(x, y);
1112
1113         BC_WindowBase::resize_event(w, h);
1114         return 1;
1115 }
1116
1117 int AWindowGUI::translation_event()
1118 {
1119         mwindow->session->awindow_x = get_x();
1120         mwindow->session->awindow_y = get_y();
1121         return 0;
1122 }
1123
1124 void AWindowGUI::reposition_objects()
1125 {
1126         int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1127         int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1128         search_text->reposition_window(x1, y1+5, w1);
1129         int dy = search_text->get_h() + 10;
1130         y1 += dy;  h1 -= dy;
1131         asset_list->reposition_window(x1, y1, w1, h1);
1132         divider->reposition_window(
1133                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1134                 mwindow->theme->adivider_w, mwindow->theme->adivider_h);
1135         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1136         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1137         add_tools->resize_event(fw-avicon_w, add_tools->get_h());
1138         avicon_drawing->reposition_window(fw-avicon_w, fy);
1139         fy += add_tools->get_h();  fh -= add_tools->get_h();
1140         folder_list->reposition_window(fx, fy, fw, fh);
1141 }
1142
1143 int AWindowGUI::save_defaults(BC_Hash *defaults)
1144 {
1145         defaults->update("PLUGIN_VISIBILTY", plugin_visibility);
1146         defaults->update("VICON_DRAWING", vicon_drawing);
1147         return 0;
1148 }
1149
1150 int AWindowGUI::load_defaults(BC_Hash *defaults)
1151 {
1152         plugin_visibility = defaults->get("PLUGIN_VISIBILTY", plugin_visibility);
1153         vicon_drawing = defaults->get("VICON_DRAWING", vicon_drawing);
1154         return 0;
1155 }
1156
1157 int AWindowGUI::close_event()
1158 {
1159         hide_window();
1160         mwindow->session->show_awindow = 0;
1161         unlock_window();
1162
1163         mwindow->gui->lock_window("AWindowGUI::close_event");
1164         mwindow->gui->mainmenu->show_awindow->set_checked(0);
1165         mwindow->gui->unlock_window();
1166
1167         lock_window("AWindowGUI::close_event");
1168         save_defaults(mwindow->defaults);
1169         mwindow->save_defaults();
1170         return 1;
1171 }
1172
1173 void AWindowGUI::start_vicon_drawing()
1174 {
1175         if( !vicon_drawing ) return;
1176         if( mwindow->edl->session->awindow_folder != AW_MEDIA_FOLDER ) return;
1177         if( mwindow->edl->session->assetlist_format != ASSETS_ICONS ) return;
1178         vicon_thread->start_drawing();
1179 }
1180
1181 void AWindowGUI::stop_vicon_drawing()
1182 {
1183         vicon_thread->stop_drawing();
1184 }
1185
1186 AWindowRemovePluginGUI::
1187 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
1188         int x, int y, PluginServer *plugin)
1189  : BC_Window(_(PROGRAM_NAME ": Remove plugin"), x,y, 500,200, 50, 50, 1, 0, 1, -1, "", 1)
1190 {
1191         this->awindow = awindow;
1192         this->thread = thread;
1193         this->plugin = plugin;
1194         VFrame *vframe = plugin->get_picon();
1195         icon = vframe ? create_pixmap(vframe) : 0;
1196         plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
1197 }
1198
1199 AWindowRemovePluginGUI::
1200 ~AWindowRemovePluginGUI()
1201 {
1202         if( !awindow->gui->protected_pixmap(icon) )
1203                 delete icon;
1204         plugin_list.remove_all();
1205 }
1206
1207 void AWindowRemovePluginGUI::create_objects()
1208 {
1209         BC_Button *ok_button = new BC_OKButton(this);
1210         add_subwindow(ok_button);
1211         BC_Button *cancel_button = new BC_CancelButton(this);
1212         add_subwindow(cancel_button);
1213         int x = 10, y = 10;
1214         BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
1215         add_subwindow(title);
1216         y += title->get_h() + 5;
1217         list = new BC_ListBox(x, y,
1218                 get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
1219                 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
1220         add_subwindow(list);
1221         show_window();
1222 }
1223
1224 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
1225 {
1226         int ret = 0;
1227         for( int i=0; i<folder.size(); ) {
1228                 AssetPicon *picon = (AssetPicon *)folder[i];
1229                 if( picon->plugin == plugin ) {
1230                         folder.remove_object_number(i);
1231                         ++ret;
1232                         continue;
1233                 }
1234                 ++i;
1235         }
1236         return ret;
1237 }
1238
1239 void AWindowRemovePlugin::handle_close_event(int result)
1240 {
1241         if( !result ) {
1242                 printf(_("remove %s\n"), plugin->path);
1243                 awindow->gui->lock_window("AWindowRemovePlugin::handle_close_event");
1244                 ArrayList<BC_ListBoxItem*> *folder =
1245                         plugin->audio ? plugin->transition ?
1246                                 &awindow->gui->atransitions :
1247                                 &awindow->gui->aeffects :
1248                         plugin->video ?  plugin->transition ?
1249                                 &awindow->gui->vtransitions :
1250                                 &awindow->gui->veffects :
1251                         0;
1252                 if( folder ) remove_plugin(plugin, *folder);
1253                 MWindow *mwindow = awindow->mwindow;
1254                 awindow->gui->unlock_window();
1255                 char plugin_path[BCTEXTLEN];
1256                 strcpy(plugin_path, plugin->path);
1257                 mwindow->plugindb->remove(plugin);
1258                 remove(plugin_path);
1259                 char index_path[BCTEXTLEN];
1260                 mwindow->create_defaults_path(index_path, PLUGIN_FILE);
1261                 remove(index_path);
1262                 char picon_path[BCTEXTLEN];
1263                 FileSystem fs;
1264                 snprintf(picon_path, sizeof(picon_path), "%s/picon",
1265                         File::get_plugin_path());
1266                 char png_name[BCSTRLEN], png_path[BCTEXTLEN];
1267                 plugin->get_plugin_png_name(png_name);
1268                 fs.update(picon_path);
1269                 for( int i=0; i<fs.dir_list.total; ++i ) {
1270                         char *fs_path = fs.dir_list[i]->path;
1271                         if( !fs.is_dir(fs_path) ) continue;
1272                         snprintf(png_path, sizeof(picon_path), "%s/%s",
1273                                 fs_path, png_name);
1274                         remove(png_path);
1275                 }
1276                 delete plugin;  plugin = 0;
1277                 awindow->gui->async_update_assets();
1278         }
1279 }
1280
1281 AWindowRemovePlugin::
1282 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
1283  : BC_DialogThread()
1284 {
1285         this->awindow = awindow;
1286         this->plugin = plugin;
1287 }
1288
1289 AWindowRemovePlugin::
1290 ~AWindowRemovePlugin()
1291 {
1292         close_window();
1293 }
1294
1295 BC_Window* AWindowRemovePlugin::new_gui()
1296 {
1297         int x = awindow->gui->get_abs_cursor_x(0);
1298         int y = awindow->gui->get_abs_cursor_y(0);
1299         AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
1300         gui->create_objects();
1301         return gui;
1302 }
1303
1304 int AWindowGUI::keypress_event()
1305 {
1306         switch( get_keypress() ) {
1307         case 'w': case 'W':
1308                 if( ctrl_down() ) {
1309                         close_event();
1310                         return 1;
1311                 }
1312                 break;
1313         case DELETE:
1314                 if( shift_down() ) {
1315                         PluginServer* plugin = selected_plugin();
1316                         if( !plugin ) break;
1317                         remove_plugin = new AWindowRemovePlugin(awindow, plugin);
1318                         unlock_window();
1319                         remove_plugin->start();
1320                         lock_window();
1321                 }
1322         }
1323         return 0;
1324 }
1325
1326
1327
1328 int AWindowGUI::create_custom_xatoms()
1329 {
1330         UpdateAssetsXAtom = create_xatom("CWINDOWGUI_UPDATE_ASSETS");
1331         return 0;
1332 }
1333 int AWindowGUI::recieve_custom_xatoms(xatom_event *event)
1334 {
1335         if( event->message_type == UpdateAssetsXAtom ) {
1336                 update_assets();
1337                 return 1;
1338         }
1339         return 0;
1340 }
1341
1342 void AWindowGUI::async_update_assets()
1343 {
1344         xatom_event event;
1345         event.message_type = UpdateAssetsXAtom;
1346         send_custom_xatom(&event);
1347 }
1348
1349
1350 void AWindowGUI::update_folder_list()
1351 {
1352         for( int i = 0; i < folders.total; i++ ) {
1353                 AssetPicon *picon = (AssetPicon*)folders.values[i];
1354                 picon->in_use = 0;
1355         }
1356
1357 // Search assets for folders
1358         for( int i = 0; i < mwindow->edl->folders.total; i++ ) {
1359                 const char *folder = mwindow->edl->folders.values[i];
1360                 int exists = 0;
1361
1362                 for( int j = 0; j < folders.total; j++ ) {
1363                         AssetPicon *picon = (AssetPicon*)folders.values[j];
1364                         if( !strcasecmp(picon->get_text(), folder) ) {
1365                                 exists = 1;
1366                                 picon->in_use = 1;
1367                                 break;
1368                         }
1369                 }
1370
1371                 if( !exists ) {
1372                         int aw_folder = folder_number(folder);
1373                         if( aw_folder >= 0 ) {
1374                                 AssetPicon *picon = new AssetPicon(mwindow, this, aw_folder, 1);
1375                                 picon->create_objects();
1376                                 folders.append(picon);
1377                         }
1378                 }
1379         }
1380
1381 // Delete unused non-persistent folders
1382         for( int i=folders.total; --i>=0; ) {
1383                 AssetPicon *picon = (AssetPicon*)folders.values[i];
1384                 if( !picon->in_use && !picon->persistent ) {
1385                         delete picon;
1386                         folders.remove_number(i);
1387                 }
1388         }
1389 }
1390
1391 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
1392         int do_audio, int do_video, int is_realtime, int is_transition)
1393 {
1394         ArrayList<PluginServer*> plugin_list;
1395 // Get pointers to plugindb entries
1396         mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
1397                         0, plugin_list);
1398
1399         for( int i = 0; i < plugin_list.total; i++ ) {
1400                 PluginServer *server = plugin_list.values[i];
1401                 int visible = plugin_visibility & (1<<server->dir_idx);
1402                 if( !visible ) continue;
1403 // Create new listitem
1404                 AssetPicon *picon = new AssetPicon(mwindow, this, server);
1405                 picon->create_objects();
1406                 output->append(picon);
1407         }
1408 }
1409
1410 void AWindowGUI::create_label_folder()
1411 {
1412         Label *current;
1413         for( current = mwindow->edl->labels->first; current; current = NEXT ) {
1414                 AssetPicon *picon = new AssetPicon(mwindow, this, current);
1415                 picon->create_objects();
1416                 labellist.append(picon);
1417         }
1418 }
1419
1420
1421 void AWindowGUI::update_asset_list()
1422 {
1423         for( int i = 0; i < assets.total; i++ ) {
1424                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1425                 picon->in_use = 0;
1426         }
1427
1428 // Synchronize EDL clips
1429         for( int i=0; i<mwindow->edl->clips.size(); ++i ) {
1430                 int exists = 0;
1431
1432 // Look for clip in existing listitems
1433                 for( int j = 0; j < assets.total && !exists; j++ ) {
1434                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1435
1436                         if( picon->id == mwindow->edl->clips[i]->id ) {
1437                                 picon->edl = mwindow->edl->clips[i];
1438                                 picon->set_text(mwindow->edl->clips[i]->local_session->clip_title);
1439                                 exists = 1;
1440                                 picon->in_use = 1;
1441                         }
1442                 }
1443
1444 // Create new listitem
1445                 if( !exists ) {
1446                         AssetPicon *picon = new AssetPicon(mwindow,
1447                                 this, mwindow->edl->clips[i]);
1448                         picon->create_objects();
1449                         assets.append(picon);
1450                 }
1451         }
1452
1453 // Synchronize EDL assets
1454         for( Asset *current=mwindow->edl->assets->first; current; current=NEXT ) {
1455                 int exists = 0;
1456
1457 // Look for asset in existing listitems
1458                 for( int j = 0; j < assets.total && !exists; j++ ) {
1459                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1460
1461                         if( picon->id == current->id ) {
1462                                 picon->indexable = current;
1463                                 picon->in_use = 1;
1464                                 exists = 1;
1465                         }
1466                 }
1467
1468 // Create new listitem
1469                 if( !exists ) {
1470                         AssetPicon *picon = new AssetPicon(mwindow,
1471                                 this, current);
1472                         picon->create_objects();
1473                         assets.append(picon);
1474                 }
1475         }
1476
1477         mwindow->gui->lock_window("AWindowGUI::update_asset_list");
1478         mwindow->gui->default_message();
1479         mwindow->gui->unlock_window();
1480
1481 // Synchronize nested EDLs
1482         for( int i=0; i<mwindow->edl->nested_edls.size(); ++i ) {
1483                 int exists = 0;
1484                 EDL *nested_edl = mwindow->edl->nested_edls[i];
1485
1486 // Look for asset in existing listitems
1487                 for( int j=0; j<assets.total && !exists; ++j ) {
1488                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1489
1490                         if( picon->id == nested_edl->id ) {
1491                                 picon->indexable = nested_edl;
1492                                 picon->in_use = 1;
1493                                 exists = 1;
1494                         }
1495                 }
1496
1497 // Create new listitem
1498                 if( !exists ) {
1499                         AssetPicon *picon = new AssetPicon(mwindow,
1500                                 this, (Indexable*)nested_edl);
1501                         picon->create_objects();
1502                         assets.append(picon);
1503                 }
1504         }
1505
1506         for( int i = assets.size() - 1; i >= 0; i-- ) {
1507                 AssetPicon *picon = (AssetPicon*)assets.get(i);
1508                 if( !picon->in_use ) {
1509                         delete picon;
1510                         assets.remove_number(i);
1511                         continue;
1512                 }
1513                 if( !picon->indexable || !picon->indexable->is_asset ) continue;
1514                 struct stat st;
1515                 picon->mtime = !stat(picon->indexable->path, &st) ? st.st_mtime : 0;
1516         }
1517 }
1518
1519 void AWindowGUI::update_picon(Indexable *indexable)
1520 {
1521         VIcon *vicon = 0;
1522         for( int i = 0; i < assets.total; i++ ) {
1523                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1524                 if( picon->indexable == indexable ||
1525                     picon->edl == (EDL *)indexable ) {
1526                         char name[BCTEXTLEN];
1527                         FileSystem fs;
1528                         fs.extract_name(name, indexable->path);
1529                         picon->set_text(name);
1530                         vicon = picon->vicon;
1531                         break;
1532                 }
1533         }
1534         if( vicon ) {
1535                 stop_vicon_drawing();
1536                 vicon->clear_images();
1537                 vicon->reset(indexable->get_frame_rate());
1538                 start_vicon_drawing();
1539         }
1540 }
1541
1542 void AWindowGUI::sort_assets(int use_mtime)
1543 {
1544         switch( mwindow->edl->session->awindow_folder ) {
1545         case AW_AEFFECT_FOLDER:
1546                 sort_picons(&aeffects);
1547                 break;
1548         case AW_VEFFECT_FOLDER:
1549                 sort_picons(&veffects);
1550                 break;
1551         case AW_ATRANSITION_FOLDER:
1552                 sort_picons(&atransitions);
1553                 break;
1554         case AW_VTRANSITION_FOLDER:
1555                 sort_picons(&vtransitions);
1556                 break;
1557         case AW_LABEL_FOLDER:
1558                 sort_picons(&labellist);
1559                 break;
1560         default:
1561                 sort_picons(&assets, use_mtime);
1562         }
1563 // reset xyposition
1564         asset_list->update_format(asset_list->get_format(), 0);
1565         update_assets();
1566 }
1567
1568 void AWindowGUI::sort_folders()
1569 {
1570         sort_picons(&folders);
1571         folder_list->update_format(folder_list->get_format(), 0);
1572         update_assets();
1573 }
1574
1575 EDL *AWindowGUI::collect_proxy(Indexable *indexable)
1576 {
1577         Asset *proxy_asset = (Asset *)indexable;
1578         char path[BCTEXTLEN];
1579         int proxy_scale = mwindow->edl->session->proxy_scale;
1580         ProxyRender::from_proxy_path(path, proxy_asset, proxy_scale);
1581         Asset *unproxy_asset = mwindow->edl->assets->get_asset(path);
1582         if( !unproxy_asset || !unproxy_asset->channels ) return 0;
1583 // make a clip from proxy video tracks and unproxy audio tracks
1584         EDL *proxy_edl = new EDL(mwindow->edl);
1585         proxy_edl->create_objects();
1586         FileSystem fs;  fs.extract_name(path, proxy_asset->path);
1587         strcpy(proxy_edl->local_session->clip_title, path);
1588         strcpy(proxy_edl->local_session->clip_notes, _("Proxy clip"));
1589         proxy_edl->session->video_tracks = proxy_asset->layers;
1590         proxy_edl->session->audio_tracks = unproxy_asset->channels;
1591         proxy_edl->create_default_tracks();
1592         double length = proxy_asset->frame_rate > 0 ?
1593                 (double)proxy_asset->video_length / proxy_asset->frame_rate :
1594                 1.0 / mwindow->edl->session->frame_rate;
1595         Track *current = proxy_edl->tracks->first;
1596         for( int vtrack=0; current; current=NEXT ) {
1597                 if( current->data_type != TRACK_VIDEO ) continue;
1598                 current->insert_asset(proxy_asset, 0, length, 0, vtrack++);
1599         }
1600         length = (double)unproxy_asset->audio_length / unproxy_asset->sample_rate;
1601         current = proxy_edl->tracks->first;
1602         for( int atrack=0; current; current=NEXT ) {
1603                 if( current->data_type != TRACK_AUDIO ) continue;
1604                 current->insert_asset(unproxy_asset, 0, length, 0, atrack++);
1605         }
1606         return proxy_edl;
1607 }
1608
1609
1610 void AWindowGUI::collect_assets(int proxy)
1611 {
1612         mwindow->session->drag_assets->remove_all();
1613         mwindow->session->drag_clips->remove_all();
1614         mwindow->session->clear_drag_proxy();
1615         int i = 0;  AssetPicon *result;
1616         while( (result = (AssetPicon*)asset_list->get_selection(0, i++)) != 0 ) {
1617                 Indexable *indexable = result->indexable;  EDL *drag_edl;
1618                 if( proxy && (drag_edl=collect_proxy(indexable)) ) {
1619                         mwindow->session->drag_clips->append(drag_edl);
1620                         mwindow->session->drag_proxy->append(drag_edl);
1621                         continue;
1622                 }
1623                 if( indexable ) {
1624                         mwindow->session->drag_assets->append(indexable);
1625                         continue;
1626                 }
1627                 if( result->edl ) {
1628                         mwindow->session->drag_clips->append(result->edl);
1629                         continue;
1630                 }
1631         }
1632 }
1633
1634 void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst,
1635         ArrayList<BC_ListBoxItem*> *src, int folder)
1636 {
1637 // Remove current pointers
1638         dst[0].remove_all();
1639         dst[1].remove_all_objects();
1640
1641 // Create new pointers
1642         for( int i = 0; i < src->total; i++ ) {
1643                 AssetPicon *picon = (AssetPicon*)src->values[i];
1644                 if( folder < 0 ||
1645                     (picon->indexable && picon->indexable->awindow_folder == folder) ||
1646                     (picon->edl && picon->edl->local_session->awindow_folder == folder) ) {
1647                         const char *text = search_text->get_text();
1648                         int hidden = text && text[0] && !bstrcasestr(picon->get_text(), text);
1649                         if( picon->vicon ) picon->vicon->hidden = hidden;
1650                         if( hidden ) continue;
1651                         BC_ListBoxItem *item2, *item1;
1652                         dst[0].append(item1 = picon);
1653                         if( picon->edl )
1654                                 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
1655                         else
1656                         if( picon->label && picon->label->textstr )
1657                                 dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr));
1658                         else if( picon->mtime ) {
1659                                 char date_time[BCSTRLEN];
1660                                 struct tm stm;  localtime_r(&picon->mtime, &stm);
1661                                 sprintf(date_time,"%04d.%02d.%02d %02d:%02d:%02d",
1662                                          stm.tm_year+1900, stm.tm_mon+1, stm.tm_mday,
1663                                          stm.tm_hour, stm.tm_min, stm.tm_sec);
1664                                 dst[1].append(item2 = new BC_ListBoxItem(date_time));
1665                         }
1666                         else
1667                                 dst[1].append(item2 = new BC_ListBoxItem(""));
1668                         item1->set_autoplace_text(1);  item1->set_autoplace_icon(1);
1669                         item2->set_autoplace_text(1);  item2->set_autoplace_icon(1);
1670                 }
1671         }
1672 }
1673
1674 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src, int use_mtime)
1675 {
1676         int done = 0, changed = 0;
1677         while( !done ) {
1678                 done = 1;
1679                 for( int i=0; i<src->total-1; ++i ) {
1680                         AssetPicon *item1 = (AssetPicon *)src->values[i];
1681                         AssetPicon *item2 = (AssetPicon *)src->values[i + 1];
1682                         if( use_mtime ? item1->mtime > item2->mtime :
1683                             strcmp(item1->get_text(), item2->get_text()) > 0 ) {
1684                                 src->values[i + 1] = item1;
1685                                 src->values[i] = item2;
1686                                 done = 0;  changed = 1;
1687                         }
1688                 }
1689         }
1690         if( changed ) {
1691                 for( int i=0; i<src->total; ++i ) {
1692                         AssetPicon *item = (AssetPicon *)src->values[i];
1693                         item->set_autoplace_icon(1);
1694                         item->set_autoplace_text(1);
1695                 }
1696         }
1697 }
1698
1699
1700 void AWindowGUI::filter_displayed_assets()
1701 {
1702         //allow_iconlisting = 1;
1703         asset_titles[0] = C_("Title");
1704         asset_titles[1] = _("Comments");
1705
1706         switch( mwindow->edl->session->awindow_folder ) {
1707         case AW_AEFFECT_FOLDER:
1708                 copy_picons(displayed_assets, &aeffects, AW_NO_FOLDER);
1709                 break;
1710         case AW_VEFFECT_FOLDER:
1711                 copy_picons(displayed_assets, &veffects, AW_NO_FOLDER);
1712                 break;
1713         case AW_ATRANSITION_FOLDER:
1714                 copy_picons(displayed_assets, &atransitions, AW_NO_FOLDER);
1715                 break;
1716         case AW_VTRANSITION_FOLDER:
1717                 copy_picons(displayed_assets, &vtransitions, AW_NO_FOLDER);
1718                 break;
1719         case AW_LABEL_FOLDER:
1720                 copy_picons(displayed_assets, &labellist, AW_NO_FOLDER);
1721                 asset_titles[0] = _("Time Stamps");
1722                 asset_titles[1] = C_("Title");
1723                 //allow_iconlisting = 0;
1724                 break;
1725         default:
1726                 copy_picons(displayed_assets, &assets, mwindow->edl->session->awindow_folder);
1727                 break;
1728         }
1729
1730         // Ensure the current folder icon is highlighted
1731         int selected_folder = mwindow->edl->session->awindow_folder;
1732         for( int i = 0; i < folders.total; i++ ) {
1733                 AssetPicon *folder_item = (AssetPicon *)folders.values[i];
1734                 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
1735                 folder_item->set_selected(selected);
1736         }
1737 }
1738
1739
1740 void AWindowGUI::update_assets()
1741 {
1742         stop_vicon_drawing();
1743         update_folder_list();
1744         update_asset_list();
1745         labellist.remove_all_objects();
1746         create_label_folder();
1747
1748         if( displayed_folder != mwindow->edl->session->awindow_folder )
1749                 search_text->clear();
1750         filter_displayed_assets();
1751
1752         if( mwindow->edl->session->folderlist_format != folder_list->get_format() ) {
1753                 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
1754         }
1755         int folder_xposition = folder_list->get_xposition();
1756         int folder_yposition = folder_list->get_yposition();
1757         folder_list->update(&folders, 0, 0, 1, folder_xposition, folder_yposition, -1);
1758
1759         if( mwindow->edl->session->assetlist_format != asset_list->get_format() ) {
1760                 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
1761         }
1762         int asset_xposition = asset_list->get_xposition();
1763         int asset_yposition = asset_list->get_yposition();
1764         if( displayed_folder != mwindow->edl->session->awindow_folder ) {
1765                 displayed_folder = mwindow->edl->session->awindow_folder;
1766                 asset_xposition = asset_yposition = 0;
1767         }
1768         asset_list->update(displayed_assets, asset_titles,
1769                 mwindow->edl->session->asset_columns, ASSET_COLUMNS,
1770                 asset_xposition, asset_yposition, -1, 0);
1771         asset_list->center_selection();
1772
1773         flush();
1774         start_vicon_drawing();
1775         return;
1776 }
1777
1778 void AWindowGUI::update_effects()
1779 {
1780         aeffects.remove_all_objects();
1781         create_persistent_folder(&aeffects, 1, 0, 1, 0);
1782         veffects.remove_all_objects();
1783         create_persistent_folder(&veffects, 0, 1, 1, 0);
1784         atransitions.remove_all_objects();
1785         create_persistent_folder(&atransitions, 1, 0, 0, 1);
1786         vtransitions.remove_all_objects();
1787         create_persistent_folder(&vtransitions, 0, 1, 0, 1);
1788 }
1789
1790 int AWindowGUI::folder_number(const char *name)
1791 {
1792         for( int i = 0; i < AWINDOW_FOLDERS; i++ ) {
1793                 if( !strcasecmp(name, folder_names[i]) ) return i;
1794         }
1795         return AW_NO_FOLDER;
1796 }
1797
1798 int AWindowGUI::drag_motion()
1799 {
1800         if( get_hidden() ) return 0;
1801
1802         int result = 0;
1803         return result;
1804 }
1805
1806 int AWindowGUI::drag_stop()
1807 {
1808         if( get_hidden() ) return 0;
1809         return 0;
1810 }
1811
1812 Indexable* AWindowGUI::selected_asset()
1813 {
1814         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1815         return picon ? picon->indexable : 0;
1816 }
1817
1818 PluginServer* AWindowGUI::selected_plugin()
1819 {
1820         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1821         return picon ? picon->plugin : 0;
1822 }
1823
1824 AssetPicon* AWindowGUI::selected_folder()
1825 {
1826         AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
1827         return picon;
1828 }
1829
1830
1831
1832
1833
1834
1835
1836
1837 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1838  : BC_SubWindow(x, y, w, h)
1839 {
1840         this->mwindow = mwindow;
1841         this->gui = gui;
1842 }
1843 AWindowDivider::~AWindowDivider()
1844 {
1845 }
1846
1847 int AWindowDivider::button_press_event()
1848 {
1849         if( is_event_win() && cursor_inside() ) {
1850                 mwindow->session->current_operation = DRAG_PARTITION;
1851                 return 1;
1852         }
1853         return 0;
1854 }
1855
1856 int AWindowDivider::cursor_motion_event()
1857 {
1858         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1859                 int wmin = 25;
1860                 int wmax = mwindow->session->awindow_w - mwindow->theme->adivider_w - wmin;
1861                 int fw = gui->get_relative_cursor_x();
1862                 if( fw > wmax ) fw = wmax;
1863                 if( fw < wmin ) fw = wmin;
1864                 mwindow->session->afolders_w = fw;
1865                 mwindow->theme->get_awindow_sizes(gui);
1866                 gui->reposition_objects();
1867                 gui->flush();
1868         }
1869         return 0;
1870 }
1871
1872 int AWindowDivider::button_release_event()
1873 {
1874         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1875                 mwindow->session->current_operation = NO_OPERATION;
1876                 return 1;
1877         }
1878         return 0;
1879 }
1880
1881
1882
1883
1884
1885
1886 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1887  : BC_ListBox(x, y, w, h,
1888                 mwindow->edl->session->folderlist_format == ASSETS_ICONS ?
1889                         LISTBOX_ICONS : LISTBOX_TEXT,
1890                 &gui->folders,    // Each column has an ArrayList of BC_ListBoxItems.
1891                 0,                // Titles for columns.  Set to 0 for no titles
1892                 0,                // width of each column
1893                 1,                // Total columns.
1894                 0,                // Pixel of top of window.
1895                 0,                // If this listbox is a popup window
1896                 LISTBOX_SINGLE,   // Select one item or multiple items
1897                 ICON_TOP,         // Position of icon relative to text of each item
1898                 1)                // Allow drags
1899 {
1900         this->mwindow = mwindow;
1901         this->gui = gui;
1902         set_drag_scroll(0);
1903 }
1904
1905 AWindowFolders::~AWindowFolders()
1906 {
1907 }
1908
1909 int AWindowFolders::selection_changed()
1910 {
1911         AssetPicon *picon = (AssetPicon*)get_selection(0, 0);
1912         if( picon ) {
1913                 gui->stop_vicon_drawing();
1914
1915                 if( get_button_down() && get_buttonpress() == 3 ) {
1916                         gui->folderlist_menu->update_titles();
1917                         gui->folderlist_menu->activate_menu();
1918                 }
1919
1920                 mwindow->edl->session->awindow_folder = picon->foldernum;
1921                 gui->asset_list->draw_background();
1922                 gui->async_update_assets();
1923
1924                 gui->start_vicon_drawing();
1925         }
1926         return 1;
1927 }
1928
1929 int AWindowFolders::button_press_event()
1930 {
1931         int result = 0;
1932
1933         result = BC_ListBox::button_press_event();
1934
1935         if( !result ) {
1936                 if( get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1937                         gui->folderlist_menu->update_titles();
1938                         gui->folderlist_menu->activate_menu();
1939                         result = 1;
1940                 }
1941         }
1942
1943
1944         return result;
1945 }
1946
1947
1948
1949
1950
1951
1952
1953 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1954  : BC_ListBox(x, y, w, h,
1955                 (mwindow->edl->session->assetlist_format == ASSETS_ICONS && gui->allow_iconlisting ) ?
1956                         LISTBOX_ICONS : LISTBOX_TEXT,
1957                 &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
1958                 gui->asset_titles,// Titles for columns.  Set to 0 for no titles
1959                 mwindow->edl->session->asset_columns, // width of each column
1960                 1,                // Total columns.
1961                 0,                // Pixel of top of window.
1962                 0,                // If this listbox is a popup window
1963                 LISTBOX_MULTIPLE, // Select one item or multiple items
1964                 ICON_TOP,         // Position of icon relative to text of each item
1965                 -1)               // Allow drags, require shift for scrolling
1966 {
1967         this->mwindow = mwindow;
1968         this->gui = gui;
1969         set_drag_scroll(0);
1970         set_scroll_stretch(1, 1);
1971 }
1972
1973 AWindowAssets::~AWindowAssets()
1974 {
1975 }
1976
1977 int AWindowAssets::button_press_event()
1978 {
1979         int result = 0;
1980
1981         result = BC_ListBox::button_press_event();
1982
1983         if( !result && get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1984                 BC_ListBox::deactivate_selection();
1985                 int folder = mwindow->edl->session->awindow_folder;
1986                 switch( folder ) {
1987                 case AW_AEFFECT_FOLDER:
1988                 case AW_VEFFECT_FOLDER:
1989                 case AW_ATRANSITION_FOLDER:
1990                 case AW_VTRANSITION_FOLDER:
1991                         gui->effectlist_menu->update();
1992                         gui->effectlist_menu->activate_menu();
1993                         break;
1994                 case AW_LABEL_FOLDER:
1995                         gui->labellist_menu->update();
1996                         gui->labellist_menu->activate_menu();
1997                         break;
1998                 case AW_CLIP_FOLDER:
1999                         gui->cliplist_menu->update();
2000                         gui->cliplist_menu->activate_menu();
2001                         break;
2002                 case AW_MEDIA_FOLDER:
2003                 case AW_PROXY_FOLDER:
2004                         gui->assetlist_menu->update_titles(folder==AW_MEDIA_FOLDER);
2005                         gui->assetlist_menu->activate_menu();
2006                         break;
2007                 }
2008                 result = 1;
2009         }
2010
2011         return result;
2012 }
2013
2014
2015 int AWindowAssets::handle_event()
2016 {
2017         AssetPicon *asset_picon = (AssetPicon *)get_selection(0, 0);
2018         if( !asset_picon ) return 0;
2019         switch( mwindow->edl->session->awindow_folder ) {
2020         case AW_AEFFECT_FOLDER:
2021         case AW_VEFFECT_FOLDER:
2022         case AW_ATRANSITION_FOLDER:
2023         case AW_VTRANSITION_FOLDER: return 1;
2024         }
2025         VWindow *vwindow = mwindow->vwindows.size() > DEFAULT_VWINDOW ?
2026                 mwindow->vwindows.get(DEFAULT_VWINDOW) : 0;
2027         if( !vwindow || !vwindow->is_running() ) return 1;
2028
2029         if( asset_picon->indexable )
2030                 vwindow->change_source(asset_picon->indexable);
2031         else if( asset_picon->edl )
2032                 vwindow->change_source(asset_picon->edl);
2033         return 1;
2034 }
2035
2036 int AWindowAssets::selection_changed()
2037 {
2038 // Show popup window
2039         AssetPicon *item;
2040         if( get_button_down() && get_buttonpress() == 3 &&
2041             (item = (AssetPicon*)get_selection(0, 0)) ) {
2042                 int folder = mwindow->edl->session->awindow_folder;
2043                 switch( folder ) {
2044                 case AW_AEFFECT_FOLDER:
2045                 case AW_VEFFECT_FOLDER:
2046                 case AW_ATRANSITION_FOLDER:
2047                 case AW_VTRANSITION_FOLDER:
2048                         gui->effectlist_menu->update();
2049                         gui->effectlist_menu->activate_menu();
2050                         break;
2051                 case AW_LABEL_FOLDER:
2052                         if( !item->label ) break;
2053                         gui->label_menu->activate_menu();
2054                         break;
2055                 case AW_CLIP_FOLDER:
2056                         if( !item->indexable && !item->edl ) break;
2057                         gui->clip_menu->update();
2058                         gui->clip_menu->activate_menu();
2059                         break;
2060                 default:
2061                         if( !item->indexable && !item->edl ) break;
2062                         gui->asset_menu->update();
2063                         gui->asset_menu->activate_menu();
2064                         break;
2065                 }
2066
2067                 BC_ListBox::deactivate_selection();
2068                 return 1;
2069         }
2070         else if( gui->vicon_drawing &&
2071                  get_button_down() && get_buttonpress() == 1 &&
2072                  (item = (AssetPicon*)get_selection(0, 0)) ) {
2073                 VIcon *vicon = 0;
2074                 if( !gui->vicon_thread->viewing ) {
2075                         vicon = item->vicon;
2076                 }
2077                 gui->vicon_thread->set_view_popup(vicon);
2078
2079         }
2080         return 0;
2081 }
2082
2083 void AWindowAssets::draw_background()
2084 {
2085         clear_box(0,0,get_w(),get_h(),get_bg_surface());
2086         set_color(BC_WindowBase::get_resources()->audiovideo_color);
2087         set_font(LARGEFONT);
2088         int aw_folder = mwindow->edl->session->awindow_folder;
2089         if( aw_folder < 0 ) return;
2090         const char *aw_name = _(AWindowGUI::folder_names[aw_folder]);
2091         draw_text(get_w() - get_text_width(LARGEFONT, aw_name) - 4, 30,
2092                 aw_name, -1, get_bg_surface());
2093 }
2094
2095 int AWindowAssets::drag_start_event()
2096 {
2097         int collect_pluginservers = 0;
2098         int collect_assets = 0, proxy = 0;
2099
2100         if( BC_ListBox::drag_start_event() ) {
2101                 switch( mwindow->edl->session->awindow_folder ) {
2102                 case AW_AEFFECT_FOLDER:
2103                         mwindow->session->current_operation = DRAG_AEFFECT;
2104                         collect_pluginservers = 1;
2105                         break;
2106                 case AW_VEFFECT_FOLDER:
2107                         mwindow->session->current_operation = DRAG_VEFFECT;
2108                         collect_pluginservers = 1;
2109                         break;
2110                 case AW_ATRANSITION_FOLDER:
2111                         mwindow->session->current_operation = DRAG_ATRANSITION;
2112                         collect_pluginservers = 1;
2113                         break;
2114                 case AW_VTRANSITION_FOLDER:
2115                         mwindow->session->current_operation = DRAG_VTRANSITION;
2116                         collect_pluginservers = 1;
2117                         break;
2118                 case AW_LABEL_FOLDER:
2119                         // do nothing!
2120                         break;
2121                 case AW_PROXY_FOLDER:
2122                         proxy = 1;
2123                         // fall thru
2124                 case AW_MEDIA_FOLDER:
2125                 default:
2126                         mwindow->session->current_operation = DRAG_ASSET;
2127                         collect_assets = 1;
2128                         break;
2129                 }
2130
2131                 if( collect_pluginservers ) {
2132                         int i = 0;
2133                         mwindow->session->drag_pluginservers->remove_all();
2134                         while(1)
2135                         {
2136                                 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
2137                                 if( !result ) break;
2138
2139                                 mwindow->session->drag_pluginservers->append(result->plugin);
2140                         }
2141                 }
2142
2143                 if( collect_assets ) {
2144                         gui->collect_assets(proxy);
2145                 }
2146
2147                 return 1;
2148         }
2149         return 0;
2150 }
2151
2152 int AWindowAssets::drag_motion_event()
2153 {
2154         BC_ListBox::drag_motion_event();
2155         unlock_window();
2156
2157         mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2158         mwindow->gui->drag_motion();
2159         mwindow->gui->unlock_window();
2160
2161         for( int i = 0; i < mwindow->vwindows.size(); i++ ) {
2162                 VWindow *vwindow = mwindow->vwindows.get(i);
2163                 if( !vwindow->is_running() ) continue;
2164                 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2165                 vwindow->gui->drag_motion();
2166                 vwindow->gui->unlock_window();
2167         }
2168
2169         mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2170         mwindow->cwindow->gui->drag_motion();
2171         mwindow->cwindow->gui->unlock_window();
2172
2173         lock_window("AWindowAssets::drag_motion_event");
2174         return 0;
2175 }
2176
2177 int AWindowAssets::drag_stop_event()
2178 {
2179         int result = 0;
2180
2181         result = gui->drag_stop();
2182
2183         unlock_window();
2184
2185         if( !result ) {
2186                 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2187                 result = mwindow->gui->drag_stop();
2188                 mwindow->gui->unlock_window();
2189         }
2190
2191         if( !result ) {
2192                 for( int i = 0; !result && i < mwindow->vwindows.size(); i++ ) {
2193                         VWindow *vwindow = mwindow->vwindows.get(i);
2194                         if( !vwindow ) continue;
2195                         if( !vwindow->is_running() ) continue;
2196                         if( vwindow->gui->is_hidden() ) continue;
2197                         vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2198                         if( vwindow->gui->cursor_above() &&
2199                             vwindow->gui->get_cursor_over_window() ) {
2200                                 result = vwindow->gui->drag_stop();
2201                         }
2202                         vwindow->gui->unlock_window();
2203                 }
2204         }
2205
2206         if( !result ) {
2207                 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2208                 result = mwindow->cwindow->gui->drag_stop();
2209                 mwindow->cwindow->gui->unlock_window();
2210         }
2211
2212         lock_window("AWindowAssets::drag_stop_event");
2213
2214         if( result )
2215                 get_drag_popup()->set_animation(0);
2216
2217         BC_ListBox::drag_stop_event();
2218 // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
2219         mwindow->session->current_operation = ::NO_OPERATION;
2220         mwindow->session->clear_drag_proxy();
2221
2222         return 1;
2223 }
2224
2225 int AWindowAssets::column_resize_event()
2226 {
2227         mwindow->edl->session->asset_columns[0] = get_column_width(0);
2228         mwindow->edl->session->asset_columns[1] = get_column_width(1);
2229         return 1;
2230 }
2231
2232 int AWindowAssets::focus_in_event()
2233 {
2234         gui->start_vicon_drawing();
2235         return 0;
2236 }
2237
2238 int AWindowAssets::focus_out_event()
2239 {
2240         gui->stop_vicon_drawing();
2241         return BC_ListBox::focus_out_event();
2242 }
2243
2244 AWindowSearchTextBox::AWindowSearchTextBox(AWindowSearchText *search_text, int x, int y, int w)
2245  : BC_TextBox(x, y, w, 1, "")
2246 {
2247         this->search_text = search_text;
2248 }
2249
2250 int AWindowSearchTextBox::handle_event()
2251 {
2252         return search_text->handle_event();
2253 }
2254
2255 AWindowSearchText::AWindowSearchText(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2256 {
2257         this->mwindow = mwindow;
2258         this->gui = gui;
2259         this->x = x;
2260         this->y = y;
2261 }
2262
2263 void AWindowSearchText::create_objects()
2264 {
2265         int x1 = x, y1 = y, margin = 10;
2266         gui->add_subwindow(text_title = new BC_Title(x1, y1, _("Search:")));
2267         x1 += text_title->get_w() + margin;
2268         int w1 = gui->get_w() - x1 - 2*margin;
2269         gui->add_subwindow(text_box = new AWindowSearchTextBox(this, x1, y1, w1));
2270 }
2271
2272 int AWindowSearchText::handle_event()
2273 {
2274         gui->async_update_assets();
2275         return 1;
2276 }
2277
2278 int AWindowSearchText::get_w()
2279 {
2280         return text_box->get_w() + text_title->get_w() + 10;
2281 }
2282
2283 int AWindowSearchText::get_h()
2284 {
2285         return bmax(text_box->get_h(),text_title->get_h());
2286 }
2287
2288 void AWindowSearchText::reposition_window(int x, int y, int w)
2289 {
2290         int x1 = x, y1 = y, margin = 10;
2291         text_title->reposition_window(x1, y1);
2292         x1 += text_title->get_w() + margin;
2293         int w1 = gui->get_w() - x1 - 2*margin;
2294         text_box->reposition_window(x1, y1, w1);
2295 }
2296
2297 const char *AWindowSearchText::get_text()
2298 {
2299         return text_box->get_text();
2300 }
2301
2302 void AWindowSearchText::clear()
2303 {
2304         text_box->update("");
2305 }
2306
2307 AWindowNewFolder::AWindowNewFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2308  : BC_Button(x, y, mwindow->theme->newbin_data)
2309 {
2310         this->mwindow = mwindow;
2311         this->gui = gui;
2312         set_tooltip(_("New bin"));
2313 }
2314
2315 int AWindowNewFolder::handle_event()
2316 {
2317         gui->newfolder_thread->start_new_folder();
2318         return 1;
2319 }
2320
2321 AWindowDeleteFolder::AWindowDeleteFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2322  : BC_Button(x, y, mwindow->theme->deletebin_data)
2323 {
2324         this->mwindow = mwindow;
2325         this->gui = gui;
2326         set_tooltip(_("Delete bin"));
2327 }
2328
2329 int AWindowDeleteFolder::handle_event()
2330 {
2331         if( gui->folder_list->get_selection(0, 0) ) {
2332                 BC_ListBoxItem *folder = gui->folder_list->get_selection(0, 0);
2333                 mwindow->delete_folder(folder->get_text());
2334         }
2335         return 1;
2336 }
2337
2338 AWindowRenameFolder::AWindowRenameFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2339  : BC_Button(x, y, mwindow->theme->renamebin_data)
2340 {
2341         this->mwindow = mwindow;
2342         this->gui = gui;
2343         set_tooltip(_("Rename bin"));
2344 }
2345
2346 int AWindowRenameFolder::handle_event()
2347 {
2348         return 1;
2349 }
2350
2351 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2352  : BC_Button(x, y, mwindow->theme->deletedisk_data)
2353 {
2354         this->mwindow = mwindow;
2355         this->gui = gui;
2356         set_tooltip(_("Delete asset from disk"));
2357 }
2358
2359 int AWindowDeleteDisk::handle_event()
2360 {
2361         return 1;
2362 }
2363
2364 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2365  : BC_Button(x, y, mwindow->theme->deleteproject_data)
2366 {
2367         this->mwindow = mwindow;
2368         this->gui = gui;
2369         set_tooltip(_("Delete asset from project"));
2370 }
2371
2372 int AWindowDeleteProject::handle_event()
2373 {
2374         return 1;
2375 }
2376
2377 // AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2378 //  : BC_Button(x, y, mwindow->theme->infoasset_data)
2379 // {
2380 //      this->mwindow = mwindow;
2381 //      this->gui = gui;
2382 //      set_tooltip(_("Edit information on asset"));
2383 // }
2384 // 
2385 // int AWindowInfo::handle_event()
2386 // {
2387 //      int cur_x, cur_y;
2388 //      gui->get_abs_cursor(cur_x, cur_y, 0);
2389 //      gui->awindow->asset_edit->edit_asset(gui->selected_asset(), cur_x, cur_y);
2390 //      return 1;
2391 // }
2392
2393 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2394  : BC_Button(x, y, mwindow->theme->redrawindex_data)
2395 {
2396         this->mwindow = mwindow;
2397         this->gui = gui;
2398         set_tooltip(_("Redraw index"));
2399 }
2400
2401 int AWindowRedrawIndex::handle_event()
2402 {
2403         return 1;
2404 }
2405
2406 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2407  : BC_Button(x, y, mwindow->theme->pasteasset_data)
2408 {
2409         this->mwindow = mwindow;
2410         this->gui = gui;
2411         set_tooltip(_("Paste asset on recordable tracks"));
2412 }
2413
2414 int AWindowPaste::handle_event()
2415 {
2416         return 1;
2417 }
2418
2419 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2420  : BC_Button(x, y, mwindow->theme->appendasset_data)
2421 {
2422         this->mwindow = mwindow;
2423         this->gui = gui;
2424         set_tooltip(_("Append asset in new tracks"));
2425 }
2426
2427 int AWindowAppend::handle_event()
2428 {
2429         return 1;
2430 }
2431
2432 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2433  : BC_Button(x, y, mwindow->theme->viewasset_data)
2434 {
2435         this->mwindow = mwindow;
2436         this->gui = gui;
2437         set_tooltip(_("View asset"));
2438 }
2439
2440 int AWindowView::handle_event()
2441 {
2442         return 1;
2443 }
2444
2445 AddTools::AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, const char *title)
2446  : BC_PopupMenu(x, y, BC_Title::calculate_w(gui, title, MEDIUMFONT)+8, title, -1, 0, 4)
2447 {
2448         this->mwindow = mwindow;
2449         this->gui = gui;
2450 }
2451
2452 void AddTools::create_objects()
2453 {
2454         uint64_t vis = 0;
2455         add_item(new AddPluginItem(this, "ladspa", PLUGIN_LADSPA_ID));
2456         vis |= 1 << PLUGIN_LADSPA_ID;
2457         add_item(new AddPluginItem(this, "ffmpeg", PLUGIN_FFMPEG_ID));
2458         vis |= 1 << PLUGIN_FFMPEG_ID;
2459         for( int i=0; i<MWindow::plugindb->size(); ++i ) {
2460                 PluginServer *plugin = MWindow::plugindb->get(i);
2461                 if( !plugin->audio && !plugin->video ) continue;
2462                 int idx = plugin->dir_idx;
2463                 uint32_t msk = 1 << idx;
2464                 if( (msk & vis) != 0 ) continue;
2465                 vis |= msk;
2466                 char parent[BCTEXTLEN];
2467                 strcpy(parent, plugin->path);
2468                 char *bp = strrchr(parent, '/');
2469                 if( bp ) { *bp = 0;  bp = strrchr(parent, '/'); }
2470                 if( !bp ) bp = parent; else ++bp;
2471                 add_item(new AddPluginItem(this, bp, idx));
2472         }
2473 }
2474
2475 #if 0
2476 // plugin_dirs list from toplevel makefile include plugin_defs
2477 N_("ladspa")
2478 N_("ffmpeg")
2479 N_("audio_tools")
2480 N_("audio_transitions")
2481 N_("blending")
2482 N_("colors")
2483 N_("exotic")
2484 N_("transforms")
2485 N_("tv_effects")
2486 N_("video_tools")
2487 N_("video_transitions")
2488 #endif
2489
2490 AddPluginItem::AddPluginItem(AddTools *menu, char const *text, int idx)
2491  : BC_MenuItem(_(text))
2492 {
2493         this->menu = menu;
2494         this->idx = idx;
2495         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2496         int chk = (msk & vis) ? 1 : 0;
2497         set_checked(chk);
2498 }
2499
2500 int AddPluginItem::handle_event()
2501 {
2502         int chk = get_checked() ^ 1;
2503         set_checked(chk);
2504         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2505         menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
2506         menu->gui->update_effects();
2507         menu->gui->save_defaults(menu->mwindow->defaults);
2508         menu->gui->async_update_assets();
2509         return 1;
2510 }
2511
2512 AVIconDrawing::AVIconDrawing(AWindowGUI *agui, int x, int y, VFrame **images)
2513  : BC_Toggle(x, y, images, agui->vicon_drawing)
2514 {
2515         this->agui = agui;
2516         set_tooltip(_("draw vicons"));
2517 }
2518
2519 void AVIconDrawing::calculate_geometry(AWindowGUI *agui, VFrame **images, int *ww, int *hh)
2520 {
2521         int text_line = -1, toggle_x = -1, toggle_y = -1;
2522         int text_x = -1, text_y = -1, text_w = -1, text_h = -1;
2523         BC_Toggle::calculate_extents(agui, images, 1,
2524                 &text_line, ww, hh, &toggle_x, &toggle_y,
2525                 &text_x, &text_y, &text_w, &text_h, "", MEDIUMFONT);
2526 }
2527
2528 AVIconDrawing::~AVIconDrawing()
2529 {
2530 }
2531
2532 int AVIconDrawing::handle_event()
2533 {
2534         agui->vicon_drawing = get_value();
2535         if( agui->vicon_drawing )
2536                 agui->start_vicon_drawing();
2537         else
2538                 agui->stop_vicon_drawing();
2539         return 1;
2540 }
2541
2542
2543 AWindowListFormat::AWindowListFormat(MWindow *mwindow, AWindowGUI *gui)
2544  : BC_MenuItem("")
2545 {
2546         this->mwindow = mwindow;
2547         this->gui = gui;
2548 }
2549
2550 int AWindowListFormat::handle_event()
2551 {
2552         gui->stop_vicon_drawing();
2553
2554         EDLSession *session = mwindow->edl->session;
2555         switch( session->assetlist_format ) {
2556         case ASSETS_TEXT:
2557                 session->assetlist_format = ASSETS_ICONS;
2558                 break;
2559         case ASSETS_ICONS:
2560                 session->assetlist_format = ASSETS_TEXT;
2561                 break;
2562         }
2563
2564         gui->asset_list->update_format(session->assetlist_format, 1);
2565         if( !mwindow->awindow->gui->allow_iconlisting ) {
2566                 mwindow->edl->session->assetlist_format = ASSETS_TEXT;
2567         }
2568
2569         gui->start_vicon_drawing();
2570         return 1;
2571 }
2572
2573 void AWindowListFormat::update()
2574 {
2575         set_text(mwindow->edl->session->assetlist_format == ASSETS_TEXT ?
2576                 (char*)_("Display icons") : (char*)_("Display text"));
2577 }
2578
2579 AWindowListSort::AWindowListSort(MWindow *mwindow, AWindowGUI *gui)
2580  : BC_MenuItem(_("Sort items"))
2581 {
2582         this->mwindow = mwindow;
2583         this->gui = gui;
2584 }
2585
2586 int AWindowListSort::handle_event()
2587 {
2588         gui->sort_assets(0);
2589         return 1;
2590 }
2591