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