4 * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
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.
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.
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
24 #include "assetedit.h"
25 #include "assetpopup.h"
27 #include "audiodevice.h"
28 #include "awindowgui.h"
30 #include "bccmodels.h"
31 #include "bcsignals.h"
33 #include "binfolder.h"
38 #include "clippopup.h"
40 #include "cwindowgui.h"
43 #include "edlsession.h"
44 #include "effectlist.h"
46 #include "filesystem.h"
47 #include "folderlistmenu.h"
48 #include "indexable.h"
52 #include "labelpopup.h"
53 #include "localsession.h"
55 #include "mainsession.h"
56 #include "mwindowgui.h"
58 #include "preferences.h"
60 #include "proxypopup.h"
61 #include "renderengine.h"
65 #include "transportque.h"
69 #include "vwindowgui.h"
72 #include "data/lad_picon_png.h"
73 #include "data/ff_audio_png.h"
74 #include "data/ff_video_png.h"
81 const char *AWindowGUI::folder_names[] =
85 N_("Audio Transitions"),
86 N_("Video Transitions"),
94 AssetVIcon::AssetVIcon(AssetPicon *picon, int w, int h, double framerate, int64_t length)
95 : VIcon(w, h, framerate), Garbage("AssetVIcon")
98 this->length = length;
102 AssetVIcon::~AssetVIcon()
104 picon->gui->vicon_thread->del_vicon(this);
108 VFrame *AssetVIcon::frame()
110 Asset *asset = (Asset *)picon->indexable;
111 if( !asset->video_data && audio_data && audio_size && length > 0 ) {
112 if( !temp ) temp = new VFrame(0, -1, vw, vh, BC_RGB888, -1);
114 int sample_rate = asset->get_sample_rate();
115 int64_t audio_samples = asset->get_audio_samples();
116 double duration = (double)audio_samples / sample_rate;
117 picon->draw_hue_bar(temp, duration);
118 int secs = length / frame_rate + 0.5;
119 if( !secs ) secs = 1;
120 int bfrsz = VICON_SAMPLE_RATE;
121 int samples = audio_size/sizeof(vicon_audio_t);
122 double line_pos = (double)seq_no/(length-1);
123 int audio_pos = samples * line_pos * (secs-1)/secs;
124 vicon_audio_t *audio_data = ((vicon_audio_t *)this->audio_data) + audio_pos;
125 static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
126 double data[bfrsz], sample_scale = 1./mx;
127 int len = samples - audio_pos;
128 if( len > bfrsz ) len = bfrsz;
130 while( i < len ) data[i++] = *audio_data++ * sample_scale;
131 while( i < bfrsz ) data[i++] = 0;
132 picon->draw_wave(temp, data, bfrsz, RED, GREEN);
133 int x = (vw-1) * line_pos;
134 temp->pixel_rgb = RED;
135 temp->draw_line(x,0, x,vh);
138 int ww = picon->gui->vicon_thread->view_w;
139 int hh = picon->gui->vicon_thread->view_h;
140 if( !asset->video_data ) {
142 temp = new VFrame(0, -1, ww, hh, BC_RGB888, -1);
147 if( seq_no >= images.size() ) {
148 MWindow *mwindow = picon->mwindow;
149 File *file = mwindow->video_cache->check_out(asset, mwindow->edl, 1);
150 if( !file ) return 0;
151 if( temp && (temp->get_w() != asset->width || temp->get_h() != asset->height) ) {
152 delete temp; temp = 0;
155 temp = new VFrame(0, -1, asset->width, asset->height, BC_RGB888, -1);
156 while( seq_no >= images.size() ) {
157 mwindow->video_cache->check_in(asset);
159 file = mwindow->video_cache->check_out(asset, mwindow->edl, 0);
160 if( !file ) { usleep(1000); continue; }
162 int64_t pos = images.size() / picon->gui->vicon_thread->refresh_rate * frame_rate;
163 file->set_video_position(pos,0);
164 if( file->read_frame(temp) ) temp->clear_frame();
165 add_image(temp, ww, hh, BC_RGB8);
167 mwindow->video_cache->check_in(asset);
169 return *images[seq_no];
172 int64_t AssetVIcon::set_seq_no(int64_t no)
174 if( no >= length ) no = 0;
178 int AssetVIcon::get_vx()
180 BC_ListBox *lbox = picon->gui->asset_list;
181 return lbox->get_icon_x(picon);
183 int AssetVIcon::get_vy()
185 BC_ListBox *lbox = picon->gui->asset_list;
186 return lbox->get_icon_y(picon);
189 void AssetVIcon::load_audio()
191 MWindow *mwindow = picon->mwindow;
192 Asset *asset = (Asset *)picon->indexable;
193 File *file = mwindow->audio_cache->check_out(asset, mwindow->edl, 1);
194 int channels = asset->get_audio_channels();
195 if( channels > 2 ) channels = 2;
196 int sample_rate = asset->get_sample_rate();
197 int bfrsz = sample_rate;
198 Samples samples(bfrsz);
199 double time_scale = (double)sample_rate / VICON_SAMPLE_RATE;
200 vicon_audio_t *audio_data = (vicon_audio_t *)this->audio_data;
201 static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
202 double sample_scale = (double)mx / channels;
203 int audio_pos = 0, audio_len = audio_size/sizeof(vicon_audio_t);
204 while( audio_pos < audio_len ) {
205 int64_t pos = audio_pos * time_scale;
206 for( int ch=0; ch<channels; ++ch ) {
207 file->set_channel(ch);
208 file->set_audio_position(pos);
209 file->read_samples(&samples, bfrsz);
210 double *data = samples.get_data();
211 for( int64_t k=audio_pos; k<audio_len; ++k ) {
212 int i = k * time_scale - pos;
213 if( i >= bfrsz ) break;
214 int v = audio_data[k] + data[i] * sample_scale;
215 audio_data[k] = CLIP(v, -mx,mx);
218 audio_pos = (pos + bfrsz) / time_scale;
220 mwindow->audio_cache->check_in(asset);
224 AssetVIconAudio::AssetVIconAudio(AWindowGUI *gui)
228 audio = new AudioDevice(gui->mwindow);
232 AssetVIconAudio::~AssetVIconAudio()
237 void AssetVIconAudio::run()
240 int64_t bfrsz = VICON_SAMPLE_RATE;
241 MWindow *mwindow = gui->mwindow;
242 EDL *edl = mwindow->edl;
243 EDLSession *session = edl->session;
244 AudioOutConfig *aconfig = session->playback_config->aconfig;
245 audio->open_output(aconfig, VICON_SAMPLE_RATE, bfrsz, channels, 0);
246 audio->start_playback();
247 double out0[bfrsz], out1[bfrsz], *out[2] = { out0, out1 };
248 vicon_audio_t *audio_data = (vicon_audio_t *)vicon->audio_data;
249 static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
251 int audio_len = vicon->audio_size/sizeof(vicon_audio_t);
252 while( !interrupted ) {
253 int len = audio_len - audio_pos;
254 if( len <= 0 ) break;
255 if( len > bfrsz ) len = bfrsz;
257 for( int i=0; i<len; ++i,++k )
258 out0[i] = out1[i] = (double)audio_data[k] / mx;
260 audio->write_buffer(out, channels, len);
264 audio->set_last_buffer();
265 audio->stop_audio(interrupted ? 0 : 1);
269 void AssetVIconAudio::start(AssetVIcon *vicon)
271 if( running() ) return;
278 void AssetVIconAudio::stop(int wait)
280 if( running() && !interrupted ) {
282 audio->stop_audio(wait);
286 vicon->playing_audio = 0;
291 void AssetVIcon::start_audio()
293 picon->gui->vicon_audio->stop(0);
295 picon->gui->vicon_audio->start(this);
298 void AssetVIcon::stop_audio()
300 picon->gui->vicon_audio->stop(0);
305 AWindowFolderItem::AWindowFolderItem()
311 AWindowFolderItem::AWindowFolderItem(const char *text, int color)
312 : BC_ListBoxItem(text, color)
317 AWindowFolderItem::AWindowFolderItem(const char *text, BC_Pixmap *icon, int color)
318 : BC_ListBoxItem(text, icon, color)
323 AssetPicon *AWindowFolderItem::get_picon()
325 AWindowFolderItem *item = this;
326 while( item->parent ) { item = (AWindowFolderItem*)item->parent; }
327 return (AssetPicon*)item;
330 int AWindowFolderSubItems::matches(const char *text)
332 int i = names.size();
333 while( --i >= 0 && strcmp(names[i], text) );
335 ArrayList<BC_ListBoxItem *> *sublist = get_sublist();
336 i = sublist ? sublist->size() : 0;
338 AWindowFolderSubItems *item = (AWindowFolderSubItems *)sublist->get(i);
339 if( item->matches(text) ) break;
342 return i >= 0 ? 1 : 0;
346 AssetPicon::AssetPicon(MWindow *mwindow,
347 AWindowGUI *gui, Indexable *indexable)
348 : AWindowFolderItem()
351 this->mwindow = mwindow;
353 this->indexable = indexable;
354 indexable->add_user();
355 this->id = indexable->id;
358 AssetPicon::AssetPicon(MWindow *mwindow,
359 AWindowGUI *gui, EDL *edl)
360 : AWindowFolderItem()
363 this->mwindow = mwindow;
370 AssetPicon::AssetPicon(MWindow *mwindow,
371 AWindowGUI *gui, int folder, int persist)
372 : AWindowFolderItem(_(AWindowGUI::folder_names[folder]),
373 folder>=0 && folder<AWINDOW_FOLDERS ?
374 gui->folder_icons[folder] : gui->folder_icon)
378 this->mwindow = mwindow;
380 persistent = persist;
383 AssetPicon::AssetPicon(MWindow *mwindow,
384 AWindowGUI *gui, int folder, const char *title)
385 : AWindowFolderItem(title, gui->folder_icon)
389 this->mwindow = mwindow;
394 AssetPicon::AssetPicon(MWindow *mwindow,
395 AWindowGUI *gui, PluginServer *plugin)
396 : AWindowFolderItem()
399 this->mwindow = mwindow;
401 this->plugin = plugin;
404 AssetPicon::AssetPicon(MWindow *mwindow,
405 AWindowGUI *gui, Label *label)
406 : AWindowFolderItem()
409 this->mwindow = mwindow;
417 AssetPicon::~AssetPicon()
419 if( vicon ) vicon->remove_user();
421 if( indexable ) indexable->remove_user();
422 if( edl ) edl->remove_user();
423 if( icon && !gui->protected_pixmap(icon) ) {
425 if( !plugin ) delete icon_vframe;
429 void AssetPicon::draw_hue_bar(VFrame *frame, double duration)
431 float t = duration > 1 ? (log(duration) / log(3600.f)) : 0;
433 float h = 300 * t, s = 1., v = 1.;
434 float r, g, b; // duration, 0..1hr == hue red..magenta
435 HSV::hsv_to_rgb(r,g,b, h,s,v);
436 int ih = frame->get_h()/8, iw = frame->get_w();
437 int ir = r * 256; CLAMP(ir, 0,255);
438 int ig = g * 256; CLAMP(ig, 0,255);
439 int ib = b * 256; CLAMP(ib, 0,255);
440 unsigned char **rows = frame->get_rows();
441 for( int y=0; y<ih; ++y ) {
442 unsigned char *rp = rows[y];
443 for( int x=0; x<iw; rp+=3,++x ) {
444 rp[0] = ir; rp[1] = ig; rp[2] = ib;
449 void AssetPicon::draw_wave(VFrame *frame, double *dp, int len, int base_color, int line_color)
451 int w = frame->get_w(), h = frame->get_h();
452 int h1 = h-1, h2 = h/2, y = h2;
453 int rgb_color = frame->pixel_rgb;
454 for( int x=0,x1=0,x2=0; x<w; ++x,x1=x2 ) {
455 double min = *dp, max = min;
456 x2 = (len * (x+1))/w;
457 for( int i=x1; i<x2; ++i ) {
458 double value = *dp++;
459 if( value < min ) min = value;
460 if( value > max ) max = value;
462 int ctr = (min + max) / 2;
463 int y0 = (int)(h2 - ctr*h2); CLAMP(y0, 0,h1);
464 int y1 = (int)(h2 - min*h2); CLAMP(y1, 0,h1);
465 int y2 = (int)(h2 - max*h2); CLAMP(y2, 0,h1);
466 frame->pixel_rgb = line_color;
467 frame->draw_line(x,y1, x,y2);
468 frame->pixel_rgb = base_color;
469 frame->draw_line(x,y, x,y0);
472 frame->pixel_rgb = rgb_color;
475 void AssetPicon::reset()
483 foldernum = AW_NO_FOLDER;
495 void AssetPicon::open_render_engine(EDL *edl, int is_audio)
497 TransportCommand command;
498 command.command = is_audio ? NORMAL_FWD : CURRENT_FRAME;
499 command.get_edl()->copy_all(edl);
500 command.change_type = CHANGE_ALL;
501 command.realtime = 0;
502 render_engine = new RenderEngine(0, mwindow->preferences, 0, 0);
503 render_engine->set_vcache(mwindow->video_cache);
504 render_engine->set_acache(mwindow->audio_cache);
505 render_engine->arm_command(&command);
507 void AssetPicon::close_render_engine()
509 delete render_engine; render_engine = 0;
511 void AssetPicon::render_video(int64_t pos, VFrame *vfrm)
513 if( !render_engine || !render_engine->vrender ) return;
514 render_engine->vrender->process_buffer(vfrm, pos, 0);
516 void AssetPicon::render_audio(int64_t pos, Samples **samples, int len)
518 if( !render_engine || !render_engine->arender ) return;
519 render_engine->arender->process_buffer(samples, len, pos);
522 void AssetPicon::create_objects()
525 char name[BCTEXTLEN];
526 int pixmap_w, pixmap_h;
528 pixmap_h = 50 * BC_WindowBase::get_resources()->icon_scale;
531 fs.extract_name(name, indexable->path);
535 set_text(strcpy(name, edl->local_session->clip_title));
539 if( indexable && indexable->is_asset ) {
540 Asset *asset = (Asset*)indexable;
541 if( asset->video_data ) {
542 if( mwindow->preferences->use_thumbnails ) {
543 gui->unlock_window();
544 File *file = mwindow->video_cache->check_out(asset,
549 int height = asset->height > 0 ? asset->height : 1;
550 pixmap_w = pixmap_h * asset->width / height;
553 file->set_video_position(0, 0);
555 if( gui->temp_picon &&
556 (gui->temp_picon->get_w() != asset->width ||
557 gui->temp_picon->get_h() != asset->height) ) {
558 delete gui->temp_picon;
562 if( !gui->temp_picon ) {
563 gui->temp_picon = new VFrame(0, -1,
564 asset->width, asset->height,
567 { char string[BCTEXTLEN];
568 sprintf(string, _("Reading %s"), name);
569 mwindow->gui->lock_window("AssetPicon::create_objects");
570 mwindow->gui->show_message(string);
571 mwindow->gui->unlock_window(); }
572 file->read_frame(gui->temp_picon);
573 mwindow->video_cache->check_in(asset);
575 gui->lock_window("AssetPicon::create_objects 0");
576 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
577 icon->draw_vframe(gui->temp_picon,
578 0, 0, pixmap_w, pixmap_h, 0, 0);
579 icon_vframe = new VFrame(0,
580 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
581 icon_vframe->transfer_from(gui->temp_picon);
582 if( asset->folder_no == AW_MEDIA_FOLDER ) {
584 double framerate = asset->get_frame_rate();
585 if( !framerate ) framerate = VICON_RATE;
586 int64_t frames = asset->get_video_frames();
587 double secs = frames / framerate;
588 if( secs > 5 ) secs = 5;
589 int64_t length = secs * gui->vicon_thread->refresh_rate;
590 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, framerate, length);
591 if( asset->audio_data && secs > 0 ) {
592 gui->unlock_window();
593 int audio_len = VICON_SAMPLE_RATE*secs+0.5;
594 vicon->init_audio(audio_len*sizeof(vicon_audio_t));
596 gui->lock_window("AssetPicon::create_objects 1");
598 gui->vicon_thread->add_vicon(vicon);
600 else if( asset->folder_no == AW_PROXY_FOLDER ) {
601 char unproxy_path[BCTEXTLEN];
602 int proxy_scale = mwindow->edl->session->proxy_scale;
603 if( !ProxyRender::from_proxy_path(unproxy_path, asset, proxy_scale) ) {
604 Asset *unproxy = mwindow->edl->assets->get_asset(unproxy_path);
606 int i = gui->assets.total;
608 AssetPicon *picon = (AssetPicon*)gui->assets[i];
609 if( picon->id == unproxy->id ) {
610 vicon = picon->vicon;
611 if( vicon ) vicon->add_user();
621 gui->lock_window("AssetPicon::create_objects 2");
622 icon = gui->video_icon;
623 icon_vframe = gui->video_vframe;
627 icon = gui->video_icon;
628 icon_vframe = gui->video_vframe;
632 if( asset->audio_data ) {
633 if( mwindow->preferences->use_thumbnails ) {
634 gui->unlock_window();
635 File *file = mwindow->audio_cache->check_out(asset,
639 pixmap_w = pixmap_h * 16/9;
640 icon_vframe = new VFrame(0,
641 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
642 icon_vframe->clear_frame();
643 { char string[BCTEXTLEN];
644 sprintf(string, _("Reading %s"), name);
645 mwindow->gui->lock_window("AssetPicon::create_objects 3");
646 mwindow->gui->show_message(string);
647 mwindow->gui->unlock_window(); }
648 int sample_rate = asset->get_sample_rate();
649 int channels = asset->get_audio_channels();
650 if( channels > 2 ) channels = 2;
651 int64_t audio_samples = asset->get_audio_samples();
652 double duration = (double)audio_samples / sample_rate;
653 draw_hue_bar(icon_vframe, duration);
654 int bfrsz = sample_rate;
655 Samples samples(bfrsz);
656 static int line_colors[2] = { GREEN, YELLOW };
657 static int base_colors[2] = { RED, PINK };
658 for( int i=channels; --i>=0; ) {
659 file->set_channel(i);
660 file->set_audio_position(0);
661 file->read_samples(&samples, bfrsz);
662 draw_wave(icon_vframe, samples.get_data(), bfrsz,
663 base_colors[i], line_colors[i]);
665 mwindow->audio_cache->check_in(asset);
666 if( asset->folder_no == AW_MEDIA_FOLDER ) {
667 double secs = duration;
668 if( secs > 5 ) secs = 5;
669 double refresh_rate = gui->vicon_thread->refresh_rate;
670 int64_t length = secs * refresh_rate;
671 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, refresh_rate, length);
672 int audio_len = VICON_SAMPLE_RATE*secs+0.5;
673 vicon->init_audio(audio_len*sizeof(vicon_audio_t));
675 gui->vicon_thread->add_vicon(vicon);
677 gui->lock_window("AssetPicon::create_objects 4");
678 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
679 icon->draw_vframe(icon_vframe,
680 0, 0, pixmap_w, pixmap_h, 0, 0);
683 gui->lock_window("AssetPicon::create_objects 5");
684 icon = gui->audio_icon;
685 icon_vframe = gui->audio_vframe;
689 icon = gui->audio_icon;
690 icon_vframe = gui->audio_vframe;
695 comments_time = !stat(asset->path, &st) ? st.st_mtime : 0;
698 if( indexable && !indexable->is_asset ) {
699 icon = gui->video_icon;
700 icon_vframe = gui->video_vframe;
704 if( edl->tracks->playable_video_tracks() ) {
705 if( mwindow->preferences->use_thumbnails ) {
706 gui->unlock_window();
707 char clip_icon_path[BCTEXTLEN];
708 char *clip_icon = edl->local_session->clip_icon;
710 snprintf(clip_icon_path, sizeof(clip_icon_path),
711 "%s/%s", File::get_config_path(), clip_icon);
712 icon_vframe = VFramePng::vframe_png(clip_icon_path);
715 //printf("render clip: %s\n", name);
716 int edl_h = edl->get_h(), edl_w = edl->get_w();
717 int height = edl_h > 0 ? edl_h : 1;
718 int width = edl_w > 0 ? edl_w : 1;
719 int color_model = edl->session->color_model;
720 pixmap_w = pixmap_h * width / height;
722 if( gui->temp_picon &&
723 (gui->temp_picon->get_color_model() != color_model ||
724 gui->temp_picon->get_w() != width ||
725 gui->temp_picon->get_h() != height) ) {
726 delete gui->temp_picon; gui->temp_picon = 0;
729 if( !gui->temp_picon ) {
730 gui->temp_picon = new VFrame(0, -1,
731 width, height, color_model, -1);
733 char string[BCTEXTLEN];
734 sprintf(string, _("Rendering %s"), name);
735 mwindow->gui->lock_window("AssetPicon::create_objects");
736 mwindow->gui->show_message(string);
737 mwindow->gui->unlock_window();
738 open_render_engine(edl, 0);
739 render_video(0, gui->temp_picon);
740 close_render_engine();
741 icon_vframe = new VFrame(0,
742 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
743 icon_vframe->transfer_from(gui->temp_picon);
744 if( clip_icon[0] ) icon_vframe->write_png(clip_icon_path);
747 pixmap_w = icon_vframe->get_w();
748 pixmap_h = icon_vframe->get_h();
750 gui->lock_window("AssetPicon::create_objects 0");
751 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
752 icon->draw_vframe(icon_vframe,
753 0, 0, pixmap_w, pixmap_h, 0, 0);
756 icon = gui->clip_icon;
757 icon_vframe = gui->clip_vframe;
761 if( edl->tracks->playable_audio_tracks() ) {
762 if( mwindow->preferences->use_thumbnails ) {
763 gui->unlock_window();
764 char clip_icon_path[BCTEXTLEN];
765 char *clip_icon = edl->local_session->clip_icon;
767 snprintf(clip_icon_path, sizeof(clip_icon_path),
768 "%s/%s", File::get_config_path(), clip_icon);
769 icon_vframe = VFramePng::vframe_png(clip_icon_path);
772 pixmap_w = pixmap_h * 16/9;
773 icon_vframe = new VFrame(0,
774 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
775 icon_vframe->clear_frame();
776 char string[BCTEXTLEN];
777 sprintf(string, _("Rendering %s"), name);
778 mwindow->gui->lock_window("AssetPicon::create_objects 3");
779 mwindow->gui->show_message(string);
780 mwindow->gui->unlock_window();
781 int sample_rate = edl->get_sample_rate();
782 int channels = edl->get_audio_channels();
783 if( channels > 2 ) channels = 2;
784 int64_t audio_samples = edl->get_audio_samples();
785 double duration = (double)audio_samples / sample_rate;
786 draw_hue_bar(icon_vframe, duration);
787 Samples *samples[MAX_CHANNELS];
788 int bfrsz = sample_rate;
789 for( int i=0; i<MAX_CHANNELS; ++i )
790 samples[i] = i<channels ? new Samples(bfrsz) : 0;
791 open_render_engine(edl, 1);
792 render_audio(0, samples, bfrsz);
793 close_render_engine();
794 gui->lock_window("AssetPicon::create_objects 4");
795 static int line_colors[2] = { GREEN, YELLOW };
796 static int base_colors[2] = { RED, PINK };
797 for( int i=channels; --i>=0; ) {
798 draw_wave(icon_vframe, samples[i]->get_data(), bfrsz,
799 base_colors[i], line_colors[i]);
801 for( int i=0; i<channels; ++i ) delete samples[i];
802 if( clip_icon[0] ) icon_vframe->write_png(clip_icon_path);
805 pixmap_w = icon_vframe->get_w();
806 pixmap_h = icon_vframe->get_h();
808 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
809 icon->draw_vframe(icon_vframe,
810 0, 0, pixmap_w, pixmap_h, 0, 0);
813 icon = gui->clip_icon;
814 icon_vframe = gui->clip_vframe;
820 strcpy(name, _(plugin->title));
822 icon_vframe = plugin->get_picon();
824 icon = gui->create_pixmap(icon_vframe);
825 else if( plugin->audio ) {
826 if( plugin->transition ) {
827 icon = gui->atransition_icon;
828 icon_vframe = gui->atransition_vframe;
830 else if( plugin->is_ffmpeg() ) {
831 icon = gui->ff_aud_icon;
832 icon_vframe = gui->ff_aud_vframe;
834 else if( plugin->is_ladspa() ) {
835 icon = gui->ladspa_icon;
836 icon_vframe = gui->ladspa_vframe;
839 icon = gui->aeffect_icon;
840 icon_vframe = gui->aeffect_vframe;
843 else if( plugin->video ) {
844 if( plugin->transition ) {
845 icon = gui->vtransition_icon;
846 icon_vframe = gui->vtransition_vframe;
848 else if( plugin->is_ffmpeg() ) {
849 icon = gui->ff_vid_icon;
850 icon_vframe = gui->ff_vid_vframe;
853 icon = gui->veffect_icon;
854 icon_vframe = gui->veffect_vframe;
862 mwindow->edl->session->time_format,
863 mwindow->edl->session->sample_rate,
864 mwindow->edl->session->frame_rate,
865 mwindow->edl->session->frames_per_foot);
867 icon = gui->label_icon;
868 icon_vframe = gui->label_vframe;
871 icon = gui->file_icon;
872 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN];
875 set_icon_vframe(icon_vframe);
878 AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
879 : BC_Window(_(PROGRAM_NAME ": Resources"),
880 mwindow->session->awindow_x, mwindow->session->awindow_y,
881 mwindow->session->awindow_w, mwindow->session->awindow_h,
884 this->mwindow = mwindow;
885 this->awindow = awindow;
887 file_vframe = 0; file_icon = 0;
888 folder_vframe = 0; folder_icon = 0;
889 audio_vframe = 0; audio_icon = 0;
890 video_vframe = 0; video_icon = 0;
891 label_vframe = 0; label_icon = 0;
893 atransition_vframe = 0; atransition_icon = 0;
894 vtransition_vframe = 0; vtransition_icon = 0;
895 aeffect_vframe = 0; aeffect_icon = 0;
896 ladspa_vframe = 0; ladspa_icon = 0;
897 veffect_vframe = 0; veffect_icon = 0;
898 ff_aud_vframe = 0; ff_aud_icon = 0;
899 ff_vid_vframe = 0; ff_vid_icon = 0;
901 aeffect_folder_vframe = 0; aeffect_folder_icon = 0;
902 atransition_folder_vframe = 0; atransition_folder_icon = 0;
903 clip_folder_vframe = 0; clip_folder_icon = 0;
904 label_folder_vframe = 0; label_folder_icon = 0;
905 media_folder_vframe = 0; media_folder_icon = 0;
906 proxy_folder_vframe = 0; proxy_folder_icon = 0;
907 veffect_folder_vframe = 0; veffect_folder_icon = 0;
908 vtransition_folder_vframe = 0; vtransition_folder_icon = 0;
910 ladspa_vframe = 0; ladspa_icon = 0;
911 ff_aud_vframe = 0; ff_aud_icon = 0;
912 ff_vid_vframe = 0; ff_vid_icon = 0;
914 clip_vframe = 0; clip_icon = 0;
915 atransition_vframe = 0; atransition_icon = 0;
916 vtransition_vframe = 0; vtransition_icon = 0;
917 aeffect_vframe = 0; aeffect_icon = 0;
918 veffect_vframe = 0; veffect_icon = 0;
920 plugin_visibility = ((uint64_t)1<<(8*sizeof(uint64_t)-1))-1;
930 allow_iconlisting = 1;
935 displayed_folder = AW_NO_FOLDER;
936 new_folder_thread = 0;
937 modify_folder_thread = 0;
938 folder_lock = new Mutex("AWindowGUI::folder_lock");
941 AWindowGUI::~AWindowGUI()
943 assets.remove_all_objects();
944 folders.remove_all_objects();
945 aeffects.remove_all_objects();
946 veffects.remove_all_objects();
947 atransitions.remove_all_objects();
948 vtransitions.remove_all_objects();
949 labellist.remove_all_objects();
950 displayed_assets[1].remove_all_objects();
952 delete new_folder_thread;
953 delete modify_folder_thread;
959 delete remove_plugin;
961 delete file_vframe; delete file_icon;
962 delete folder_vframe; delete folder_icon;
963 delete audio_vframe; delete audio_icon;
964 delete video_vframe; delete video_icon;
965 delete label_vframe; delete label_icon;
966 delete clip_vframe; delete clip_icon;
967 delete aeffect_folder_vframe; delete aeffect_folder_icon;
968 delete atransition_folder_vframe; delete atransition_folder_icon;
969 delete veffect_folder_vframe; delete veffect_folder_icon;
970 delete vtransition_folder_vframe; delete vtransition_folder_icon;
971 delete clip_folder_vframe; delete clip_folder_icon;
972 delete label_folder_vframe; delete label_folder_icon;
973 delete media_folder_vframe; delete media_folder_icon;
974 delete proxy_folder_vframe; delete proxy_folder_icon;
975 delete ladspa_vframe; delete ladspa_icon;
976 delete ff_aud_vframe; delete ff_aud_icon;
977 delete ff_vid_vframe; delete ff_vid_icon;
978 delete atransition_vframe; delete atransition_icon;
979 delete vtransition_vframe; delete vtransition_icon;
980 delete aeffect_vframe; delete aeffect_icon;
981 delete veffect_vframe; delete veffect_icon;
985 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
987 return icon == file_icon ||
988 icon == folder_icon ||
989 icon == audio_icon ||
990 icon == video_icon ||
992 icon == label_icon ||
993 icon == vtransition_icon ||
994 icon == atransition_icon ||
995 icon == veffect_icon ||
996 icon == aeffect_icon ||
997 icon == ladspa_icon ||
998 icon == ff_aud_icon ||
999 icon == ff_vid_icon ||
1000 icon == aeffect_folder_icon ||
1001 icon == veffect_folder_icon ||
1002 icon == atransition_folder_icon ||
1003 icon == vtransition_folder_icon ||
1004 icon == label_folder_icon ||
1005 icon == clip_folder_icon ||
1006 icon == media_folder_icon ||
1007 icon == proxy_folder_icon;
1010 VFrame *AWindowGUI::get_picon(const char *name, const char *plugin_icons)
1012 char png_path[BCTEXTLEN];
1013 char *pp = png_path, *ep = pp + sizeof(png_path)-1;
1014 snprintf(pp, ep-pp, "%s/picon/%s/%s.png",
1015 File::get_plugin_path(), plugin_icons, name);
1016 if( access(png_path, R_OK) ) return 0;
1017 return VFramePng::vframe_png(png_path,0,0);
1020 VFrame *AWindowGUI::get_picon(const char *name)
1022 VFrame *vframe = get_picon(name, mwindow->preferences->plugin_icons);
1024 char png_name[BCSTRLEN], *pp = png_name, *ep = pp + sizeof(png_name)-1;
1025 snprintf(pp, ep-pp, "%s.png", name);
1026 unsigned char *data = mwindow->theme->get_image_data(png_name);
1027 if( data ) vframe = new VFramePng(data, 0.);
1032 void AWindowGUI::resource_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, int idx)
1034 vfrm = get_picon(fn);
1035 if( !vfrm ) vfrm = BC_WindowBase::get_resources()->type_to_icon[idx];
1036 icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
1038 void AWindowGUI::theme_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn)
1040 vfrm = get_picon(fn);
1041 if( !vfrm ) vfrm = mwindow->theme->get_image(fn);
1042 icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
1044 void AWindowGUI::plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, unsigned char *png)
1046 vfrm = get_picon(fn);
1047 if( !vfrm ) vfrm = new VFramePng(png);
1048 icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
1051 void AWindowGUI::create_objects()
1053 lock_window("AWindowGUI::create_objects");
1054 asset_titles[0] = C_("Title");
1055 asset_titles[1] = _("Comments");
1057 set_icon(mwindow->theme->get_image("awindow_icon"));
1059 resource_icon(file_vframe, file_icon, "film_icon", ICON_UNKNOWN);
1060 resource_icon(folder_vframe, folder_icon, "folder_icon", ICON_FOLDER);
1061 resource_icon(audio_vframe, audio_icon, "audio_icon", ICON_SOUND);
1062 resource_icon(video_vframe, video_icon, "video_icon", ICON_FILM);
1063 resource_icon(label_vframe, label_icon, "label_icon", ICON_LABEL);
1065 theme_icon(aeffect_folder_vframe, aeffect_folder_icon, "aeffect_folder");
1066 theme_icon(atransition_folder_vframe, atransition_folder_icon, "atransition_folder");
1067 theme_icon(clip_folder_vframe, clip_folder_icon, "clip_folder");
1068 theme_icon(label_folder_vframe, label_folder_icon, "label_folder");
1069 theme_icon(media_folder_vframe, media_folder_icon, "media_folder");
1070 theme_icon(proxy_folder_vframe, proxy_folder_icon, "proxy_folder");
1071 theme_icon(veffect_folder_vframe, veffect_folder_icon, "veffect_folder");
1072 theme_icon(vtransition_folder_vframe, vtransition_folder_icon, "vtransition_folder");
1074 folder_icons[AW_AEFFECT_FOLDER] = aeffect_folder_icon;
1075 folder_icons[AW_VEFFECT_FOLDER] = veffect_folder_icon;
1076 folder_icons[AW_ATRANSITION_FOLDER] = atransition_folder_icon;
1077 folder_icons[AW_VTRANSITION_FOLDER] = vtransition_folder_icon;
1078 folder_icons[AW_LABEL_FOLDER] = label_folder_icon;
1079 folder_icons[AW_CLIP_FOLDER] = clip_folder_icon;
1080 folder_icons[AW_MEDIA_FOLDER] = media_folder_icon;
1081 folder_icons[AW_PROXY_FOLDER] = proxy_folder_icon;
1083 theme_icon(clip_vframe, clip_icon, "clip_icon");
1084 theme_icon(atransition_vframe, atransition_icon, "atransition_icon");
1085 theme_icon(vtransition_vframe, vtransition_icon, "vtransition_icon");
1086 theme_icon(aeffect_vframe, aeffect_icon, "aeffect_icon");
1087 theme_icon(veffect_vframe, veffect_icon, "veffect_icon");
1089 plugin_icon(ladspa_vframe, ladspa_icon, "lad_picon", lad_picon_png);
1090 plugin_icon(ff_aud_vframe, ff_aud_icon, "ff_audio", ff_audio_png);
1091 plugin_icon(ff_vid_vframe, ff_vid_icon, "ff_video", ff_video_png);
1092 folder_lock->lock("AWindowGUI::create_objects");
1093 // Mandatory folders
1094 folders.append(new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER, 1));
1095 folders.append(new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER, 1));
1096 folders.append(new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER, 1));
1097 folders.append(new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER, 1));
1098 folders.append(new AssetPicon(mwindow, this, AW_LABEL_FOLDER, 1));
1099 folders.append(new AssetPicon(mwindow, this, AW_CLIP_FOLDER, 1));
1100 folders.append(new AssetPicon(mwindow, this, AW_PROXY_FOLDER, 1));
1101 folders.append(new AssetPicon(mwindow, this, AW_MEDIA_FOLDER, 1));
1103 create_label_folder();
1104 folder_lock->unlock();
1106 mwindow->theme->get_awindow_sizes(this);
1107 load_defaults(mwindow->defaults);
1108 new_folder_thread = new NewFolderThread(this);
1109 modify_folder_thread = new ModifyFolderThread(this);
1111 int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1112 int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1113 search_text = new AWindowSearchText(mwindow, this, x1, y1+5);
1114 search_text->create_objects();
1115 int dy = search_text->get_h() + 10;
1117 add_subwindow(asset_list = new AWindowAssets(mwindow, this, x1, y1, w1, h1));
1119 vicon_thread = new VIconThread(asset_list);
1120 asset_list->update_vicon_area();
1121 vicon_thread->start();
1122 vicon_audio = new AssetVIconAudio(this);
1124 add_subwindow(divider = new AWindowDivider(mwindow, this,
1125 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1126 mwindow->theme->adivider_w, mwindow->theme->adivider_h));
1128 divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
1130 int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1131 int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1132 VFrame **images = mwindow->theme->get_image_set("playpatch_data");
1133 AVIconDrawing::calculate_geometry(this, images, &avicon_w, &avicon_h);
1134 add_subwindow(avicon_drawing = new AVIconDrawing(this, fw-avicon_w, fy, images));
1135 add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, _("Visibility")));
1136 add_tools->create_objects();
1137 fy += add_tools->get_h(); fh -= add_tools->get_h();
1138 add_subwindow(folder_list = new AWindowFolders(mwindow,
1139 this, fx, fy, fw, fh));
1141 folder_list->load_expanders();
1143 //int x = mwindow->theme->abuttons_x;
1144 //int y = mwindow->theme->abuttons_y;
1146 add_subwindow(asset_menu = new AssetPopup(mwindow, this));
1147 asset_menu->create_objects();
1148 add_subwindow(clip_menu = new ClipPopup(mwindow, this));
1149 clip_menu->create_objects();
1150 add_subwindow(label_menu = new LabelPopup(mwindow, this));
1151 label_menu->create_objects();
1152 add_subwindow(proxy_menu = new ProxyPopup(mwindow, this));
1153 proxy_menu->create_objects();
1155 add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this));
1156 effectlist_menu->create_objects();
1157 add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
1158 assetlist_menu->create_objects();
1159 add_subwindow(cliplist_menu = new ClipListMenu(mwindow, this));
1160 cliplist_menu->create_objects();
1161 add_subwindow(labellist_menu = new LabelListMenu(mwindow, this));
1162 labellist_menu->create_objects();
1163 add_subwindow(proxylist_menu = new ProxyListMenu(mwindow, this));
1164 proxylist_menu->create_objects();
1166 add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
1167 folderlist_menu->create_objects();
1169 create_custom_xatoms();
1173 int AWindowGUI::resize_event(int w, int h)
1175 mwindow->session->awindow_x = get_x();
1176 mwindow->session->awindow_y = get_y();
1177 mwindow->session->awindow_w = w;
1178 mwindow->session->awindow_h = h;
1180 mwindow->theme->get_awindow_sizes(this);
1181 mwindow->theme->draw_awindow_bg(this);
1182 reposition_objects();
1184 // int x = mwindow->theme->abuttons_x;
1185 // int y = mwindow->theme->abuttons_y;
1186 // new_bin->reposition_window(x, y);
1187 // x += new_bin->get_w();
1188 // delete_bin->reposition_window(x, y);
1189 // x += delete_bin->get_w();
1190 // rename_bin->reposition_window(x, y);
1191 // x += rename_bin->get_w();
1192 // delete_disk->reposition_window(x, y);
1193 // x += delete_disk->get_w();
1194 // delete_project->reposition_window(x, y);
1195 // x += delete_project->get_w();
1196 // info->reposition_window(x, y);
1197 // x += info->get_w();
1198 // redraw_index->reposition_window(x, y);
1199 // x += redraw_index->get_w();
1200 // paste->reposition_window(x, y);
1201 // x += paste->get_w();
1202 // append->reposition_window(x, y);
1203 // x += append->get_w();
1204 // view->reposition_window(x, y);
1206 BC_WindowBase::resize_event(w, h);
1207 asset_list->update_vicon_area();
1211 int AWindowGUI::translation_event()
1213 mwindow->session->awindow_x = get_x();
1214 mwindow->session->awindow_y = get_y();
1218 void AWindowGUI::reposition_objects()
1220 int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1221 int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1222 search_text->reposition_window(x1, y1+5, w1);
1223 int dy = search_text->get_h() + 10;
1225 asset_list->reposition_window(x1, y1, w1, h1);
1226 divider->reposition_window(
1227 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1228 mwindow->theme->adivider_w, mwindow->theme->adivider_h);
1229 int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1230 int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1231 add_tools->resize_event(fw-avicon_w, add_tools->get_h());
1232 avicon_drawing->reposition_window(fw-avicon_w, fy);
1233 fy += add_tools->get_h(); fh -= add_tools->get_h();
1234 folder_list->reposition_window(fx, fy, fw, fh);
1237 int AWindowGUI::save_defaults(BC_Hash *defaults)
1239 defaults->update("PLUGIN_VISIBILTY", plugin_visibility);
1240 defaults->update("VICON_DRAWING", vicon_drawing);
1244 int AWindowGUI::load_defaults(BC_Hash *defaults)
1246 plugin_visibility = defaults->get("PLUGIN_VISIBILTY", plugin_visibility);
1247 vicon_drawing = defaults->get("VICON_DRAWING", vicon_drawing);
1251 int AWindowGUI::close_event()
1254 mwindow->session->show_awindow = 0;
1257 mwindow->gui->lock_window("AWindowGUI::close_event");
1258 mwindow->gui->mainmenu->show_awindow->set_checked(0);
1259 mwindow->gui->unlock_window();
1261 lock_window("AWindowGUI::close_event");
1262 save_defaults(mwindow->defaults);
1263 mwindow->save_defaults();
1267 void AWindowGUI::start_vicon_drawing()
1269 if( !vicon_drawing || !vicon_thread->interrupted ) return;
1270 if( mwindow->edl->session->awindow_folder == AW_MEDIA_FOLDER ||
1271 mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ||
1272 mwindow->edl->session->awindow_folder >= AWINDOW_USER_FOLDERS ) {
1273 switch( mwindow->edl->session->assetlist_format ) {
1275 case ASSETS_ICONS_PACKED:
1276 case ASSETS_ICON_LIST:
1277 asset_list->update_vicon_area();
1278 vicon_thread->start_drawing();
1286 void AWindowGUI::stop_vicon_drawing()
1288 if( vicon_thread->interrupted ) return;
1289 vicon_thread->stop_drawing();
1292 VFrame *AssetPicon::get_vicon_frame()
1294 if( !vicon ) return 0;
1295 if( gui->vicon_thread->interrupted ) return 0;
1296 VFrame *frame = vicon->frame();
1297 if( !frame ) return 0;
1299 vicon_frame = new VFrame(vicon->vw, vicon->vh, frame->get_color_model());
1300 vicon_frame->transfer_from(frame);
1304 int AWindowGUI::cycle_assetlist_format()
1306 EDLSession *session = mwindow->edl->session;
1307 int format = ASSETS_TEXT;
1308 if( allow_iconlisting ) {
1309 switch( session->assetlist_format ) {
1311 format = ASSETS_ICONS;
1314 format = ASSETS_ICONS_PACKED;
1316 case ASSETS_ICONS_PACKED:
1317 format = ASSETS_ICON_LIST;
1319 case ASSETS_ICON_LIST:
1320 format = ASSETS_TEXT;
1324 stop_vicon_drawing();
1325 session->assetlist_format = format;
1326 asset_list->update_format(session->assetlist_format, 0);
1327 async_update_assets();
1328 start_vicon_drawing();
1332 AWindowRemovePluginGUI::
1333 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
1334 int x, int y, PluginServer *plugin)
1335 : BC_Window(_(PROGRAM_NAME ": Remove plugin"), x,y, 500,200, 50, 50, 1, 0, 1, -1, "", 1)
1337 this->awindow = awindow;
1338 this->thread = thread;
1339 this->plugin = plugin;
1340 VFrame *vframe = plugin->get_picon();
1341 icon = vframe ? create_pixmap(vframe) : 0;
1342 plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
1345 AWindowRemovePluginGUI::
1346 ~AWindowRemovePluginGUI()
1348 if( !awindow->gui->protected_pixmap(icon) )
1350 plugin_list.remove_all();
1353 void AWindowRemovePluginGUI::create_objects()
1355 lock_window("AWindowRemovePluginGUI::create_objects");
1356 BC_Button *ok_button = new BC_OKButton(this);
1357 add_subwindow(ok_button);
1358 BC_Button *cancel_button = new BC_CancelButton(this);
1359 add_subwindow(cancel_button);
1361 BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
1362 add_subwindow(title);
1363 y += title->get_h() + 5;
1364 list = new BC_ListBox(x, y,
1365 get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
1366 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
1367 add_subwindow(list);
1372 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
1375 for( int i=0; i<folder.size(); ) {
1376 AssetPicon *picon = (AssetPicon *)folder[i];
1377 if( picon->plugin == plugin ) {
1378 folder.remove_object_number(i);
1387 void AWindowRemovePlugin::handle_close_event(int result)
1390 printf(_("remove %s\n"), plugin->path);
1391 awindow->gui->lock_window("AWindowRemovePlugin::handle_close_event");
1392 ArrayList<BC_ListBoxItem*> *folder =
1393 plugin->audio ? plugin->transition ?
1394 &awindow->gui->atransitions :
1395 &awindow->gui->aeffects :
1396 plugin->video ? plugin->transition ?
1397 &awindow->gui->vtransitions :
1398 &awindow->gui->veffects :
1400 if( folder ) remove_plugin(plugin, *folder);
1401 MWindow *mwindow = awindow->mwindow;
1402 awindow->gui->unlock_window();
1403 char plugin_path[BCTEXTLEN];
1404 strcpy(plugin_path, plugin->path);
1405 mwindow->plugindb->remove(plugin);
1406 remove(plugin_path);
1407 char index_path[BCTEXTLEN];
1408 mwindow->create_defaults_path(index_path, PLUGIN_FILE);
1410 char picon_path[BCTEXTLEN];
1412 snprintf(picon_path, sizeof(picon_path), "%s/picon",
1413 File::get_plugin_path());
1414 char png_name[BCSTRLEN], png_path[BCTEXTLEN];
1415 plugin->get_plugin_png_name(png_name);
1416 fs.update(picon_path);
1417 for( int i=0; i<fs.dir_list.total; ++i ) {
1418 char *fs_path = fs.dir_list[i]->path;
1419 if( !fs.is_dir(fs_path) ) continue;
1420 snprintf(png_path, sizeof(picon_path), "%s/%s",
1424 delete plugin; plugin = 0;
1425 awindow->gui->async_update_assets();
1429 AWindowRemovePlugin::
1430 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
1433 this->awindow = awindow;
1434 this->plugin = plugin;
1437 AWindowRemovePlugin::
1438 ~AWindowRemovePlugin()
1443 BC_Window* AWindowRemovePlugin::new_gui()
1445 int x = awindow->gui->get_abs_cursor_x(0);
1446 int y = awindow->gui->get_abs_cursor_y(0);
1447 AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
1448 gui->create_objects();
1452 int AWindowGUI::keypress_event()
1454 switch( get_keypress() ) {
1462 if( !ctrl_down() && !shift_down() ) {
1463 assetlist_menu->load_file->handle_event();
1468 return cycle_assetlist_format();
1470 if( shift_down() ) {
1471 PluginServer* plugin = selected_plugin();
1472 if( !plugin ) break;
1473 remove_plugin = new AWindowRemovePlugin(awindow, plugin);
1475 remove_plugin->start();
1484 int AWindowGUI::create_custom_xatoms()
1486 UpdateAssetsXAtom = create_xatom("CWINDOWGUI_UPDATE_ASSETS");
1489 int AWindowGUI::receive_custom_xatoms(xatom_event *event)
1491 if( event->message_type == UpdateAssetsXAtom ) {
1498 void AWindowGUI::async_update_assets()
1501 event.message_type = UpdateAssetsXAtom;
1502 send_custom_xatom(&event);
1506 void AWindowGUI::update_folder_list()
1508 for( int i = 0; i < folders.total; i++ ) {
1509 AssetPicon *picon = (AssetPicon*)folders.values[i];
1513 // Search assets for folders
1514 for( int i = 0; i < mwindow->edl->folders.total; i++ ) {
1515 BinFolder *bin_folder = mwindow->edl->folders[i];
1518 for( int j = 0; j < folders.total; j++ ) {
1519 AssetPicon *picon = (AssetPicon*)folders[j];
1520 if( !strcasecmp(picon->get_text(), bin_folder->title) ) {
1528 const char *title = bin_folder->title;
1529 int folder = bin_folder->awindow_folder;
1530 AssetPicon *picon = new AssetPicon(mwindow, this, folder, title);
1531 picon->create_objects();
1532 folders.append(picon);
1536 // Delete unused non-persistent folders
1537 int do_autoplace = 0;
1538 for( int i=folders.total; --i>=0; ) {
1539 AssetPicon *picon = (AssetPicon*)folders.values[i];
1540 if( !picon->in_use && !picon->persistent ) {
1542 folders.remove_number(i);
1547 folder_list->set_autoplacement(&folders, 0, 1);
1550 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
1551 int do_audio, int do_video, int is_realtime, int is_transition)
1553 ArrayList<PluginServer*> plugin_list;
1554 // Get pointers to plugindb entries
1555 mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
1558 for( int i = 0; i < plugin_list.total; i++ ) {
1559 PluginServer *server = plugin_list.values[i];
1560 int visible = plugin_visibility & (1<<server->dir_idx);
1561 if( !visible ) continue;
1562 // Create new listitem
1563 AssetPicon *picon = new AssetPicon(mwindow, this, server);
1564 picon->create_objects();
1565 output->append(picon);
1569 void AWindowGUI::create_label_folder()
1572 for( current = mwindow->edl->labels->first; current; current = NEXT ) {
1573 AssetPicon *picon = new AssetPicon(mwindow, this, current);
1574 picon->create_objects();
1575 labellist.append(picon);
1580 void AWindowGUI::update_asset_list()
1582 ArrayList<AssetPicon *> new_assets;
1583 for( int i = 0; i < assets.total; i++ ) {
1584 AssetPicon *picon = (AssetPicon*)assets.values[i];
1588 mwindow->gui->lock_window("AWindowGUI::update_asset_list");
1589 // Synchronize EDL clips
1590 for( int i=0; i<mwindow->edl->clips.size(); ++i ) {
1593 // Look for clip in existing listitems
1594 for( int j = 0; j < assets.total && !exists; j++ ) {
1595 AssetPicon *picon = (AssetPicon*)assets.values[j];
1597 if( picon->id == mwindow->edl->clips[i]->id ) {
1598 picon->edl = mwindow->edl->clips[i];
1599 picon->set_text(mwindow->edl->clips[i]->local_session->clip_title);
1605 // Create new listitem
1607 AssetPicon *picon = new AssetPicon(mwindow,
1608 this, mwindow->edl->clips[i]);
1609 new_assets.append(picon);
1613 // Synchronize EDL assets
1614 for( Asset *current=mwindow->edl->assets->first; current; current=NEXT ) {
1617 // Look for asset in existing listitems
1618 for( int j = 0; j < assets.total && !exists; j++ ) {
1619 AssetPicon *picon = (AssetPicon*)assets.values[j];
1621 if( picon->id == current->id ) {
1622 picon->indexable = current;
1628 // Create new listitem
1630 AssetPicon *picon = new AssetPicon(mwindow,
1632 new_assets.append(picon);
1636 // Synchronize nested EDLs
1637 for( int i=0; i<mwindow->edl->nested_edls.size(); ++i ) {
1639 EDL *nested_edl = mwindow->edl->nested_edls[i];
1641 // Look for asset in existing listitems
1642 for( int j=0; j<assets.total && !exists; ++j ) {
1643 AssetPicon *picon = (AssetPicon*)assets.values[j];
1645 if( picon->id == nested_edl->id ) {
1646 picon->indexable = nested_edl;
1652 // Create new listitem
1654 AssetPicon *picon = new AssetPicon(mwindow,
1655 this, (Indexable*)nested_edl);
1656 new_assets.append(picon);
1659 mwindow->gui->unlock_window();
1661 for( int i=0; i<new_assets.size(); ++i ) {
1662 AssetPicon *picon = new_assets[i];
1663 picon->create_objects();
1664 if( picon->indexable )
1665 picon->foldernum = AW_MEDIA_FOLDER;
1666 else if( picon->edl )
1667 picon->foldernum = AW_CLIP_FOLDER;
1668 assets.append(picon);
1671 mwindow->gui->lock_window();
1672 mwindow->gui->default_message();
1673 mwindow->gui->unlock_window();
1675 for( int i = assets.size() - 1; i >= 0; i-- ) {
1676 AssetPicon *picon = (AssetPicon*)assets.get(i);
1677 if( !picon->in_use ) {
1679 assets.remove_number(i);
1682 if( picon->indexable && picon->indexable->is_asset ) {
1684 picon->comments_time = !stat(picon->indexable->path, &st) ?
1690 void AWindowGUI::update_picon(Indexable *indexable)
1693 for( int i = 0; i < assets.total; i++ ) {
1694 AssetPicon *picon = (AssetPicon*)assets.values[i];
1695 if( picon->indexable == indexable ||
1696 picon->edl == (EDL *)indexable ) {
1697 char name[BCTEXTLEN];
1699 fs.extract_name(name, indexable->path);
1700 picon->set_text(name);
1701 vicon = picon->vicon;
1706 stop_vicon_drawing();
1707 vicon->clear_images();
1708 vicon->reset(indexable->get_frame_rate());
1709 start_vicon_drawing();
1713 void AWindowGUI::sort_assets()
1715 folder_lock->lock("AWindowGUI::sort_assets");
1716 switch( mwindow->edl->session->awindow_folder ) {
1717 case AW_AEFFECT_FOLDER:
1718 sort_picons(&aeffects);
1720 case AW_VEFFECT_FOLDER:
1721 sort_picons(&veffects);
1723 case AW_ATRANSITION_FOLDER:
1724 sort_picons(&atransitions);
1726 case AW_VTRANSITION_FOLDER:
1727 sort_picons(&vtransitions);
1729 case AW_LABEL_FOLDER:
1730 sort_picons(&labellist);
1733 sort_picons(&assets);
1737 asset_list->update_format(asset_list->get_format(), 0);
1738 folder_lock->unlock();
1742 void AWindowGUI::sort_folders()
1744 folder_lock->lock("AWindowGUI::update_assets");
1745 // folder_list->collapse_recursive(&folders, 0);
1746 folder_list->set_autoplacement(&folders, 0, 1);
1747 sort_picons(&folders);
1748 folder_list->update_format(folder_list->get_format(), 0);
1749 folder_lock->unlock();
1753 EDL *AWindowGUI::collect_proxy(Indexable *indexable)
1755 Asset *proxy_asset = (Asset *)indexable;
1756 char path[BCTEXTLEN];
1757 int proxy_scale = mwindow->edl->session->proxy_scale;
1758 ProxyRender::from_proxy_path(path, proxy_asset, proxy_scale);
1759 Asset *unproxy_asset = mwindow->edl->assets->get_asset(path);
1760 if( !unproxy_asset || !unproxy_asset->layers ) return 0;
1761 // make a clip from proxy video tracks and unproxy audio tracks
1762 EDL *proxy_edl = new EDL(mwindow->edl);
1763 proxy_edl->create_objects();
1764 proxy_edl->set_path(proxy_asset->path);
1765 FileSystem fs; fs.extract_name(path, proxy_asset->path);
1766 strcpy(proxy_edl->local_session->clip_title, path);
1767 strcpy(proxy_edl->local_session->clip_notes, _("Proxy clip"));
1768 proxy_edl->session->video_tracks = proxy_asset->layers;
1769 proxy_edl->session->audio_tracks = unproxy_asset->channels;
1770 proxy_edl->create_default_tracks();
1771 double length = proxy_asset->frame_rate > 0 ?
1772 ( proxy_asset->video_length >= 0 ?
1773 ( proxy_asset->video_length / proxy_asset->frame_rate ) :
1774 ( proxy_edl->session->si_useduration ?
1775 proxy_edl->session->si_duration :
1776 1.0 / proxy_asset->frame_rate ) ) :
1777 1.0 / proxy_edl->session->frame_rate;
1778 Track *current = proxy_edl->tracks->first;
1779 for( int vtrack=0; current; current=NEXT ) {
1780 if( current->data_type != TRACK_VIDEO ) continue;
1781 current->insert_asset(proxy_asset, 0, length, 0, vtrack++);
1783 length = (double)unproxy_asset->audio_length / unproxy_asset->sample_rate;
1784 current = proxy_edl->tracks->first;
1785 for( int atrack=0; current; current=NEXT ) {
1786 if( current->data_type != TRACK_AUDIO ) continue;
1787 current->insert_asset(unproxy_asset, 0, length, 0, atrack++);
1789 proxy_edl->folder_no = AW_PROXY_FOLDER;
1794 void AWindowGUI::collect_assets(int proxy)
1796 mwindow->session->drag_assets->remove_all();
1797 mwindow->session->drag_clips->remove_all();
1798 int i = 0; AssetPicon *result;
1799 while( (result = (AssetPicon*)asset_list->get_selection(0, i++)) != 0 ) {
1800 Indexable *indexable = result->indexable;
1801 if( proxy && indexable && indexable->is_asset &&
1802 indexable->folder_no == AW_PROXY_FOLDER ) {
1803 EDL *drag_edl = collect_proxy(indexable);
1804 if( drag_edl ) mwindow->session->drag_clips->append(drag_edl);
1808 mwindow->session->drag_assets->append(indexable);
1812 mwindow->session->drag_clips->append(result->edl);
1818 void AWindowGUI::copy_picons(AssetPicon *picon, ArrayList<BC_ListBoxItem*> *src)
1820 // Remove current pointers
1821 ArrayList<BC_ListBoxItem*> *dst = displayed_assets;
1822 dst[0].remove_all();
1823 dst[1].remove_all_objects();
1825 AWindowFolderSubItems *sub_items = picon ? picon->sub_items : 0;
1826 int folder = mwindow->edl->session->awindow_folder;
1827 BinFolder *bin_folder = folder < AWINDOW_USER_FOLDERS ? 0 :
1828 mwindow->edl->get_folder(folder);
1830 // Create new pointers
1831 for( int i = 0; i < src->total; i++ ) {
1832 int visible = folder >= AW_CLIP_FOLDER ? 0 : 1;
1833 picon = (AssetPicon*)src->values[i];
1834 picon->sort_key = -1;
1835 if( !visible && bin_folder ) {
1836 Indexable *idxbl = bin_folder->is_clips ? (Indexable *)picon->edl :
1837 picon->indexable ? picon->indexable :
1838 picon->edl ? picon->edl->get_proxy_asset() : 0;
1840 picon->sort_key = mwindow->edl->folders.matches_indexable(folder, idxbl);
1841 if( picon->sort_key < 0 ) continue;
1845 if( !visible && picon->indexable && picon->indexable->folder_no == folder )
1847 if( !visible && picon->edl && picon->edl->folder_no == folder )
1849 if( visible && sub_items ) {
1850 if( !sub_items->matches(picon->get_text()) )
1854 const char *text = search_text->get_text();
1855 if( text && text[0] )
1856 visible = bstrcasestr(picon->get_text(), text) ? 1 : 0;
1858 if( visible && picon->vicon && picon->vicon->hidden )
1859 picon->vicon->hidden = 0;
1861 BC_ListBoxItem *item2, *item1;
1862 dst[0].append(item1 = picon);
1864 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
1867 dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr));
1868 else if( picon->comments_time ) {
1869 char date_time[BCSTRLEN];
1870 struct tm stm; localtime_r(&picon->comments_time, &stm);
1871 sprintf(date_time,"%04d.%02d.%02d %02d:%02d:%02d",
1872 stm.tm_year+1900, stm.tm_mon+1, stm.tm_mday,
1873 stm.tm_hour, stm.tm_min, stm.tm_sec);
1874 dst[1].append(item2 = new BC_ListBoxItem(date_time));
1877 dst[1].append(item2 = new BC_ListBoxItem(""));
1878 item1->set_autoplace_text(1); item1->set_autoplace_icon(1);
1879 item2->set_autoplace_text(1); item2->set_autoplace_icon(1);
1884 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src)
1886 int done = 0, changed = 0;
1889 for( int i=0; i<src->total-1; ++i ) {
1890 AssetPicon *item1 = (AssetPicon *)src->values[i];
1891 AssetPicon *item2 = (AssetPicon *)src->values[i + 1];
1892 double v = item2->sort_key - item1->sort_key;
1893 if( v > 0 ) continue;
1895 const char *cp1 = item1->get_text();
1896 const char *bp1 = strrchr(cp1, '/');
1897 if( bp1 ) cp1 = bp1 + 1;
1898 const char *cp2 = item2->get_text();
1899 const char *bp2 = strrchr(cp2, '/');
1900 if( bp2 ) cp2 = bp2 + 1;
1901 if( strcmp(cp2, cp1) >= 0 ) continue;
1903 src->values[i + 1] = item1;
1904 src->values[i] = item2;
1905 done = 0; changed = 1;
1909 for( int i=0; i<src->total; ++i ) {
1910 AssetPicon *item = (AssetPicon *)src->values[i];
1911 item->set_autoplace_icon(1);
1912 item->set_autoplace_text(1);
1917 void AWindowGUI::filter_displayed_assets()
1919 //allow_iconlisting = 1;
1920 asset_titles[0] = C_("Title");
1921 asset_titles[1] = _("Comments");
1922 AssetPicon *picon = 0;
1923 int selected_folder = mwindow->edl->session->awindow_folder;
1924 // Ensure the current folder icon is highlighted
1925 for( int i = 0; i < folders.total; i++ ) {
1926 AssetPicon *folder_item = (AssetPicon *)folders.values[i];
1927 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
1928 folder_item->set_selected(selected);
1929 if( selected ) picon = folder_item;
1932 ArrayList<BC_ListBoxItem*> *src = &assets;
1933 switch( selected_folder ) {
1934 case AW_AEFFECT_FOLDER: src = &aeffects; break;
1935 case AW_VEFFECT_FOLDER: src = &veffects; break;
1936 case AW_ATRANSITION_FOLDER: src = &atransitions; break;
1937 case AW_VTRANSITION_FOLDER: src = &vtransitions; break;
1938 case AW_LABEL_FOLDER: src = &labellist;
1939 asset_titles[0] = _("Time Stamps");
1940 asset_titles[1] = C_("Title");
1941 //allow_iconlisting = 0;
1944 copy_picons(picon, src);
1948 void AWindowGUI::update_assets()
1950 stop_vicon_drawing();
1951 folder_lock->lock("AWindowGUI::update_assets");
1952 update_folder_list();
1953 update_asset_list();
1954 labellist.remove_all_objects();
1955 create_label_folder();
1957 if( displayed_folder != mwindow->edl->session->awindow_folder )
1958 search_text->clear();
1959 vicon_thread->hide_vicons();
1960 filter_displayed_assets();
1961 folder_lock->unlock();
1963 if( mwindow->edl->session->folderlist_format != folder_list->get_format() ) {
1964 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
1966 int folder_xposition = folder_list->get_xposition();
1967 int folder_yposition = folder_list->get_yposition();
1968 folder_list->update(&folders, 0, 0, 1, folder_xposition, folder_yposition, -1);
1970 if( mwindow->edl->session->assetlist_format != asset_list->get_format() ) {
1971 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
1973 int asset_xposition = asset_list->get_xposition();
1974 int asset_yposition = asset_list->get_yposition();
1975 if( displayed_folder != mwindow->edl->session->awindow_folder ) {
1976 displayed_folder = mwindow->edl->session->awindow_folder;
1977 asset_xposition = asset_yposition = 0;
1979 asset_list->update(displayed_assets, asset_titles,
1980 mwindow->edl->session->asset_columns, ASSET_COLUMNS,
1981 asset_xposition, asset_yposition, -1, 0);
1982 asset_list->center_selection();
1985 start_vicon_drawing();
1989 void AWindowGUI::update_effects()
1991 aeffects.remove_all_objects();
1992 create_persistent_folder(&aeffects, 1, 0, 1, 0);
1993 veffects.remove_all_objects();
1994 create_persistent_folder(&veffects, 0, 1, 1, 0);
1995 atransitions.remove_all_objects();
1996 create_persistent_folder(&atransitions, 1, 0, 0, 1);
1997 vtransitions.remove_all_objects();
1998 create_persistent_folder(&vtransitions, 0, 1, 0, 1);
2001 int AWindowGUI::drag_motion()
2003 if( get_hidden() ) return 0;
2009 int AWindowGUI::drag_stop()
2011 if( get_hidden() ) return 0;
2015 Indexable* AWindowGUI::selected_asset()
2017 AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
2018 return picon ? picon->indexable : 0;
2021 PluginServer* AWindowGUI::selected_plugin()
2023 AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
2024 return picon ? picon->plugin : 0;
2027 AssetPicon* AWindowGUI::selected_folder()
2029 AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
2040 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
2041 : BC_SubWindow(x, y, w, h)
2043 this->mwindow = mwindow;
2046 AWindowDivider::~AWindowDivider()
2050 int AWindowDivider::button_press_event()
2052 if( is_event_win() && cursor_inside() ) {
2053 mwindow->session->current_operation = DRAG_PARTITION;
2059 int AWindowDivider::cursor_motion_event()
2061 if( mwindow->session->current_operation == DRAG_PARTITION ) {
2063 int wmax = mwindow->session->awindow_w - mwindow->theme->adivider_w - wmin;
2064 int fw = gui->get_relative_cursor_x();
2065 if( fw > wmax ) fw = wmax;
2066 if( fw < wmin ) fw = wmin;
2067 mwindow->session->afolders_w = fw;
2068 mwindow->theme->get_awindow_sizes(gui);
2069 gui->reposition_objects();
2075 int AWindowDivider::button_release_event()
2077 if( mwindow->session->current_operation == DRAG_PARTITION ) {
2078 mwindow->session->current_operation = NO_OPERATION;
2089 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
2090 : BC_ListBox(x, y, w, h,
2091 mwindow->edl->session->folderlist_format == FOLDERS_ICONS ?
2092 LISTBOX_ICONS : LISTBOX_TEXT,
2093 &gui->folders, // Each column has an ArrayList of BC_ListBoxItems.
2094 0, // Titles for columns. Set to 0 for no titles
2095 0, // width of each column
2096 1, // Total columns.
2097 0, // Pixel of top of window.
2098 0, // If this listbox is a popup window
2099 LISTBOX_SINGLE, // Select one item or multiple items
2100 ICON_TOP, // Position of icon relative to text of each item
2103 this->mwindow = mwindow;
2110 AWindowFolders::~AWindowFolders()
2114 int AWindowFolders::selection_changed()
2116 AWindowFolderItem *item0 = (AWindowFolderItem*)get_selection(0, 0);
2117 AWindowFolderItem *item1 = (AWindowFolderItem*)get_selection(0, 1);
2118 // prefer expanded entry
2119 AWindowFolderItem *item = item1 ? item1 : item0;
2120 if( item0 && item1 && last_item0 == item0 && last_item1 == item1 ) {
2121 item1->set_selected(0);
2128 AssetPicon *picon = item->get_picon();
2129 picon->sub_items = (AWindowFolderSubItems*)(!item->parent ? 0 : item);
2131 gui->stop_vicon_drawing();
2133 if( get_button_down() && get_buttonpress() == 3 ) {
2134 gui->folderlist_menu->update_titles();
2135 gui->folderlist_menu->activate_menu();
2138 mwindow->edl->session->awindow_folder = picon->foldernum;
2139 gui->asset_list->draw_background();
2140 gui->async_update_assets();
2142 gui->start_vicon_drawing();
2147 int AWindowFolders::button_press_event()
2151 result = BC_ListBox::button_press_event();
2154 if( get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
2155 gui->folderlist_menu->update_titles();
2156 gui->folderlist_menu->activate_menu();
2165 int AWindowFolders::drag_stop()
2168 if( get_hidden() ) return 0;
2169 if( mwindow->session->current_operation == DRAG_ASSET &&
2170 gui->folder_list->cursor_above() ) { // check user folder
2171 int item_no = gui->folder_list->get_cursor_data_item_no();
2172 AssetPicon *picon = (AssetPicon *)(item_no < 0 ? 0 : gui->folders[item_no]);
2173 if( picon && picon->foldernum >= AWINDOW_USER_FOLDERS ) {
2174 BinFolder *folder = mwindow->edl->get_folder(picon->foldernum);
2175 ArrayList<Indexable *> *drags = folder->is_clips ?
2176 ((ArrayList<Indexable *> *)mwindow->session->drag_clips) :
2177 ((ArrayList<Indexable *> *)mwindow->session->drag_assets);
2178 if( folder && drags && !folder->add_patterns(drags, shift_down()) )
2180 mwindow->session->current_operation = ::NO_OPERATION;
2187 AWindowFolderSubItems::AWindowFolderSubItems(AWindowFolderItem *parent, const char *text)
2188 : AWindowFolderItem(text)
2190 this->parent = parent;
2193 int AWindowFolders::load_expanders()
2195 char expanders_path[BCTEXTLEN];
2196 mwindow->create_defaults_path(expanders_path, EXPANDERS_FILE);
2197 FILE *fp = fopen(expanders_path, "r");
2199 snprintf(expanders_path, sizeof(expanders_path), "%s/%s",
2200 File::get_cindat_path(), EXPANDERS_FILE);
2201 fp = fopen(expanders_path, "r");
2205 const char tab = '\t';
2206 char line[BCTEXTLEN]; line[0] = 0;
2207 AWindowFolderItem *item = 0, *parent;
2208 AWindowFolderSubItems *sub_items = 0;
2210 while( fgets(line,sizeof(line),fp) ) {
2211 if( line[0] == '#' ) continue;
2212 int i = strlen(line);
2213 if( i > 0 && line[i-1] == '\n' ) line[--i] = 0;
2214 if( i == 0 ) continue;
2216 for( char *cp=line; *cp==tab; ++cp ) ++i;
2218 int i = gui->folders.size();
2220 AssetPicon *folder = (AssetPicon *)gui->folders[i];
2221 if( !strcmp(folder->get_text(),_(line)) ) break;
2223 item = (AWindowFolderItem*)(i >= 0 ? gui->folders[i] : 0);
2228 if( i > k+1 ) continue;
2230 if( line[i] != '-' && sub_items ) {
2231 sub_items->names.append(cstrdup(_(&line[i])));
2239 item = item->parent;
2242 parent = item->parent;
2244 ArrayList<BC_ListBoxItem*> *sublist = parent->get_sublist();
2245 if( !sublist ) sublist = parent->new_sublist(1);
2246 sub_items = new AWindowFolderSubItems(parent, &line[i]);
2247 sublist->append(item = sub_items);
2254 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
2255 : BC_ListBox(x, y, w, h, !gui->allow_iconlisting ? LISTBOX_TEXT :
2256 mwindow->edl->session->assetlist_format == ASSETS_ICONS ? LISTBOX_ICONS :
2257 mwindow->edl->session->assetlist_format == ASSETS_ICONS_PACKED ? LISTBOX_ICONS_PACKED :
2258 mwindow->edl->session->assetlist_format == ASSETS_ICON_LIST ? LISTBOX_ICON_LIST :
2260 &gui->assets, // Each column has an ArrayList of BC_ListBoxItems.
2261 gui->asset_titles,// Titles for columns. Set to 0 for no titles
2262 mwindow->edl->session->asset_columns, // width of each column
2263 1, // Total columns.
2264 0, // Pixel of top of window.
2265 0, // If this listbox is a popup window
2266 LISTBOX_MULTIPLE, // Select one item or multiple items
2267 ICON_TOP, // Position of icon relative to text of each item
2268 -1) // Allow drags, require shift for scrolling
2270 this->mwindow = mwindow;
2273 set_scroll_stretch(1, 1);
2276 AWindowAssets::~AWindowAssets()
2280 int AWindowAssets::button_press_event()
2284 result = BC_ListBox::button_press_event();
2286 if( !result && get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
2287 BC_ListBox::deactivate_selection();
2288 int folder = mwindow->edl->session->awindow_folder;
2290 case AW_AEFFECT_FOLDER:
2291 case AW_VEFFECT_FOLDER:
2292 case AW_ATRANSITION_FOLDER:
2293 case AW_VTRANSITION_FOLDER:
2294 gui->effectlist_menu->update();
2295 gui->effectlist_menu->activate_menu();
2297 case AW_LABEL_FOLDER:
2298 gui->labellist_menu->update();
2299 gui->labellist_menu->activate_menu();
2301 case AW_CLIP_FOLDER:
2302 gui->cliplist_menu->update();
2303 gui->cliplist_menu->activate_menu();
2305 case AW_PROXY_FOLDER:
2306 gui->proxylist_menu->update();
2307 gui->proxylist_menu->activate_menu();
2310 case AW_MEDIA_FOLDER: {
2311 int shots = folder==AW_MEDIA_FOLDER || folder>=AWINDOW_USER_FOLDERS;
2312 gui->assetlist_menu->update_titles(shots);
2313 gui->assetlist_menu->activate_menu();
2323 int AWindowAssets::handle_event()
2325 AssetPicon *asset_picon = (AssetPicon *)get_selection(0, 0);
2326 if( !asset_picon ) return 0;
2327 Indexable *picon_idxbl = asset_picon->indexable;
2328 EDL *picon_edl = asset_picon->edl;
2330 VWindow *vwindow = 0;
2331 switch( mwindow->edl->session->awindow_folder ) {
2332 case AW_AEFFECT_FOLDER:
2333 case AW_VEFFECT_FOLDER:
2334 case AW_ATRANSITION_FOLDER:
2335 case AW_VTRANSITION_FOLDER: return 1;
2336 case AW_PROXY_FOLDER:
2337 proxy = 1; // fall thru
2339 if( mwindow->vwindows.size() > DEFAULT_VWINDOW )
2340 vwindow = mwindow->vwindows.get(DEFAULT_VWINDOW);
2343 if( !vwindow || !vwindow->is_running() ) return 1;
2344 if( proxy && picon_idxbl ) {
2345 picon_edl = gui->collect_proxy(picon_idxbl);
2349 if( picon_idxbl ) vwindow->change_source(picon_idxbl);
2350 else if( picon_edl ) vwindow->change_source(picon_edl);
2354 int AWindowAssets::selection_changed()
2356 // Show popup window
2358 if( get_button_down() && get_buttonpress() == 3 &&
2359 (item = (AssetPicon*)get_selection(0, 0)) ) {
2360 int folder = mwindow->edl->session->awindow_folder;
2362 case AW_AEFFECT_FOLDER:
2363 case AW_VEFFECT_FOLDER:
2364 case AW_ATRANSITION_FOLDER:
2365 case AW_VTRANSITION_FOLDER:
2366 gui->effectlist_menu->update();
2367 gui->effectlist_menu->activate_menu();
2369 case AW_LABEL_FOLDER:
2370 if( !item->label ) break;
2371 gui->label_menu->activate_menu();
2373 case AW_CLIP_FOLDER:
2374 if( !item->indexable && !item->edl ) break;
2375 gui->clip_menu->update();
2376 gui->clip_menu->activate_menu();
2378 case AW_PROXY_FOLDER:
2379 if( !item->indexable && !item->edl ) break;
2380 gui->proxy_menu->update();
2381 gui->proxy_menu->activate_menu();
2384 if( !item->indexable && !item->edl ) break;
2385 gui->asset_menu->update();
2386 gui->asset_menu->activate_menu();
2390 deactivate_selection();
2392 else if( gui->vicon_drawing && get_button_down() && get_buttonpress() == 1 &&
2393 ( mwindow->edl->session->awindow_folder == AW_MEDIA_FOLDER ||
2394 mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ||
2395 mwindow->edl->session->awindow_folder >= AWINDOW_USER_FOLDERS ) &&
2396 (item = (AssetPicon*)get_selection(0, 0)) != 0 ) {
2398 if( !gui->vicon_thread->vicon ) {
2399 vicon = item->vicon;
2401 gui->vicon_thread->set_view_popup(vicon);
2406 void AWindowAssets::draw_background()
2408 clear_box(0,0,get_w(),get_h(),get_bg_surface());
2409 set_color(BC_WindowBase::get_resources()->audiovideo_color);
2410 set_font(LARGEFONT);
2411 int folder = mwindow->edl->session->awindow_folder;
2412 const char *title = mwindow->edl->get_folder_name(folder);
2413 draw_text(get_w() - get_text_width(LARGEFONT, title) - 4, 30,
2414 title, -1, get_bg_surface());
2417 int AWindowAssets::drag_start_event()
2419 int collect_pluginservers = 0;
2420 int collect_assets = 0, proxy = 0;
2422 if( BC_ListBox::drag_start_event() ) {
2423 switch( mwindow->edl->session->awindow_folder ) {
2424 case AW_AEFFECT_FOLDER:
2425 mwindow->session->current_operation = DRAG_AEFFECT;
2426 collect_pluginservers = 1;
2428 case AW_VEFFECT_FOLDER:
2429 mwindow->session->current_operation = DRAG_VEFFECT;
2430 collect_pluginservers = 1;
2432 case AW_ATRANSITION_FOLDER:
2433 mwindow->session->current_operation = DRAG_ATRANSITION;
2434 collect_pluginservers = 1;
2436 case AW_VTRANSITION_FOLDER:
2437 mwindow->session->current_operation = DRAG_VTRANSITION;
2438 collect_pluginservers = 1;
2440 case AW_LABEL_FOLDER:
2443 case AW_PROXY_FOLDER:
2444 proxy = 1; // fall thru
2445 case AW_MEDIA_FOLDER:
2447 mwindow->session->current_operation = DRAG_ASSET;
2452 if( collect_pluginservers ) {
2454 mwindow->session->drag_pluginservers->remove_all();
2457 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
2458 if( !result ) break;
2460 mwindow->session->drag_pluginservers->append(result->plugin);
2464 if( collect_assets ) {
2465 gui->collect_assets(proxy);
2473 int AWindowAssets::drag_motion_event()
2475 BC_ListBox::drag_motion_event();
2478 mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2479 mwindow->gui->drag_motion();
2480 mwindow->gui->unlock_window();
2482 for( int i = 0; i < mwindow->vwindows.size(); i++ ) {
2483 VWindow *vwindow = mwindow->vwindows.get(i);
2484 if( !vwindow->is_running() ) continue;
2485 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2486 vwindow->gui->drag_motion();
2487 vwindow->gui->unlock_window();
2490 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2491 mwindow->cwindow->gui->drag_motion();
2492 mwindow->cwindow->gui->unlock_window();
2494 lock_window("AWindowAssets::drag_motion_event");
2495 if( mwindow->session->current_operation == DRAG_ASSET &&
2496 gui->folder_list->cursor_above() ) { // highlight user folder
2497 BC_ListBoxItem *item = 0;
2498 int item_no = gui->folder_list->get_cursor_data_item_no(&item);
2499 if( item_no >= 0 ) {
2500 AssetPicon *folder = (AssetPicon *)gui->folders[item_no];
2501 if( folder->foldernum < AWINDOW_USER_FOLDERS ) item_no = -1;
2504 item_no = gui->folder_list->item_to_index(&gui->folders, item);
2505 int folder_xposition = gui->folder_list->get_xposition();
2506 int folder_yposition = gui->folder_list->get_yposition();
2507 gui->folder_list->update(&gui->folders, 0, 0, 1,
2508 folder_xposition, folder_yposition, item_no, 0, 1);
2513 int AWindowAssets::drag_stop_event()
2517 result = gui->drag_stop();
2522 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2523 result = mwindow->gui->drag_stop();
2524 mwindow->gui->unlock_window();
2528 for( int i = 0; !result && i < mwindow->vwindows.size(); i++ ) {
2529 VWindow *vwindow = mwindow->vwindows.get(i);
2530 if( !vwindow ) continue;
2531 if( !vwindow->is_running() ) continue;
2532 if( vwindow->gui->is_hidden() ) continue;
2533 vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2534 if( vwindow->gui->cursor_above() &&
2535 vwindow->gui->get_cursor_over_window() ) {
2536 result = vwindow->gui->drag_stop();
2538 vwindow->gui->unlock_window();
2543 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2544 result = mwindow->cwindow->gui->drag_stop();
2545 mwindow->cwindow->gui->unlock_window();
2548 lock_window("AWindowAssets::drag_stop_event");
2550 result = gui->folder_list->drag_stop();
2555 get_drag_popup()->set_animation(0);
2557 BC_ListBox::drag_stop_event();
2558 // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
2559 mwindow->session->current_operation = ::NO_OPERATION;
2564 int AWindowAssets::column_resize_event()
2566 mwindow->edl->session->asset_columns[0] = get_column_width(0);
2567 mwindow->edl->session->asset_columns[1] = get_column_width(1);
2571 int AWindowAssets::focus_in_event()
2573 int ret = BC_ListBox::focus_in_event();
2574 gui->start_vicon_drawing();
2578 int AWindowAssets::focus_out_event()
2580 gui->stop_vicon_drawing();
2581 return BC_ListBox::focus_out_event();
2584 int AWindowAssets::cursor_enter_event()
2586 int ret = BC_ListBox::cursor_enter_event();
2587 gui->start_vicon_drawing();
2591 int AWindowAssets::cursor_leave_event()
2593 gui->stop_vicon_drawing();
2594 return BC_ListBox::cursor_leave_event();
2597 void AWindowAssets::update_vicon_area()
2599 int x0 = 0, x1 = get_w();
2600 int y0 = get_title_h();
2602 if( is_highlighted() ) {
2603 x0 += LISTBOX_BORDER; x1 -= LISTBOX_BORDER;
2604 y0 += LISTBOX_BORDER; y1 -= LISTBOX_BORDER;
2606 gui->vicon_thread->set_drawing_area(x0,y0, x1,y1);
2609 int AWindowAssets::mouse_over_event(int no)
2611 if( gui->vicon_thread->viewing &&
2612 no >= 0 && no < gui->displayed_assets[0].size() ) {
2613 AssetPicon *picon = (AssetPicon *)gui->displayed_assets[0][no];
2614 VIcon *vicon = picon->vicon;
2615 picon->gui->vicon_thread->set_view_popup(vicon);
2621 AWindowSearchTextBox::AWindowSearchTextBox(AWindowSearchText *search_text, int x, int y, int w)
2622 : BC_TextBox(x, y, w, 1, "")
2624 this->search_text = search_text;
2627 int AWindowSearchTextBox::handle_event()
2629 return search_text->handle_event();
2632 AWindowSearchText::AWindowSearchText(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2634 this->mwindow = mwindow;
2640 void AWindowSearchText::create_objects()
2642 int x1 = x, y1 = y, margin = 10;
2643 gui->add_subwindow(text_title = new BC_Title(x1, y1, _("Search:")));
2644 x1 += text_title->get_w() + margin;
2645 int w1 = gui->get_w() - x1 - 2*margin;
2646 gui->add_subwindow(text_box = new AWindowSearchTextBox(this, x1, y1, w1));
2649 int AWindowSearchText::handle_event()
2651 gui->async_update_assets();
2655 int AWindowSearchText::get_w()
2657 return text_box->get_w() + text_title->get_w() + 10;
2660 int AWindowSearchText::get_h()
2662 return bmax(text_box->get_h(),text_title->get_h());
2665 void AWindowSearchText::reposition_window(int x, int y, int w)
2667 int x1 = x, y1 = y, margin = 10;
2668 text_title->reposition_window(x1, y1);
2669 x1 += text_title->get_w() + margin;
2670 int w1 = gui->get_w() - x1 - 2*margin;
2671 text_box->reposition_window(x1, y1, w1);
2674 const char *AWindowSearchText::get_text()
2676 return text_box->get_text();
2679 void AWindowSearchText::clear()
2681 text_box->update("");
2684 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2685 : BC_Button(x, y, mwindow->theme->deletedisk_data)
2687 this->mwindow = mwindow;
2689 set_tooltip(_("Delete asset from disk"));
2692 int AWindowDeleteDisk::handle_event()
2697 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2698 : BC_Button(x, y, mwindow->theme->deleteproject_data)
2700 this->mwindow = mwindow;
2702 set_tooltip(_("Delete asset from project"));
2705 int AWindowDeleteProject::handle_event()
2710 // AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2711 // : BC_Button(x, y, mwindow->theme->infoasset_data)
2713 // this->mwindow = mwindow;
2715 // set_tooltip(_("Edit information on asset"));
2718 // int AWindowInfo::handle_event()
2720 // int cur_x, cur_y;
2721 // gui->get_abs_cursor(cur_x, cur_y, 0);
2722 // gui->awindow->asset_edit->edit_asset(gui->selected_asset(), cur_x, cur_y);
2726 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2727 : BC_Button(x, y, mwindow->theme->redrawindex_data)
2729 this->mwindow = mwindow;
2731 set_tooltip(_("Redraw index"));
2734 int AWindowRedrawIndex::handle_event()
2739 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2740 : BC_Button(x, y, mwindow->theme->pasteasset_data)
2742 this->mwindow = mwindow;
2744 set_tooltip(_("Paste asset on recordable tracks"));
2747 int AWindowPaste::handle_event()
2752 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2753 : BC_Button(x, y, mwindow->theme->appendasset_data)
2755 this->mwindow = mwindow;
2757 set_tooltip(_("Append asset in new tracks"));
2760 int AWindowAppend::handle_event()
2765 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2766 : BC_Button(x, y, mwindow->theme->viewasset_data)
2768 this->mwindow = mwindow;
2770 set_tooltip(_("View asset"));
2773 int AWindowView::handle_event()
2778 AddTools::AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, const char *title)
2779 : BC_PopupMenu(x, y, BC_Title::calculate_w(gui, title, MEDIUMFONT)+8, title, -1, 0, 4)
2781 this->mwindow = mwindow;
2785 void AddTools::create_objects()
2788 add_item(new AddPluginItem(this, "ffmpeg", PLUGIN_FFMPEG_ID));
2789 vis |= 1 << PLUGIN_FFMPEG_ID;
2790 add_item(new AddPluginItem(this, "ladspa", PLUGIN_LADSPA_ID));
2791 vis |= 1 << PLUGIN_LADSPA_ID;
2793 add_item(new AddPluginItem(this, "lv2", PLUGIN_LV2_ID));
2794 vis |= 1 << PLUGIN_LV2_ID;
2796 for( int i=0; i<MWindow::plugindb->size(); ++i ) {
2797 PluginServer *plugin = MWindow::plugindb->get(i);
2798 if( !plugin->audio && !plugin->video ) continue;
2799 int idx = plugin->dir_idx;
2800 uint32_t msk = 1 << idx;
2801 if( (msk & vis) != 0 ) continue;
2803 char parent[BCTEXTLEN];
2804 strcpy(parent, plugin->path);
2805 char *bp = strrchr(parent, '/');
2806 if( bp ) { *bp = 0; bp = strrchr(parent, '/'); }
2807 if( !bp ) bp = parent; else ++bp;
2808 add_item(new AddPluginItem(this, bp, idx));
2813 // plugin_dirs list from toplevel makefile include plugin_defs
2818 N_("audio_transitions")
2825 N_("video_transitions")
2828 AddPluginItem::AddPluginItem(AddTools *menu, char const *text, int idx)
2829 : BC_MenuItem(_(text))
2833 uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2834 int chk = (msk & vis) ? 1 : 0;
2838 int AddPluginItem::handle_event()
2840 int chk = get_checked() ^ 1;
2842 uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2843 menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
2844 menu->gui->update_effects();
2845 menu->gui->save_defaults(menu->mwindow->defaults);
2846 menu->gui->async_update_assets();
2850 AVIconDrawing::AVIconDrawing(AWindowGUI *agui, int x, int y, VFrame **images)
2851 : BC_Toggle(x, y, images, agui->vicon_drawing)
2854 set_tooltip(_("Preview"));
2857 void AVIconDrawing::calculate_geometry(AWindowGUI *agui, VFrame **images, int *ww, int *hh)
2859 int text_line = -1, toggle_x = -1, toggle_y = -1;
2860 int text_x = -1, text_y = -1, text_w = -1, text_h = -1;
2861 BC_Toggle::calculate_extents(agui, images, 1,
2862 &text_line, ww, hh, &toggle_x, &toggle_y,
2863 &text_x, &text_y, &text_w, &text_h, "", MEDIUMFONT);
2866 AVIconDrawing::~AVIconDrawing()
2870 int AVIconDrawing::handle_event()
2872 agui->vicon_drawing = get_value();
2873 if( agui->vicon_drawing )
2874 agui->start_vicon_drawing();
2876 agui->stop_vicon_drawing();
2881 AWindowListFormat::AWindowListFormat(MWindow *mwindow, AWindowGUI *gui)
2882 : BC_MenuItem("","v",'v')
2884 this->mwindow = mwindow;
2888 int AWindowListFormat::handle_event()
2890 return gui->cycle_assetlist_format();
2893 void AWindowListFormat::update()
2895 EDLSession *session = mwindow->edl->session;
2896 const char *text = 0;
2897 switch( session->assetlist_format ) {
2899 text = _("Display icons");
2902 text = _("Display icons packed");
2904 case ASSETS_ICONS_PACKED:
2905 text = _("Display icon list");
2907 case ASSETS_ICON_LIST:
2908 text = _("Display text");
2914 AWindowListSort::AWindowListSort(MWindow *mwindow, AWindowGUI *gui)
2915 : BC_MenuItem(_("Sort items"))
2917 this->mwindow = mwindow;
2921 int AWindowListSort::handle_event()