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