42672233ec775b5fe10e0273db3573e232c62f94
[goodguy/history.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 "assets.h"
27 #include "audiodevice.h"
28 #include "awindowgui.h"
29 #include "awindow.h"
30 #include "bccmodels.h"
31 #include "bcsignals.h"
32 #include "bchash.h"
33 #include "cache.h"
34 #include "cstrdup.h"
35 #include "clip.h"
36 #include "clipedls.h"
37 #include "clippopup.h"
38 #include "cursors.h"
39 #include "cwindowgui.h"
40 #include "cwindow.h"
41 #include "edl.h"
42 #include "edlsession.h"
43 #include "effectlist.h"
44 #include "file.h"
45 #include "filesystem.h"
46 #include "folderlistmenu.h"
47 #include "indexable.h"
48 #include "keys.h"
49 #include "language.h"
50 #include "labels.h"
51 #include "labelpopup.h"
52 #include "localsession.h"
53 #include "mainmenu.h"
54 #include "mainsession.h"
55 #include "mwindowgui.h"
56 #include "mwindow.h"
57 #include "newfolder.h"
58 #include "preferences.h"
59 #include "proxy.h"
60 #include "proxypopup.h"
61 #include "renderengine.h"
62 #include "samples.h"
63 #include "theme.h"
64 #include "tracks.h"
65 #include "transportque.h"
66 #include "vframe.h"
67 #include "vicon.h"
68 #include "vrender.h"
69 #include "vwindowgui.h"
70 #include "vwindow.h"
71
72 #include "data/lad_picon_png.h"
73 #include "data/ff_audio_png.h"
74 #include "data/ff_video_png.h"
75
76 #include<stdio.h>
77 #include<unistd.h>
78 #include<fcntl.h>
79
80
81 const char *AWindowGUI::folder_names[] =
82 {
83         N_("Audio Effects"),
84         N_("Video Effects"),
85         N_("Audio Transitions"),
86         N_("Video Transitions"),
87         N_("Labels"),
88         N_("Clips"),
89         N_("Media"),
90         N_("Proxy"),
91 };
92
93
94 AssetVIcon::AssetVIcon(AssetPicon *picon, int w, int h, double framerate, int64_t length)
95  : VIcon(w, h, framerate)
96 {
97         this->picon = picon;
98         this->length = length;
99         temp = 0;
100 }
101
102 AssetVIcon::~AssetVIcon()
103 {
104         delete temp;
105 }
106
107 VFrame *AssetVIcon::frame()
108 {
109         Asset *asset = (Asset *)picon->indexable;
110         if( !asset->video_data && audio_data && audio_size && length > 0 ) {
111                 if( !temp ) temp = new VFrame(0, -1, vw, vh, BC_RGB888, -1);
112                 temp->clear_frame();
113                 int sample_rate = asset->get_sample_rate();
114                 int64_t audio_samples = asset->get_audio_samples();
115                 double duration = (double)audio_samples / sample_rate;
116                 picon->draw_hue_bar(temp, duration);
117                 int secs = length / frame_rate + 0.5;
118                 if( !secs ) secs = 1;
119                 int bfrsz = VICON_SAMPLE_RATE;
120                 int samples = audio_size/sizeof(vicon_audio_t);
121                 double line_pos = (double)seq_no/(length-1);
122                 int audio_pos = samples * line_pos * (secs-1)/secs;
123                 vicon_audio_t *audio_data = ((vicon_audio_t *)this->audio_data) + audio_pos;
124                 static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
125                 double data[bfrsz], sample_scale = 1./mx;
126                 int len = samples - audio_pos;
127                 if( len > bfrsz ) len = bfrsz;
128                 int i = 0;
129                 while( i < len ) data[i++] = *audio_data++ * sample_scale;
130                 while( i < bfrsz ) data[i++] = 0;
131                 picon->draw_wave(temp, data, bfrsz, RED, GREEN);
132                 int x = (vw-1) * line_pos;
133                 temp->pixel_rgb = RED;
134                 temp->draw_line(x,0, x,vh);
135                 return temp;
136         }
137         if( seq_no >= images.size() ) {
138                 MWindow *mwindow = picon->mwindow;
139                 File *file = mwindow->video_cache->check_out(asset, mwindow->edl, 1);
140                 if( !file ) return 0;
141                 if( temp && (temp->get_w() != asset->width || temp->get_h() != asset->height) ) {
142                         delete temp;  temp = 0;
143                 }
144                 if( !temp )
145                         temp = new VFrame(0, -1, asset->width, asset->height, BC_RGB888, -1);
146                 int ww = picon->gui->vicon_thread->view_w;
147                 int hh = picon->gui->vicon_thread->view_h;
148                 while( seq_no >= images.size() ) {
149                         file->set_layer(0);
150                         int64_t pos = images.size() / picon->gui->vicon_thread->refresh_rate * frame_rate;
151                         file->set_video_position(pos,0);
152                         if( file->read_frame(temp) ) temp->clear_frame();
153                         add_image(temp, ww, hh, BC_RGB8);
154                 }
155                 mwindow->video_cache->check_in(asset);
156         }
157         return *images[seq_no];
158 }
159
160 int64_t AssetVIcon::set_seq_no(int64_t no)
161 {
162         if( no >= length ) no = 0;
163         return seq_no = no;
164 }
165
166 int AssetVIcon::get_vx()
167 {
168         BC_ListBox *lbox = picon->gui->asset_list;
169         return lbox->get_item_x(picon);
170 }
171 int AssetVIcon::get_vy()
172 {
173         BC_ListBox *lbox = picon->gui->asset_list;
174         return lbox->get_item_y(picon) + lbox->get_title_h();
175 }
176
177 void AssetVIcon::load_audio()
178 {
179         MWindow *mwindow = picon->mwindow;
180         Asset *asset = (Asset *)picon->indexable;
181         File *file = mwindow->audio_cache->check_out(asset, mwindow->edl, 1);
182         int channels = asset->get_audio_channels();
183         if( channels > 2 ) channels = 2;
184         int sample_rate = asset->get_sample_rate();
185         int bfrsz = sample_rate;
186         Samples samples(bfrsz);
187         double time_scale = (double)sample_rate / VICON_SAMPLE_RATE;
188         vicon_audio_t *audio_data = (vicon_audio_t *)this->audio_data;
189         static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
190         double sample_scale = (double)mx / channels;
191         int audio_pos = 0, audio_len = audio_size/sizeof(vicon_audio_t);
192         while( audio_pos < audio_len ) {
193                 int64_t pos = audio_pos * time_scale;
194                 for( int ch=0; ch<channels; ++ch ) {
195                         file->set_channel(ch);
196                         file->set_audio_position(pos);
197                         file->read_samples(&samples, bfrsz);
198                         double *data = samples.get_data();
199                         for( int64_t k=audio_pos; k<audio_len; ++k ) {
200                                 int i = k * time_scale - pos;
201                                 if( i >= bfrsz ) break;
202                                 int v = audio_data[k] + data[i] * sample_scale;
203                                 audio_data[k] = CLIP(v, -mx,mx);
204                         }
205                 }
206                 audio_pos = (pos + bfrsz) / time_scale;
207         }
208         mwindow->audio_cache->check_in(asset);
209 }
210
211
212 AssetVIconAudio::AssetVIconAudio(AWindowGUI *gui)
213  : Thread(1, 0, 0)
214 {
215         this->gui = gui;
216         audio = new AudioDevice(gui->mwindow);
217         interrupted = 0;
218         vicon = 0;
219 }
220 AssetVIconAudio::~AssetVIconAudio()
221 {
222         delete audio;
223 }
224
225 void AssetVIconAudio::run()
226 {
227         int channels = 2;
228         int64_t bfrsz = VICON_SAMPLE_RATE;
229         MWindow *mwindow = gui->mwindow;
230         EDL *edl = mwindow->edl;
231         EDLSession *session = edl->session;
232         AudioOutConfig *aconfig = session->playback_config->aconfig;
233         audio->open_output(aconfig, VICON_SAMPLE_RATE, bfrsz, channels, 0);
234         audio->start_playback();
235         double out0[bfrsz], out1[bfrsz], *out[2] = { out0, out1 };
236         vicon_audio_t *audio_data = (vicon_audio_t *)vicon->audio_data;
237         static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
238
239         int audio_len = vicon->audio_size/sizeof(vicon_audio_t);
240         while( !interrupted ) {
241                 int len = audio_len - audio_pos;
242                 if( len <= 0 ) break;
243                 if( len > bfrsz ) len = bfrsz;
244                 int k = audio_pos;
245                 for( int i=0; i<len; ++i,++k )
246                         out0[i] = out1[i] = (double)audio_data[k] / mx;
247                 audio_pos = k;
248                 audio->write_buffer(out, channels, len);
249         }
250
251         if( !interrupted )
252                 audio->set_last_buffer();
253         audio->stop_audio(interrupted ? 0 : 1);
254         audio->close_all();
255 }
256
257 void AssetVIconAudio::start(AssetVIcon *vicon)
258 {
259         if( running() ) return;
260         interrupted = 0;
261         audio_pos = 0;
262         this->vicon = vicon;
263         Thread::start();
264 }
265
266 void AssetVIconAudio::stop(int wait)
267 {
268         if( running() && !interrupted ) {
269                 interrupted = 1;
270                 audio->stop_audio(wait);
271         }
272         Thread::join();
273         if( vicon ) {
274                 vicon->playing_audio = 0;
275                 vicon = 0;
276         }
277 }
278
279 void AssetVIcon::start_audio()
280 {
281         picon->gui->vicon_audio->stop(0);
282         playing_audio = 1;
283         picon->gui->vicon_audio->start(this);
284 }
285
286 void AssetVIcon::stop_audio()
287 {
288         picon->gui->vicon_audio->stop(0);
289         playing_audio = 0;
290 }
291
292 AssetPicon::AssetPicon(MWindow *mwindow,
293         AWindowGUI *gui, Indexable *indexable)
294  : BC_ListBoxItem()
295 {
296         reset();
297         this->mwindow = mwindow;
298         this->gui = gui;
299         this->indexable = indexable;
300         indexable->add_user();
301         this->id = indexable->id;
302 }
303
304 AssetPicon::AssetPicon(MWindow *mwindow,
305         AWindowGUI *gui, EDL *edl)
306  : BC_ListBoxItem()
307 {
308         reset();
309         this->mwindow = mwindow;
310         this->gui = gui;
311         this->edl = edl;
312         edl->add_user();
313         this->id = edl->id;
314 }
315
316 AssetPicon::AssetPicon(MWindow *mwindow,
317         AWindowGUI *gui, int folder, int persist)
318  : BC_ListBoxItem(_(AWindowGUI::folder_names[folder]),
319         folder>=0 && folder<AWINDOW_FOLDERS ?
320                 gui->folder_icons[folder]: gui->folder_icon)
321 {
322         reset();
323         foldernum = folder;
324         this->mwindow = mwindow;
325         this->gui = gui;
326         persistent = persist;
327 }
328
329 AssetPicon::AssetPicon(MWindow *mwindow,
330         AWindowGUI *gui, PluginServer *plugin)
331  : BC_ListBoxItem()
332 {
333         reset();
334         this->mwindow = mwindow;
335         this->gui = gui;
336         this->plugin = plugin;
337 }
338
339 AssetPicon::AssetPicon(MWindow *mwindow,
340         AWindowGUI *gui, Label *label)
341  : BC_ListBoxItem()
342 {
343         reset();
344         this->mwindow = mwindow;
345         this->gui = gui;
346         this->label = label;
347         indexable = 0;
348         icon = 0;
349         id = 0;
350 }
351
352 AssetPicon::~AssetPicon()
353 {
354         if( vicon )
355                 gui->vicon_thread->del_vicon(vicon);
356         if( indexable ) indexable->remove_user();
357         if( edl ) edl->remove_user();
358         if( icon && !gui->protected_pixmap(icon) ) {
359                 delete icon;
360                 if( !plugin ) delete icon_vframe;
361         }
362 }
363
364 void AssetPicon::draw_hue_bar(VFrame *frame, double duration)
365 {
366         float t = duration > 1 ? (log(duration) / log(3600.f)) : 0;
367         if( t > 1 ) t = 1;
368         float h = 300 * t, s = 1., v = 1.;
369         float r, g, b; // duration, 0..1hr == hue red..magenta
370         HSV::hsv_to_rgb(r,g,b, h,s,v);
371         int ih = frame->get_h()/8, iw = frame->get_w();
372         int ir = r * 256;  CLAMP(ir, 0,255);
373         int ig = g * 256;  CLAMP(ig, 0,255);
374         int ib = b * 256;  CLAMP(ib, 0,255);
375         unsigned char **rows = frame->get_rows();
376         for( int y=0; y<ih; ++y ) {
377                 unsigned char *rp = rows[y];
378                 for( int x=0; x<iw; rp+=3,++x ) {
379                         rp[0] = ir;  rp[1] = ig;  rp[2] = ib;
380                 }
381         }
382 }
383
384 void AssetPicon::draw_wave(VFrame *frame, double *dp, int len, int base_color, int line_color)
385 {
386         int w = frame->get_w(), h = frame->get_h();
387         int h1 = h-1, h2 = h/2, y = h2;
388         int rgb_color = frame->pixel_rgb;
389         for( int x=0,x1=0,x2=0; x<w; ++x,x1=x2 ) {
390                 double min = *dp, max = min;
391                 x2 = (len * (x+1))/w;
392                 for( int i=x1; i<x2; ++i ) {
393                         double value = *dp++;
394                         if( value < min ) min = value;
395                         if( value > max ) max = value;
396                 }
397                 int ctr = (min + max) / 2;
398                 int y0 = (int)(h2 - ctr*h2);  CLAMP(y0, 0,h1);
399                 int y1 = (int)(h2 - min*h2);  CLAMP(y1, 0,h1);
400                 int y2 = (int)(h2 - max*h2);  CLAMP(y2, 0,h1);
401                 frame->pixel_rgb = line_color;
402                 frame->draw_line(x,y1, x,y2);
403                 frame->pixel_rgb = base_color;
404                 frame->draw_line(x,y, x,y0);
405                 y = y0;
406         }
407         frame->pixel_rgb = rgb_color;
408 }
409
410 void AssetPicon::reset()
411 {
412         plugin = 0;
413         label = 0;
414         indexable = 0;
415         edl = 0;
416         foldernum = AW_NO_FOLDER;
417         icon = 0;
418         icon_vframe = 0;
419         vicon = 0;
420         in_use = 1;
421         mtime = 0;
422         id = 0;
423         persistent = 0;
424 }
425
426 void AssetPicon::open_render_engine(EDL *edl, int is_audio)
427 {
428         TransportCommand command;
429         command.command = is_audio ? NORMAL_FWD : CURRENT_FRAME;
430         command.get_edl()->copy_all(edl);
431         command.change_type = CHANGE_ALL;
432         command.realtime = 0;
433         render_engine = new RenderEngine(0, mwindow->preferences, 0, 0);
434         render_engine->set_vcache(mwindow->video_cache);
435         render_engine->set_acache(mwindow->audio_cache);
436         render_engine->arm_command(&command);
437 }
438 void AssetPicon::close_render_engine()
439 {
440         delete render_engine;  render_engine = 0;
441 }
442 void AssetPicon::render_video(int64_t pos, VFrame *vfrm)
443 {
444         if( !render_engine || !render_engine->vrender ) return;
445         render_engine->vrender->process_buffer(vfrm, pos, 0);
446 }
447 void AssetPicon::render_audio(int64_t pos, Samples **samples, int len)
448 {
449         if( !render_engine || !render_engine->arender ) return;
450         render_engine->arender->process_buffer(samples, len, pos);
451 }
452
453 void AssetPicon::create_objects()
454 {
455         FileSystem fs;
456         char name[BCTEXTLEN];
457         int pixmap_w, pixmap_h;
458
459         pixmap_h = 50 * BC_WindowBase::get_resources()->icon_scale;
460
461         if( indexable ) {
462                 fs.extract_name(name, indexable->path);
463                 set_text(name);
464         }
465         else if( edl ) {
466                 set_text(strcpy(name, edl->local_session->clip_title));
467                 set_text(name);
468         }
469
470         if( indexable && indexable->is_asset ) {
471                 Asset *asset = (Asset*)indexable;
472                 if( asset->video_data ) {
473                         if( mwindow->preferences->use_thumbnails ) {
474                                 gui->unlock_window();
475                                 File *file = mwindow->video_cache->check_out(asset,
476                                         mwindow->edl,
477                                         1);
478
479                                 if( file ) {
480                                         int height = asset->height > 0 ? asset->height : 1;
481                                         pixmap_w = pixmap_h * asset->width / height;
482
483                                         file->set_layer(0);
484                                         file->set_video_position(0, 0);
485
486                                         if( gui->temp_picon &&
487                                                 (gui->temp_picon->get_w() != asset->width ||
488                                                 gui->temp_picon->get_h() != asset->height) ) {
489                                                 delete gui->temp_picon;
490                                                 gui->temp_picon = 0;
491                                         }
492
493                                         if( !gui->temp_picon ) {
494                                                 gui->temp_picon = new VFrame(0, -1,
495                                                         asset->width, asset->height,
496                                                         BC_RGB888, -1);
497                                         }
498                                         { char string[BCTEXTLEN];
499                                         sprintf(string, _("Reading %s"), name);
500                                         mwindow->gui->lock_window("AssetPicon::create_objects");
501                                         mwindow->gui->show_message(string);
502                                         mwindow->gui->unlock_window(); }
503                                         file->read_frame(gui->temp_picon);
504                                         mwindow->video_cache->check_in(asset);
505
506                                         gui->lock_window("AssetPicon::create_objects 0");
507                                         icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
508                                         icon->draw_vframe(gui->temp_picon,
509                                                 0, 0, pixmap_w, pixmap_h, 0, 0);
510                                         icon_vframe = new VFrame(0,
511                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
512                                         icon_vframe->transfer_from(gui->temp_picon);
513                                         if( asset->awindow_folder == AW_MEDIA_FOLDER ) {
514 // vicon images
515                                                 double framerate = asset->get_frame_rate();
516                                                 if( !framerate ) framerate = VICON_RATE;
517                                                 int64_t frames = asset->get_video_frames();
518                                                 double secs = frames / framerate;
519                                                 if( secs > 5 ) secs = 5;
520                                                 int64_t length = secs * gui->vicon_thread->refresh_rate;
521                                                 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, framerate, length);
522                                                 if( asset->audio_data && secs > 0 ) {
523                                                         gui->unlock_window();
524                                                         int audio_len = VICON_SAMPLE_RATE*secs+0.5;
525                                                         vicon->init_audio(audio_len*sizeof(vicon_audio_t));
526                                                         vicon->load_audio();
527                                                         gui->lock_window("AssetPicon::create_objects 1");
528                                                 }
529                                                 gui->vicon_thread->add_vicon(vicon);
530                                         }
531
532                                 }
533                                 else {
534                                         gui->lock_window("AssetPicon::create_objects 2");
535                                         icon = gui->video_icon;
536                                         icon_vframe = gui->video_vframe;
537                                 }
538                         }
539                         else {
540                                 icon = gui->video_icon;
541                                 icon_vframe = gui->video_vframe;
542                         }
543                 }
544                 else
545                 if( asset->audio_data ) {
546                         if( mwindow->preferences->use_thumbnails ) {
547                                 gui->unlock_window();
548                                 File *file = mwindow->audio_cache->check_out(asset,
549                                         mwindow->edl,
550                                         1);
551                                 if( file ) {
552                                         pixmap_w = pixmap_h * 16/9;
553                                         icon_vframe = new VFrame(0,
554                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
555                                         { char string[BCTEXTLEN];
556                                         sprintf(string, _("Reading %s"), name);
557                                         mwindow->gui->lock_window("AssetPicon::create_objects 3");
558                                         mwindow->gui->show_message(string);
559                                         mwindow->gui->unlock_window(); }
560                                         int sample_rate = asset->get_sample_rate();
561                                         int channels = asset->get_audio_channels();
562                                         if( channels > 2 ) channels = 2;
563                                         int64_t audio_samples = asset->get_audio_samples();
564                                         double duration = (double)audio_samples / sample_rate;
565                                         draw_hue_bar(icon_vframe, duration);
566                                         int bfrsz = sample_rate;
567                                         Samples samples(bfrsz);
568                                         static int line_colors[2] = { GREEN, YELLOW };
569                                         static int base_colors[2] = { RED, PINK };
570                                         for( int i=channels; --i>=0; ) {
571                                                 file->set_channel(i);
572                                                 file->set_audio_position(0);
573                                                 file->read_samples(&samples, bfrsz);
574                                                 draw_wave(icon_vframe, samples.get_data(), bfrsz,
575                                                         base_colors[i], line_colors[i]);
576                                         }
577                                         mwindow->audio_cache->check_in(asset);
578                                         if( asset->awindow_folder == AW_MEDIA_FOLDER ) {
579                                                 double secs = duration;
580                                                 if( secs > 5 ) secs = 5;
581                                                 double refresh_rate = gui->vicon_thread->refresh_rate;
582                                                 int64_t length = secs * refresh_rate;
583                                                 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, refresh_rate, length);
584                                                 int audio_len = VICON_SAMPLE_RATE*secs+0.5;
585                                                 vicon->init_audio(audio_len*sizeof(vicon_audio_t));
586                                                 vicon->load_audio();
587                                                 gui->vicon_thread->add_vicon(vicon);
588                                         }
589                                         gui->lock_window("AssetPicon::create_objects 4");
590                                         icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
591                                         icon->draw_vframe(icon_vframe,
592                                                 0, 0, pixmap_w, pixmap_h, 0, 0);
593                                 }
594                                 else {
595                                         gui->lock_window("AssetPicon::create_objects 5");
596                                         icon = gui->audio_icon;
597                                         icon_vframe = gui->audio_vframe;
598                                 }
599                         }
600                         else {
601                                 icon = gui->audio_icon;
602                                 icon_vframe = gui->audio_vframe;
603                         }
604
605                 }
606                 struct stat st;
607                 mtime = !stat(asset->path, &st) ? st.st_mtime : 0;
608         }
609         else
610         if( indexable && !indexable->is_asset ) {
611                 icon = gui->video_icon;
612                 icon_vframe = gui->video_vframe;
613         }
614         else
615         if( edl ) {
616                 if( edl->tracks->playable_video_tracks() ) {
617                         if( mwindow->preferences->use_thumbnails ) {
618                                 gui->unlock_window();
619                                 char clip_icon_path[BCTEXTLEN];
620                                 char *clip_icon = edl->local_session->clip_icon;
621                                 if( clip_icon[0] ) {
622                                         snprintf(clip_icon_path, sizeof(clip_icon_path),
623                                                 "%s/%s", File::get_config_path(), clip_icon);
624                                         icon_vframe = VFramePng::vframe_png(clip_icon_path);
625                                 }
626                                 if( !icon_vframe ) {
627 //printf("render clip: %s\n", name);
628                                         int edl_h = edl->get_h(), edl_w = edl->get_w();
629                                         int height = edl_h > 0 ? edl_h : 1;
630                                         int width = edl_w > 0 ? edl_w : 1;
631                                         int color_model = edl->session->color_model;
632                                         pixmap_w = pixmap_h * width / height;
633
634                                         if( gui->temp_picon &&
635                                             (gui->temp_picon->get_color_model() != color_model ||
636                                              gui->temp_picon->get_w() != width ||
637                                              gui->temp_picon->get_h() != height) ) {
638                                                 delete gui->temp_picon;  gui->temp_picon = 0;
639                                         }
640
641                                         if( !gui->temp_picon ) {
642                                                 gui->temp_picon = new VFrame(0, -1,
643                                                         width, height, color_model, -1);
644                                         }
645                                         char string[BCTEXTLEN];
646                                         sprintf(string, _("Rendering %s"), name);
647                                         mwindow->gui->lock_window("AssetPicon::create_objects");
648                                         mwindow->gui->show_message(string);
649                                         mwindow->gui->unlock_window();
650                                         open_render_engine(edl, 0);
651                                         render_video(0, gui->temp_picon);
652                                         close_render_engine();
653                                         gui->lock_window("AssetPicon::create_objects 0");
654                                         icon_vframe = new VFrame(0,
655                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
656                                         icon_vframe->transfer_from(gui->temp_picon);
657                                         if( clip_icon[0] ) icon_vframe->write_png(clip_icon_path);
658                                 }
659                                 else {
660                                         pixmap_w = icon_vframe->get_w();
661                                         pixmap_h = icon_vframe->get_h();
662                                 }
663                                 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
664                                 icon->draw_vframe(icon_vframe,
665                                         0, 0, pixmap_w, pixmap_h, 0, 0);
666                         }
667                         else {
668                                 icon = gui->clip_icon;
669                                 icon_vframe = gui->clip_vframe;
670                         }
671                 }
672                 else
673                 if( edl->tracks->playable_audio_tracks() ) {
674                         if( mwindow->preferences->use_thumbnails ) {
675                                 gui->unlock_window();
676                                 char clip_icon_path[BCTEXTLEN];
677                                 char *clip_icon = edl->local_session->clip_icon;
678                                 if( clip_icon[0] ) {
679                                         snprintf(clip_icon_path, sizeof(clip_icon_path),
680                                                 "%s/%s", File::get_config_path(), clip_icon);
681                                         icon_vframe = VFramePng::vframe_png(clip_icon_path);
682                                 }
683                                 if( !icon_vframe ) {
684                                         pixmap_w = pixmap_h * 16/9;
685                                         icon_vframe = new VFrame(0,
686                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
687                                         char string[BCTEXTLEN];
688                                         sprintf(string, _("Rendering %s"), name);
689                                         mwindow->gui->lock_window("AssetPicon::create_objects 3");
690                                         mwindow->gui->show_message(string);
691                                         mwindow->gui->unlock_window();
692                                         int sample_rate = edl->get_sample_rate();
693                                         int channels = edl->get_audio_channels();
694                                         if( channels > 2 ) channels = 2;
695                                         int64_t audio_samples = edl->get_audio_samples();
696                                         double duration = (double)audio_samples / sample_rate;
697                                         draw_hue_bar(icon_vframe, duration);
698                                         Samples *samples[MAX_CHANNELS];
699                                         int bfrsz = sample_rate;
700                                         for( int i=0; i<MAX_CHANNELS; ++i )
701                                                 samples[i] = i<channels ? new Samples(bfrsz) : 0;
702                                         open_render_engine(edl, 1);
703                                         render_audio(0, samples, bfrsz);
704                                         close_render_engine();
705                                         gui->lock_window("AssetPicon::create_objects 4");
706                                         static int line_colors[2] = { GREEN, YELLOW };
707                                         static int base_colors[2] = { RED, PINK };
708                                         for( int i=channels; --i>=0; ) {
709                                                 draw_wave(icon_vframe, samples[i]->get_data(), bfrsz,
710                                                         base_colors[i], line_colors[i]);
711                                         }
712                                         for( int i=0; i<channels; ++i ) delete samples[i];
713                                         if( clip_icon[0] ) icon_vframe->write_png(clip_icon_path);
714                                 }
715                                 else {
716                                         pixmap_w = icon_vframe->get_w();
717                                         pixmap_h = icon_vframe->get_h();
718                                 }
719                                 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
720                                 icon->draw_vframe(icon_vframe,
721                                         0, 0, pixmap_w, pixmap_h, 0, 0);
722                         }
723                         else {
724                                 icon = gui->clip_icon;
725                                 icon_vframe = gui->clip_vframe;
726                         }
727                 }
728         }
729         else
730         if( plugin ) {
731                 strcpy(name, _(plugin->title));
732                 set_text(name);
733                 icon_vframe = plugin->get_picon();
734                 if( icon_vframe )
735                         icon = gui->create_pixmap(icon_vframe);
736                 else if( plugin->audio ) {
737                         if( plugin->transition ) {
738                                 icon = gui->atransition_icon;
739                                 icon_vframe = gui->atransition_vframe;
740                         }
741                         else if( plugin->is_ffmpeg() ) {
742                                 icon = gui->ff_aud_icon;
743                                 icon_vframe = gui->ff_aud_vframe;
744                         }
745                         else if( plugin->is_ladspa() ) {
746                                 icon = gui->ladspa_icon;
747                                 icon_vframe = gui->ladspa_vframe;
748                         }
749                         else {
750                                 icon = gui->aeffect_icon;
751                                 icon_vframe = gui->aeffect_vframe;
752                         }
753                 }
754                 else if( plugin->video ) {
755                         if( plugin->transition ) {
756                                 icon = gui->vtransition_icon;
757                                 icon_vframe = gui->vtransition_vframe;
758                         }
759                         else if( plugin->is_ffmpeg() ) {
760                                 icon = gui->ff_vid_icon;
761                                 icon_vframe = gui->ff_vid_vframe;
762                         }
763                         else {
764                                 icon = gui->veffect_icon;
765                                 icon_vframe = gui->veffect_vframe;
766                         }
767                 }
768         }
769         else
770         if( label ) {
771                 Units::totext(name,
772                               label->position,
773                               mwindow->edl->session->time_format,
774                               mwindow->edl->session->sample_rate,
775                               mwindow->edl->session->frame_rate,
776                               mwindow->edl->session->frames_per_foot);
777                 set_text(name);
778                 icon = gui->label_icon;
779                 icon_vframe = gui->label_vframe;
780         }
781         if( !icon ) {
782                 icon = gui->file_icon;
783                 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN];
784         }
785         set_icon(icon);
786         set_icon_vframe(icon_vframe);
787 }
788
789 AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
790  : BC_Window(_(PROGRAM_NAME ": Resources"),
791         mwindow->session->awindow_x, mwindow->session->awindow_y,
792         mwindow->session->awindow_w, mwindow->session->awindow_h,
793         100, 100, 1, 1, 1)
794 {
795         this->mwindow = mwindow;
796         this->awindow = awindow;
797
798         file_vframe = 0;                file_icon = 0;
799         folder_vframe = 0;              folder_icon = 0;
800         audio_vframe = 0;               audio_icon = 0;
801         video_vframe = 0;               video_icon = 0;
802         label_vframe = 0;               label_icon = 0;
803
804         atransition_vframe = 0;         atransition_icon = 0;
805         vtransition_vframe = 0;         vtransition_icon = 0;
806         aeffect_vframe = 0;             aeffect_icon = 0;
807         ladspa_vframe = 0;              ladspa_icon = 0;
808         veffect_vframe = 0;             veffect_icon = 0;
809         ff_aud_vframe = 0;              ff_aud_icon = 0;
810         ff_vid_vframe = 0;              ff_vid_icon = 0;
811
812         aeffect_folder_vframe = 0;      aeffect_folder_icon = 0;
813         atransition_folder_vframe = 0;  atransition_folder_icon = 0;
814         clip_folder_vframe = 0;         clip_folder_icon = 0;
815         label_folder_vframe = 0;        label_folder_icon = 0;
816         media_folder_vframe = 0;        media_folder_icon = 0;
817         proxy_folder_vframe = 0;        proxy_folder_icon = 0;
818         veffect_folder_vframe = 0;      veffect_folder_icon = 0;
819         vtransition_folder_vframe = 0;  vtransition_folder_icon = 0;
820
821         ladspa_vframe = 0;              ladspa_icon = 0;
822         ff_aud_vframe = 0;              ff_aud_icon = 0;
823         ff_vid_vframe = 0;              ff_vid_icon = 0;
824
825         clip_vframe = 0;                clip_icon = 0;
826         atransition_vframe = 0;         atransition_icon = 0;
827         vtransition_vframe = 0;         vtransition_icon = 0;
828         aeffect_vframe = 0;             aeffect_icon = 0;
829         veffect_vframe = 0;             veffect_icon = 0;
830
831         plugin_visibility = ((uint64_t)1<<(8*sizeof(uint64_t)-1))-1;
832         newfolder_thread = 0;
833         asset_menu = 0;
834         effectlist_menu = 0;
835         assetlist_menu = 0;
836         cliplist_menu = 0;
837         proxylist_menu = 0;
838         labellist_menu = 0;
839         folderlist_menu = 0;
840         temp_picon = 0;
841         search_text = 0;
842         allow_iconlisting = 1;
843         remove_plugin = 0;
844         vicon_thread = 0;
845         vicon_audio = 0;
846         vicon_drawing = 1;
847         displayed_folder = AW_NO_FOLDER;
848 }
849
850 AWindowGUI::~AWindowGUI()
851 {
852         assets.remove_all_objects();
853         folders.remove_all_objects();
854         aeffects.remove_all_objects();
855         veffects.remove_all_objects();
856         atransitions.remove_all_objects();
857         vtransitions.remove_all_objects();
858         labellist.remove_all_objects();
859         displayed_assets[1].remove_all_objects();
860
861         delete vicon_thread;
862         delete vicon_audio;
863         delete newfolder_thread;
864
865         delete search_text;
866         delete temp_picon;
867         delete remove_plugin;
868
869         delete file_vframe;             delete file_icon;
870         delete folder_vframe;           delete folder_icon;
871         delete audio_vframe;            delete audio_icon;
872         delete video_vframe;            delete video_icon;
873         delete label_vframe;            delete label_icon;
874         delete clip_vframe;             delete clip_icon;
875         delete aeffect_folder_vframe;   delete aeffect_folder_icon;
876         delete atransition_folder_vframe; delete atransition_folder_icon;
877         delete veffect_folder_vframe;   delete veffect_folder_icon;
878         delete vtransition_folder_vframe; delete vtransition_folder_icon;
879         delete clip_folder_vframe;      delete clip_folder_icon;
880         delete label_folder_vframe;     delete label_folder_icon;
881         delete media_folder_vframe;     delete media_folder_icon;
882         delete proxy_folder_vframe;     delete proxy_folder_icon;
883         delete ladspa_vframe;           delete ladspa_icon;
884         delete ff_aud_vframe;           delete ff_aud_icon;
885         delete ff_vid_vframe;           delete ff_vid_icon;
886         delete atransition_vframe;      delete atransition_icon;
887         delete vtransition_vframe;      delete vtransition_icon;
888         delete aeffect_vframe;          delete aeffect_icon;
889         delete veffect_vframe;          delete veffect_icon;
890 }
891
892 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
893 {
894         return  icon == file_icon ||
895                 icon == folder_icon ||
896                 icon == audio_icon ||
897                 icon == video_icon ||
898                 icon == clip_icon ||
899                 icon == label_icon ||
900                 icon == vtransition_icon ||
901                 icon == atransition_icon ||
902                 icon == veffect_icon ||
903                 icon == aeffect_icon ||
904                 icon == ladspa_icon ||
905                 icon == ff_aud_icon ||
906                 icon == ff_vid_icon ||
907                 icon == aeffect_folder_icon ||
908                 icon == veffect_folder_icon ||
909                 icon == atransition_folder_icon ||
910                 icon == vtransition_folder_icon ||
911                 icon == label_folder_icon ||
912                 icon == clip_folder_icon ||
913                 icon == media_folder_icon ||
914                 icon == proxy_folder_icon;
915 }
916
917 VFrame *AWindowGUI::get_picon(const char *name, const char *plugin_icons)
918 {
919         char png_path[BCTEXTLEN];
920         char *pp = png_path, *ep = pp + sizeof(png_path)-1;
921         snprintf(pp, ep-pp, "%s/picon/%s/%s.png",
922                 File::get_plugin_path(), plugin_icons, name);
923         if( access(png_path, R_OK) ) return 0;
924         return VFramePng::vframe_png(png_path,0,0);
925 }
926
927 VFrame *AWindowGUI::get_picon(const char *name)
928 {
929         VFrame *vframe = get_picon(name, mwindow->preferences->plugin_icons);
930         if( !vframe ) {
931                 char png_name[BCSTRLEN], *pp = png_name, *ep = pp + sizeof(png_name)-1;
932                 snprintf(pp, ep-pp, "%s.png", name);
933                 unsigned char *data = mwindow->theme->get_image_data(png_name);
934                 if( data ) vframe = new VFramePng(data, 0.);
935         }
936         return vframe;
937 }
938
939 void AWindowGUI::resource_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, int idx)
940 {
941         vfrm = get_picon(fn);
942         if( !vfrm ) vfrm = BC_WindowBase::get_resources()->type_to_icon[idx];
943         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
944 }
945 void AWindowGUI::theme_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn)
946 {
947         vfrm = get_picon(fn);
948         if( !vfrm ) vfrm = mwindow->theme->get_image(fn);
949         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
950 }
951 void AWindowGUI::plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, unsigned char *png)
952 {
953         vfrm = get_picon(fn);
954         if( !vfrm ) vfrm = new VFramePng(png);
955         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
956 }
957
958 void AWindowGUI::create_objects()
959 {
960         lock_window("AWindowGUI::create_objects");
961         asset_titles[0] = C_("Title");
962         asset_titles[1] = _("Comments");
963
964         set_icon(mwindow->theme->get_image("awindow_icon"));
965
966         resource_icon(file_vframe,   file_icon,   "film_icon",   ICON_UNKNOWN);
967         resource_icon(folder_vframe, folder_icon, "folder_icon", ICON_FOLDER);
968         resource_icon(audio_vframe,  audio_icon,  "audio_icon",  ICON_SOUND);
969         resource_icon(video_vframe,  video_icon,  "video_icon",  ICON_FILM);
970         resource_icon(label_vframe,  label_icon,  "label_icon",  ICON_LABEL);
971
972         theme_icon(aeffect_folder_vframe,      aeffect_folder_icon,     "aeffect_folder");
973         theme_icon(atransition_folder_vframe,  atransition_folder_icon, "atransition_folder");
974         theme_icon(clip_folder_vframe,         clip_folder_icon,        "clip_folder");
975         theme_icon(label_folder_vframe,        label_folder_icon,       "label_folder");
976         theme_icon(media_folder_vframe,        media_folder_icon,       "media_folder");
977         theme_icon(proxy_folder_vframe,        proxy_folder_icon,       "proxy_folder");
978         theme_icon(veffect_folder_vframe,      veffect_folder_icon,     "veffect_folder");
979         theme_icon(vtransition_folder_vframe,  vtransition_folder_icon, "vtransition_folder");
980
981         folder_icons[AW_AEFFECT_FOLDER] = aeffect_folder_icon;
982         folder_icons[AW_VEFFECT_FOLDER] = veffect_folder_icon;
983         folder_icons[AW_ATRANSITION_FOLDER] = atransition_folder_icon;
984         folder_icons[AW_VTRANSITION_FOLDER] = vtransition_folder_icon;
985         folder_icons[AW_LABEL_FOLDER] = label_folder_icon;
986         folder_icons[AW_CLIP_FOLDER] = clip_folder_icon;
987         folder_icons[AW_MEDIA_FOLDER] = media_folder_icon;
988         folder_icons[AW_PROXY_FOLDER] = proxy_folder_icon;
989
990         theme_icon(clip_vframe,        clip_icon,        "clip_icon");
991         theme_icon(atransition_vframe, atransition_icon, "atransition_icon");
992         theme_icon(vtransition_vframe, vtransition_icon, "vtransition_icon");
993         theme_icon(aeffect_vframe,     aeffect_icon,     "aeffect_icon");
994         theme_icon(veffect_vframe,     veffect_icon,     "veffect_icon");
995
996         plugin_icon(ladspa_vframe, ladspa_icon, "lad_picon", lad_picon_png);
997         plugin_icon(ff_aud_vframe, ff_aud_icon, "ff_audio",  ff_audio_png);
998         plugin_icon(ff_vid_vframe, ff_vid_icon, "ff_video",  ff_video_png);
999
1000 // Mandatory folders
1001         folders.append(new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER, 1));
1002         folders.append(new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER, 1));
1003         folders.append(new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER, 1));
1004         folders.append(new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER, 1));
1005         folders.append(new AssetPicon(mwindow, this, AW_LABEL_FOLDER, 1));
1006         folders.append(new AssetPicon(mwindow, this, AW_CLIP_FOLDER, 1));
1007         folders.append(new AssetPicon(mwindow, this, AW_PROXY_FOLDER, 1));
1008         folders.append(new AssetPicon(mwindow, this, AW_MEDIA_FOLDER, 1));
1009
1010         create_label_folder();
1011
1012         mwindow->theme->get_awindow_sizes(this);
1013         load_defaults(mwindow->defaults);
1014
1015         int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1016         int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1017         search_text = new AWindowSearchText(mwindow, this, x1, y1+5);
1018         search_text->create_objects();
1019         int dy = search_text->get_h() + 10;
1020         y1 += dy;  h1 -= dy;
1021         add_subwindow(asset_list = new AWindowAssets(mwindow, this, x1, y1, w1, h1));
1022
1023         vicon_thread = new VIconThread(asset_list);
1024         vicon_thread->start();
1025         vicon_audio = new AssetVIconAudio(this);
1026
1027         add_subwindow(divider = new AWindowDivider(mwindow, this,
1028                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1029                 mwindow->theme->adivider_w, mwindow->theme->adivider_h));
1030
1031         divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
1032
1033         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1034         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1035         VFrame **images = mwindow->theme->get_image_set("playpatch_data");
1036         AVIconDrawing::calculate_geometry(this, images, &avicon_w, &avicon_h);
1037         add_subwindow(avicon_drawing = new AVIconDrawing(this, fw-avicon_w, fy, images));
1038         add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, _("Visibility")));
1039         add_tools->create_objects();
1040         fy += add_tools->get_h();  fh -= add_tools->get_h();
1041         add_subwindow(folder_list = new AWindowFolders(mwindow,
1042                 this, fx, fy, fw, fh));
1043         update_effects();
1044
1045         //int x = mwindow->theme->abuttons_x;
1046         //int y = mwindow->theme->abuttons_y;
1047
1048
1049         newfolder_thread = new NewFolderThread(mwindow, this);
1050
1051         add_subwindow(asset_menu = new AssetPopup(mwindow, this));
1052         asset_menu->create_objects();
1053         add_subwindow(clip_menu = new ClipPopup(mwindow, this));
1054         clip_menu->create_objects();
1055         add_subwindow(label_menu = new LabelPopup(mwindow, this));
1056         label_menu->create_objects();
1057         add_subwindow(proxy_menu = new ProxyPopup(mwindow, this));
1058         proxy_menu->create_objects();
1059
1060         add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this));
1061         effectlist_menu->create_objects();
1062         add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
1063         assetlist_menu->create_objects();
1064         add_subwindow(cliplist_menu = new ClipListMenu(mwindow, this));
1065         cliplist_menu->create_objects();
1066         add_subwindow(labellist_menu = new LabelListMenu(mwindow, this));
1067         labellist_menu->create_objects();
1068         add_subwindow(proxylist_menu = new ProxyListMenu(mwindow, this));
1069         proxylist_menu->create_objects();
1070
1071         add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
1072         folderlist_menu->create_objects();
1073
1074         create_custom_xatoms();
1075         unlock_window();
1076 }
1077
1078 int AWindowGUI::resize_event(int w, int h)
1079 {
1080         mwindow->session->awindow_x = get_x();
1081         mwindow->session->awindow_y = get_y();
1082         mwindow->session->awindow_w = w;
1083         mwindow->session->awindow_h = h;
1084
1085         mwindow->theme->get_awindow_sizes(this);
1086         mwindow->theme->draw_awindow_bg(this);
1087         reposition_objects();
1088
1089 //      int x = mwindow->theme->abuttons_x;
1090 //      int y = mwindow->theme->abuttons_y;
1091 //      new_bin->reposition_window(x, y);
1092 //      x += new_bin->get_w();
1093 //      delete_bin->reposition_window(x, y);
1094 //      x += delete_bin->get_w();
1095 //      rename_bin->reposition_window(x, y);
1096 //      x += rename_bin->get_w();
1097 //      delete_disk->reposition_window(x, y);
1098 //      x += delete_disk->get_w();
1099 //      delete_project->reposition_window(x, y);
1100 //      x += delete_project->get_w();
1101 //      info->reposition_window(x, y);
1102 //      x += info->get_w();
1103 //      redraw_index->reposition_window(x, y);
1104 //      x += redraw_index->get_w();
1105 //      paste->reposition_window(x, y);
1106 //      x += paste->get_w();
1107 //      append->reposition_window(x, y);
1108 //      x += append->get_w();
1109 //      view->reposition_window(x, y);
1110
1111         BC_WindowBase::resize_event(w, h);
1112         return 1;
1113 }
1114
1115 int AWindowGUI::translation_event()
1116 {
1117         mwindow->session->awindow_x = get_x();
1118         mwindow->session->awindow_y = get_y();
1119         return 0;
1120 }
1121
1122 void AWindowGUI::reposition_objects()
1123 {
1124         int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1125         int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1126         search_text->reposition_window(x1, y1+5, w1);
1127         int dy = search_text->get_h() + 10;
1128         y1 += dy;  h1 -= dy;
1129         asset_list->reposition_window(x1, y1, w1, h1);
1130         divider->reposition_window(
1131                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1132                 mwindow->theme->adivider_w, mwindow->theme->adivider_h);
1133         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1134         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1135         add_tools->resize_event(fw-avicon_w, add_tools->get_h());
1136         avicon_drawing->reposition_window(fw-avicon_w, fy);
1137         fy += add_tools->get_h();  fh -= add_tools->get_h();
1138         folder_list->reposition_window(fx, fy, fw, fh);
1139 }
1140
1141 int AWindowGUI::save_defaults(BC_Hash *defaults)
1142 {
1143         defaults->update("PLUGIN_VISIBILTY", plugin_visibility);
1144         defaults->update("VICON_DRAWING", vicon_drawing);
1145         return 0;
1146 }
1147
1148 int AWindowGUI::load_defaults(BC_Hash *defaults)
1149 {
1150         plugin_visibility = defaults->get("PLUGIN_VISIBILTY", plugin_visibility);
1151         vicon_drawing = defaults->get("VICON_DRAWING", vicon_drawing);
1152         return 0;
1153 }
1154
1155 int AWindowGUI::close_event()
1156 {
1157         hide_window();
1158         mwindow->session->show_awindow = 0;
1159         unlock_window();
1160
1161         mwindow->gui->lock_window("AWindowGUI::close_event");
1162         mwindow->gui->mainmenu->show_awindow->set_checked(0);
1163         mwindow->gui->unlock_window();
1164
1165         lock_window("AWindowGUI::close_event");
1166         save_defaults(mwindow->defaults);
1167         mwindow->save_defaults();
1168         return 1;
1169 }
1170
1171 void AWindowGUI::start_vicon_drawing()
1172 {
1173         if( !vicon_drawing ) return;
1174         if( mwindow->edl->session->awindow_folder != AW_MEDIA_FOLDER ) return;
1175         if( mwindow->edl->session->assetlist_format != ASSETS_ICONS ) return;
1176         vicon_thread->start_drawing();
1177 }
1178
1179 void AWindowGUI::stop_vicon_drawing()
1180 {
1181         vicon_thread->stop_drawing();
1182 }
1183
1184 AWindowRemovePluginGUI::
1185 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
1186         int x, int y, PluginServer *plugin)
1187  : BC_Window(_(PROGRAM_NAME ": Remove plugin"), x,y, 500,200, 50, 50, 1, 0, 1, -1, "", 1)
1188 {
1189         this->awindow = awindow;
1190         this->thread = thread;
1191         this->plugin = plugin;
1192         VFrame *vframe = plugin->get_picon();
1193         icon = vframe ? create_pixmap(vframe) : 0;
1194         plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
1195 }
1196
1197 AWindowRemovePluginGUI::
1198 ~AWindowRemovePluginGUI()
1199 {
1200         if( !awindow->gui->protected_pixmap(icon) )
1201                 delete icon;
1202         plugin_list.remove_all();
1203 }
1204
1205 void AWindowRemovePluginGUI::create_objects()
1206 {
1207         BC_Button *ok_button = new BC_OKButton(this);
1208         add_subwindow(ok_button);
1209         BC_Button *cancel_button = new BC_CancelButton(this);
1210         add_subwindow(cancel_button);
1211         int x = 10, y = 10;
1212         BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
1213         add_subwindow(title);
1214         y += title->get_h() + 5;
1215         list = new BC_ListBox(x, y,
1216                 get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
1217                 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
1218         add_subwindow(list);
1219         show_window();
1220 }
1221
1222 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
1223 {
1224         int ret = 0;
1225         for( int i=0; i<folder.size(); ) {
1226                 AssetPicon *picon = (AssetPicon *)folder[i];
1227                 if( picon->plugin == plugin ) {
1228                         folder.remove_object_number(i);
1229                         ++ret;
1230                         continue;
1231                 }
1232                 ++i;
1233         }
1234         return ret;
1235 }
1236
1237 void AWindowRemovePlugin::handle_close_event(int result)
1238 {
1239         if( !result ) {
1240                 printf(_("remove %s\n"), plugin->path);
1241                 awindow->gui->lock_window("AWindowRemovePlugin::handle_close_event");
1242                 ArrayList<BC_ListBoxItem*> *folder =
1243                         plugin->audio ? plugin->transition ?
1244                                 &awindow->gui->atransitions :
1245                                 &awindow->gui->aeffects :
1246                         plugin->video ?  plugin->transition ?
1247                                 &awindow->gui->vtransitions :
1248                                 &awindow->gui->veffects :
1249                         0;
1250                 if( folder ) remove_plugin(plugin, *folder);
1251                 MWindow *mwindow = awindow->mwindow;
1252                 awindow->gui->unlock_window();
1253                 char plugin_path[BCTEXTLEN];
1254                 strcpy(plugin_path, plugin->path);
1255                 mwindow->plugindb->remove(plugin);
1256                 remove(plugin_path);
1257                 char index_path[BCTEXTLEN];
1258                 mwindow->create_defaults_path(index_path, PLUGIN_FILE);
1259                 remove(index_path);
1260                 char picon_path[BCTEXTLEN];
1261                 FileSystem fs;
1262                 snprintf(picon_path, sizeof(picon_path), "%s/picon",
1263                         File::get_plugin_path());
1264                 char png_name[BCSTRLEN], png_path[BCTEXTLEN];
1265                 plugin->get_plugin_png_name(png_name);
1266                 fs.update(picon_path);
1267                 for( int i=0; i<fs.dir_list.total; ++i ) {
1268                         char *fs_path = fs.dir_list[i]->path;
1269                         if( !fs.is_dir(fs_path) ) continue;
1270                         snprintf(png_path, sizeof(picon_path), "%s/%s",
1271                                 fs_path, png_name);
1272                         remove(png_path);
1273                 }
1274                 delete plugin;  plugin = 0;
1275                 awindow->gui->async_update_assets();
1276         }
1277 }
1278
1279 AWindowRemovePlugin::
1280 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
1281  : BC_DialogThread()
1282 {
1283         this->awindow = awindow;
1284         this->plugin = plugin;
1285 }
1286
1287 AWindowRemovePlugin::
1288 ~AWindowRemovePlugin()
1289 {
1290         close_window();
1291 }
1292
1293 BC_Window* AWindowRemovePlugin::new_gui()
1294 {
1295         int x = awindow->gui->get_abs_cursor_x(0);
1296         int y = awindow->gui->get_abs_cursor_y(0);
1297         AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
1298         gui->create_objects();
1299         return gui;
1300 }
1301
1302 int AWindowGUI::keypress_event()
1303 {
1304         switch( get_keypress() ) {
1305         case 'w': case 'W':
1306                 if( ctrl_down() ) {
1307                         close_event();
1308                         return 1;
1309                 }
1310                 break;
1311         case DELETE:
1312                 if( shift_down() ) {
1313                         PluginServer* plugin = selected_plugin();
1314                         if( !plugin ) break;
1315                         remove_plugin = new AWindowRemovePlugin(awindow, plugin);
1316                         unlock_window();
1317                         remove_plugin->start();
1318                         lock_window();
1319                 }
1320         }
1321         return 0;
1322 }
1323
1324
1325
1326 int AWindowGUI::create_custom_xatoms()
1327 {
1328         UpdateAssetsXAtom = create_xatom("CWINDOWGUI_UPDATE_ASSETS");
1329         return 0;
1330 }
1331 int AWindowGUI::recieve_custom_xatoms(xatom_event *event)
1332 {
1333         if( event->message_type == UpdateAssetsXAtom ) {
1334                 update_assets();
1335                 return 1;
1336         }
1337         return 0;
1338 }
1339
1340 void AWindowGUI::async_update_assets()
1341 {
1342         xatom_event event;
1343         event.message_type = UpdateAssetsXAtom;
1344         send_custom_xatom(&event);
1345 }
1346
1347
1348 void AWindowGUI::update_folder_list()
1349 {
1350         for( int i = 0; i < folders.total; i++ ) {
1351                 AssetPicon *picon = (AssetPicon*)folders.values[i];
1352                 picon->in_use = 0;
1353         }
1354
1355 // Search assets for folders
1356         for( int i = 0; i < mwindow->edl->folders.total; i++ ) {
1357                 const char *folder = mwindow->edl->folders.values[i];
1358                 int exists = 0;
1359
1360                 for( int j = 0; j < folders.total; j++ ) {
1361                         AssetPicon *picon = (AssetPicon*)folders.values[j];
1362                         if( !strcasecmp(picon->get_text(), folder) ) {
1363                                 exists = 1;
1364                                 picon->in_use = 1;
1365                                 break;
1366                         }
1367                 }
1368
1369                 if( !exists ) {
1370                         int aw_folder = folder_number(folder);
1371                         if( aw_folder >= 0 ) {
1372                                 AssetPicon *picon = new AssetPicon(mwindow, this, aw_folder, 1);
1373                                 picon->create_objects();
1374                                 folders.append(picon);
1375                         }
1376                 }
1377         }
1378
1379 // Delete unused non-persistent folders
1380         for( int i=folders.total; --i>=0; ) {
1381                 AssetPicon *picon = (AssetPicon*)folders.values[i];
1382                 if( !picon->in_use && !picon->persistent ) {
1383                         delete picon;
1384                         folders.remove_number(i);
1385                 }
1386         }
1387 }
1388
1389 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
1390         int do_audio, int do_video, int is_realtime, int is_transition)
1391 {
1392         ArrayList<PluginServer*> plugin_list;
1393 // Get pointers to plugindb entries
1394         mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
1395                         0, plugin_list);
1396
1397         for( int i = 0; i < plugin_list.total; i++ ) {
1398                 PluginServer *server = plugin_list.values[i];
1399                 int visible = plugin_visibility & (1<<server->dir_idx);
1400                 if( !visible ) continue;
1401 // Create new listitem
1402                 AssetPicon *picon = new AssetPicon(mwindow, this, server);
1403                 picon->create_objects();
1404                 output->append(picon);
1405         }
1406 }
1407
1408 void AWindowGUI::create_label_folder()
1409 {
1410         Label *current;
1411         for( current = mwindow->edl->labels->first; current; current = NEXT ) {
1412                 AssetPicon *picon = new AssetPicon(mwindow, this, current);
1413                 picon->create_objects();
1414                 labellist.append(picon);
1415         }
1416 }
1417
1418
1419 void AWindowGUI::update_asset_list()
1420 {
1421         for( int i = 0; i < assets.total; i++ ) {
1422                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1423                 picon->in_use = 0;
1424         }
1425
1426 // Synchronize EDL clips
1427         for( int i=0; i<mwindow->edl->clips.size(); ++i ) {
1428                 int exists = 0;
1429
1430 // Look for clip in existing listitems
1431                 for( int j = 0; j < assets.total && !exists; j++ ) {
1432                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1433
1434                         if( picon->id == mwindow->edl->clips[i]->id ) {
1435                                 picon->edl = mwindow->edl->clips[i];
1436                                 picon->set_text(mwindow->edl->clips[i]->local_session->clip_title);
1437                                 exists = 1;
1438                                 picon->in_use = 1;
1439                         }
1440                 }
1441
1442 // Create new listitem
1443                 if( !exists ) {
1444                         AssetPicon *picon = new AssetPicon(mwindow,
1445                                 this, mwindow->edl->clips[i]);
1446                         picon->create_objects();
1447                         assets.append(picon);
1448                 }
1449         }
1450
1451 // Synchronize EDL assets
1452         for( Asset *current=mwindow->edl->assets->first; current; current=NEXT ) {
1453                 int exists = 0;
1454
1455 // Look for asset in existing listitems
1456                 for( int j = 0; j < assets.total && !exists; j++ ) {
1457                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1458
1459                         if( picon->id == current->id ) {
1460                                 picon->indexable = current;
1461                                 picon->in_use = 1;
1462                                 exists = 1;
1463                         }
1464                 }
1465
1466 // Create new listitem
1467                 if( !exists ) {
1468                         AssetPicon *picon = new AssetPicon(mwindow,
1469                                 this, current);
1470                         picon->create_objects();
1471                         assets.append(picon);
1472                 }
1473         }
1474
1475         mwindow->gui->lock_window("AWindowGUI::update_asset_list");
1476         mwindow->gui->default_message();
1477         mwindow->gui->unlock_window();
1478
1479 // Synchronize nested EDLs
1480         for( int i=0; i<mwindow->edl->nested_edls.size(); ++i ) {
1481                 int exists = 0;
1482                 EDL *nested_edl = mwindow->edl->nested_edls[i];
1483
1484 // Look for asset in existing listitems
1485                 for( int j=0; j<assets.total && !exists; ++j ) {
1486                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1487
1488                         if( picon->id == nested_edl->id ) {
1489                                 picon->indexable = nested_edl;
1490                                 picon->in_use = 1;
1491                                 exists = 1;
1492                         }
1493                 }
1494
1495 // Create new listitem
1496                 if( !exists ) {
1497                         AssetPicon *picon = new AssetPicon(mwindow,
1498                                 this, (Indexable*)nested_edl);
1499                         picon->create_objects();
1500                         assets.append(picon);
1501                 }
1502         }
1503
1504         for( int i = assets.size() - 1; i >= 0; i-- ) {
1505                 AssetPicon *picon = (AssetPicon*)assets.get(i);
1506                 if( !picon->in_use ) {
1507                         delete picon;
1508                         assets.remove_number(i);
1509                         continue;
1510                 }
1511                 if( !picon->indexable || !picon->indexable->is_asset ) continue;
1512                 struct stat st;
1513                 picon->mtime = !stat(picon->indexable->path, &st) ? st.st_mtime : 0;
1514         }
1515 }
1516
1517 void AWindowGUI::update_picon(Indexable *indexable)
1518 {
1519         VIcon *vicon = 0;
1520         for( int i = 0; i < assets.total; i++ ) {
1521                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1522                 if( picon->indexable == indexable ||
1523                     picon->edl == (EDL *)indexable ) {
1524                         char name[BCTEXTLEN];
1525                         FileSystem fs;
1526                         fs.extract_name(name, indexable->path);
1527                         picon->set_text(name);
1528                         vicon = picon->vicon;
1529                         break;
1530                 }
1531         }
1532         if( vicon ) {
1533                 stop_vicon_drawing();
1534                 vicon->clear_images();
1535                 vicon->reset(indexable->get_frame_rate());
1536                 start_vicon_drawing();
1537         }
1538 }
1539
1540 void AWindowGUI::sort_assets(int use_mtime)
1541 {
1542         switch( mwindow->edl->session->awindow_folder ) {
1543         case AW_AEFFECT_FOLDER:
1544                 sort_picons(&aeffects);
1545                 break;
1546         case AW_VEFFECT_FOLDER:
1547                 sort_picons(&veffects);
1548                 break;
1549         case AW_ATRANSITION_FOLDER:
1550                 sort_picons(&atransitions);
1551                 break;
1552         case AW_VTRANSITION_FOLDER:
1553                 sort_picons(&vtransitions);
1554                 break;
1555         case AW_LABEL_FOLDER:
1556                 sort_picons(&labellist);
1557                 break;
1558         default:
1559                 sort_picons(&assets, use_mtime);
1560         }
1561 // reset xyposition
1562         asset_list->update_format(asset_list->get_format(), 0);
1563         update_assets();
1564 }
1565
1566 void AWindowGUI::sort_folders()
1567 {
1568         sort_picons(&folders);
1569         folder_list->update_format(folder_list->get_format(), 0);
1570         update_assets();
1571 }
1572
1573 EDL *AWindowGUI::collect_proxy(Indexable *indexable)
1574 {
1575         Asset *proxy_asset = (Asset *)indexable;
1576         char path[BCTEXTLEN];
1577         int proxy_scale = mwindow->edl->session->proxy_scale;
1578         ProxyRender::from_proxy_path(path, proxy_asset, proxy_scale);
1579         Asset *unproxy_asset = mwindow->edl->assets->get_asset(path);
1580         if( !unproxy_asset || !unproxy_asset->channels ) return 0;
1581 // make a clip from proxy video tracks and unproxy audio tracks
1582         EDL *proxy_edl = new EDL(mwindow->edl);
1583         proxy_edl->create_objects();
1584         FileSystem fs;  fs.extract_name(path, proxy_asset->path);
1585         proxy_edl->set_path(path);
1586         strcpy(proxy_edl->local_session->clip_title, path);
1587         strcpy(proxy_edl->local_session->clip_notes, _("Proxy clip"));
1588         proxy_edl->session->video_tracks = proxy_asset->layers;
1589         proxy_edl->session->audio_tracks = unproxy_asset->channels;
1590         proxy_edl->create_default_tracks();
1591         double length = proxy_asset->frame_rate > 0 ?
1592                 (double)proxy_asset->video_length / proxy_asset->frame_rate :
1593                 1.0 / mwindow->edl->session->frame_rate;
1594         Track *current = proxy_edl->tracks->first;
1595         for( int vtrack=0; current; current=NEXT ) {
1596                 if( current->data_type != TRACK_VIDEO ) continue;
1597                 current->insert_asset(proxy_asset, 0, length, 0, vtrack++);
1598         }
1599         length = (double)unproxy_asset->audio_length / unproxy_asset->sample_rate;
1600         current = proxy_edl->tracks->first;
1601         for( int atrack=0; current; current=NEXT ) {
1602                 if( current->data_type != TRACK_AUDIO ) continue;
1603                 current->insert_asset(unproxy_asset, 0, length, 0, atrack++);
1604         }
1605         return proxy_edl;
1606 }
1607
1608
1609 void AWindowGUI::collect_assets(int proxy)
1610 {
1611         mwindow->session->drag_assets->remove_all();
1612         mwindow->session->drag_clips->remove_all();
1613         mwindow->session->clear_drag_proxy();
1614         int i = 0;  AssetPicon *result;
1615         while( (result = (AssetPicon*)asset_list->get_selection(0, i++)) != 0 ) {
1616                 Indexable *indexable = result->indexable;  EDL *drag_edl;
1617                 if( proxy && (drag_edl=collect_proxy(indexable)) ) {
1618                         mwindow->session->drag_clips->append(drag_edl);
1619                         mwindow->session->drag_proxy->append(drag_edl);
1620                         continue;
1621                 }
1622                 if( indexable ) {
1623                         mwindow->session->drag_assets->append(indexable);
1624                         continue;
1625                 }
1626                 if( result->edl ) {
1627                         mwindow->session->drag_clips->append(result->edl);
1628                         continue;
1629                 }
1630         }
1631 }
1632
1633 void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst,
1634         ArrayList<BC_ListBoxItem*> *src, int folder)
1635 {
1636 // Remove current pointers
1637         dst[0].remove_all();
1638         dst[1].remove_all_objects();
1639
1640 // Create new pointers
1641         for( int i = 0; i < src->total; i++ ) {
1642                 AssetPicon *picon = (AssetPicon*)src->values[i];
1643                 if( folder < 0 ||
1644                     (picon->indexable && picon->indexable->awindow_folder == folder) ||
1645                     (picon->edl && picon->edl->local_session->awindow_folder == folder) ) {
1646                         const char *text = search_text->get_text();
1647                         int hidden = text && text[0] && !bstrcasestr(picon->get_text(), text);
1648                         if( picon->vicon ) picon->vicon->hidden = hidden;
1649                         if( hidden ) continue;
1650                         BC_ListBoxItem *item2, *item1;
1651                         dst[0].append(item1 = picon);
1652                         if( picon->edl )
1653                                 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
1654                         else
1655                         if( picon->label && picon->label->textstr )
1656                                 dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr));
1657                         else if( picon->mtime ) {
1658                                 char date_time[BCSTRLEN];
1659                                 struct tm stm;  localtime_r(&picon->mtime, &stm);
1660                                 sprintf(date_time,"%04d.%02d.%02d %02d:%02d:%02d",
1661                                          stm.tm_year+1900, stm.tm_mon+1, stm.tm_mday,
1662                                          stm.tm_hour, stm.tm_min, stm.tm_sec);
1663                                 dst[1].append(item2 = new BC_ListBoxItem(date_time));
1664                         }
1665                         else
1666                                 dst[1].append(item2 = new BC_ListBoxItem(""));
1667                         item1->set_autoplace_text(1);  item1->set_autoplace_icon(1);
1668                         item2->set_autoplace_text(1);  item2->set_autoplace_icon(1);
1669                 }
1670         }
1671 }
1672
1673 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src, int use_mtime)
1674 {
1675         int done = 0, changed = 0;
1676         while( !done ) {
1677                 done = 1;
1678                 for( int i=0; i<src->total-1; ++i ) {
1679                         AssetPicon *item1 = (AssetPicon *)src->values[i];
1680                         AssetPicon *item2 = (AssetPicon *)src->values[i + 1];
1681                         if( use_mtime ? item1->mtime > item2->mtime :
1682                             strcmp(item1->get_text(), item2->get_text()) > 0 ) {
1683                                 src->values[i + 1] = item1;
1684                                 src->values[i] = item2;
1685                                 done = 0;  changed = 1;
1686                         }
1687                 }
1688         }
1689         if( changed ) {
1690                 for( int i=0; i<src->total; ++i ) {
1691                         AssetPicon *item = (AssetPicon *)src->values[i];
1692                         item->set_autoplace_icon(1);
1693                         item->set_autoplace_text(1);
1694                 }
1695         }
1696 }
1697
1698
1699 void AWindowGUI::filter_displayed_assets()
1700 {
1701         //allow_iconlisting = 1;
1702         asset_titles[0] = C_("Title");
1703         asset_titles[1] = _("Comments");
1704
1705         switch( mwindow->edl->session->awindow_folder ) {
1706         case AW_AEFFECT_FOLDER:
1707                 copy_picons(displayed_assets, &aeffects, AW_NO_FOLDER);
1708                 break;
1709         case AW_VEFFECT_FOLDER:
1710                 copy_picons(displayed_assets, &veffects, AW_NO_FOLDER);
1711                 break;
1712         case AW_ATRANSITION_FOLDER:
1713                 copy_picons(displayed_assets, &atransitions, AW_NO_FOLDER);
1714                 break;
1715         case AW_VTRANSITION_FOLDER:
1716                 copy_picons(displayed_assets, &vtransitions, AW_NO_FOLDER);
1717                 break;
1718         case AW_LABEL_FOLDER:
1719                 copy_picons(displayed_assets, &labellist, AW_NO_FOLDER);
1720                 asset_titles[0] = _("Time Stamps");
1721                 asset_titles[1] = C_("Title");
1722                 //allow_iconlisting = 0;
1723                 break;
1724         default:
1725                 copy_picons(displayed_assets, &assets, mwindow->edl->session->awindow_folder);
1726                 break;
1727         }
1728
1729         // Ensure the current folder icon is highlighted
1730         int selected_folder = mwindow->edl->session->awindow_folder;
1731         for( int i = 0; i < folders.total; i++ ) {
1732                 AssetPicon *folder_item = (AssetPicon *)folders.values[i];
1733                 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
1734                 folder_item->set_selected(selected);
1735         }
1736 }
1737
1738
1739 void AWindowGUI::update_assets()
1740 {
1741         stop_vicon_drawing();
1742         update_folder_list();
1743         update_asset_list();
1744         labellist.remove_all_objects();
1745         create_label_folder();
1746
1747         if( displayed_folder != mwindow->edl->session->awindow_folder )
1748                 search_text->clear();
1749         filter_displayed_assets();
1750
1751         if( mwindow->edl->session->folderlist_format != folder_list->get_format() ) {
1752                 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
1753         }
1754         int folder_xposition = folder_list->get_xposition();
1755         int folder_yposition = folder_list->get_yposition();
1756         folder_list->update(&folders, 0, 0, 1, folder_xposition, folder_yposition, -1);
1757
1758         if( mwindow->edl->session->assetlist_format != asset_list->get_format() ) {
1759                 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
1760         }
1761         int asset_xposition = asset_list->get_xposition();
1762         int asset_yposition = asset_list->get_yposition();
1763         if( displayed_folder != mwindow->edl->session->awindow_folder ) {
1764                 displayed_folder = mwindow->edl->session->awindow_folder;
1765                 asset_xposition = asset_yposition = 0;
1766         }
1767         asset_list->update(displayed_assets, asset_titles,
1768                 mwindow->edl->session->asset_columns, ASSET_COLUMNS,
1769                 asset_xposition, asset_yposition, -1, 0);
1770         asset_list->center_selection();
1771
1772         flush();
1773         start_vicon_drawing();
1774         return;
1775 }
1776
1777 void AWindowGUI::update_effects()
1778 {
1779         aeffects.remove_all_objects();
1780         create_persistent_folder(&aeffects, 1, 0, 1, 0);
1781         veffects.remove_all_objects();
1782         create_persistent_folder(&veffects, 0, 1, 1, 0);
1783         atransitions.remove_all_objects();
1784         create_persistent_folder(&atransitions, 1, 0, 0, 1);
1785         vtransitions.remove_all_objects();
1786         create_persistent_folder(&vtransitions, 0, 1, 0, 1);
1787 }
1788
1789 int AWindowGUI::folder_number(const char *name)
1790 {
1791         for( int i = 0; i < AWINDOW_FOLDERS; i++ ) {
1792                 if( !strcasecmp(name, folder_names[i]) ) return i;
1793         }
1794         return AW_NO_FOLDER;
1795 }
1796
1797 int AWindowGUI::drag_motion()
1798 {
1799         if( get_hidden() ) return 0;
1800
1801         int result = 0;
1802         return result;
1803 }
1804
1805 int AWindowGUI::drag_stop()
1806 {
1807         if( get_hidden() ) return 0;
1808         return 0;
1809 }
1810
1811 Indexable* AWindowGUI::selected_asset()
1812 {
1813         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1814         return picon ? picon->indexable : 0;
1815 }
1816
1817 PluginServer* AWindowGUI::selected_plugin()
1818 {
1819         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1820         return picon ? picon->plugin : 0;
1821 }
1822
1823 AssetPicon* AWindowGUI::selected_folder()
1824 {
1825         AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
1826         return picon;
1827 }
1828
1829
1830
1831
1832
1833
1834
1835
1836 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1837  : BC_SubWindow(x, y, w, h)
1838 {
1839         this->mwindow = mwindow;
1840         this->gui = gui;
1841 }
1842 AWindowDivider::~AWindowDivider()
1843 {
1844 }
1845
1846 int AWindowDivider::button_press_event()
1847 {
1848         if( is_event_win() && cursor_inside() ) {
1849                 mwindow->session->current_operation = DRAG_PARTITION;
1850                 return 1;
1851         }
1852         return 0;
1853 }
1854
1855 int AWindowDivider::cursor_motion_event()
1856 {
1857         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1858                 int wmin = 25;
1859                 int wmax = mwindow->session->awindow_w - mwindow->theme->adivider_w - wmin;
1860                 int fw = gui->get_relative_cursor_x();
1861                 if( fw > wmax ) fw = wmax;
1862                 if( fw < wmin ) fw = wmin;
1863                 mwindow->session->afolders_w = fw;
1864                 mwindow->theme->get_awindow_sizes(gui);
1865                 gui->reposition_objects();
1866                 gui->flush();
1867         }
1868         return 0;
1869 }
1870
1871 int AWindowDivider::button_release_event()
1872 {
1873         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1874                 mwindow->session->current_operation = NO_OPERATION;
1875                 return 1;
1876         }
1877         return 0;
1878 }
1879
1880
1881
1882
1883
1884
1885 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1886  : BC_ListBox(x, y, w, h,
1887                 mwindow->edl->session->folderlist_format == ASSETS_ICONS ?
1888                         LISTBOX_ICONS : LISTBOX_TEXT,
1889                 &gui->folders,    // Each column has an ArrayList of BC_ListBoxItems.
1890                 0,                // Titles for columns.  Set to 0 for no titles
1891                 0,                // width of each column
1892                 1,                // Total columns.
1893                 0,                // Pixel of top of window.
1894                 0,                // If this listbox is a popup window
1895                 LISTBOX_SINGLE,   // Select one item or multiple items
1896                 ICON_TOP,         // Position of icon relative to text of each item
1897                 1)                // Allow drags
1898 {
1899         this->mwindow = mwindow;
1900         this->gui = gui;
1901         set_drag_scroll(0);
1902 }
1903
1904 AWindowFolders::~AWindowFolders()
1905 {
1906 }
1907
1908 int AWindowFolders::selection_changed()
1909 {
1910         AssetPicon *picon = (AssetPicon*)get_selection(0, 0);
1911         if( picon ) {
1912                 gui->stop_vicon_drawing();
1913
1914                 if( get_button_down() && get_buttonpress() == 3 ) {
1915                         gui->folderlist_menu->update_titles();
1916                         gui->folderlist_menu->activate_menu();
1917                 }
1918
1919                 mwindow->edl->session->awindow_folder = picon->foldernum;
1920                 gui->asset_list->draw_background();
1921                 gui->async_update_assets();
1922
1923                 gui->start_vicon_drawing();
1924         }
1925         return 1;
1926 }
1927
1928 int AWindowFolders::button_press_event()
1929 {
1930         int result = 0;
1931
1932         result = BC_ListBox::button_press_event();
1933
1934         if( !result ) {
1935                 if( get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1936                         gui->folderlist_menu->update_titles();
1937                         gui->folderlist_menu->activate_menu();
1938                         result = 1;
1939                 }
1940         }
1941
1942
1943         return result;
1944 }
1945
1946
1947
1948
1949
1950
1951
1952 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1953  : BC_ListBox(x, y, w, h,
1954                 (mwindow->edl->session->assetlist_format == ASSETS_ICONS && gui->allow_iconlisting ) ?
1955                         LISTBOX_ICONS : LISTBOX_TEXT,
1956                 &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
1957                 gui->asset_titles,// Titles for columns.  Set to 0 for no titles
1958                 mwindow->edl->session->asset_columns, // width of each column
1959                 1,                // Total columns.
1960                 0,                // Pixel of top of window.
1961                 0,                // If this listbox is a popup window
1962                 LISTBOX_MULTIPLE, // Select one item or multiple items
1963                 ICON_TOP,         // Position of icon relative to text of each item
1964                 -1)               // Allow drags, require shift for scrolling
1965 {
1966         this->mwindow = mwindow;
1967         this->gui = gui;
1968         set_drag_scroll(0);
1969         set_scroll_stretch(1, 1);
1970 }
1971
1972 AWindowAssets::~AWindowAssets()
1973 {
1974 }
1975
1976 int AWindowAssets::button_press_event()
1977 {
1978         int result = 0;
1979
1980         result = BC_ListBox::button_press_event();
1981
1982         if( !result && get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1983                 BC_ListBox::deactivate_selection();
1984                 int folder = mwindow->edl->session->awindow_folder;
1985                 switch( folder ) {
1986                 case AW_AEFFECT_FOLDER:
1987                 case AW_VEFFECT_FOLDER:
1988                 case AW_ATRANSITION_FOLDER:
1989                 case AW_VTRANSITION_FOLDER:
1990                         gui->effectlist_menu->update();
1991                         gui->effectlist_menu->activate_menu();
1992                         break;
1993                 case AW_LABEL_FOLDER:
1994                         gui->labellist_menu->update();
1995                         gui->labellist_menu->activate_menu();
1996                         break;
1997                 case AW_CLIP_FOLDER:
1998                         gui->cliplist_menu->update();
1999                         gui->cliplist_menu->activate_menu();
2000                         break;
2001                 case AW_PROXY_FOLDER:
2002                         gui->proxylist_menu->update();
2003                         gui->proxylist_menu->activate_menu();
2004                         break;
2005                 case AW_MEDIA_FOLDER:
2006                         gui->assetlist_menu->update_titles(folder==AW_MEDIA_FOLDER);
2007                         gui->assetlist_menu->activate_menu();
2008                         break;
2009                 }
2010                 result = 1;
2011         }
2012
2013         return result;
2014 }
2015
2016
2017 int AWindowAssets::handle_event()
2018 {
2019         AssetPicon *asset_picon = (AssetPicon *)get_selection(0, 0);
2020         if( !asset_picon ) return 0;
2021         switch( mwindow->edl->session->awindow_folder ) {
2022         case AW_AEFFECT_FOLDER:
2023         case AW_VEFFECT_FOLDER:
2024         case AW_ATRANSITION_FOLDER:
2025         case AW_VTRANSITION_FOLDER: return 1;
2026         }
2027         VWindow *vwindow = mwindow->vwindows.size() > DEFAULT_VWINDOW ?
2028                 mwindow->vwindows.get(DEFAULT_VWINDOW) : 0;
2029         if( !vwindow || !vwindow->is_running() ) return 1;
2030
2031         if( asset_picon->indexable )
2032                 vwindow->change_source(asset_picon->indexable);
2033         else if( asset_picon->edl )
2034                 vwindow->change_source(asset_picon->edl);
2035         return 1;
2036 }
2037
2038 int AWindowAssets::selection_changed()
2039 {
2040 // Show popup window
2041         AssetPicon *item;
2042         if( get_button_down() && get_buttonpress() == 3 &&
2043             (item = (AssetPicon*)get_selection(0, 0)) ) {
2044                 int folder = mwindow->edl->session->awindow_folder;
2045                 switch( folder ) {
2046                 case AW_AEFFECT_FOLDER:
2047                 case AW_VEFFECT_FOLDER:
2048                 case AW_ATRANSITION_FOLDER:
2049                 case AW_VTRANSITION_FOLDER:
2050                         gui->effectlist_menu->update();
2051                         gui->effectlist_menu->activate_menu();
2052                         break;
2053                 case AW_LABEL_FOLDER:
2054                         if( !item->label ) break;
2055                         gui->label_menu->activate_menu();
2056                         break;
2057                 case AW_CLIP_FOLDER:
2058                         if( !item->indexable && !item->edl ) break;
2059                         gui->clip_menu->update();
2060                         gui->clip_menu->activate_menu();
2061                         break;
2062                 case AW_PROXY_FOLDER:
2063                         if( !item->indexable && !item->edl ) break;
2064                         gui->proxy_menu->update();
2065                         gui->proxy_menu->activate_menu();
2066                         break;
2067                 default:
2068                         if( !item->indexable && !item->edl ) break;
2069                         gui->asset_menu->update();
2070                         gui->asset_menu->activate_menu();
2071                         break;
2072                 }
2073
2074                 BC_ListBox::deactivate_selection();
2075                 return 1;
2076         }
2077         else if( gui->vicon_drawing &&
2078                  get_button_down() && get_buttonpress() == 1 &&
2079                  (item = (AssetPicon*)get_selection(0, 0)) ) {
2080                 VIcon *vicon = 0;
2081                 if( !gui->vicon_thread->viewing ) {
2082                         vicon = item->vicon;
2083                 }
2084                 gui->vicon_thread->set_view_popup(vicon);
2085
2086         }
2087         return 0;
2088 }
2089
2090 void AWindowAssets::draw_background()
2091 {
2092         clear_box(0,0,get_w(),get_h(),get_bg_surface());
2093         set_color(BC_WindowBase::get_resources()->audiovideo_color);
2094         set_font(LARGEFONT);
2095         int aw_folder = mwindow->edl->session->awindow_folder;
2096         if( aw_folder < 0 ) return;
2097         const char *aw_name = _(AWindowGUI::folder_names[aw_folder]);
2098         draw_text(get_w() - get_text_width(LARGEFONT, aw_name) - 4, 30,
2099                 aw_name, -1, get_bg_surface());
2100 }
2101
2102 int AWindowAssets::drag_start_event()
2103 {
2104         int collect_pluginservers = 0;
2105         int collect_assets = 0, proxy = 0;
2106
2107         if( BC_ListBox::drag_start_event() ) {
2108                 switch( mwindow->edl->session->awindow_folder ) {
2109                 case AW_AEFFECT_FOLDER:
2110                         mwindow->session->current_operation = DRAG_AEFFECT;
2111                         collect_pluginservers = 1;
2112                         break;
2113                 case AW_VEFFECT_FOLDER:
2114                         mwindow->session->current_operation = DRAG_VEFFECT;
2115                         collect_pluginservers = 1;
2116                         break;
2117                 case AW_ATRANSITION_FOLDER:
2118                         mwindow->session->current_operation = DRAG_ATRANSITION;
2119                         collect_pluginservers = 1;
2120                         break;
2121                 case AW_VTRANSITION_FOLDER:
2122                         mwindow->session->current_operation = DRAG_VTRANSITION;
2123                         collect_pluginservers = 1;
2124                         break;
2125                 case AW_LABEL_FOLDER:
2126                         // do nothing!
2127                         break;
2128                 case AW_PROXY_FOLDER:
2129                         proxy = 1;
2130                         // fall thru
2131                 case AW_MEDIA_FOLDER:
2132                 default:
2133                         mwindow->session->current_operation = DRAG_ASSET;
2134                         collect_assets = 1;
2135                         break;
2136                 }
2137
2138                 if( collect_pluginservers ) {
2139                         int i = 0;
2140                         mwindow->session->drag_pluginservers->remove_all();
2141                         while(1)
2142                         {
2143                                 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
2144                                 if( !result ) break;
2145
2146                                 mwindow->session->drag_pluginservers->append(result->plugin);
2147                         }
2148                 }
2149
2150                 if( collect_assets ) {
2151                         gui->collect_assets(proxy);
2152                 }
2153
2154                 return 1;
2155         }
2156         return 0;
2157 }
2158
2159 int AWindowAssets::drag_motion_event()
2160 {
2161         BC_ListBox::drag_motion_event();
2162         unlock_window();
2163
2164         mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2165         mwindow->gui->drag_motion();
2166         mwindow->gui->unlock_window();
2167
2168         for( int i = 0; i < mwindow->vwindows.size(); i++ ) {
2169                 VWindow *vwindow = mwindow->vwindows.get(i);
2170                 if( !vwindow->is_running() ) continue;
2171                 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2172                 vwindow->gui->drag_motion();
2173                 vwindow->gui->unlock_window();
2174         }
2175
2176         mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2177         mwindow->cwindow->gui->drag_motion();
2178         mwindow->cwindow->gui->unlock_window();
2179
2180         lock_window("AWindowAssets::drag_motion_event");
2181         return 0;
2182 }
2183
2184 int AWindowAssets::drag_stop_event()
2185 {
2186         int result = 0;
2187
2188         result = gui->drag_stop();
2189
2190         unlock_window();
2191
2192         if( !result ) {
2193                 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2194                 result = mwindow->gui->drag_stop();
2195                 mwindow->gui->unlock_window();
2196         }
2197
2198         if( !result ) {
2199                 for( int i = 0; !result && i < mwindow->vwindows.size(); i++ ) {
2200                         VWindow *vwindow = mwindow->vwindows.get(i);
2201                         if( !vwindow ) continue;
2202                         if( !vwindow->is_running() ) continue;
2203                         if( vwindow->gui->is_hidden() ) continue;
2204                         vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2205                         if( vwindow->gui->cursor_above() &&
2206                             vwindow->gui->get_cursor_over_window() ) {
2207                                 result = vwindow->gui->drag_stop();
2208                         }
2209                         vwindow->gui->unlock_window();
2210                 }
2211         }
2212
2213         if( !result ) {
2214                 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2215                 result = mwindow->cwindow->gui->drag_stop();
2216                 mwindow->cwindow->gui->unlock_window();
2217         }
2218
2219         lock_window("AWindowAssets::drag_stop_event");
2220
2221         if( result )
2222                 get_drag_popup()->set_animation(0);
2223
2224         BC_ListBox::drag_stop_event();
2225 // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
2226         mwindow->session->current_operation = ::NO_OPERATION;
2227         mwindow->session->clear_drag_proxy();
2228
2229         return 1;
2230 }
2231
2232 int AWindowAssets::column_resize_event()
2233 {
2234         mwindow->edl->session->asset_columns[0] = get_column_width(0);
2235         mwindow->edl->session->asset_columns[1] = get_column_width(1);
2236         return 1;
2237 }
2238
2239 int AWindowAssets::focus_in_event()
2240 {
2241         gui->start_vicon_drawing();
2242         return 0;
2243 }
2244
2245 int AWindowAssets::focus_out_event()
2246 {
2247         gui->stop_vicon_drawing();
2248         return BC_ListBox::focus_out_event();
2249 }
2250
2251 AWindowSearchTextBox::AWindowSearchTextBox(AWindowSearchText *search_text, int x, int y, int w)
2252  : BC_TextBox(x, y, w, 1, "")
2253 {
2254         this->search_text = search_text;
2255 }
2256
2257 int AWindowSearchTextBox::handle_event()
2258 {
2259         return search_text->handle_event();
2260 }
2261
2262 AWindowSearchText::AWindowSearchText(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2263 {
2264         this->mwindow = mwindow;
2265         this->gui = gui;
2266         this->x = x;
2267         this->y = y;
2268 }
2269
2270 void AWindowSearchText::create_objects()
2271 {
2272         int x1 = x, y1 = y, margin = 10;
2273         gui->add_subwindow(text_title = new BC_Title(x1, y1, _("Search:")));
2274         x1 += text_title->get_w() + margin;
2275         int w1 = gui->get_w() - x1 - 2*margin;
2276         gui->add_subwindow(text_box = new AWindowSearchTextBox(this, x1, y1, w1));
2277 }
2278
2279 int AWindowSearchText::handle_event()
2280 {
2281         gui->async_update_assets();
2282         return 1;
2283 }
2284
2285 int AWindowSearchText::get_w()
2286 {
2287         return text_box->get_w() + text_title->get_w() + 10;
2288 }
2289
2290 int AWindowSearchText::get_h()
2291 {
2292         return bmax(text_box->get_h(),text_title->get_h());
2293 }
2294
2295 void AWindowSearchText::reposition_window(int x, int y, int w)
2296 {
2297         int x1 = x, y1 = y, margin = 10;
2298         text_title->reposition_window(x1, y1);
2299         x1 += text_title->get_w() + margin;
2300         int w1 = gui->get_w() - x1 - 2*margin;
2301         text_box->reposition_window(x1, y1, w1);
2302 }
2303
2304 const char *AWindowSearchText::get_text()
2305 {
2306         return text_box->get_text();
2307 }
2308
2309 void AWindowSearchText::clear()
2310 {
2311         text_box->update("");
2312 }
2313
2314 AWindowNewFolder::AWindowNewFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2315  : BC_Button(x, y, mwindow->theme->newbin_data)
2316 {
2317         this->mwindow = mwindow;
2318         this->gui = gui;
2319         set_tooltip(_("New bin"));
2320 }
2321
2322 int AWindowNewFolder::handle_event()
2323 {
2324         gui->newfolder_thread->start_new_folder();
2325         return 1;
2326 }
2327
2328 AWindowDeleteFolder::AWindowDeleteFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2329  : BC_Button(x, y, mwindow->theme->deletebin_data)
2330 {
2331         this->mwindow = mwindow;
2332         this->gui = gui;
2333         set_tooltip(_("Delete bin"));
2334 }
2335
2336 int AWindowDeleteFolder::handle_event()
2337 {
2338         if( gui->folder_list->get_selection(0, 0) ) {
2339                 BC_ListBoxItem *folder = gui->folder_list->get_selection(0, 0);
2340                 mwindow->delete_folder(folder->get_text());
2341         }
2342         return 1;
2343 }
2344
2345 AWindowRenameFolder::AWindowRenameFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2346  : BC_Button(x, y, mwindow->theme->renamebin_data)
2347 {
2348         this->mwindow = mwindow;
2349         this->gui = gui;
2350         set_tooltip(_("Rename bin"));
2351 }
2352
2353 int AWindowRenameFolder::handle_event()
2354 {
2355         return 1;
2356 }
2357
2358 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2359  : BC_Button(x, y, mwindow->theme->deletedisk_data)
2360 {
2361         this->mwindow = mwindow;
2362         this->gui = gui;
2363         set_tooltip(_("Delete asset from disk"));
2364 }
2365
2366 int AWindowDeleteDisk::handle_event()
2367 {
2368         return 1;
2369 }
2370
2371 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2372  : BC_Button(x, y, mwindow->theme->deleteproject_data)
2373 {
2374         this->mwindow = mwindow;
2375         this->gui = gui;
2376         set_tooltip(_("Delete asset from project"));
2377 }
2378
2379 int AWindowDeleteProject::handle_event()
2380 {
2381         return 1;
2382 }
2383
2384 // AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2385 //  : BC_Button(x, y, mwindow->theme->infoasset_data)
2386 // {
2387 //      this->mwindow = mwindow;
2388 //      this->gui = gui;
2389 //      set_tooltip(_("Edit information on asset"));
2390 // }
2391 // 
2392 // int AWindowInfo::handle_event()
2393 // {
2394 //      int cur_x, cur_y;
2395 //      gui->get_abs_cursor(cur_x, cur_y, 0);
2396 //      gui->awindow->asset_edit->edit_asset(gui->selected_asset(), cur_x, cur_y);
2397 //      return 1;
2398 // }
2399
2400 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2401  : BC_Button(x, y, mwindow->theme->redrawindex_data)
2402 {
2403         this->mwindow = mwindow;
2404         this->gui = gui;
2405         set_tooltip(_("Redraw index"));
2406 }
2407
2408 int AWindowRedrawIndex::handle_event()
2409 {
2410         return 1;
2411 }
2412
2413 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2414  : BC_Button(x, y, mwindow->theme->pasteasset_data)
2415 {
2416         this->mwindow = mwindow;
2417         this->gui = gui;
2418         set_tooltip(_("Paste asset on recordable tracks"));
2419 }
2420
2421 int AWindowPaste::handle_event()
2422 {
2423         return 1;
2424 }
2425
2426 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2427  : BC_Button(x, y, mwindow->theme->appendasset_data)
2428 {
2429         this->mwindow = mwindow;
2430         this->gui = gui;
2431         set_tooltip(_("Append asset in new tracks"));
2432 }
2433
2434 int AWindowAppend::handle_event()
2435 {
2436         return 1;
2437 }
2438
2439 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2440  : BC_Button(x, y, mwindow->theme->viewasset_data)
2441 {
2442         this->mwindow = mwindow;
2443         this->gui = gui;
2444         set_tooltip(_("View asset"));
2445 }
2446
2447 int AWindowView::handle_event()
2448 {
2449         return 1;
2450 }
2451
2452 AddTools::AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, const char *title)
2453  : BC_PopupMenu(x, y, BC_Title::calculate_w(gui, title, MEDIUMFONT)+8, title, -1, 0, 4)
2454 {
2455         this->mwindow = mwindow;
2456         this->gui = gui;
2457 }
2458
2459 void AddTools::create_objects()
2460 {
2461         uint64_t vis = 0;
2462         add_item(new AddPluginItem(this, "ladspa", PLUGIN_LADSPA_ID));
2463         vis |= 1 << PLUGIN_LADSPA_ID;
2464         add_item(new AddPluginItem(this, "ffmpeg", PLUGIN_FFMPEG_ID));
2465         vis |= 1 << PLUGIN_FFMPEG_ID;
2466         for( int i=0; i<MWindow::plugindb->size(); ++i ) {
2467                 PluginServer *plugin = MWindow::plugindb->get(i);
2468                 if( !plugin->audio && !plugin->video ) continue;
2469                 int idx = plugin->dir_idx;
2470                 uint32_t msk = 1 << idx;
2471                 if( (msk & vis) != 0 ) continue;
2472                 vis |= msk;
2473                 char parent[BCTEXTLEN];
2474                 strcpy(parent, plugin->path);
2475                 char *bp = strrchr(parent, '/');
2476                 if( bp ) { *bp = 0;  bp = strrchr(parent, '/'); }
2477                 if( !bp ) bp = parent; else ++bp;
2478                 add_item(new AddPluginItem(this, bp, idx));
2479         }
2480 }
2481
2482 #if 0
2483 // plugin_dirs list from toplevel makefile include plugin_defs
2484 N_("ladspa")
2485 N_("ffmpeg")
2486 N_("audio_tools")
2487 N_("audio_transitions")
2488 N_("blending")
2489 N_("colors")
2490 N_("exotic")
2491 N_("transforms")
2492 N_("tv_effects")
2493 N_("video_tools")
2494 N_("video_transitions")
2495 #endif
2496
2497 AddPluginItem::AddPluginItem(AddTools *menu, char const *text, int idx)
2498  : BC_MenuItem(_(text))
2499 {
2500         this->menu = menu;
2501         this->idx = idx;
2502         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2503         int chk = (msk & vis) ? 1 : 0;
2504         set_checked(chk);
2505 }
2506
2507 int AddPluginItem::handle_event()
2508 {
2509         int chk = get_checked() ^ 1;
2510         set_checked(chk);
2511         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2512         menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
2513         menu->gui->update_effects();
2514         menu->gui->save_defaults(menu->mwindow->defaults);
2515         menu->gui->async_update_assets();
2516         return 1;
2517 }
2518
2519 AVIconDrawing::AVIconDrawing(AWindowGUI *agui, int x, int y, VFrame **images)
2520  : BC_Toggle(x, y, images, agui->vicon_drawing)
2521 {
2522         this->agui = agui;
2523         set_tooltip(_("draw vicons"));
2524 }
2525
2526 void AVIconDrawing::calculate_geometry(AWindowGUI *agui, VFrame **images, int *ww, int *hh)
2527 {
2528         int text_line = -1, toggle_x = -1, toggle_y = -1;
2529         int text_x = -1, text_y = -1, text_w = -1, text_h = -1;
2530         BC_Toggle::calculate_extents(agui, images, 1,
2531                 &text_line, ww, hh, &toggle_x, &toggle_y,
2532                 &text_x, &text_y, &text_w, &text_h, "", MEDIUMFONT);
2533 }
2534
2535 AVIconDrawing::~AVIconDrawing()
2536 {
2537 }
2538
2539 int AVIconDrawing::handle_event()
2540 {
2541         agui->vicon_drawing = get_value();
2542         if( agui->vicon_drawing )
2543                 agui->start_vicon_drawing();
2544         else
2545                 agui->stop_vicon_drawing();
2546         return 1;
2547 }
2548
2549
2550 AWindowListFormat::AWindowListFormat(MWindow *mwindow, AWindowGUI *gui)
2551  : BC_MenuItem("")
2552 {
2553         this->mwindow = mwindow;
2554         this->gui = gui;
2555 }
2556
2557 int AWindowListFormat::handle_event()
2558 {
2559         gui->stop_vicon_drawing();
2560
2561         EDLSession *session = mwindow->edl->session;
2562         switch( session->assetlist_format ) {
2563         case ASSETS_TEXT:
2564                 session->assetlist_format = ASSETS_ICONS;
2565                 break;
2566         case ASSETS_ICONS:
2567                 session->assetlist_format = ASSETS_TEXT;
2568                 break;
2569         }
2570
2571         gui->asset_list->update_format(session->assetlist_format, 1);
2572         if( !mwindow->awindow->gui->allow_iconlisting ) {
2573                 mwindow->edl->session->assetlist_format = ASSETS_TEXT;
2574         }
2575
2576         gui->start_vicon_drawing();
2577         return 1;
2578 }
2579
2580 void AWindowListFormat::update()
2581 {
2582         set_text(mwindow->edl->session->assetlist_format == ASSETS_TEXT ?
2583                 (char*)_("Display icons") : (char*)_("Display text"));
2584 }
2585
2586 AWindowListSort::AWindowListSort(MWindow *mwindow, AWindowGUI *gui)
2587  : BC_MenuItem(_("Sort items"))
2588 {
2589         this->mwindow = mwindow;
2590         this->gui = gui;
2591 }
2592
2593 int AWindowListSort::handle_event()
2594 {
2595         gui->sort_assets(0);
2596         return 1;
2597 }
2598