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