p/s proxy icon, rework window locks, segv in close_mixers + exportedl, ffmpeg default...
[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                                         icon_vframe = new VFrame(0,
655                                                 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
656                                         icon_vframe->transfer_from(gui->temp_picon);
657                                         if( clip_icon[0] ) icon_vframe->write_png(clip_icon_path);
658                                 }
659                                 else {
660                                         pixmap_w = icon_vframe->get_w();
661                                         pixmap_h = icon_vframe->get_h();
662                                 }
663                                 gui->lock_window("AssetPicon::create_objects 0");
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         folder_lock = new Mutex("AWindowGUI::folder_lock");
851 }
852
853 AWindowGUI::~AWindowGUI()
854 {
855         assets.remove_all_objects();
856         folders.remove_all_objects();
857         aeffects.remove_all_objects();
858         veffects.remove_all_objects();
859         atransitions.remove_all_objects();
860         vtransitions.remove_all_objects();
861         labellist.remove_all_objects();
862         displayed_assets[1].remove_all_objects();
863
864         delete vicon_thread;
865         delete vicon_audio;
866         delete newfolder_thread;
867
868         delete search_text;
869         delete temp_picon;
870         delete remove_plugin;
871
872         delete file_vframe;             delete file_icon;
873         delete folder_vframe;           delete folder_icon;
874         delete audio_vframe;            delete audio_icon;
875         delete video_vframe;            delete video_icon;
876         delete label_vframe;            delete label_icon;
877         delete clip_vframe;             delete clip_icon;
878         delete aeffect_folder_vframe;   delete aeffect_folder_icon;
879         delete atransition_folder_vframe; delete atransition_folder_icon;
880         delete veffect_folder_vframe;   delete veffect_folder_icon;
881         delete vtransition_folder_vframe; delete vtransition_folder_icon;
882         delete clip_folder_vframe;      delete clip_folder_icon;
883         delete label_folder_vframe;     delete label_folder_icon;
884         delete media_folder_vframe;     delete media_folder_icon;
885         delete proxy_folder_vframe;     delete proxy_folder_icon;
886         delete ladspa_vframe;           delete ladspa_icon;
887         delete ff_aud_vframe;           delete ff_aud_icon;
888         delete ff_vid_vframe;           delete ff_vid_icon;
889         delete atransition_vframe;      delete atransition_icon;
890         delete vtransition_vframe;      delete vtransition_icon;
891         delete aeffect_vframe;          delete aeffect_icon;
892         delete veffect_vframe;          delete veffect_icon;
893         delete folder_lock;
894 }
895
896 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
897 {
898         return  icon == file_icon ||
899                 icon == folder_icon ||
900                 icon == audio_icon ||
901                 icon == video_icon ||
902                 icon == clip_icon ||
903                 icon == label_icon ||
904                 icon == vtransition_icon ||
905                 icon == atransition_icon ||
906                 icon == veffect_icon ||
907                 icon == aeffect_icon ||
908                 icon == ladspa_icon ||
909                 icon == ff_aud_icon ||
910                 icon == ff_vid_icon ||
911                 icon == aeffect_folder_icon ||
912                 icon == veffect_folder_icon ||
913                 icon == atransition_folder_icon ||
914                 icon == vtransition_folder_icon ||
915                 icon == label_folder_icon ||
916                 icon == clip_folder_icon ||
917                 icon == media_folder_icon ||
918                 icon == proxy_folder_icon;
919 }
920
921 VFrame *AWindowGUI::get_picon(const char *name, const char *plugin_icons)
922 {
923         char png_path[BCTEXTLEN];
924         char *pp = png_path, *ep = pp + sizeof(png_path)-1;
925         snprintf(pp, ep-pp, "%s/picon/%s/%s.png",
926                 File::get_plugin_path(), plugin_icons, name);
927         if( access(png_path, R_OK) ) return 0;
928         return VFramePng::vframe_png(png_path,0,0);
929 }
930
931 VFrame *AWindowGUI::get_picon(const char *name)
932 {
933         VFrame *vframe = get_picon(name, mwindow->preferences->plugin_icons);
934         if( !vframe ) {
935                 char png_name[BCSTRLEN], *pp = png_name, *ep = pp + sizeof(png_name)-1;
936                 snprintf(pp, ep-pp, "%s.png", name);
937                 unsigned char *data = mwindow->theme->get_image_data(png_name);
938                 if( data ) vframe = new VFramePng(data, 0.);
939         }
940         return vframe;
941 }
942
943 void AWindowGUI::resource_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, int idx)
944 {
945         vfrm = get_picon(fn);
946         if( !vfrm ) vfrm = BC_WindowBase::get_resources()->type_to_icon[idx];
947         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
948 }
949 void AWindowGUI::theme_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn)
950 {
951         vfrm = get_picon(fn);
952         if( !vfrm ) vfrm = mwindow->theme->get_image(fn);
953         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
954 }
955 void AWindowGUI::plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, unsigned char *png)
956 {
957         vfrm = get_picon(fn);
958         if( !vfrm ) vfrm = new VFramePng(png);
959         icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
960 }
961
962 void AWindowGUI::create_objects()
963 {
964         lock_window("AWindowGUI::create_objects");
965         asset_titles[0] = C_("Title");
966         asset_titles[1] = _("Comments");
967
968         set_icon(mwindow->theme->get_image("awindow_icon"));
969
970         resource_icon(file_vframe,   file_icon,   "film_icon",   ICON_UNKNOWN);
971         resource_icon(folder_vframe, folder_icon, "folder_icon", ICON_FOLDER);
972         resource_icon(audio_vframe,  audio_icon,  "audio_icon",  ICON_SOUND);
973         resource_icon(video_vframe,  video_icon,  "video_icon",  ICON_FILM);
974         resource_icon(label_vframe,  label_icon,  "label_icon",  ICON_LABEL);
975
976         theme_icon(aeffect_folder_vframe,      aeffect_folder_icon,     "aeffect_folder");
977         theme_icon(atransition_folder_vframe,  atransition_folder_icon, "atransition_folder");
978         theme_icon(clip_folder_vframe,         clip_folder_icon,        "clip_folder");
979         theme_icon(label_folder_vframe,        label_folder_icon,       "label_folder");
980         theme_icon(media_folder_vframe,        media_folder_icon,       "media_folder");
981         theme_icon(proxy_folder_vframe,        proxy_folder_icon,       "proxy_folder");
982         theme_icon(veffect_folder_vframe,      veffect_folder_icon,     "veffect_folder");
983         theme_icon(vtransition_folder_vframe,  vtransition_folder_icon, "vtransition_folder");
984
985         folder_icons[AW_AEFFECT_FOLDER] = aeffect_folder_icon;
986         folder_icons[AW_VEFFECT_FOLDER] = veffect_folder_icon;
987         folder_icons[AW_ATRANSITION_FOLDER] = atransition_folder_icon;
988         folder_icons[AW_VTRANSITION_FOLDER] = vtransition_folder_icon;
989         folder_icons[AW_LABEL_FOLDER] = label_folder_icon;
990         folder_icons[AW_CLIP_FOLDER] = clip_folder_icon;
991         folder_icons[AW_MEDIA_FOLDER] = media_folder_icon;
992         folder_icons[AW_PROXY_FOLDER] = proxy_folder_icon;
993
994         theme_icon(clip_vframe,        clip_icon,        "clip_icon");
995         theme_icon(atransition_vframe, atransition_icon, "atransition_icon");
996         theme_icon(vtransition_vframe, vtransition_icon, "vtransition_icon");
997         theme_icon(aeffect_vframe,     aeffect_icon,     "aeffect_icon");
998         theme_icon(veffect_vframe,     veffect_icon,     "veffect_icon");
999
1000         plugin_icon(ladspa_vframe, ladspa_icon, "lad_picon", lad_picon_png);
1001         plugin_icon(ff_aud_vframe, ff_aud_icon, "ff_audio",  ff_audio_png);
1002         plugin_icon(ff_vid_vframe, ff_vid_icon, "ff_video",  ff_video_png);
1003         folder_lock->lock("AWindowGUI::create_objects");
1004 // Mandatory folders
1005         folders.append(new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER, 1));
1006         folders.append(new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER, 1));
1007         folders.append(new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER, 1));
1008         folders.append(new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER, 1));
1009         folders.append(new AssetPicon(mwindow, this, AW_LABEL_FOLDER, 1));
1010         folders.append(new AssetPicon(mwindow, this, AW_CLIP_FOLDER, 1));
1011         folders.append(new AssetPicon(mwindow, this, AW_PROXY_FOLDER, 1));
1012         folders.append(new AssetPicon(mwindow, this, AW_MEDIA_FOLDER, 1));
1013
1014         create_label_folder();
1015         folder_lock->unlock();
1016
1017         mwindow->theme->get_awindow_sizes(this);
1018         load_defaults(mwindow->defaults);
1019
1020         int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1021         int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1022         search_text = new AWindowSearchText(mwindow, this, x1, y1+5);
1023         search_text->create_objects();
1024         int dy = search_text->get_h() + 10;
1025         y1 += dy;  h1 -= dy;
1026         add_subwindow(asset_list = new AWindowAssets(mwindow, this, x1, y1, w1, h1));
1027
1028         vicon_thread = new VIconThread(asset_list);
1029         vicon_thread->start();
1030         vicon_audio = new AssetVIconAudio(this);
1031
1032         add_subwindow(divider = new AWindowDivider(mwindow, this,
1033                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1034                 mwindow->theme->adivider_w, mwindow->theme->adivider_h));
1035
1036         divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
1037
1038         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1039         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1040         VFrame **images = mwindow->theme->get_image_set("playpatch_data");
1041         AVIconDrawing::calculate_geometry(this, images, &avicon_w, &avicon_h);
1042         add_subwindow(avicon_drawing = new AVIconDrawing(this, fw-avicon_w, fy, images));
1043         add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, _("Visibility")));
1044         add_tools->create_objects();
1045         fy += add_tools->get_h();  fh -= add_tools->get_h();
1046         add_subwindow(folder_list = new AWindowFolders(mwindow,
1047                 this, fx, fy, fw, fh));
1048         update_effects();
1049
1050         //int x = mwindow->theme->abuttons_x;
1051         //int y = mwindow->theme->abuttons_y;
1052
1053
1054         newfolder_thread = new NewFolderThread(mwindow, this);
1055
1056         add_subwindow(asset_menu = new AssetPopup(mwindow, this));
1057         asset_menu->create_objects();
1058         add_subwindow(clip_menu = new ClipPopup(mwindow, this));
1059         clip_menu->create_objects();
1060         add_subwindow(label_menu = new LabelPopup(mwindow, this));
1061         label_menu->create_objects();
1062         add_subwindow(proxy_menu = new ProxyPopup(mwindow, this));
1063         proxy_menu->create_objects();
1064
1065         add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this));
1066         effectlist_menu->create_objects();
1067         add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
1068         assetlist_menu->create_objects();
1069         add_subwindow(cliplist_menu = new ClipListMenu(mwindow, this));
1070         cliplist_menu->create_objects();
1071         add_subwindow(labellist_menu = new LabelListMenu(mwindow, this));
1072         labellist_menu->create_objects();
1073         add_subwindow(proxylist_menu = new ProxyListMenu(mwindow, this));
1074         proxylist_menu->create_objects();
1075
1076         add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
1077         folderlist_menu->create_objects();
1078
1079         create_custom_xatoms();
1080         unlock_window();
1081 }
1082
1083 int AWindowGUI::resize_event(int w, int h)
1084 {
1085         mwindow->session->awindow_x = get_x();
1086         mwindow->session->awindow_y = get_y();
1087         mwindow->session->awindow_w = w;
1088         mwindow->session->awindow_h = h;
1089
1090         mwindow->theme->get_awindow_sizes(this);
1091         mwindow->theme->draw_awindow_bg(this);
1092         reposition_objects();
1093
1094 //      int x = mwindow->theme->abuttons_x;
1095 //      int y = mwindow->theme->abuttons_y;
1096 //      new_bin->reposition_window(x, y);
1097 //      x += new_bin->get_w();
1098 //      delete_bin->reposition_window(x, y);
1099 //      x += delete_bin->get_w();
1100 //      rename_bin->reposition_window(x, y);
1101 //      x += rename_bin->get_w();
1102 //      delete_disk->reposition_window(x, y);
1103 //      x += delete_disk->get_w();
1104 //      delete_project->reposition_window(x, y);
1105 //      x += delete_project->get_w();
1106 //      info->reposition_window(x, y);
1107 //      x += info->get_w();
1108 //      redraw_index->reposition_window(x, y);
1109 //      x += redraw_index->get_w();
1110 //      paste->reposition_window(x, y);
1111 //      x += paste->get_w();
1112 //      append->reposition_window(x, y);
1113 //      x += append->get_w();
1114 //      view->reposition_window(x, y);
1115
1116         BC_WindowBase::resize_event(w, h);
1117         return 1;
1118 }
1119
1120 int AWindowGUI::translation_event()
1121 {
1122         mwindow->session->awindow_x = get_x();
1123         mwindow->session->awindow_y = get_y();
1124         return 0;
1125 }
1126
1127 void AWindowGUI::reposition_objects()
1128 {
1129         int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1130         int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1131         search_text->reposition_window(x1, y1+5, w1);
1132         int dy = search_text->get_h() + 10;
1133         y1 += dy;  h1 -= dy;
1134         asset_list->reposition_window(x1, y1, w1, h1);
1135         divider->reposition_window(
1136                 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1137                 mwindow->theme->adivider_w, mwindow->theme->adivider_h);
1138         int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1139         int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1140         add_tools->resize_event(fw-avicon_w, add_tools->get_h());
1141         avicon_drawing->reposition_window(fw-avicon_w, fy);
1142         fy += add_tools->get_h();  fh -= add_tools->get_h();
1143         folder_list->reposition_window(fx, fy, fw, fh);
1144 }
1145
1146 int AWindowGUI::save_defaults(BC_Hash *defaults)
1147 {
1148         defaults->update("PLUGIN_VISIBILTY", plugin_visibility);
1149         defaults->update("VICON_DRAWING", vicon_drawing);
1150         return 0;
1151 }
1152
1153 int AWindowGUI::load_defaults(BC_Hash *defaults)
1154 {
1155         plugin_visibility = defaults->get("PLUGIN_VISIBILTY", plugin_visibility);
1156         vicon_drawing = defaults->get("VICON_DRAWING", vicon_drawing);
1157         return 0;
1158 }
1159
1160 int AWindowGUI::close_event()
1161 {
1162         hide_window();
1163         mwindow->session->show_awindow = 0;
1164         unlock_window();
1165
1166         mwindow->gui->lock_window("AWindowGUI::close_event");
1167         mwindow->gui->mainmenu->show_awindow->set_checked(0);
1168         mwindow->gui->unlock_window();
1169
1170         lock_window("AWindowGUI::close_event");
1171         save_defaults(mwindow->defaults);
1172         mwindow->save_defaults();
1173         return 1;
1174 }
1175
1176 void AWindowGUI::start_vicon_drawing()
1177 {
1178         if( !vicon_drawing ) return;
1179         if( mwindow->edl->session->awindow_folder != AW_MEDIA_FOLDER ) return;
1180         if( mwindow->edl->session->assetlist_format != ASSETS_ICONS ) return;
1181         vicon_thread->start_drawing();
1182 }
1183
1184 void AWindowGUI::stop_vicon_drawing()
1185 {
1186         vicon_thread->stop_drawing();
1187 }
1188
1189 AWindowRemovePluginGUI::
1190 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
1191         int x, int y, PluginServer *plugin)
1192  : BC_Window(_(PROGRAM_NAME ": Remove plugin"), x,y, 500,200, 50, 50, 1, 0, 1, -1, "", 1)
1193 {
1194         this->awindow = awindow;
1195         this->thread = thread;
1196         this->plugin = plugin;
1197         VFrame *vframe = plugin->get_picon();
1198         icon = vframe ? create_pixmap(vframe) : 0;
1199         plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
1200 }
1201
1202 AWindowRemovePluginGUI::
1203 ~AWindowRemovePluginGUI()
1204 {
1205         if( !awindow->gui->protected_pixmap(icon) )
1206                 delete icon;
1207         plugin_list.remove_all();
1208 }
1209
1210 void AWindowRemovePluginGUI::create_objects()
1211 {
1212         lock_window("AWindowRemovePluginGUI::create_objects");
1213         BC_Button *ok_button = new BC_OKButton(this);
1214         add_subwindow(ok_button);
1215         BC_Button *cancel_button = new BC_CancelButton(this);
1216         add_subwindow(cancel_button);
1217         int x = 10, y = 10;
1218         BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
1219         add_subwindow(title);
1220         y += title->get_h() + 5;
1221         list = new BC_ListBox(x, y,
1222                 get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
1223                 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
1224         add_subwindow(list);
1225         show_window();
1226         unlock_window();
1227 }
1228
1229 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
1230 {
1231         int ret = 0;
1232         for( int i=0; i<folder.size(); ) {
1233                 AssetPicon *picon = (AssetPicon *)folder[i];
1234                 if( picon->plugin == plugin ) {
1235                         folder.remove_object_number(i);
1236                         ++ret;
1237                         continue;
1238                 }
1239                 ++i;
1240         }
1241         return ret;
1242 }
1243
1244 void AWindowRemovePlugin::handle_close_event(int result)
1245 {
1246         if( !result ) {
1247                 printf(_("remove %s\n"), plugin->path);
1248                 awindow->gui->lock_window("AWindowRemovePlugin::handle_close_event");
1249                 ArrayList<BC_ListBoxItem*> *folder =
1250                         plugin->audio ? plugin->transition ?
1251                                 &awindow->gui->atransitions :
1252                                 &awindow->gui->aeffects :
1253                         plugin->video ?  plugin->transition ?
1254                                 &awindow->gui->vtransitions :
1255                                 &awindow->gui->veffects :
1256                         0;
1257                 if( folder ) remove_plugin(plugin, *folder);
1258                 MWindow *mwindow = awindow->mwindow;
1259                 awindow->gui->unlock_window();
1260                 char plugin_path[BCTEXTLEN];
1261                 strcpy(plugin_path, plugin->path);
1262                 mwindow->plugindb->remove(plugin);
1263                 remove(plugin_path);
1264                 char index_path[BCTEXTLEN];
1265                 mwindow->create_defaults_path(index_path, PLUGIN_FILE);
1266                 remove(index_path);
1267                 char picon_path[BCTEXTLEN];
1268                 FileSystem fs;
1269                 snprintf(picon_path, sizeof(picon_path), "%s/picon",
1270                         File::get_plugin_path());
1271                 char png_name[BCSTRLEN], png_path[BCTEXTLEN];
1272                 plugin->get_plugin_png_name(png_name);
1273                 fs.update(picon_path);
1274                 for( int i=0; i<fs.dir_list.total; ++i ) {
1275                         char *fs_path = fs.dir_list[i]->path;
1276                         if( !fs.is_dir(fs_path) ) continue;
1277                         snprintf(png_path, sizeof(picon_path), "%s/%s",
1278                                 fs_path, png_name);
1279                         remove(png_path);
1280                 }
1281                 delete plugin;  plugin = 0;
1282                 awindow->gui->async_update_assets();
1283         }
1284 }
1285
1286 AWindowRemovePlugin::
1287 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
1288  : BC_DialogThread()
1289 {
1290         this->awindow = awindow;
1291         this->plugin = plugin;
1292 }
1293
1294 AWindowRemovePlugin::
1295 ~AWindowRemovePlugin()
1296 {
1297         close_window();
1298 }
1299
1300 BC_Window* AWindowRemovePlugin::new_gui()
1301 {
1302         int x = awindow->gui->get_abs_cursor_x(0);
1303         int y = awindow->gui->get_abs_cursor_y(0);
1304         AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
1305         gui->create_objects();
1306         return gui;
1307 }
1308
1309 int AWindowGUI::keypress_event()
1310 {
1311         switch( get_keypress() ) {
1312         case 'w': case 'W':
1313                 if( ctrl_down() ) {
1314                         close_event();
1315                         return 1;
1316                 }
1317                 break;
1318         case 'o':
1319                 if( !ctrl_down() && !shift_down() ) {
1320                         assetlist_menu->load_file->handle_event();
1321                         return 1;
1322                 }
1323                 break;
1324         case DELETE:
1325                 if( shift_down() ) {
1326                         PluginServer* plugin = selected_plugin();
1327                         if( !plugin ) break;
1328                         remove_plugin = new AWindowRemovePlugin(awindow, plugin);
1329                         unlock_window();
1330                         remove_plugin->start();
1331                         lock_window();
1332                 }
1333         }
1334         return 0;
1335 }
1336
1337
1338
1339 int AWindowGUI::create_custom_xatoms()
1340 {
1341         UpdateAssetsXAtom = create_xatom("CWINDOWGUI_UPDATE_ASSETS");
1342         return 0;
1343 }
1344 int AWindowGUI::recieve_custom_xatoms(xatom_event *event)
1345 {
1346         if( event->message_type == UpdateAssetsXAtom ) {
1347                 update_assets();
1348                 return 1;
1349         }
1350         return 0;
1351 }
1352
1353 void AWindowGUI::async_update_assets()
1354 {
1355         xatom_event event;
1356         event.message_type = UpdateAssetsXAtom;
1357         send_custom_xatom(&event);
1358 }
1359
1360
1361 void AWindowGUI::update_folder_list()
1362 {
1363         for( int i = 0; i < folders.total; i++ ) {
1364                 AssetPicon *picon = (AssetPicon*)folders.values[i];
1365                 picon->in_use = 0;
1366         }
1367
1368 // Search assets for folders
1369         for( int i = 0; i < mwindow->edl->folders.total; i++ ) {
1370                 const char *folder = mwindow->edl->folders.values[i];
1371                 int exists = 0;
1372
1373                 for( int j = 0; j < folders.total; j++ ) {
1374                         AssetPicon *picon = (AssetPicon*)folders.values[j];
1375                         if( !strcasecmp(picon->get_text(), folder) ) {
1376                                 exists = 1;
1377                                 picon->in_use = 1;
1378                                 break;
1379                         }
1380                 }
1381
1382                 if( !exists ) {
1383                         int aw_folder = folder_number(folder);
1384                         if( aw_folder >= 0 ) {
1385                                 AssetPicon *picon = new AssetPicon(mwindow, this, aw_folder, 1);
1386                                 picon->create_objects();
1387                                 folders.append(picon);
1388                         }
1389                 }
1390         }
1391
1392 // Delete unused non-persistent folders
1393         for( int i=folders.total; --i>=0; ) {
1394                 AssetPicon *picon = (AssetPicon*)folders.values[i];
1395                 if( !picon->in_use && !picon->persistent ) {
1396                         delete picon;
1397                         folders.remove_number(i);
1398                 }
1399         }
1400 }
1401
1402 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
1403         int do_audio, int do_video, int is_realtime, int is_transition)
1404 {
1405         ArrayList<PluginServer*> plugin_list;
1406 // Get pointers to plugindb entries
1407         mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
1408                         0, plugin_list);
1409
1410         for( int i = 0; i < plugin_list.total; i++ ) {
1411                 PluginServer *server = plugin_list.values[i];
1412                 int visible = plugin_visibility & (1<<server->dir_idx);
1413                 if( !visible ) continue;
1414 // Create new listitem
1415                 AssetPicon *picon = new AssetPicon(mwindow, this, server);
1416                 picon->create_objects();
1417                 output->append(picon);
1418         }
1419 }
1420
1421 void AWindowGUI::create_label_folder()
1422 {
1423         Label *current;
1424         for( current = mwindow->edl->labels->first; current; current = NEXT ) {
1425                 AssetPicon *picon = new AssetPicon(mwindow, this, current);
1426                 picon->create_objects();
1427                 labellist.append(picon);
1428         }
1429 }
1430
1431
1432 void AWindowGUI::update_asset_list()
1433 {
1434         ArrayList<AssetPicon *> new_assets;
1435         for( int i = 0; i < assets.total; i++ ) {
1436                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1437                 picon->in_use = 0;
1438         }
1439
1440         mwindow->gui->lock_window("AWindowGUI::update_asset_list");
1441 // Synchronize EDL clips
1442         for( int i=0; i<mwindow->edl->clips.size(); ++i ) {
1443                 int exists = 0;
1444
1445 // Look for clip in existing listitems
1446                 for( int j = 0; j < assets.total && !exists; j++ ) {
1447                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1448
1449                         if( picon->id == mwindow->edl->clips[i]->id ) {
1450                                 picon->edl = mwindow->edl->clips[i];
1451                                 picon->set_text(mwindow->edl->clips[i]->local_session->clip_title);
1452                                 exists = 1;
1453                                 picon->in_use = 1;
1454                         }
1455                 }
1456
1457 // Create new listitem
1458                 if( !exists ) {
1459                         AssetPicon *picon = new AssetPicon(mwindow,
1460                                 this, mwindow->edl->clips[i]);
1461                         new_assets.append(picon);
1462                 }
1463         }
1464
1465 // Synchronize EDL assets
1466         for( Asset *current=mwindow->edl->assets->first; current; current=NEXT ) {
1467                 int exists = 0;
1468
1469 // Look for asset in existing listitems
1470                 for( int j = 0; j < assets.total && !exists; j++ ) {
1471                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1472
1473                         if( picon->id == current->id ) {
1474                                 picon->indexable = current;
1475                                 picon->in_use = 1;
1476                                 exists = 1;
1477                         }
1478                 }
1479
1480 // Create new listitem
1481                 if( !exists ) {
1482                         AssetPicon *picon = new AssetPicon(mwindow,
1483                                 this, current);
1484                         new_assets.append(picon);
1485                 }
1486         }
1487
1488 // Synchronize nested EDLs
1489         for( int i=0; i<mwindow->edl->nested_edls.size(); ++i ) {
1490                 int exists = 0;
1491                 EDL *nested_edl = mwindow->edl->nested_edls[i];
1492
1493 // Look for asset in existing listitems
1494                 for( int j=0; j<assets.total && !exists; ++j ) {
1495                         AssetPicon *picon = (AssetPicon*)assets.values[j];
1496
1497                         if( picon->id == nested_edl->id ) {
1498                                 picon->indexable = nested_edl;
1499                                 picon->in_use = 1;
1500                                 exists = 1;
1501                         }
1502                 }
1503
1504 // Create new listitem
1505                 if( !exists ) {
1506                         AssetPicon *picon = new AssetPicon(mwindow,
1507                                 this, (Indexable*)nested_edl);
1508                         new_assets.append(picon);
1509                 }
1510         }
1511         mwindow->gui->unlock_window();
1512
1513         for( int i=0; i<new_assets.size(); ++i ) {
1514                 AssetPicon *picon = new_assets[i];
1515                 picon->create_objects();
1516                 assets.append(picon);
1517         }
1518
1519         mwindow->gui->lock_window();
1520         mwindow->gui->default_message();
1521         mwindow->gui->unlock_window();
1522
1523         for( int i = assets.size() - 1; i >= 0; i-- ) {
1524                 AssetPicon *picon = (AssetPicon*)assets.get(i);
1525                 if( !picon->in_use ) {
1526                         delete picon;
1527                         assets.remove_number(i);
1528                         continue;
1529                 }
1530                 if( !picon->indexable || !picon->indexable->is_asset ) continue;
1531                 struct stat st;
1532                 picon->mtime = !stat(picon->indexable->path, &st) ? st.st_mtime : 0;
1533         }
1534 }
1535
1536 void AWindowGUI::update_picon(Indexable *indexable)
1537 {
1538         VIcon *vicon = 0;
1539         for( int i = 0; i < assets.total; i++ ) {
1540                 AssetPicon *picon = (AssetPicon*)assets.values[i];
1541                 if( picon->indexable == indexable ||
1542                     picon->edl == (EDL *)indexable ) {
1543                         char name[BCTEXTLEN];
1544                         FileSystem fs;
1545                         fs.extract_name(name, indexable->path);
1546                         picon->set_text(name);
1547                         vicon = picon->vicon;
1548                         break;
1549                 }
1550         }
1551         if( vicon ) {
1552                 stop_vicon_drawing();
1553                 vicon->clear_images();
1554                 vicon->reset(indexable->get_frame_rate());
1555                 start_vicon_drawing();
1556         }
1557 }
1558
1559 void AWindowGUI::sort_assets(int use_mtime)
1560 {
1561         folder_lock->lock("AWindowGUI::sort_assets");
1562         switch( mwindow->edl->session->awindow_folder ) {
1563         case AW_AEFFECT_FOLDER:
1564                 sort_picons(&aeffects);
1565                 break;
1566         case AW_VEFFECT_FOLDER:
1567                 sort_picons(&veffects);
1568                 break;
1569         case AW_ATRANSITION_FOLDER:
1570                 sort_picons(&atransitions);
1571                 break;
1572         case AW_VTRANSITION_FOLDER:
1573                 sort_picons(&vtransitions);
1574                 break;
1575         case AW_LABEL_FOLDER:
1576                 sort_picons(&labellist);
1577                 break;
1578         default:
1579                 sort_picons(&assets, use_mtime);
1580                 break;
1581         }
1582 // reset xyposition
1583         asset_list->update_format(asset_list->get_format(), 0);
1584         folder_lock->unlock();
1585         update_assets();
1586 }
1587
1588 void AWindowGUI::sort_folders()
1589 {
1590         folder_lock->lock("AWindowGUI::update_assets");
1591         sort_picons(&folders);
1592         folder_list->update_format(folder_list->get_format(), 0);
1593         folder_lock->unlock();
1594         update_assets();
1595 }
1596
1597 EDL *AWindowGUI::collect_proxy(Indexable *indexable)
1598 {
1599         Asset *proxy_asset = (Asset *)indexable;
1600         char path[BCTEXTLEN];
1601         int proxy_scale = mwindow->edl->session->proxy_scale;
1602         ProxyRender::from_proxy_path(path, proxy_asset, proxy_scale);
1603         Asset *unproxy_asset = mwindow->edl->assets->get_asset(path);
1604         if( !unproxy_asset || !unproxy_asset->channels ) return 0;
1605 // make a clip from proxy video tracks and unproxy audio tracks
1606         EDL *proxy_edl = new EDL(mwindow->edl);
1607         proxy_edl->create_objects();
1608         FileSystem fs;  fs.extract_name(path, proxy_asset->path);
1609         proxy_edl->set_path(path);
1610         strcpy(proxy_edl->local_session->clip_title, path);
1611         strcpy(proxy_edl->local_session->clip_notes, _("Proxy clip"));
1612         proxy_edl->session->video_tracks = proxy_asset->layers;
1613         proxy_edl->session->audio_tracks = unproxy_asset->channels;
1614         proxy_edl->create_default_tracks();
1615         double length = proxy_asset->frame_rate > 0 ?
1616                 (double)proxy_asset->video_length / proxy_asset->frame_rate :
1617                 1.0 / mwindow->edl->session->frame_rate;
1618         Track *current = proxy_edl->tracks->first;
1619         for( int vtrack=0; current; current=NEXT ) {
1620                 if( current->data_type != TRACK_VIDEO ) continue;
1621                 current->insert_asset(proxy_asset, 0, length, 0, vtrack++);
1622         }
1623         length = (double)unproxy_asset->audio_length / unproxy_asset->sample_rate;
1624         current = proxy_edl->tracks->first;
1625         for( int atrack=0; current; current=NEXT ) {
1626                 if( current->data_type != TRACK_AUDIO ) continue;
1627                 current->insert_asset(unproxy_asset, 0, length, 0, atrack++);
1628         }
1629         return proxy_edl;
1630 }
1631
1632
1633 void AWindowGUI::collect_assets(int proxy)
1634 {
1635         mwindow->session->drag_assets->remove_all();
1636         mwindow->session->drag_clips->remove_all();
1637         mwindow->session->clear_drag_proxy();
1638         int i = 0;  AssetPicon *result;
1639         while( (result = (AssetPicon*)asset_list->get_selection(0, i++)) != 0 ) {
1640                 Indexable *indexable = result->indexable;  EDL *drag_edl;
1641                 if( proxy && (drag_edl=collect_proxy(indexable)) ) {
1642                         mwindow->session->drag_clips->append(drag_edl);
1643                         mwindow->session->drag_proxy->append(drag_edl);
1644                         continue;
1645                 }
1646                 if( indexable ) {
1647                         mwindow->session->drag_assets->append(indexable);
1648                         continue;
1649                 }
1650                 if( result->edl ) {
1651                         mwindow->session->drag_clips->append(result->edl);
1652                         continue;
1653                 }
1654         }
1655 }
1656
1657 void AWindowGUI::copy_picons(ArrayList<BC_ListBoxItem*> *dst,
1658         ArrayList<BC_ListBoxItem*> *src, int folder)
1659 {
1660 // Remove current pointers
1661         dst[0].remove_all();
1662         dst[1].remove_all_objects();
1663
1664 // Create new pointers
1665         for( int i = 0; i < src->total; i++ ) {
1666                 AssetPicon *picon = (AssetPicon*)src->values[i];
1667                 if( folder < 0 ||
1668                     (picon->indexable && picon->indexable->awindow_folder == folder) ||
1669                     (picon->edl && picon->edl->local_session->awindow_folder == folder) ) {
1670                         const char *text = search_text->get_text();
1671                         int hidden = text && text[0] && !bstrcasestr(picon->get_text(), text);
1672                         if( picon->vicon ) picon->vicon->hidden = hidden;
1673                         if( hidden ) continue;
1674                         BC_ListBoxItem *item2, *item1;
1675                         dst[0].append(item1 = picon);
1676                         if( picon->edl )
1677                                 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
1678                         else
1679                         if( picon->label )
1680                                 dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr));
1681                         else if( picon->mtime ) {
1682                                 char date_time[BCSTRLEN];
1683                                 struct tm stm;  localtime_r(&picon->mtime, &stm);
1684                                 sprintf(date_time,"%04d.%02d.%02d %02d:%02d:%02d",
1685                                          stm.tm_year+1900, stm.tm_mon+1, stm.tm_mday,
1686                                          stm.tm_hour, stm.tm_min, stm.tm_sec);
1687                                 dst[1].append(item2 = new BC_ListBoxItem(date_time));
1688                         }
1689                         else
1690                                 dst[1].append(item2 = new BC_ListBoxItem(""));
1691                         item1->set_autoplace_text(1);  item1->set_autoplace_icon(1);
1692                         item2->set_autoplace_text(1);  item2->set_autoplace_icon(1);
1693                 }
1694         }
1695 }
1696
1697 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src, int use_mtime)
1698 {
1699         int done = 0, changed = 0;
1700         while( !done ) {
1701                 done = 1;
1702                 for( int i=0; i<src->total-1; ++i ) {
1703                         AssetPicon *item1 = (AssetPicon *)src->values[i];
1704                         AssetPicon *item2 = (AssetPicon *)src->values[i + 1];
1705                         if( use_mtime ? item1->mtime > item2->mtime :
1706                             strcmp(item1->get_text(), item2->get_text()) > 0 ) {
1707                                 src->values[i + 1] = item1;
1708                                 src->values[i] = item2;
1709                                 done = 0;  changed = 1;
1710                         }
1711                 }
1712         }
1713         if( changed ) {
1714                 for( int i=0; i<src->total; ++i ) {
1715                         AssetPicon *item = (AssetPicon *)src->values[i];
1716                         item->set_autoplace_icon(1);
1717                         item->set_autoplace_text(1);
1718                 }
1719         }
1720 }
1721
1722
1723 void AWindowGUI::filter_displayed_assets()
1724 {
1725         //allow_iconlisting = 1;
1726         asset_titles[0] = C_("Title");
1727         asset_titles[1] = _("Comments");
1728
1729         switch( mwindow->edl->session->awindow_folder ) {
1730         case AW_AEFFECT_FOLDER:
1731                 copy_picons(displayed_assets, &aeffects, AW_NO_FOLDER);
1732                 break;
1733         case AW_VEFFECT_FOLDER:
1734                 copy_picons(displayed_assets, &veffects, AW_NO_FOLDER);
1735                 break;
1736         case AW_ATRANSITION_FOLDER:
1737                 copy_picons(displayed_assets, &atransitions, AW_NO_FOLDER);
1738                 break;
1739         case AW_VTRANSITION_FOLDER:
1740                 copy_picons(displayed_assets, &vtransitions, AW_NO_FOLDER);
1741                 break;
1742         case AW_LABEL_FOLDER:
1743                 copy_picons(displayed_assets, &labellist, AW_NO_FOLDER);
1744                 asset_titles[0] = _("Time Stamps");
1745                 asset_titles[1] = C_("Title");
1746                 //allow_iconlisting = 0;
1747                 break;
1748         default:
1749                 copy_picons(displayed_assets, &assets, mwindow->edl->session->awindow_folder);
1750                 break;
1751         }
1752
1753         // Ensure the current folder icon is highlighted
1754         int selected_folder = mwindow->edl->session->awindow_folder;
1755         for( int i = 0; i < folders.total; i++ ) {
1756                 AssetPicon *folder_item = (AssetPicon *)folders.values[i];
1757                 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
1758                 folder_item->set_selected(selected);
1759         }
1760 }
1761
1762
1763 void AWindowGUI::update_assets()
1764 {
1765         stop_vicon_drawing();
1766         folder_lock->lock("AWindowGUI::update_assets");
1767         update_folder_list();
1768         update_asset_list();
1769         labellist.remove_all_objects();
1770         create_label_folder();
1771
1772         if( displayed_folder != mwindow->edl->session->awindow_folder )
1773                 search_text->clear();
1774         filter_displayed_assets();
1775         folder_lock->unlock();
1776
1777         if( mwindow->edl->session->folderlist_format != folder_list->get_format() ) {
1778                 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
1779         }
1780         int folder_xposition = folder_list->get_xposition();
1781         int folder_yposition = folder_list->get_yposition();
1782         folder_list->update(&folders, 0, 0, 1, folder_xposition, folder_yposition, -1);
1783
1784         if( mwindow->edl->session->assetlist_format != asset_list->get_format() ) {
1785                 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
1786         }
1787         int asset_xposition = asset_list->get_xposition();
1788         int asset_yposition = asset_list->get_yposition();
1789         if( displayed_folder != mwindow->edl->session->awindow_folder ) {
1790                 displayed_folder = mwindow->edl->session->awindow_folder;
1791                 asset_xposition = asset_yposition = 0;
1792         }
1793         asset_list->update(displayed_assets, asset_titles,
1794                 mwindow->edl->session->asset_columns, ASSET_COLUMNS,
1795                 asset_xposition, asset_yposition, -1, 0);
1796         asset_list->center_selection();
1797
1798         flush();
1799         start_vicon_drawing();
1800         return;
1801 }
1802
1803 void AWindowGUI::update_effects()
1804 {
1805         aeffects.remove_all_objects();
1806         create_persistent_folder(&aeffects, 1, 0, 1, 0);
1807         veffects.remove_all_objects();
1808         create_persistent_folder(&veffects, 0, 1, 1, 0);
1809         atransitions.remove_all_objects();
1810         create_persistent_folder(&atransitions, 1, 0, 0, 1);
1811         vtransitions.remove_all_objects();
1812         create_persistent_folder(&vtransitions, 0, 1, 0, 1);
1813 }
1814
1815 int AWindowGUI::folder_number(const char *name)
1816 {
1817         for( int i = 0; i < AWINDOW_FOLDERS; i++ ) {
1818                 if( !strcasecmp(name, folder_names[i]) ) return i;
1819         }
1820         return AW_NO_FOLDER;
1821 }
1822
1823 int AWindowGUI::drag_motion()
1824 {
1825         if( get_hidden() ) return 0;
1826
1827         int result = 0;
1828         return result;
1829 }
1830
1831 int AWindowGUI::drag_stop()
1832 {
1833         if( get_hidden() ) return 0;
1834         return 0;
1835 }
1836
1837 Indexable* AWindowGUI::selected_asset()
1838 {
1839         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1840         return picon ? picon->indexable : 0;
1841 }
1842
1843 PluginServer* AWindowGUI::selected_plugin()
1844 {
1845         AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
1846         return picon ? picon->plugin : 0;
1847 }
1848
1849 AssetPicon* AWindowGUI::selected_folder()
1850 {
1851         AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
1852         return picon;
1853 }
1854
1855
1856
1857
1858
1859
1860
1861
1862 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1863  : BC_SubWindow(x, y, w, h)
1864 {
1865         this->mwindow = mwindow;
1866         this->gui = gui;
1867 }
1868 AWindowDivider::~AWindowDivider()
1869 {
1870 }
1871
1872 int AWindowDivider::button_press_event()
1873 {
1874         if( is_event_win() && cursor_inside() ) {
1875                 mwindow->session->current_operation = DRAG_PARTITION;
1876                 return 1;
1877         }
1878         return 0;
1879 }
1880
1881 int AWindowDivider::cursor_motion_event()
1882 {
1883         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1884                 int wmin = 25;
1885                 int wmax = mwindow->session->awindow_w - mwindow->theme->adivider_w - wmin;
1886                 int fw = gui->get_relative_cursor_x();
1887                 if( fw > wmax ) fw = wmax;
1888                 if( fw < wmin ) fw = wmin;
1889                 mwindow->session->afolders_w = fw;
1890                 mwindow->theme->get_awindow_sizes(gui);
1891                 gui->reposition_objects();
1892                 gui->flush();
1893         }
1894         return 0;
1895 }
1896
1897 int AWindowDivider::button_release_event()
1898 {
1899         if( mwindow->session->current_operation == DRAG_PARTITION ) {
1900                 mwindow->session->current_operation = NO_OPERATION;
1901                 return 1;
1902         }
1903         return 0;
1904 }
1905
1906
1907
1908
1909
1910
1911 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1912  : BC_ListBox(x, y, w, h,
1913                 mwindow->edl->session->folderlist_format == ASSETS_ICONS ?
1914                         LISTBOX_ICONS : LISTBOX_TEXT,
1915                 &gui->folders,    // Each column has an ArrayList of BC_ListBoxItems.
1916                 0,                // Titles for columns.  Set to 0 for no titles
1917                 0,                // width of each column
1918                 1,                // Total columns.
1919                 0,                // Pixel of top of window.
1920                 0,                // If this listbox is a popup window
1921                 LISTBOX_SINGLE,   // Select one item or multiple items
1922                 ICON_TOP,         // Position of icon relative to text of each item
1923                 1)                // Allow drags
1924 {
1925         this->mwindow = mwindow;
1926         this->gui = gui;
1927         set_drag_scroll(0);
1928 }
1929
1930 AWindowFolders::~AWindowFolders()
1931 {
1932 }
1933
1934 int AWindowFolders::selection_changed()
1935 {
1936         AssetPicon *picon = (AssetPicon*)get_selection(0, 0);
1937         if( picon ) {
1938                 gui->stop_vicon_drawing();
1939
1940                 if( get_button_down() && get_buttonpress() == 3 ) {
1941                         gui->folderlist_menu->update_titles();
1942                         gui->folderlist_menu->activate_menu();
1943                 }
1944
1945                 mwindow->edl->session->awindow_folder = picon->foldernum;
1946                 gui->asset_list->draw_background();
1947                 gui->async_update_assets();
1948
1949                 gui->start_vicon_drawing();
1950         }
1951         return 1;
1952 }
1953
1954 int AWindowFolders::button_press_event()
1955 {
1956         int result = 0;
1957
1958         result = BC_ListBox::button_press_event();
1959
1960         if( !result ) {
1961                 if( get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
1962                         gui->folderlist_menu->update_titles();
1963                         gui->folderlist_menu->activate_menu();
1964                         result = 1;
1965                 }
1966         }
1967
1968
1969         return result;
1970 }
1971
1972
1973
1974
1975
1976
1977
1978 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
1979  : BC_ListBox(x, y, w, h,
1980                 (mwindow->edl->session->assetlist_format == ASSETS_ICONS && gui->allow_iconlisting ) ?
1981                         LISTBOX_ICONS : LISTBOX_TEXT,
1982                 &gui->assets,     // Each column has an ArrayList of BC_ListBoxItems.
1983                 gui->asset_titles,// Titles for columns.  Set to 0 for no titles
1984                 mwindow->edl->session->asset_columns, // width of each column
1985                 1,                // Total columns.
1986                 0,                // Pixel of top of window.
1987                 0,                // If this listbox is a popup window
1988                 LISTBOX_MULTIPLE, // Select one item or multiple items
1989                 ICON_TOP,         // Position of icon relative to text of each item
1990                 -1)               // Allow drags, require shift for scrolling
1991 {
1992         this->mwindow = mwindow;
1993         this->gui = gui;
1994         set_drag_scroll(0);
1995         set_scroll_stretch(1, 1);
1996 }
1997
1998 AWindowAssets::~AWindowAssets()
1999 {
2000 }
2001
2002 int AWindowAssets::button_press_event()
2003 {
2004         int result = 0;
2005
2006         result = BC_ListBox::button_press_event();
2007
2008         if( !result && get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
2009                 BC_ListBox::deactivate_selection();
2010                 int folder = mwindow->edl->session->awindow_folder;
2011                 switch( folder ) {
2012                 case AW_AEFFECT_FOLDER:
2013                 case AW_VEFFECT_FOLDER:
2014                 case AW_ATRANSITION_FOLDER:
2015                 case AW_VTRANSITION_FOLDER:
2016                         gui->effectlist_menu->update();
2017                         gui->effectlist_menu->activate_menu();
2018                         break;
2019                 case AW_LABEL_FOLDER:
2020                         gui->labellist_menu->update();
2021                         gui->labellist_menu->activate_menu();
2022                         break;
2023                 case AW_CLIP_FOLDER:
2024                         gui->cliplist_menu->update();
2025                         gui->cliplist_menu->activate_menu();
2026                         break;
2027                 case AW_PROXY_FOLDER:
2028                         gui->proxylist_menu->update();
2029                         gui->proxylist_menu->activate_menu();
2030                         break;
2031                 case AW_MEDIA_FOLDER:
2032                         gui->assetlist_menu->update_titles(folder==AW_MEDIA_FOLDER);
2033                         gui->assetlist_menu->activate_menu();
2034                         break;
2035                 }
2036                 result = 1;
2037         }
2038
2039         return result;
2040 }
2041
2042
2043 int AWindowAssets::handle_event()
2044 {
2045         AssetPicon *asset_picon = (AssetPicon *)get_selection(0, 0);
2046         if( !asset_picon ) return 0;
2047         Indexable *picon_idxbl = asset_picon->indexable;
2048         EDL *picon_edl = asset_picon->edl;
2049         int proxy = 0;
2050         VWindow *vwindow = 0;
2051         switch( mwindow->edl->session->awindow_folder ) {
2052         case AW_AEFFECT_FOLDER:
2053         case AW_VEFFECT_FOLDER:
2054         case AW_ATRANSITION_FOLDER:
2055         case AW_VTRANSITION_FOLDER: return 1;
2056         case AW_PROXY_FOLDER:
2057                 proxy = 1; // fall thru
2058         default:
2059                 if( mwindow->vwindows.size() > DEFAULT_VWINDOW )
2060                         vwindow = mwindow->vwindows.get(DEFAULT_VWINDOW);
2061                 break;
2062         }
2063         if( !vwindow || !vwindow->is_running() ) return 1;
2064         if( proxy && picon_idxbl ) {
2065                 picon_edl = gui->collect_proxy(picon_idxbl);
2066                 picon_idxbl = 0;
2067         }
2068
2069         if( picon_idxbl ) vwindow->change_source(picon_idxbl);
2070         else if( picon_edl ) vwindow->change_source(picon_edl);
2071         return 1;
2072 }
2073
2074 int AWindowAssets::selection_changed()
2075 {
2076 // Show popup window
2077         AssetPicon *item;
2078         if( get_button_down() && get_buttonpress() == 3 &&
2079             (item = (AssetPicon*)get_selection(0, 0)) ) {
2080                 int folder = mwindow->edl->session->awindow_folder;
2081                 switch( folder ) {
2082                 case AW_AEFFECT_FOLDER:
2083                 case AW_VEFFECT_FOLDER:
2084                 case AW_ATRANSITION_FOLDER:
2085                 case AW_VTRANSITION_FOLDER:
2086                         gui->effectlist_menu->update();
2087                         gui->effectlist_menu->activate_menu();
2088                         break;
2089                 case AW_LABEL_FOLDER:
2090                         if( !item->label ) break;
2091                         gui->label_menu->activate_menu();
2092                         break;
2093                 case AW_CLIP_FOLDER:
2094                         if( !item->indexable && !item->edl ) break;
2095                         gui->clip_menu->update();
2096                         gui->clip_menu->activate_menu();
2097                         break;
2098                 case AW_PROXY_FOLDER:
2099                         if( !item->indexable && !item->edl ) break;
2100                         gui->proxy_menu->update();
2101                         gui->proxy_menu->activate_menu();
2102                         break;
2103                 default:
2104                         if( !item->indexable && !item->edl ) break;
2105                         gui->asset_menu->update();
2106                         gui->asset_menu->activate_menu();
2107                         break;
2108                 }
2109
2110                 BC_ListBox::deactivate_selection();
2111                 return 1;
2112         }
2113         else if( gui->vicon_drawing &&
2114                  get_button_down() && get_buttonpress() == 1 &&
2115                  (item = (AssetPicon*)get_selection(0, 0)) ) {
2116                 VIcon *vicon = 0;
2117                 if( !gui->vicon_thread->viewing ) {
2118                         vicon = item->vicon;
2119                 }
2120                 gui->vicon_thread->set_view_popup(vicon);
2121
2122         }
2123         return 0;
2124 }
2125
2126 void AWindowAssets::draw_background()
2127 {
2128         clear_box(0,0,get_w(),get_h(),get_bg_surface());
2129         set_color(BC_WindowBase::get_resources()->audiovideo_color);
2130         set_font(LARGEFONT);
2131         int aw_folder = mwindow->edl->session->awindow_folder;
2132         if( aw_folder < 0 ) return;
2133         const char *aw_name = _(AWindowGUI::folder_names[aw_folder]);
2134         draw_text(get_w() - get_text_width(LARGEFONT, aw_name) - 4, 30,
2135                 aw_name, -1, get_bg_surface());
2136 }
2137
2138 int AWindowAssets::drag_start_event()
2139 {
2140         int collect_pluginservers = 0;
2141         int collect_assets = 0, proxy = 0;
2142
2143         if( BC_ListBox::drag_start_event() ) {
2144                 switch( mwindow->edl->session->awindow_folder ) {
2145                 case AW_AEFFECT_FOLDER:
2146                         mwindow->session->current_operation = DRAG_AEFFECT;
2147                         collect_pluginservers = 1;
2148                         break;
2149                 case AW_VEFFECT_FOLDER:
2150                         mwindow->session->current_operation = DRAG_VEFFECT;
2151                         collect_pluginservers = 1;
2152                         break;
2153                 case AW_ATRANSITION_FOLDER:
2154                         mwindow->session->current_operation = DRAG_ATRANSITION;
2155                         collect_pluginservers = 1;
2156                         break;
2157                 case AW_VTRANSITION_FOLDER:
2158                         mwindow->session->current_operation = DRAG_VTRANSITION;
2159                         collect_pluginservers = 1;
2160                         break;
2161                 case AW_LABEL_FOLDER:
2162                         // do nothing!
2163                         break;
2164                 case AW_PROXY_FOLDER:
2165                         proxy = 1;
2166                         // fall thru
2167                 case AW_MEDIA_FOLDER:
2168                 default:
2169                         mwindow->session->current_operation = DRAG_ASSET;
2170                         collect_assets = 1;
2171                         break;
2172                 }
2173
2174                 if( collect_pluginservers ) {
2175                         int i = 0;
2176                         mwindow->session->drag_pluginservers->remove_all();
2177                         while(1)
2178                         {
2179                                 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
2180                                 if( !result ) break;
2181
2182                                 mwindow->session->drag_pluginservers->append(result->plugin);
2183                         }
2184                 }
2185
2186                 if( collect_assets ) {
2187                         gui->collect_assets(proxy);
2188                 }
2189
2190                 return 1;
2191         }
2192         return 0;
2193 }
2194
2195 int AWindowAssets::drag_motion_event()
2196 {
2197         BC_ListBox::drag_motion_event();
2198         unlock_window();
2199
2200         mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2201         mwindow->gui->drag_motion();
2202         mwindow->gui->unlock_window();
2203
2204         for( int i = 0; i < mwindow->vwindows.size(); i++ ) {
2205                 VWindow *vwindow = mwindow->vwindows.get(i);
2206                 if( !vwindow->is_running() ) continue;
2207                 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2208                 vwindow->gui->drag_motion();
2209                 vwindow->gui->unlock_window();
2210         }
2211
2212         mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2213         mwindow->cwindow->gui->drag_motion();
2214         mwindow->cwindow->gui->unlock_window();
2215
2216         lock_window("AWindowAssets::drag_motion_event");
2217         return 0;
2218 }
2219
2220 int AWindowAssets::drag_stop_event()
2221 {
2222         int result = 0;
2223
2224         result = gui->drag_stop();
2225
2226         unlock_window();
2227
2228         if( !result ) {
2229                 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2230                 result = mwindow->gui->drag_stop();
2231                 mwindow->gui->unlock_window();
2232         }
2233
2234         if( !result ) {
2235                 for( int i = 0; !result && i < mwindow->vwindows.size(); i++ ) {
2236                         VWindow *vwindow = mwindow->vwindows.get(i);
2237                         if( !vwindow ) continue;
2238                         if( !vwindow->is_running() ) continue;
2239                         if( vwindow->gui->is_hidden() ) continue;
2240                         vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2241                         if( vwindow->gui->cursor_above() &&
2242                             vwindow->gui->get_cursor_over_window() ) {
2243                                 result = vwindow->gui->drag_stop();
2244                         }
2245                         vwindow->gui->unlock_window();
2246                 }
2247         }
2248
2249         if( !result ) {
2250                 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2251                 result = mwindow->cwindow->gui->drag_stop();
2252                 mwindow->cwindow->gui->unlock_window();
2253         }
2254
2255         lock_window("AWindowAssets::drag_stop_event");
2256
2257         if( result )
2258                 get_drag_popup()->set_animation(0);
2259
2260         BC_ListBox::drag_stop_event();
2261 // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
2262         mwindow->session->current_operation = ::NO_OPERATION;
2263         mwindow->session->clear_drag_proxy();
2264
2265         return 1;
2266 }
2267
2268 int AWindowAssets::column_resize_event()
2269 {
2270         mwindow->edl->session->asset_columns[0] = get_column_width(0);
2271         mwindow->edl->session->asset_columns[1] = get_column_width(1);
2272         return 1;
2273 }
2274
2275 int AWindowAssets::focus_in_event()
2276 {
2277         gui->start_vicon_drawing();
2278         return 0;
2279 }
2280
2281 int AWindowAssets::focus_out_event()
2282 {
2283         gui->stop_vicon_drawing();
2284         return BC_ListBox::focus_out_event();
2285 }
2286
2287 AWindowSearchTextBox::AWindowSearchTextBox(AWindowSearchText *search_text, int x, int y, int w)
2288  : BC_TextBox(x, y, w, 1, "")
2289 {
2290         this->search_text = search_text;
2291 }
2292
2293 int AWindowSearchTextBox::handle_event()
2294 {
2295         return search_text->handle_event();
2296 }
2297
2298 AWindowSearchText::AWindowSearchText(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2299 {
2300         this->mwindow = mwindow;
2301         this->gui = gui;
2302         this->x = x;
2303         this->y = y;
2304 }
2305
2306 void AWindowSearchText::create_objects()
2307 {
2308         int x1 = x, y1 = y, margin = 10;
2309         gui->add_subwindow(text_title = new BC_Title(x1, y1, _("Search:")));
2310         x1 += text_title->get_w() + margin;
2311         int w1 = gui->get_w() - x1 - 2*margin;
2312         gui->add_subwindow(text_box = new AWindowSearchTextBox(this, x1, y1, w1));
2313 }
2314
2315 int AWindowSearchText::handle_event()
2316 {
2317         gui->async_update_assets();
2318         return 1;
2319 }
2320
2321 int AWindowSearchText::get_w()
2322 {
2323         return text_box->get_w() + text_title->get_w() + 10;
2324 }
2325
2326 int AWindowSearchText::get_h()
2327 {
2328         return bmax(text_box->get_h(),text_title->get_h());
2329 }
2330
2331 void AWindowSearchText::reposition_window(int x, int y, int w)
2332 {
2333         int x1 = x, y1 = y, margin = 10;
2334         text_title->reposition_window(x1, y1);
2335         x1 += text_title->get_w() + margin;
2336         int w1 = gui->get_w() - x1 - 2*margin;
2337         text_box->reposition_window(x1, y1, w1);
2338 }
2339
2340 const char *AWindowSearchText::get_text()
2341 {
2342         return text_box->get_text();
2343 }
2344
2345 void AWindowSearchText::clear()
2346 {
2347         text_box->update("");
2348 }
2349
2350 AWindowNewFolder::AWindowNewFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2351  : BC_Button(x, y, mwindow->theme->newbin_data)
2352 {
2353         this->mwindow = mwindow;
2354         this->gui = gui;
2355         set_tooltip(_("New bin"));
2356 }
2357
2358 int AWindowNewFolder::handle_event()
2359 {
2360         gui->newfolder_thread->start_new_folder();
2361         return 1;
2362 }
2363
2364 AWindowDeleteFolder::AWindowDeleteFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2365  : BC_Button(x, y, mwindow->theme->deletebin_data)
2366 {
2367         this->mwindow = mwindow;
2368         this->gui = gui;
2369         set_tooltip(_("Delete bin"));
2370 }
2371
2372 int AWindowDeleteFolder::handle_event()
2373 {
2374         if( gui->folder_list->get_selection(0, 0) ) {
2375                 BC_ListBoxItem *folder = gui->folder_list->get_selection(0, 0);
2376                 mwindow->delete_folder(folder->get_text());
2377         }
2378         return 1;
2379 }
2380
2381 AWindowRenameFolder::AWindowRenameFolder(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2382  : BC_Button(x, y, mwindow->theme->renamebin_data)
2383 {
2384         this->mwindow = mwindow;
2385         this->gui = gui;
2386         set_tooltip(_("Rename bin"));
2387 }
2388
2389 int AWindowRenameFolder::handle_event()
2390 {
2391         return 1;
2392 }
2393
2394 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2395  : BC_Button(x, y, mwindow->theme->deletedisk_data)
2396 {
2397         this->mwindow = mwindow;
2398         this->gui = gui;
2399         set_tooltip(_("Delete asset from disk"));
2400 }
2401
2402 int AWindowDeleteDisk::handle_event()
2403 {
2404         return 1;
2405 }
2406
2407 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2408  : BC_Button(x, y, mwindow->theme->deleteproject_data)
2409 {
2410         this->mwindow = mwindow;
2411         this->gui = gui;
2412         set_tooltip(_("Delete asset from project"));
2413 }
2414
2415 int AWindowDeleteProject::handle_event()
2416 {
2417         return 1;
2418 }
2419
2420 // AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2421 //  : BC_Button(x, y, mwindow->theme->infoasset_data)
2422 // {
2423 //      this->mwindow = mwindow;
2424 //      this->gui = gui;
2425 //      set_tooltip(_("Edit information on asset"));
2426 // }
2427 // 
2428 // int AWindowInfo::handle_event()
2429 // {
2430 //      int cur_x, cur_y;
2431 //      gui->get_abs_cursor(cur_x, cur_y, 0);
2432 //      gui->awindow->asset_edit->edit_asset(gui->selected_asset(), cur_x, cur_y);
2433 //      return 1;
2434 // }
2435
2436 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2437  : BC_Button(x, y, mwindow->theme->redrawindex_data)
2438 {
2439         this->mwindow = mwindow;
2440         this->gui = gui;
2441         set_tooltip(_("Redraw index"));
2442 }
2443
2444 int AWindowRedrawIndex::handle_event()
2445 {
2446         return 1;
2447 }
2448
2449 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2450  : BC_Button(x, y, mwindow->theme->pasteasset_data)
2451 {
2452         this->mwindow = mwindow;
2453         this->gui = gui;
2454         set_tooltip(_("Paste asset on recordable tracks"));
2455 }
2456
2457 int AWindowPaste::handle_event()
2458 {
2459         return 1;
2460 }
2461
2462 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2463  : BC_Button(x, y, mwindow->theme->appendasset_data)
2464 {
2465         this->mwindow = mwindow;
2466         this->gui = gui;
2467         set_tooltip(_("Append asset in new tracks"));
2468 }
2469
2470 int AWindowAppend::handle_event()
2471 {
2472         return 1;
2473 }
2474
2475 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2476  : BC_Button(x, y, mwindow->theme->viewasset_data)
2477 {
2478         this->mwindow = mwindow;
2479         this->gui = gui;
2480         set_tooltip(_("View asset"));
2481 }
2482
2483 int AWindowView::handle_event()
2484 {
2485         return 1;
2486 }
2487
2488 AddTools::AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, const char *title)
2489  : BC_PopupMenu(x, y, BC_Title::calculate_w(gui, title, MEDIUMFONT)+8, title, -1, 0, 4)
2490 {
2491         this->mwindow = mwindow;
2492         this->gui = gui;
2493 }
2494
2495 void AddTools::create_objects()
2496 {
2497         uint64_t vis = 0;
2498         add_item(new AddPluginItem(this, "ffmpeg", PLUGIN_FFMPEG_ID));
2499         vis |= 1 << PLUGIN_FFMPEG_ID;
2500         add_item(new AddPluginItem(this, "ladspa", PLUGIN_LADSPA_ID));
2501         vis |= 1 << PLUGIN_LADSPA_ID;
2502 #ifdef HAVE_LV2
2503         add_item(new AddPluginItem(this, "lv2", PLUGIN_LV2_ID));
2504         vis |= 1 << PLUGIN_LV2_ID;
2505 #endif
2506         for( int i=0; i<MWindow::plugindb->size(); ++i ) {
2507                 PluginServer *plugin = MWindow::plugindb->get(i);
2508                 if( !plugin->audio && !plugin->video ) continue;
2509                 int idx = plugin->dir_idx;
2510                 uint32_t msk = 1 << idx;
2511                 if( (msk & vis) != 0 ) continue;
2512                 vis |= msk;
2513                 char parent[BCTEXTLEN];
2514                 strcpy(parent, plugin->path);
2515                 char *bp = strrchr(parent, '/');
2516                 if( bp ) { *bp = 0;  bp = strrchr(parent, '/'); }
2517                 if( !bp ) bp = parent; else ++bp;
2518                 add_item(new AddPluginItem(this, bp, idx));
2519         }
2520 }
2521
2522 #if 0
2523 // plugin_dirs list from toplevel makefile include plugin_defs
2524 N_("ffmpeg")
2525 N_("ladspa")
2526 N_("lv2")
2527 N_("audio_tools")
2528 N_("audio_transitions")
2529 N_("blending")
2530 N_("colors")
2531 N_("exotic")
2532 N_("transforms")
2533 N_("tv_effects")
2534 N_("video_tools")
2535 N_("video_transitions")
2536 #endif
2537
2538 AddPluginItem::AddPluginItem(AddTools *menu, char const *text, int idx)
2539  : BC_MenuItem(_(text))
2540 {
2541         this->menu = menu;
2542         this->idx = idx;
2543         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2544         int chk = (msk & vis) ? 1 : 0;
2545         set_checked(chk);
2546 }
2547
2548 int AddPluginItem::handle_event()
2549 {
2550         int chk = get_checked() ^ 1;
2551         set_checked(chk);
2552         uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2553         menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
2554         menu->gui->update_effects();
2555         menu->gui->save_defaults(menu->mwindow->defaults);
2556         menu->gui->async_update_assets();
2557         return 1;
2558 }
2559
2560 AVIconDrawing::AVIconDrawing(AWindowGUI *agui, int x, int y, VFrame **images)
2561  : BC_Toggle(x, y, images, agui->vicon_drawing)
2562 {
2563         this->agui = agui;
2564         set_tooltip(_("draw vicons"));
2565 }
2566
2567 void AVIconDrawing::calculate_geometry(AWindowGUI *agui, VFrame **images, int *ww, int *hh)
2568 {
2569         int text_line = -1, toggle_x = -1, toggle_y = -1;
2570         int text_x = -1, text_y = -1, text_w = -1, text_h = -1;
2571         BC_Toggle::calculate_extents(agui, images, 1,
2572                 &text_line, ww, hh, &toggle_x, &toggle_y,
2573                 &text_x, &text_y, &text_w, &text_h, "", MEDIUMFONT);
2574 }
2575
2576 AVIconDrawing::~AVIconDrawing()
2577 {
2578 }
2579
2580 int AVIconDrawing::handle_event()
2581 {
2582         agui->vicon_drawing = get_value();
2583         if( agui->vicon_drawing )
2584                 agui->start_vicon_drawing();
2585         else
2586                 agui->stop_vicon_drawing();
2587         return 1;
2588 }
2589
2590
2591 AWindowListFormat::AWindowListFormat(MWindow *mwindow, AWindowGUI *gui)
2592  : BC_MenuItem("")
2593 {
2594         this->mwindow = mwindow;
2595         this->gui = gui;
2596 }
2597
2598 int AWindowListFormat::handle_event()
2599 {
2600         gui->stop_vicon_drawing();
2601
2602         EDLSession *session = mwindow->edl->session;
2603         switch( session->assetlist_format ) {
2604         case ASSETS_TEXT:
2605                 session->assetlist_format = ASSETS_ICONS;
2606                 break;
2607         case ASSETS_ICONS:
2608                 session->assetlist_format = ASSETS_TEXT;
2609                 break;
2610         }
2611
2612         gui->asset_list->update_format(session->assetlist_format, 1);
2613         if( !mwindow->awindow->gui->allow_iconlisting ) {
2614                 mwindow->edl->session->assetlist_format = ASSETS_TEXT;
2615         }
2616
2617         gui->start_vicon_drawing();
2618         return 1;
2619 }
2620
2621 void AWindowListFormat::update()
2622 {
2623         set_text(mwindow->edl->session->assetlist_format == ASSETS_TEXT ?
2624                 (char*)_("Display icons") : (char*)_("Display text"));
2625 }
2626
2627 AWindowListSort::AWindowListSort(MWindow *mwindow, AWindowGUI *gui)
2628  : BC_MenuItem(_("Sort items"))
2629 {
2630         this->mwindow = mwindow;
2631         this->gui = gui;
2632 }
2633
2634 int AWindowListSort::handle_event()
2635 {
2636         gui->sort_assets(0);
2637         return 1;
2638 }
2639