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