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