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