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