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