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