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"
26 #include "assetremove.h"
28 #include "audiodevice.h"
30 #include "awindowgui.h"
31 #include "bccmodels.h"
32 #include "bcsignals.h"
34 #include "binfolder.h"
39 #include "clippopup.h"
41 #include "cwindowgui.h"
44 #include "edlsession.h"
45 #include "effectlist.h"
47 #include "filesystem.h"
48 #include "folderlistmenu.h"
49 #include "indexable.h"
53 #include "labelpopup.h"
54 #include "localsession.h"
56 #include "mainsession.h"
57 #include "mwindowgui.h"
59 #include "preferences.h"
61 #include "proxypopup.h"
62 #include "renderengine.h"
66 #include "transportque.h"
70 #include "vwindowgui.h"
73 #include "data/lad_picon_png.h"
74 #include "data/ff_audio_png.h"
75 #include "data/ff_video_png.h"
82 const char *AWindowGUI::folder_names[] =
86 N_("Audio Transitions"),
87 N_("Video Transitions"),
95 AssetVIcon::AssetVIcon(AssetPicon *picon, int w, int h, double framerate, int64_t length)
96 : VIcon(w, h, framerate), Garbage("AssetVIcon")
99 this->length = length;
103 AssetVIcon::~AssetVIcon()
105 picon->gui->vicon_thread->del_vicon(this);
109 VFrame *AssetVIcon::frame()
111 Asset *asset = (Asset *)picon->indexable;
112 if( !asset->video_data && audio_data && audio_size && length > 0 ) {
113 if( !temp ) temp = new VFrame(0, -1, vw, vh, BC_RGB888, -1);
115 int sample_rate = asset->get_sample_rate();
116 int64_t audio_samples = asset->get_audio_samples();
117 double duration = (double)audio_samples / sample_rate;
118 picon->draw_hue_bar(temp, duration);
119 int secs = length / frame_rate + 0.5;
120 if( !secs ) secs = 1;
121 int bfrsz = VICON_SAMPLE_RATE;
122 int samples = audio_size/sizeof(vicon_audio_t);
123 double line_pos = (double)seq_no/(length-1);
124 int audio_pos = samples * line_pos * (secs-1)/secs;
125 vicon_audio_t *audio_data = ((vicon_audio_t *)this->audio_data) + audio_pos;
126 static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
127 double data[bfrsz], sample_scale = 1./mx;
128 int len = samples - audio_pos;
129 if( len > bfrsz ) len = bfrsz;
131 while( i < len ) data[i++] = *audio_data++ * sample_scale;
132 while( i < bfrsz ) data[i++] = 0;
133 picon->draw_wave(temp, data, bfrsz, RED, GREEN);
134 int x = (vw-1) * line_pos;
135 temp->pixel_rgb = RED;
136 temp->draw_line(x,0, x,vh);
139 int ww = picon->gui->vicon_thread->view_w;
140 int hh = picon->gui->vicon_thread->view_h;
141 if( !asset->video_data ) {
143 temp = new VFrame(0, -1, ww, hh, BC_RGB888, -1);
148 if( seq_no >= images.size() ) {
149 MWindow *mwindow = picon->mwindow;
150 File *file = mwindow->video_cache->check_out(asset, mwindow->edl, 1);
151 if( !file ) return 0;
152 if( temp && (temp->get_w() != asset->width || temp->get_h() != asset->height) ) {
153 delete temp; temp = 0;
156 temp = new VFrame(0, -1, asset->width, asset->height, BC_RGB888, -1);
157 while( seq_no >= images.size() ) {
158 mwindow->video_cache->check_in(asset);
160 file = mwindow->video_cache->check_out(asset, mwindow->edl, 0);
161 if( !file ) { usleep(1000); continue; }
163 int64_t pos = images.size() / picon->gui->vicon_thread->refresh_rate * frame_rate;
164 file->set_video_position(pos,0);
165 if( file->read_frame(temp) ) temp->clear_frame();
166 add_image(temp, ww, hh, BC_RGB8);
168 mwindow->video_cache->check_in(asset);
170 return *images[seq_no];
173 int64_t AssetVIcon::set_seq_no(int64_t no)
175 if( no >= length ) no = 0;
179 int AssetVIcon::get_vx()
181 BC_ListBox *lbox = picon->gui->asset_list;
182 return lbox->get_icon_x(picon);
184 int AssetVIcon::get_vy()
186 BC_ListBox *lbox = picon->gui->asset_list;
187 return lbox->get_icon_y(picon);
190 void AssetVIcon::load_audio()
192 MWindow *mwindow = picon->mwindow;
193 Asset *asset = (Asset *)picon->indexable;
194 File *file = mwindow->audio_cache->check_out(asset, mwindow->edl, 1);
195 int channels = asset->get_audio_channels();
196 if( channels > 2 ) channels = 2;
197 int sample_rate = asset->get_sample_rate();
198 int bfrsz = sample_rate;
199 Samples samples(bfrsz);
200 double time_scale = (double)sample_rate / VICON_SAMPLE_RATE;
201 vicon_audio_t *audio_data = (vicon_audio_t *)this->audio_data;
202 static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
203 double sample_scale = (double)mx / channels;
204 int audio_pos = 0, audio_len = audio_size/sizeof(vicon_audio_t);
205 while( audio_pos < audio_len ) {
206 int64_t pos = audio_pos * time_scale;
207 for( int ch=0; ch<channels; ++ch ) {
208 file->set_channel(ch);
209 file->set_audio_position(pos);
210 file->read_samples(&samples, bfrsz);
211 double *data = samples.get_data();
212 for( int64_t k=audio_pos; k<audio_len; ++k ) {
213 int i = k * time_scale - pos;
214 if( i >= bfrsz ) break;
215 int v = audio_data[k] + data[i] * sample_scale;
216 audio_data[k] = CLIP(v, -mx,mx);
219 audio_pos = (pos + bfrsz) / time_scale;
221 mwindow->audio_cache->check_in(asset);
225 AssetVIconAudio::AssetVIconAudio(AWindowGUI *gui)
229 audio = new AudioDevice(gui->mwindow);
233 AssetVIconAudio::~AssetVIconAudio()
238 void AssetVIconAudio::run()
241 int64_t bfrsz = VICON_SAMPLE_RATE;
242 MWindow *mwindow = gui->mwindow;
243 EDL *edl = mwindow->edl;
244 EDLSession *session = edl->session;
245 AudioOutConfig *aconfig = session->playback_config->aconfig;
246 audio->open_output(aconfig, VICON_SAMPLE_RATE, bfrsz, channels, 0);
247 audio->start_playback();
248 double out0[bfrsz], out1[bfrsz], *out[2] = { out0, out1 };
249 vicon_audio_t *audio_data = (vicon_audio_t *)vicon->audio_data;
250 static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
252 int audio_len = vicon->audio_size/sizeof(vicon_audio_t);
253 while( !interrupted ) {
254 int len = audio_len - audio_pos;
255 if( len <= 0 ) break;
256 if( len > bfrsz ) len = bfrsz;
258 for( int i=0; i<len; ++i,++k )
259 out0[i] = out1[i] = (double)audio_data[k] / mx;
261 audio->write_buffer(out, channels, len);
265 audio->set_last_buffer();
266 audio->stop_audio(interrupted ? 0 : 1);
270 void AssetVIconAudio::start(AssetVIcon *vicon)
272 if( running() ) return;
279 void AssetVIconAudio::stop(int wait)
281 if( running() && !interrupted ) {
283 audio->stop_audio(wait);
287 vicon->playing_audio = 0;
292 void AssetVIcon::start_audio()
294 picon->gui->vicon_audio->stop(0);
296 picon->gui->vicon_audio->start(this);
299 void AssetVIcon::stop_audio()
301 picon->gui->vicon_audio->stop(0);
306 AWindowFolderItem::AWindowFolderItem()
312 AWindowFolderItem::AWindowFolderItem(const char *text, int color)
313 : BC_ListBoxItem(text, color)
318 AWindowFolderItem::AWindowFolderItem(const char *text, BC_Pixmap *icon, int color)
319 : BC_ListBoxItem(text, icon, color)
324 AssetPicon *AWindowFolderItem::get_picon()
326 AWindowFolderItem *item = this;
327 while( item->parent ) { item = (AWindowFolderItem*)item->parent; }
328 return (AssetPicon*)item;
331 int AWindowFolderSubItems::matches(const char *text)
333 int i = names.size();
334 while( --i >= 0 && strcmp(names[i], text) );
336 ArrayList<BC_ListBoxItem *> *sublist = get_sublist();
337 i = sublist ? sublist->size() : 0;
339 AWindowFolderSubItems *item = (AWindowFolderSubItems *)sublist->get(i);
340 if( item->matches(text) ) break;
343 return i >= 0 ? 1 : 0;
347 AssetPicon::AssetPicon(MWindow *mwindow,
348 AWindowGUI *gui, Indexable *indexable)
349 : AWindowFolderItem()
352 this->mwindow = mwindow;
354 this->indexable = indexable;
355 indexable->add_user();
356 this->id = indexable->id;
359 AssetPicon::AssetPicon(MWindow *mwindow,
360 AWindowGUI *gui, EDL *edl)
361 : AWindowFolderItem()
364 this->mwindow = mwindow;
371 AssetPicon::AssetPicon(MWindow *mwindow,
372 AWindowGUI *gui, int folder, int persist)
373 : AWindowFolderItem(_(AWindowGUI::folder_names[folder]),
374 folder>=0 && folder<AWINDOW_FOLDERS ?
375 gui->folder_icons[folder] : gui->folder_icon)
379 this->mwindow = mwindow;
381 persistent = persist;
384 AssetPicon::AssetPicon(MWindow *mwindow,
385 AWindowGUI *gui, int folder, const char *title)
386 : AWindowFolderItem(title, gui->folder_icon)
390 this->mwindow = mwindow;
395 AssetPicon::AssetPicon(MWindow *mwindow,
396 AWindowGUI *gui, PluginServer *plugin)
397 : AWindowFolderItem()
400 this->mwindow = mwindow;
402 this->plugin = plugin;
405 AssetPicon::AssetPicon(MWindow *mwindow,
406 AWindowGUI *gui, Label *label)
407 : AWindowFolderItem()
410 this->mwindow = mwindow;
418 AssetPicon::~AssetPicon()
420 if( vicon ) vicon->remove_user();
422 if( indexable ) indexable->remove_user();
423 if( edl ) edl->remove_user();
424 if( icon && !gui->protected_pixmap(icon) ) {
426 if( !plugin ) delete icon_vframe;
430 void AssetPicon::draw_hue_bar(VFrame *frame, double duration)
432 float t = duration > 1 ? (log(duration) / log(3600.f)) : 0;
434 float h = 300 * t, s = 1., v = 1.;
435 float r, g, b; // duration, 0..1hr == hue red..magenta
436 HSV::hsv_to_rgb(r,g,b, h,s,v);
437 int ih = frame->get_h()/8, iw = frame->get_w();
438 int ir = r * 256; CLAMP(ir, 0,255);
439 int ig = g * 256; CLAMP(ig, 0,255);
440 int ib = b * 256; CLAMP(ib, 0,255);
441 unsigned char **rows = frame->get_rows();
442 for( int y=0; y<ih; ++y ) {
443 unsigned char *rp = rows[y];
444 for( int x=0; x<iw; rp+=3,++x ) {
445 rp[0] = ir; rp[1] = ig; rp[2] = ib;
450 void AssetPicon::draw_wave(VFrame *frame, double *dp, int len, int base_color, int line_color)
452 int w = frame->get_w(), h = frame->get_h();
453 int h1 = h-1, h2 = h/2, y = h2;
454 int rgb_color = frame->pixel_rgb;
455 for( int x=0,x1=0,x2=0; x<w; ++x,x1=x2 ) {
456 double min = *dp, max = min;
457 x2 = (len * (x+1))/w;
458 for( int i=x1; i<x2; ++i ) {
459 double value = *dp++;
460 if( value < min ) min = value;
461 if( value > max ) max = value;
463 int ctr = (min + max) / 2;
464 int y0 = (int)(h2 - ctr*h2); CLAMP(y0, 0,h1);
465 int y1 = (int)(h2 - min*h2); CLAMP(y1, 0,h1);
466 int y2 = (int)(h2 - max*h2); CLAMP(y2, 0,h1);
467 frame->pixel_rgb = line_color;
468 frame->draw_line(x,y1, x,y2);
469 frame->pixel_rgb = base_color;
470 frame->draw_line(x,y, x,y0);
473 frame->pixel_rgb = rgb_color;
476 void AssetPicon::reset()
484 foldernum = AW_NO_FOLDER;
496 void AssetPicon::open_render_engine(EDL *edl, int is_audio)
498 TransportCommand command;
499 command.command = is_audio ? NORMAL_FWD : CURRENT_FRAME;
500 command.get_edl()->copy_all(edl);
501 command.change_type = CHANGE_ALL;
502 command.realtime = 0;
503 render_engine = new RenderEngine(0, mwindow->preferences, 0, 0);
504 render_engine->set_vcache(mwindow->video_cache);
505 render_engine->set_acache(mwindow->audio_cache);
506 render_engine->arm_command(&command);
508 void AssetPicon::close_render_engine()
510 delete render_engine; render_engine = 0;
512 void AssetPicon::render_video(int64_t pos, VFrame *vfrm)
514 if( !render_engine || !render_engine->vrender ) return;
515 render_engine->vrender->process_buffer(vfrm, pos, 0);
517 void AssetPicon::render_audio(int64_t pos, Samples **samples, int len)
519 if( !render_engine || !render_engine->arender ) return;
520 render_engine->arender->process_buffer(samples, len, pos);
523 void AssetPicon::create_objects()
526 char name[BCTEXTLEN];
527 int pixmap_w, pixmap_h;
529 pixmap_h = 50 * BC_WindowBase::get_resources()->icon_scale;
532 fs.extract_name(name, indexable->path);
536 set_text(strcpy(name, edl->local_session->clip_title));
540 if( indexable && indexable->is_asset ) {
541 Asset *asset = (Asset*)indexable;
542 if( asset->video_data ) {
543 if( mwindow->preferences->use_thumbnails ) {
544 gui->unlock_window();
545 File *file = mwindow->video_cache->check_out(asset,
550 int height = asset->height > 0 ? asset->height : 1;
551 pixmap_w = pixmap_h * asset->width / height;
554 file->set_video_position(0, 0);
556 if( gui->temp_picon &&
557 (gui->temp_picon->get_w() != asset->width ||
558 gui->temp_picon->get_h() != asset->height) ) {
559 delete gui->temp_picon;
563 if( !gui->temp_picon ) {
564 gui->temp_picon = new VFrame(0, -1,
565 asset->width, asset->height,
568 { char string[BCTEXTLEN];
569 sprintf(string, _("Reading %s"), name);
570 mwindow->gui->lock_window("AssetPicon::create_objects");
571 mwindow->gui->show_message(string);
572 mwindow->gui->unlock_window(); }
573 file->read_frame(gui->temp_picon);
574 mwindow->video_cache->check_in(asset);
576 gui->lock_window("AssetPicon::create_objects 0");
577 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
578 icon->draw_vframe(gui->temp_picon,
579 0, 0, pixmap_w, pixmap_h, 0, 0);
580 icon_vframe = new VFrame(0,
581 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
582 icon_vframe->transfer_from(gui->temp_picon);
583 if( asset->folder_no == AW_MEDIA_FOLDER ) {
585 double framerate = asset->get_frame_rate();
586 if( !framerate ) framerate = VICON_RATE;
587 int64_t frames = asset->get_video_frames();
588 double secs = frames / framerate;
589 if( secs > 5 ) secs = 5;
590 int64_t length = secs * gui->vicon_thread->refresh_rate;
591 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, framerate, length);
592 if( asset->audio_data && secs > 0 ) {
593 gui->unlock_window();
594 int audio_len = VICON_SAMPLE_RATE*secs+0.5;
595 vicon->init_audio(audio_len*sizeof(vicon_audio_t));
597 gui->lock_window("AssetPicon::create_objects 1");
599 gui->vicon_thread->add_vicon(vicon);
601 else if( asset->folder_no == AW_PROXY_FOLDER ) {
602 char unproxy_path[BCTEXTLEN];
603 int proxy_scale = mwindow->edl->session->proxy_scale;
604 if( !ProxyRender::from_proxy_path(unproxy_path, asset, proxy_scale) ) {
605 Asset *unproxy = mwindow->edl->assets->get_asset(unproxy_path);
607 int i = gui->assets.total;
609 AssetPicon *picon = (AssetPicon*)gui->assets[i];
610 if( picon->id == unproxy->id ) {
611 vicon = picon->vicon;
612 if( vicon ) vicon->add_user();
622 gui->lock_window("AssetPicon::create_objects 2");
623 icon = gui->video_icon;
624 icon_vframe = gui->video_vframe;
628 icon = gui->video_icon;
629 icon_vframe = gui->video_vframe;
633 if( asset->audio_data ) {
634 if( mwindow->preferences->use_thumbnails ) {
635 gui->unlock_window();
636 File *file = mwindow->audio_cache->check_out(asset,
640 pixmap_w = pixmap_h * 16/9;
641 icon_vframe = new VFrame(0,
642 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
643 icon_vframe->clear_frame();
644 { char string[BCTEXTLEN];
645 sprintf(string, _("Reading %s"), name);
646 mwindow->gui->lock_window("AssetPicon::create_objects 3");
647 mwindow->gui->show_message(string);
648 mwindow->gui->unlock_window(); }
649 int sample_rate = asset->get_sample_rate();
650 int channels = asset->get_audio_channels();
651 if( channels > 2 ) channels = 2;
652 int64_t audio_samples = asset->get_audio_samples();
653 double duration = (double)audio_samples / sample_rate;
654 draw_hue_bar(icon_vframe, duration);
655 int bfrsz = sample_rate;
656 Samples samples(bfrsz);
657 static int line_colors[2] = { GREEN, YELLOW };
658 static int base_colors[2] = { RED, PINK };
659 for( int i=channels; --i>=0; ) {
660 file->set_channel(i);
661 file->set_audio_position(0);
662 file->read_samples(&samples, bfrsz);
663 draw_wave(icon_vframe, samples.get_data(), bfrsz,
664 base_colors[i], line_colors[i]);
666 mwindow->audio_cache->check_in(asset);
667 if( asset->folder_no == AW_MEDIA_FOLDER ) {
668 double secs = duration;
669 if( secs > 5 ) secs = 5;
670 double refresh_rate = gui->vicon_thread->refresh_rate;
671 int64_t length = secs * refresh_rate;
672 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, refresh_rate, length);
673 int audio_len = VICON_SAMPLE_RATE*secs+0.5;
674 vicon->init_audio(audio_len*sizeof(vicon_audio_t));
676 gui->vicon_thread->add_vicon(vicon);
678 gui->lock_window("AssetPicon::create_objects 4");
679 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
680 icon->draw_vframe(icon_vframe,
681 0, 0, pixmap_w, pixmap_h, 0, 0);
684 gui->lock_window("AssetPicon::create_objects 5");
685 icon = gui->audio_icon;
686 icon_vframe = gui->audio_vframe;
690 icon = gui->audio_icon;
691 icon_vframe = gui->audio_vframe;
696 comments_time = !stat(asset->path, &st) ? st.st_mtime : 0;
699 if( indexable && !indexable->is_asset ) {
700 icon = gui->video_icon;
701 icon_vframe = gui->video_vframe;
705 if( edl->tracks->playable_video_tracks() ) {
706 if( mwindow->preferences->use_thumbnails ) {
707 gui->unlock_window();
708 char clip_icon_path[BCTEXTLEN];
709 char *clip_icon = edl->local_session->clip_icon;
711 snprintf(clip_icon_path, sizeof(clip_icon_path),
712 "%s/%s", File::get_config_path(), clip_icon);
713 icon_vframe = VFramePng::vframe_png(clip_icon_path);
716 //printf("render clip: %s\n", name);
717 int edl_h = edl->get_h(), edl_w = edl->get_w();
718 int height = edl_h > 0 ? edl_h : 1;
719 int width = edl_w > 0 ? edl_w : 1;
720 int color_model = edl->session->color_model;
721 pixmap_w = pixmap_h * width / height;
723 if( gui->temp_picon &&
724 (gui->temp_picon->get_color_model() != color_model ||
725 gui->temp_picon->get_w() != width ||
726 gui->temp_picon->get_h() != height) ) {
727 delete gui->temp_picon; gui->temp_picon = 0;
730 if( !gui->temp_picon ) {
731 gui->temp_picon = new VFrame(0, -1,
732 width, height, color_model, -1);
734 char string[BCTEXTLEN];
735 sprintf(string, _("Rendering %s"), name);
736 mwindow->gui->lock_window("AssetPicon::create_objects");
737 mwindow->gui->show_message(string);
738 mwindow->gui->unlock_window();
739 open_render_engine(edl, 0);
740 render_video(0, gui->temp_picon);
741 close_render_engine();
742 icon_vframe = new VFrame(0,
743 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
744 icon_vframe->transfer_from(gui->temp_picon);
745 if( clip_icon[0] ) icon_vframe->write_png(clip_icon_path);
748 pixmap_w = icon_vframe->get_w();
749 pixmap_h = icon_vframe->get_h();
751 gui->lock_window("AssetPicon::create_objects 0");
752 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
753 icon->draw_vframe(icon_vframe,
754 0, 0, pixmap_w, pixmap_h, 0, 0);
757 icon = gui->clip_icon;
758 icon_vframe = gui->clip_vframe;
762 if( edl->tracks->playable_audio_tracks() ) {
763 if( mwindow->preferences->use_thumbnails ) {
764 gui->unlock_window();
765 char clip_icon_path[BCTEXTLEN];
766 char *clip_icon = edl->local_session->clip_icon;
768 snprintf(clip_icon_path, sizeof(clip_icon_path),
769 "%s/%s", File::get_config_path(), clip_icon);
770 icon_vframe = VFramePng::vframe_png(clip_icon_path);
773 pixmap_w = pixmap_h * 16/9;
774 icon_vframe = new VFrame(0,
775 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
776 icon_vframe->clear_frame();
777 char string[BCTEXTLEN];
778 sprintf(string, _("Rendering %s"), name);
779 mwindow->gui->lock_window("AssetPicon::create_objects 3");
780 mwindow->gui->show_message(string);
781 mwindow->gui->unlock_window();
782 int sample_rate = edl->get_sample_rate();
783 int channels = edl->get_audio_channels();
784 if( channels > 2 ) channels = 2;
785 int64_t audio_samples = edl->get_audio_samples();
786 double duration = (double)audio_samples / sample_rate;
787 draw_hue_bar(icon_vframe, duration);
788 Samples *samples[MAX_CHANNELS];
789 int bfrsz = sample_rate;
790 for( int i=0; i<MAX_CHANNELS; ++i )
791 samples[i] = i<channels ? new Samples(bfrsz) : 0;
792 open_render_engine(edl, 1);
793 render_audio(0, samples, bfrsz);
794 close_render_engine();
795 gui->lock_window("AssetPicon::create_objects 4");
796 static int line_colors[2] = { GREEN, YELLOW };
797 static int base_colors[2] = { RED, PINK };
798 for( int i=channels; --i>=0; ) {
799 draw_wave(icon_vframe, samples[i]->get_data(), bfrsz,
800 base_colors[i], line_colors[i]);
802 for( int i=0; i<channels; ++i ) delete samples[i];
803 if( clip_icon[0] ) icon_vframe->write_png(clip_icon_path);
806 pixmap_w = icon_vframe->get_w();
807 pixmap_h = icon_vframe->get_h();
809 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
810 icon->draw_vframe(icon_vframe,
811 0, 0, pixmap_w, pixmap_h, 0, 0);
814 icon = gui->clip_icon;
815 icon_vframe = gui->clip_vframe;
821 strcpy(name, _(plugin->title));
823 icon_vframe = plugin->get_picon();
825 icon = gui->create_pixmap(icon_vframe);
826 else if( plugin->audio ) {
827 if( plugin->transition ) {
828 icon = gui->atransition_icon;
829 icon_vframe = gui->atransition_vframe;
831 else if( plugin->is_ffmpeg() ) {
832 icon = gui->ff_aud_icon;
833 icon_vframe = gui->ff_aud_vframe;
835 else if( plugin->is_ladspa() ) {
836 icon = gui->ladspa_icon;
837 icon_vframe = gui->ladspa_vframe;
840 icon = gui->aeffect_icon;
841 icon_vframe = gui->aeffect_vframe;
844 else if( plugin->video ) {
845 if( plugin->transition ) {
846 icon = gui->vtransition_icon;
847 icon_vframe = gui->vtransition_vframe;
849 else if( plugin->is_ffmpeg() ) {
850 icon = gui->ff_vid_icon;
851 icon_vframe = gui->ff_vid_vframe;
854 icon = gui->veffect_icon;
855 icon_vframe = gui->veffect_vframe;
863 mwindow->edl->session->time_format,
864 mwindow->edl->session->sample_rate,
865 mwindow->edl->session->frame_rate,
866 mwindow->edl->session->frames_per_foot);
868 icon = gui->label_icon;
869 icon_vframe = gui->label_vframe;
872 icon = gui->file_icon;
873 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN];
876 set_icon_vframe(icon_vframe);
879 AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
880 : BC_Window(_(PROGRAM_NAME ": Resources"),
881 mwindow->session->awindow_x, mwindow->session->awindow_y,
882 mwindow->session->awindow_w, mwindow->session->awindow_h,
885 this->mwindow = mwindow;
886 this->awindow = awindow;
888 file_vframe = 0; file_icon = 0;
889 folder_vframe = 0; folder_icon = 0;
890 audio_vframe = 0; audio_icon = 0;
891 video_vframe = 0; video_icon = 0;
892 label_vframe = 0; label_icon = 0;
894 atransition_vframe = 0; atransition_icon = 0;
895 vtransition_vframe = 0; vtransition_icon = 0;
896 aeffect_vframe = 0; aeffect_icon = 0;
897 ladspa_vframe = 0; ladspa_icon = 0;
898 veffect_vframe = 0; veffect_icon = 0;
899 ff_aud_vframe = 0; ff_aud_icon = 0;
900 ff_vid_vframe = 0; ff_vid_icon = 0;
902 aeffect_folder_vframe = 0; aeffect_folder_icon = 0;
903 atransition_folder_vframe = 0; atransition_folder_icon = 0;
904 clip_folder_vframe = 0; clip_folder_icon = 0;
905 label_folder_vframe = 0; label_folder_icon = 0;
906 media_folder_vframe = 0; media_folder_icon = 0;
907 proxy_folder_vframe = 0; proxy_folder_icon = 0;
908 veffect_folder_vframe = 0; veffect_folder_icon = 0;
909 vtransition_folder_vframe = 0; vtransition_folder_icon = 0;
911 ladspa_vframe = 0; ladspa_icon = 0;
912 ff_aud_vframe = 0; ff_aud_icon = 0;
913 ff_vid_vframe = 0; ff_vid_icon = 0;
915 clip_vframe = 0; clip_icon = 0;
916 atransition_vframe = 0; atransition_icon = 0;
917 vtransition_vframe = 0; vtransition_icon = 0;
918 aeffect_vframe = 0; aeffect_icon = 0;
919 veffect_vframe = 0; veffect_icon = 0;
921 plugin_visibility = ((uint64_t)1<<(8*sizeof(uint64_t)-1))-1;
931 allow_iconlisting = 1;
936 displayed_folder = AW_NO_FOLDER;
937 new_folder_thread = 0;
938 modify_folder_thread = 0;
939 folder_lock = new Mutex("AWindowGUI::folder_lock");
942 AWindowGUI::~AWindowGUI()
944 assets.remove_all_objects();
945 folders.remove_all_objects();
946 aeffects.remove_all_objects();
947 veffects.remove_all_objects();
948 atransitions.remove_all_objects();
949 vtransitions.remove_all_objects();
950 labellist.remove_all_objects();
951 displayed_assets[1].remove_all_objects();
953 delete new_folder_thread;
954 delete modify_folder_thread;
960 delete remove_plugin;
962 delete file_vframe; delete file_icon;
963 delete folder_vframe; delete folder_icon;
964 delete audio_vframe; delete audio_icon;
965 delete video_vframe; delete video_icon;
966 delete label_vframe; delete label_icon;
967 delete clip_vframe; delete clip_icon;
968 delete aeffect_folder_vframe; delete aeffect_folder_icon;
969 delete atransition_folder_vframe; delete atransition_folder_icon;
970 delete veffect_folder_vframe; delete veffect_folder_icon;
971 delete vtransition_folder_vframe; delete vtransition_folder_icon;
972 delete clip_folder_vframe; delete clip_folder_icon;
973 delete label_folder_vframe; delete label_folder_icon;
974 delete media_folder_vframe; delete media_folder_icon;
975 delete proxy_folder_vframe; delete proxy_folder_icon;
976 delete ladspa_vframe; delete ladspa_icon;
977 delete ff_aud_vframe; delete ff_aud_icon;
978 delete ff_vid_vframe; delete ff_vid_icon;
979 delete atransition_vframe; delete atransition_icon;
980 delete vtransition_vframe; delete vtransition_icon;
981 delete aeffect_vframe; delete aeffect_icon;
982 delete veffect_vframe; delete veffect_icon;
986 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
988 return icon == file_icon ||
989 icon == folder_icon ||
990 icon == audio_icon ||
991 icon == video_icon ||
993 icon == label_icon ||
994 icon == vtransition_icon ||
995 icon == atransition_icon ||
996 icon == veffect_icon ||
997 icon == aeffect_icon ||
998 icon == ladspa_icon ||
999 icon == ff_aud_icon ||
1000 icon == ff_vid_icon ||
1001 icon == aeffect_folder_icon ||
1002 icon == veffect_folder_icon ||
1003 icon == atransition_folder_icon ||
1004 icon == vtransition_folder_icon ||
1005 icon == label_folder_icon ||
1006 icon == clip_folder_icon ||
1007 icon == media_folder_icon ||
1008 icon == proxy_folder_icon;
1011 VFrame *AWindowGUI::get_picon(const char *name, const char *plugin_icons)
1013 char png_path[BCTEXTLEN];
1014 char *pp = png_path, *ep = pp + sizeof(png_path)-1;
1015 snprintf(pp, ep-pp, "%s/picon/%s/%s.png",
1016 File::get_plugin_path(), plugin_icons, name);
1017 if( access(png_path, R_OK) ) return 0;
1018 return VFramePng::vframe_png(png_path,0,0);
1021 VFrame *AWindowGUI::get_picon(const char *name)
1023 VFrame *vframe = get_picon(name, mwindow->preferences->plugin_icons);
1025 char png_name[BCSTRLEN], *pp = png_name, *ep = pp + sizeof(png_name)-1;
1026 snprintf(pp, ep-pp, "%s.png", name);
1027 unsigned char *data = mwindow->theme->get_image_data(png_name);
1028 if( data ) vframe = new VFramePng(data, 0.);
1033 void AWindowGUI::resource_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, int idx)
1035 vfrm = get_picon(fn);
1036 if( !vfrm ) vfrm = BC_WindowBase::get_resources()->type_to_icon[idx];
1037 icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
1039 void AWindowGUI::theme_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn)
1041 vfrm = get_picon(fn);
1042 if( !vfrm ) vfrm = mwindow->theme->get_image(fn);
1043 icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
1045 void AWindowGUI::plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, unsigned char *png)
1047 vfrm = get_picon(fn);
1048 if( !vfrm ) vfrm = new VFramePng(png);
1049 icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
1052 void AWindowGUI::create_objects()
1054 lock_window("AWindowGUI::create_objects");
1055 asset_titles[0] = C_("Title");
1056 asset_titles[1] = _("Comments");
1058 set_icon(mwindow->theme->get_image("awindow_icon"));
1060 resource_icon(file_vframe, file_icon, "film_icon", ICON_UNKNOWN);
1061 resource_icon(folder_vframe, folder_icon, "folder_icon", ICON_FOLDER);
1062 resource_icon(audio_vframe, audio_icon, "audio_icon", ICON_SOUND);
1063 resource_icon(video_vframe, video_icon, "video_icon", ICON_FILM);
1064 resource_icon(label_vframe, label_icon, "label_icon", ICON_LABEL);
1066 theme_icon(aeffect_folder_vframe, aeffect_folder_icon, "aeffect_folder");
1067 theme_icon(atransition_folder_vframe, atransition_folder_icon, "atransition_folder");
1068 theme_icon(clip_folder_vframe, clip_folder_icon, "clip_folder");
1069 theme_icon(label_folder_vframe, label_folder_icon, "label_folder");
1070 theme_icon(media_folder_vframe, media_folder_icon, "media_folder");
1071 theme_icon(proxy_folder_vframe, proxy_folder_icon, "proxy_folder");
1072 theme_icon(veffect_folder_vframe, veffect_folder_icon, "veffect_folder");
1073 theme_icon(vtransition_folder_vframe, vtransition_folder_icon, "vtransition_folder");
1075 folder_icons[AW_AEFFECT_FOLDER] = aeffect_folder_icon;
1076 folder_icons[AW_VEFFECT_FOLDER] = veffect_folder_icon;
1077 folder_icons[AW_ATRANSITION_FOLDER] = atransition_folder_icon;
1078 folder_icons[AW_VTRANSITION_FOLDER] = vtransition_folder_icon;
1079 folder_icons[AW_LABEL_FOLDER] = label_folder_icon;
1080 folder_icons[AW_CLIP_FOLDER] = clip_folder_icon;
1081 folder_icons[AW_MEDIA_FOLDER] = media_folder_icon;
1082 folder_icons[AW_PROXY_FOLDER] = proxy_folder_icon;
1084 theme_icon(clip_vframe, clip_icon, "clip_icon");
1085 theme_icon(atransition_vframe, atransition_icon, "atransition_icon");
1086 theme_icon(vtransition_vframe, vtransition_icon, "vtransition_icon");
1087 theme_icon(aeffect_vframe, aeffect_icon, "aeffect_icon");
1088 theme_icon(veffect_vframe, veffect_icon, "veffect_icon");
1090 plugin_icon(ladspa_vframe, ladspa_icon, "lad_picon", lad_picon_png);
1091 plugin_icon(ff_aud_vframe, ff_aud_icon, "ff_audio", ff_audio_png);
1092 plugin_icon(ff_vid_vframe, ff_vid_icon, "ff_video", ff_video_png);
1093 folder_lock->lock("AWindowGUI::create_objects");
1094 // Mandatory folders
1095 folders.append(new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER, 1));
1096 folders.append(new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER, 1));
1097 folders.append(new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER, 1));
1098 folders.append(new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER, 1));
1099 folders.append(new AssetPicon(mwindow, this, AW_LABEL_FOLDER, 1));
1100 folders.append(new AssetPicon(mwindow, this, AW_CLIP_FOLDER, 1));
1101 folders.append(new AssetPicon(mwindow, this, AW_PROXY_FOLDER, 1));
1102 folders.append(new AssetPicon(mwindow, this, AW_MEDIA_FOLDER, 1));
1104 create_label_folder();
1105 folder_lock->unlock();
1107 mwindow->theme->get_awindow_sizes(this);
1108 load_defaults(mwindow->defaults);
1109 new_folder_thread = new NewFolderThread(this);
1110 modify_folder_thread = new ModifyFolderThread(this);
1112 int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1113 int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1114 search_text = new AWindowSearchText(mwindow, this, x1, y1+5);
1115 search_text->create_objects();
1116 int dy = search_text->get_h() + 10;
1118 add_subwindow(asset_list = new AWindowAssets(mwindow, this, x1, y1, w1, h1));
1120 vicon_thread = new VIconThread(asset_list);
1121 asset_list->update_vicon_area();
1122 vicon_thread->start();
1123 vicon_audio = new AssetVIconAudio(this);
1125 add_subwindow(divider = new AWindowDivider(mwindow, this,
1126 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1127 mwindow->theme->adivider_w, mwindow->theme->adivider_h));
1129 divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
1131 int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1132 int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1133 VFrame **images = mwindow->theme->get_image_set("playpatch_data");
1134 AVIconDrawing::calculate_geometry(this, images, &avicon_w, &avicon_h);
1135 add_subwindow(avicon_drawing = new AVIconDrawing(this, fw-avicon_w, fy, images));
1136 add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, _("Visibility")));
1137 add_tools->create_objects();
1138 fy += add_tools->get_h(); fh -= add_tools->get_h();
1139 add_subwindow(folder_list = new AWindowFolders(mwindow,
1140 this, fx, fy, fw, fh));
1142 folder_list->load_expanders();
1144 //int x = mwindow->theme->abuttons_x;
1145 //int y = mwindow->theme->abuttons_y;
1147 add_subwindow(asset_menu = new AssetPopup(mwindow, this));
1148 asset_menu->create_objects();
1149 add_subwindow(clip_menu = new ClipPopup(mwindow, this));
1150 clip_menu->create_objects();
1151 add_subwindow(label_menu = new LabelPopup(mwindow, this));
1152 label_menu->create_objects();
1153 add_subwindow(proxy_menu = new ProxyPopup(mwindow, this));
1154 proxy_menu->create_objects();
1156 add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this));
1157 effectlist_menu->create_objects();
1158 add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
1159 assetlist_menu->create_objects();
1160 add_subwindow(cliplist_menu = new ClipListMenu(mwindow, this));
1161 cliplist_menu->create_objects();
1162 add_subwindow(labellist_menu = new LabelListMenu(mwindow, this));
1163 labellist_menu->create_objects();
1164 add_subwindow(proxylist_menu = new ProxyListMenu(mwindow, this));
1165 proxylist_menu->create_objects();
1167 add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
1168 folderlist_menu->create_objects();
1170 create_custom_xatoms();
1174 int AWindowGUI::resize_event(int w, int h)
1176 mwindow->session->awindow_x = get_x();
1177 mwindow->session->awindow_y = get_y();
1178 mwindow->session->awindow_w = w;
1179 mwindow->session->awindow_h = h;
1181 mwindow->theme->get_awindow_sizes(this);
1182 mwindow->theme->draw_awindow_bg(this);
1183 reposition_objects();
1185 // int x = mwindow->theme->abuttons_x;
1186 // int y = mwindow->theme->abuttons_y;
1187 // new_bin->reposition_window(x, y);
1188 // x += new_bin->get_w();
1189 // delete_bin->reposition_window(x, y);
1190 // x += delete_bin->get_w();
1191 // rename_bin->reposition_window(x, y);
1192 // x += rename_bin->get_w();
1193 // delete_disk->reposition_window(x, y);
1194 // x += delete_disk->get_w();
1195 // delete_project->reposition_window(x, y);
1196 // x += delete_project->get_w();
1197 // info->reposition_window(x, y);
1198 // x += info->get_w();
1199 // redraw_index->reposition_window(x, y);
1200 // x += redraw_index->get_w();
1201 // paste->reposition_window(x, y);
1202 // x += paste->get_w();
1203 // append->reposition_window(x, y);
1204 // x += append->get_w();
1205 // view->reposition_window(x, y);
1207 BC_WindowBase::resize_event(w, h);
1208 asset_list->update_vicon_area();
1212 int AWindowGUI::translation_event()
1214 mwindow->session->awindow_x = get_x();
1215 mwindow->session->awindow_y = get_y();
1219 void AWindowGUI::reposition_objects()
1221 int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1222 int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1223 search_text->reposition_window(x1, y1+5, w1);
1224 int dy = search_text->get_h() + 10;
1226 asset_list->reposition_window(x1, y1, w1, h1);
1227 divider->reposition_window(
1228 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1229 mwindow->theme->adivider_w, mwindow->theme->adivider_h);
1230 int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1231 int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1232 add_tools->resize_event(fw-avicon_w, add_tools->get_h());
1233 avicon_drawing->reposition_window(fw-avicon_w, fy);
1234 fy += add_tools->get_h(); fh -= add_tools->get_h();
1235 folder_list->reposition_window(fx, fy, fw, fh);
1238 int AWindowGUI::save_defaults(BC_Hash *defaults)
1240 defaults->update("PLUGIN_VISIBILTY", plugin_visibility);
1241 defaults->update("VICON_DRAWING", vicon_drawing);
1245 int AWindowGUI::load_defaults(BC_Hash *defaults)
1247 plugin_visibility = defaults->get("PLUGIN_VISIBILTY", plugin_visibility);
1248 vicon_drawing = defaults->get("VICON_DRAWING", vicon_drawing);
1252 int AWindowGUI::close_event()
1255 mwindow->session->show_awindow = 0;
1258 mwindow->gui->lock_window("AWindowGUI::close_event");
1259 mwindow->gui->mainmenu->show_awindow->set_checked(0);
1260 mwindow->gui->unlock_window();
1262 lock_window("AWindowGUI::close_event");
1263 save_defaults(mwindow->defaults);
1264 mwindow->save_defaults();
1268 void AWindowGUI::start_vicon_drawing()
1270 if( !vicon_drawing || !vicon_thread->interrupted ) return;
1271 if( mwindow->edl->session->awindow_folder == AW_MEDIA_FOLDER ||
1272 mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ||
1273 mwindow->edl->session->awindow_folder >= AWINDOW_USER_FOLDERS ) {
1274 switch( mwindow->edl->session->assetlist_format ) {
1276 case ASSETS_ICONS_PACKED:
1277 case ASSETS_ICON_LIST:
1278 asset_list->update_vicon_area();
1279 vicon_thread->start_drawing();
1287 void AWindowGUI::stop_vicon_drawing()
1289 if( vicon_thread->interrupted ) return;
1290 vicon_thread->stop_drawing();
1293 VFrame *AssetPicon::get_vicon_frame()
1295 if( !vicon ) return 0;
1296 if( gui->vicon_thread->interrupted ) return 0;
1297 VFrame *frame = vicon->frame();
1298 if( !frame ) return 0;
1300 vicon_frame = new VFrame(vicon->vw, vicon->vh, frame->get_color_model());
1301 vicon_frame->transfer_from(frame);
1305 int AWindowGUI::cycle_assetlist_format()
1307 EDLSession *session = mwindow->edl->session;
1308 int format = ASSETS_TEXT;
1309 if( allow_iconlisting ) {
1310 switch( session->assetlist_format ) {
1312 format = ASSETS_ICONS;
1315 format = ASSETS_ICONS_PACKED;
1317 case ASSETS_ICONS_PACKED:
1318 format = ASSETS_ICON_LIST;
1320 case ASSETS_ICON_LIST:
1321 format = ASSETS_TEXT;
1325 stop_vicon_drawing();
1326 session->assetlist_format = format;
1327 asset_list->update_format(session->assetlist_format, 0);
1328 async_update_assets();
1329 start_vicon_drawing();
1333 AWindowRemovePluginGUI::
1334 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
1335 int x, int y, PluginServer *plugin)
1336 : BC_Window(_(PROGRAM_NAME ": Remove plugin"), x,y, 500,200, 50, 50, 1, 0, 1, -1, "", 1)
1338 this->awindow = awindow;
1339 this->thread = thread;
1340 this->plugin = plugin;
1341 VFrame *vframe = plugin->get_picon();
1342 icon = vframe ? create_pixmap(vframe) : 0;
1343 plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
1346 AWindowRemovePluginGUI::
1347 ~AWindowRemovePluginGUI()
1349 if( !awindow->gui->protected_pixmap(icon) )
1351 plugin_list.remove_all();
1354 void AWindowRemovePluginGUI::create_objects()
1356 lock_window("AWindowRemovePluginGUI::create_objects");
1357 BC_Button *ok_button = new BC_OKButton(this);
1358 add_subwindow(ok_button);
1359 BC_Button *cancel_button = new BC_CancelButton(this);
1360 add_subwindow(cancel_button);
1362 BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
1363 add_subwindow(title);
1364 y += title->get_h() + 5;
1365 list = new BC_ListBox(x, y,
1366 get_w() - 20, ok_button->get_y() - y - 5, LISTBOX_TEXT, &plugin_list,
1367 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
1368 add_subwindow(list);
1373 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
1376 for( int i=0; i<folder.size(); ) {
1377 AssetPicon *picon = (AssetPicon *)folder[i];
1378 if( picon->plugin == plugin ) {
1379 folder.remove_object_number(i);
1388 void AWindowRemovePlugin::handle_close_event(int result)
1391 printf(_("remove %s\n"), plugin->path);
1392 awindow->gui->lock_window("AWindowRemovePlugin::handle_close_event");
1393 ArrayList<BC_ListBoxItem*> *folder =
1394 plugin->audio ? plugin->transition ?
1395 &awindow->gui->atransitions :
1396 &awindow->gui->aeffects :
1397 plugin->video ? plugin->transition ?
1398 &awindow->gui->vtransitions :
1399 &awindow->gui->veffects :
1401 if( folder ) remove_plugin(plugin, *folder);
1402 MWindow *mwindow = awindow->mwindow;
1403 awindow->gui->unlock_window();
1404 char plugin_path[BCTEXTLEN];
1405 strcpy(plugin_path, plugin->path);
1406 mwindow->plugindb->remove(plugin);
1407 remove(plugin_path);
1408 char index_path[BCTEXTLEN];
1409 mwindow->create_defaults_path(index_path, PLUGIN_FILE);
1411 char picon_path[BCTEXTLEN];
1413 snprintf(picon_path, sizeof(picon_path), "%s/picon",
1414 File::get_plugin_path());
1415 char png_name[BCSTRLEN], png_path[BCTEXTLEN];
1416 plugin->get_plugin_png_name(png_name);
1417 fs.update(picon_path);
1418 for( int i=0; i<fs.dir_list.total; ++i ) {
1419 char *fs_path = fs.dir_list[i]->path;
1420 if( !fs.is_dir(fs_path) ) continue;
1421 snprintf(png_path, sizeof(picon_path), "%s/%s",
1425 delete plugin; plugin = 0;
1426 awindow->gui->async_update_assets();
1430 AWindowRemovePlugin::
1431 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
1434 this->awindow = awindow;
1435 this->plugin = plugin;
1438 AWindowRemovePlugin::
1439 ~AWindowRemovePlugin()
1444 BC_Window* AWindowRemovePlugin::new_gui()
1446 int x = awindow->gui->get_abs_cursor_x(0);
1447 int y = awindow->gui->get_abs_cursor_y(0);
1448 AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
1449 gui->create_objects();
1453 int AWindowGUI::keypress_event()
1455 switch( get_keypress() ) {
1463 if( !ctrl_down() && !shift_down() ) {
1464 assetlist_menu->load_file->handle_event();
1469 return cycle_assetlist_format();
1471 if( shift_down() && ctrl_down() ) {
1472 PluginServer* plugin = selected_plugin();
1473 if( !plugin ) break;
1474 remove_plugin = new AWindowRemovePlugin(awindow, plugin);
1476 remove_plugin->start();
1477 lock_window("AWindowGUI::keypress_event 1");
1481 if( shift_down() ) {
1482 mwindow->awindow->asset_remove->start();
1486 mwindow->remove_assets_from_project(1, 1,
1487 mwindow->session->drag_assets,
1488 mwindow->session->drag_clips);
1489 lock_window("AWindowGUI::keypress_event 2");
1497 int AWindowGUI::create_custom_xatoms()
1499 UpdateAssetsXAtom = create_xatom("CWINDOWGUI_UPDATE_ASSETS");
1502 int AWindowGUI::receive_custom_xatoms(xatom_event *event)
1504 if( event->message_type == UpdateAssetsXAtom ) {
1511 void AWindowGUI::async_update_assets()
1514 event.message_type = UpdateAssetsXAtom;
1515 send_custom_xatom(&event);
1519 void AWindowGUI::update_folder_list()
1521 for( int i = 0; i < folders.total; i++ ) {
1522 AssetPicon *picon = (AssetPicon*)folders.values[i];
1526 // Search assets for folders
1527 for( int i = 0; i < mwindow->edl->folders.total; i++ ) {
1528 BinFolder *bin_folder = mwindow->edl->folders[i];
1531 for( int j = 0; j < folders.total; j++ ) {
1532 AssetPicon *picon = (AssetPicon*)folders[j];
1533 if( !strcasecmp(picon->get_text(), bin_folder->title) ) {
1541 const char *title = bin_folder->title;
1542 int folder = bin_folder->awindow_folder;
1543 AssetPicon *picon = new AssetPicon(mwindow, this, folder, title);
1544 picon->create_objects();
1545 folders.append(picon);
1549 // Delete unused non-persistent folders
1550 int do_autoplace = 0;
1551 for( int i=folders.total; --i>=0; ) {
1552 AssetPicon *picon = (AssetPicon*)folders.values[i];
1553 if( !picon->in_use && !picon->persistent ) {
1555 folders.remove_number(i);
1560 folder_list->set_autoplacement(&folders, 0, 1);
1563 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
1564 int do_audio, int do_video, int is_realtime, int is_transition)
1566 ArrayList<PluginServer*> plugin_list;
1567 // Get pointers to plugindb entries
1568 mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
1571 for( int i = 0; i < plugin_list.total; i++ ) {
1572 PluginServer *server = plugin_list.values[i];
1573 int visible = plugin_visibility & (1<<server->dir_idx);
1574 if( !visible ) continue;
1575 // Create new listitem
1576 AssetPicon *picon = new AssetPicon(mwindow, this, server);
1577 picon->create_objects();
1578 output->append(picon);
1582 void AWindowGUI::create_label_folder()
1585 for( current = mwindow->edl->labels->first; current; current = NEXT ) {
1586 AssetPicon *picon = new AssetPicon(mwindow, this, current);
1587 picon->create_objects();
1588 labellist.append(picon);
1593 void AWindowGUI::update_asset_list()
1595 ArrayList<AssetPicon *> new_assets;
1596 for( int i = 0; i < assets.total; i++ ) {
1597 AssetPicon *picon = (AssetPicon*)assets.values[i];
1601 mwindow->gui->lock_window("AWindowGUI::update_asset_list");
1602 // Synchronize EDL clips
1603 for( int i=0; i<mwindow->edl->clips.size(); ++i ) {
1606 // Look for clip in existing listitems
1607 for( int j = 0; j < assets.total && !exists; j++ ) {
1608 AssetPicon *picon = (AssetPicon*)assets.values[j];
1610 if( picon->id == mwindow->edl->clips[i]->id ) {
1611 picon->edl = mwindow->edl->clips[i];
1612 picon->set_text(mwindow->edl->clips[i]->local_session->clip_title);
1618 // Create new listitem
1620 AssetPicon *picon = new AssetPicon(mwindow,
1621 this, mwindow->edl->clips[i]);
1622 new_assets.append(picon);
1626 // Synchronize EDL assets
1627 for( Asset *current=mwindow->edl->assets->first; current; current=NEXT ) {
1630 // Look for asset in existing listitems
1631 for( int j = 0; j < assets.total && !exists; j++ ) {
1632 AssetPicon *picon = (AssetPicon*)assets.values[j];
1634 if( picon->id == current->id ) {
1635 picon->indexable = current;
1641 // Create new listitem
1643 AssetPicon *picon = new AssetPicon(mwindow,
1645 new_assets.append(picon);
1649 // Synchronize nested EDLs
1650 for( int i=0; i<mwindow->edl->nested_edls.size(); ++i ) {
1652 EDL *nested_edl = mwindow->edl->nested_edls[i];
1654 // Look for asset in existing listitems
1655 for( int j=0; j<assets.total && !exists; ++j ) {
1656 AssetPicon *picon = (AssetPicon*)assets.values[j];
1658 if( picon->id == nested_edl->id ) {
1659 picon->indexable = nested_edl;
1665 // Create new listitem
1667 AssetPicon *picon = new AssetPicon(mwindow,
1668 this, (Indexable*)nested_edl);
1669 new_assets.append(picon);
1672 mwindow->gui->unlock_window();
1674 for( int i=0; i<new_assets.size(); ++i ) {
1675 AssetPicon *picon = new_assets[i];
1676 picon->create_objects();
1677 if( picon->indexable )
1678 picon->foldernum = AW_MEDIA_FOLDER;
1679 else if( picon->edl )
1680 picon->foldernum = AW_CLIP_FOLDER;
1681 assets.append(picon);
1684 mwindow->gui->lock_window();
1685 mwindow->gui->default_message();
1686 mwindow->gui->unlock_window();
1688 for( int i = assets.size() - 1; i >= 0; i-- ) {
1689 AssetPicon *picon = (AssetPicon*)assets.get(i);
1690 if( !picon->in_use ) {
1692 assets.remove_number(i);
1695 if( picon->indexable && picon->indexable->is_asset ) {
1697 picon->comments_time = !stat(picon->indexable->path, &st) ?
1703 void AWindowGUI::update_picon(Indexable *indexable)
1706 for( int i = 0; i < assets.total; i++ ) {
1707 AssetPicon *picon = (AssetPicon*)assets.values[i];
1708 if( picon->indexable == indexable ||
1709 picon->edl == (EDL *)indexable ) {
1710 char name[BCTEXTLEN];
1712 fs.extract_name(name, indexable->path);
1713 picon->set_text(name);
1714 vicon = picon->vicon;
1719 stop_vicon_drawing();
1720 vicon->clear_images();
1721 vicon->reset(indexable->get_frame_rate());
1722 start_vicon_drawing();
1726 void AWindowGUI::sort_assets()
1728 folder_lock->lock("AWindowGUI::sort_assets");
1729 switch( mwindow->edl->session->awindow_folder ) {
1730 case AW_AEFFECT_FOLDER:
1731 sort_picons(&aeffects);
1733 case AW_VEFFECT_FOLDER:
1734 sort_picons(&veffects);
1736 case AW_ATRANSITION_FOLDER:
1737 sort_picons(&atransitions);
1739 case AW_VTRANSITION_FOLDER:
1740 sort_picons(&vtransitions);
1742 case AW_LABEL_FOLDER:
1743 sort_picons(&labellist);
1746 sort_picons(&assets);
1750 asset_list->update_format(asset_list->get_format(), 0);
1751 folder_lock->unlock();
1755 void AWindowGUI::sort_folders()
1757 folder_lock->lock("AWindowGUI::update_assets");
1758 // folder_list->collapse_recursive(&folders, 0);
1759 folder_list->set_autoplacement(&folders, 0, 1);
1760 sort_picons(&folders);
1761 folder_list->update_format(folder_list->get_format(), 0);
1762 folder_lock->unlock();
1766 EDL *AWindowGUI::collect_proxy(Indexable *indexable)
1768 Asset *proxy_asset = (Asset *)indexable;
1769 char path[BCTEXTLEN];
1770 int proxy_scale = mwindow->edl->session->proxy_scale;
1771 ProxyRender::from_proxy_path(path, proxy_asset, proxy_scale);
1772 Asset *unproxy_asset = mwindow->edl->assets->get_asset(path);
1773 if( !unproxy_asset || !unproxy_asset->layers ) return 0;
1774 // make a clip from proxy video tracks and unproxy audio tracks
1775 EDL *proxy_edl = new EDL(mwindow->edl);
1776 proxy_edl->create_objects();
1777 proxy_edl->set_path(proxy_asset->path);
1778 FileSystem fs; fs.extract_name(path, proxy_asset->path);
1779 strcpy(proxy_edl->local_session->clip_title, path);
1780 strcpy(proxy_edl->local_session->clip_notes, _("Proxy clip"));
1781 proxy_edl->session->video_tracks = proxy_asset->layers;
1782 proxy_edl->session->audio_tracks = unproxy_asset->channels;
1783 proxy_edl->create_default_tracks();
1784 double length = proxy_asset->frame_rate > 0 ?
1785 ( proxy_asset->video_length >= 0 ?
1786 ( proxy_asset->video_length / proxy_asset->frame_rate ) :
1787 ( proxy_edl->session->si_useduration ?
1788 proxy_edl->session->si_duration :
1789 1.0 / proxy_asset->frame_rate ) ) :
1790 1.0 / proxy_edl->session->frame_rate;
1791 Track *current = proxy_edl->tracks->first;
1792 for( int vtrack=0; current; current=NEXT ) {
1793 if( current->data_type != TRACK_VIDEO ) continue;
1794 current->insert_asset(proxy_asset, 0, length, 0, vtrack++);
1796 length = (double)unproxy_asset->audio_length / unproxy_asset->sample_rate;
1797 current = proxy_edl->tracks->first;
1798 for( int atrack=0; current; current=NEXT ) {
1799 if( current->data_type != TRACK_AUDIO ) continue;
1800 current->insert_asset(unproxy_asset, 0, length, 0, atrack++);
1802 proxy_edl->folder_no = AW_PROXY_FOLDER;
1807 void AWindowGUI::collect_assets(int proxy)
1809 mwindow->session->drag_assets->remove_all();
1810 mwindow->session->drag_clips->remove_all();
1811 int i = 0; AssetPicon *result;
1812 while( (result = (AssetPicon*)asset_list->get_selection(0, i++)) != 0 ) {
1813 Indexable *indexable = result->indexable;
1814 if( proxy && indexable && indexable->is_asset &&
1815 indexable->folder_no == AW_PROXY_FOLDER ) {
1816 EDL *drag_edl = collect_proxy(indexable);
1817 if( drag_edl ) mwindow->session->drag_clips->append(drag_edl);
1821 mwindow->session->drag_assets->append(indexable);
1825 mwindow->session->drag_clips->append(result->edl);
1831 void AWindowGUI::copy_picons(AssetPicon *picon, ArrayList<BC_ListBoxItem*> *src)
1833 // Remove current pointers
1834 ArrayList<BC_ListBoxItem*> *dst = displayed_assets;
1835 dst[0].remove_all();
1836 dst[1].remove_all_objects();
1838 AWindowFolderSubItems *sub_items = picon ? picon->sub_items : 0;
1839 int folder = mwindow->edl->session->awindow_folder;
1840 BinFolder *bin_folder = folder < AWINDOW_USER_FOLDERS ? 0 :
1841 mwindow->edl->get_folder(folder);
1843 // Create new pointers
1844 for( int i = 0; i < src->total; i++ ) {
1845 int visible = folder >= AW_CLIP_FOLDER ? 0 : 1;
1846 picon = (AssetPicon*)src->values[i];
1847 picon->sort_key = -1;
1848 if( !visible && bin_folder ) {
1849 Indexable *idxbl = bin_folder->is_clips ? (Indexable *)picon->edl :
1850 picon->indexable ? picon->indexable :
1851 picon->edl ? picon->edl->get_proxy_asset() : 0;
1853 picon->sort_key = mwindow->edl->folders.matches_indexable(folder, idxbl);
1854 if( picon->sort_key < 0 ) continue;
1858 if( !visible && picon->indexable && picon->indexable->folder_no == folder )
1860 if( !visible && picon->edl && picon->edl->folder_no == folder )
1862 if( visible && sub_items ) {
1863 if( !sub_items->matches(picon->get_text()) )
1867 const char *text = search_text->get_text();
1868 if( text && text[0] )
1869 visible = bstrcasestr(picon->get_text(), text) ? 1 : 0;
1871 if( visible && picon->vicon && picon->vicon->hidden )
1872 picon->vicon->hidden = 0;
1874 BC_ListBoxItem *item2, *item1;
1875 dst[0].append(item1 = picon);
1877 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
1880 dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr));
1881 else if( picon->comments_time ) {
1882 char date_time[BCSTRLEN];
1883 struct tm stm; localtime_r(&picon->comments_time, &stm);
1884 sprintf(date_time,"%04d.%02d.%02d %02d:%02d:%02d",
1885 stm.tm_year+1900, stm.tm_mon+1, stm.tm_mday,
1886 stm.tm_hour, stm.tm_min, stm.tm_sec);
1887 dst[1].append(item2 = new BC_ListBoxItem(date_time));
1890 dst[1].append(item2 = new BC_ListBoxItem(""));
1891 item1->set_autoplace_text(1); item1->set_autoplace_icon(1);
1892 item2->set_autoplace_text(1); item2->set_autoplace_icon(1);
1897 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src)
1899 int done = 0, changed = 0;
1902 for( int i=0; i<src->total-1; ++i ) {
1903 AssetPicon *item1 = (AssetPicon *)src->values[i];
1904 AssetPicon *item2 = (AssetPicon *)src->values[i + 1];
1905 double v = item2->sort_key - item1->sort_key;
1906 if( v > 0 ) continue;
1908 const char *cp1 = item1->get_text();
1909 const char *bp1 = strrchr(cp1, '/');
1910 if( bp1 ) cp1 = bp1 + 1;
1911 const char *cp2 = item2->get_text();
1912 const char *bp2 = strrchr(cp2, '/');
1913 if( bp2 ) cp2 = bp2 + 1;
1914 if( strcmp(cp2, cp1) >= 0 ) continue;
1916 src->values[i + 1] = item1;
1917 src->values[i] = item2;
1918 done = 0; changed = 1;
1922 for( int i=0; i<src->total; ++i ) {
1923 AssetPicon *item = (AssetPicon *)src->values[i];
1924 item->set_autoplace_icon(1);
1925 item->set_autoplace_text(1);
1930 void AWindowGUI::filter_displayed_assets()
1932 //allow_iconlisting = 1;
1933 asset_titles[0] = C_("Title");
1934 asset_titles[1] = _("Comments");
1935 AssetPicon *picon = 0;
1936 int selected_folder = mwindow->edl->session->awindow_folder;
1937 // Ensure the current folder icon is highlighted
1938 for( int i = 0; i < folders.total; i++ ) {
1939 AssetPicon *folder_item = (AssetPicon *)folders.values[i];
1940 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
1941 folder_item->set_selected(selected);
1942 if( selected ) picon = folder_item;
1945 ArrayList<BC_ListBoxItem*> *src = &assets;
1946 switch( selected_folder ) {
1947 case AW_AEFFECT_FOLDER: src = &aeffects; break;
1948 case AW_VEFFECT_FOLDER: src = &veffects; break;
1949 case AW_ATRANSITION_FOLDER: src = &atransitions; break;
1950 case AW_VTRANSITION_FOLDER: src = &vtransitions; break;
1951 case AW_LABEL_FOLDER: src = &labellist;
1952 asset_titles[0] = _("Time Stamps");
1953 asset_titles[1] = C_("Title");
1954 //allow_iconlisting = 0;
1957 copy_picons(picon, src);
1961 void AWindowGUI::update_assets()
1963 stop_vicon_drawing();
1964 folder_lock->lock("AWindowGUI::update_assets");
1965 update_folder_list();
1966 update_asset_list();
1967 labellist.remove_all_objects();
1968 create_label_folder();
1970 if( displayed_folder != mwindow->edl->session->awindow_folder )
1971 search_text->clear();
1972 vicon_thread->hide_vicons();
1973 filter_displayed_assets();
1974 folder_lock->unlock();
1976 if( mwindow->edl->session->folderlist_format != folder_list->get_format() ) {
1977 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
1979 int folder_xposition = folder_list->get_xposition();
1980 int folder_yposition = folder_list->get_yposition();
1981 folder_list->update(&folders, 0, 0, 1, folder_xposition, folder_yposition, -1);
1983 if( mwindow->edl->session->assetlist_format != asset_list->get_format() ) {
1984 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
1986 int asset_xposition = asset_list->get_xposition();
1987 int asset_yposition = asset_list->get_yposition();
1988 if( displayed_folder != mwindow->edl->session->awindow_folder ) {
1989 displayed_folder = mwindow->edl->session->awindow_folder;
1990 asset_xposition = asset_yposition = 0;
1992 asset_list->update(displayed_assets, asset_titles,
1993 mwindow->edl->session->asset_columns, ASSET_COLUMNS,
1994 asset_xposition, asset_yposition, -1, 0);
1995 asset_list->center_selection();
1998 start_vicon_drawing();
2002 void AWindowGUI::update_effects()
2004 aeffects.remove_all_objects();
2005 create_persistent_folder(&aeffects, 1, 0, 1, 0);
2006 veffects.remove_all_objects();
2007 create_persistent_folder(&veffects, 0, 1, 1, 0);
2008 atransitions.remove_all_objects();
2009 create_persistent_folder(&atransitions, 1, 0, 0, 1);
2010 vtransitions.remove_all_objects();
2011 create_persistent_folder(&vtransitions, 0, 1, 0, 1);
2014 int AWindowGUI::drag_motion()
2016 if( get_hidden() ) return 0;
2022 int AWindowGUI::drag_stop()
2024 if( get_hidden() ) return 0;
2028 Indexable* AWindowGUI::selected_asset()
2030 AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
2031 return picon ? picon->indexable : 0;
2034 PluginServer* AWindowGUI::selected_plugin()
2036 AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
2037 return picon ? picon->plugin : 0;
2040 AssetPicon* AWindowGUI::selected_folder()
2042 AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
2053 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
2054 : BC_SubWindow(x, y, w, h)
2056 this->mwindow = mwindow;
2059 AWindowDivider::~AWindowDivider()
2063 int AWindowDivider::button_press_event()
2065 if( is_event_win() && cursor_inside() ) {
2066 mwindow->session->current_operation = DRAG_PARTITION;
2072 int AWindowDivider::cursor_motion_event()
2074 if( mwindow->session->current_operation == DRAG_PARTITION ) {
2076 int wmax = mwindow->session->awindow_w - mwindow->theme->adivider_w - wmin;
2077 int fw = gui->get_relative_cursor_x();
2078 if( fw > wmax ) fw = wmax;
2079 if( fw < wmin ) fw = wmin;
2080 mwindow->session->afolders_w = fw;
2081 mwindow->theme->get_awindow_sizes(gui);
2082 gui->reposition_objects();
2088 int AWindowDivider::button_release_event()
2090 if( mwindow->session->current_operation == DRAG_PARTITION ) {
2091 mwindow->session->current_operation = NO_OPERATION;
2102 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
2103 : BC_ListBox(x, y, w, h,
2104 mwindow->edl->session->folderlist_format == FOLDERS_ICONS ?
2105 LISTBOX_ICONS : LISTBOX_TEXT,
2106 &gui->folders, // Each column has an ArrayList of BC_ListBoxItems.
2107 0, // Titles for columns. Set to 0 for no titles
2108 0, // width of each column
2109 1, // Total columns.
2110 0, // Pixel of top of window.
2111 0, // If this listbox is a popup window
2112 LISTBOX_SINGLE, // Select one item or multiple items
2113 ICON_TOP, // Position of icon relative to text of each item
2116 this->mwindow = mwindow;
2123 AWindowFolders::~AWindowFolders()
2127 int AWindowFolders::selection_changed()
2129 AWindowFolderItem *item0 = (AWindowFolderItem*)get_selection(0, 0);
2130 AWindowFolderItem *item1 = (AWindowFolderItem*)get_selection(0, 1);
2131 // prefer expanded entry
2132 AWindowFolderItem *item = item1 ? item1 : item0;
2133 if( item0 && item1 && last_item0 == item0 && last_item1 == item1 ) {
2134 item1->set_selected(0);
2141 AssetPicon *picon = item->get_picon();
2142 picon->sub_items = (AWindowFolderSubItems*)(!item->parent ? 0 : item);
2144 gui->stop_vicon_drawing();
2146 if( get_button_down() && get_buttonpress() == 3 ) {
2147 gui->folderlist_menu->update_titles();
2148 gui->folderlist_menu->activate_menu();
2151 mwindow->edl->session->awindow_folder = picon->foldernum;
2152 gui->asset_list->draw_background();
2153 gui->async_update_assets();
2155 gui->start_vicon_drawing();
2160 int AWindowFolders::button_press_event()
2164 result = BC_ListBox::button_press_event();
2167 if( get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
2168 gui->folderlist_menu->update_titles();
2169 gui->folderlist_menu->activate_menu();
2178 int AWindowFolders::drag_stop()
2181 if( get_hidden() ) return 0;
2182 if( mwindow->session->current_operation == DRAG_ASSET &&
2183 gui->folder_list->cursor_above() ) { // check user folder
2184 int item_no = gui->folder_list->get_cursor_data_item_no();
2185 AssetPicon *picon = (AssetPicon *)(item_no < 0 ? 0 : gui->folders[item_no]);
2186 if( picon && picon->foldernum >= AWINDOW_USER_FOLDERS ) {
2187 BinFolder *folder = mwindow->edl->get_folder(picon->foldernum);
2188 ArrayList<Indexable *> *drags = folder->is_clips ?
2189 ((ArrayList<Indexable *> *)mwindow->session->drag_clips) :
2190 ((ArrayList<Indexable *> *)mwindow->session->drag_assets);
2191 if( folder && drags && !folder->add_patterns(drags, shift_down()) )
2193 mwindow->session->current_operation = ::NO_OPERATION;
2200 AWindowFolderSubItems::AWindowFolderSubItems(AWindowFolderItem *parent, const char *text)
2201 : AWindowFolderItem(text)
2203 this->parent = parent;
2206 int AWindowFolders::load_expanders()
2208 char expanders_path[BCTEXTLEN];
2209 mwindow->create_defaults_path(expanders_path, EXPANDERS_FILE);
2210 FILE *fp = fopen(expanders_path, "r");
2212 snprintf(expanders_path, sizeof(expanders_path), "%s/%s",
2213 File::get_cindat_path(), EXPANDERS_FILE);
2214 fp = fopen(expanders_path, "r");
2218 const char tab = '\t';
2219 char line[BCTEXTLEN]; line[0] = 0;
2220 AWindowFolderItem *item = 0, *parent;
2221 AWindowFolderSubItems *sub_items = 0;
2223 while( fgets(line,sizeof(line),fp) ) {
2224 if( line[0] == '#' ) continue;
2225 int i = strlen(line);
2226 if( i > 0 && line[i-1] == '\n' ) line[--i] = 0;
2227 if( i == 0 ) continue;
2229 for( char *cp=line; *cp==tab; ++cp ) ++i;
2231 int i = gui->folders.size();
2233 AssetPicon *folder = (AssetPicon *)gui->folders[i];
2234 if( !strcmp(folder->get_text(),_(line)) ) break;
2236 item = (AWindowFolderItem*)(i >= 0 ? gui->folders[i] : 0);
2241 if( i > k+1 ) continue;
2243 if( line[i] != '-' && sub_items ) {
2244 sub_items->names.append(cstrdup(_(&line[i])));
2252 item = item->parent;
2255 parent = item->parent;
2257 ArrayList<BC_ListBoxItem*> *sublist = parent->get_sublist();
2258 if( !sublist ) sublist = parent->new_sublist(1);
2259 sub_items = new AWindowFolderSubItems(parent, &line[i]);
2260 sublist->append(item = sub_items);
2267 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
2268 : BC_ListBox(x, y, w, h, !gui->allow_iconlisting ? LISTBOX_TEXT :
2269 mwindow->edl->session->assetlist_format == ASSETS_ICONS ? LISTBOX_ICONS :
2270 mwindow->edl->session->assetlist_format == ASSETS_ICONS_PACKED ? LISTBOX_ICONS_PACKED :
2271 mwindow->edl->session->assetlist_format == ASSETS_ICON_LIST ? LISTBOX_ICON_LIST :
2273 &gui->assets, // Each column has an ArrayList of BC_ListBoxItems.
2274 gui->asset_titles,// Titles for columns. Set to 0 for no titles
2275 mwindow->edl->session->asset_columns, // width of each column
2276 1, // Total columns.
2277 0, // Pixel of top of window.
2278 0, // If this listbox is a popup window
2279 LISTBOX_MULTIPLE, // Select one item or multiple items
2280 ICON_TOP, // Position of icon relative to text of each item
2281 -1) // Allow drags, require shift for scrolling
2283 this->mwindow = mwindow;
2286 set_scroll_stretch(1, 1);
2289 AWindowAssets::~AWindowAssets()
2293 int AWindowAssets::button_press_event()
2297 result = BC_ListBox::button_press_event();
2299 if( !result && get_buttonpress() == 3 && is_event_win() && cursor_inside() ) {
2300 BC_ListBox::deactivate_selection();
2301 int folder = mwindow->edl->session->awindow_folder;
2303 case AW_AEFFECT_FOLDER:
2304 case AW_VEFFECT_FOLDER:
2305 case AW_ATRANSITION_FOLDER:
2306 case AW_VTRANSITION_FOLDER:
2307 gui->effectlist_menu->update();
2308 gui->effectlist_menu->activate_menu();
2310 case AW_LABEL_FOLDER:
2311 gui->labellist_menu->update();
2312 gui->labellist_menu->activate_menu();
2314 case AW_CLIP_FOLDER:
2315 gui->cliplist_menu->update();
2316 gui->cliplist_menu->activate_menu();
2318 case AW_PROXY_FOLDER:
2319 gui->proxylist_menu->update();
2320 gui->proxylist_menu->activate_menu();
2323 case AW_MEDIA_FOLDER: {
2324 int shots = folder==AW_MEDIA_FOLDER || folder>=AWINDOW_USER_FOLDERS;
2325 gui->assetlist_menu->update_titles(shots);
2326 gui->assetlist_menu->activate_menu();
2336 int AWindowAssets::handle_event()
2338 AssetPicon *asset_picon = (AssetPicon *)get_selection(0, 0);
2339 if( !asset_picon ) return 0;
2340 Indexable *picon_idxbl = asset_picon->indexable;
2341 EDL *picon_edl = asset_picon->edl;
2343 VWindow *vwindow = 0;
2344 switch( mwindow->edl->session->awindow_folder ) {
2345 case AW_AEFFECT_FOLDER:
2346 case AW_VEFFECT_FOLDER:
2347 case AW_ATRANSITION_FOLDER:
2348 case AW_VTRANSITION_FOLDER: return 1;
2349 case AW_PROXY_FOLDER:
2350 proxy = 1; // fall thru
2352 if( mwindow->vwindows.size() > DEFAULT_VWINDOW )
2353 vwindow = mwindow->vwindows.get(DEFAULT_VWINDOW);
2356 if( !vwindow || !vwindow->is_running() ) return 1;
2357 if( proxy && picon_idxbl ) {
2358 picon_edl = gui->collect_proxy(picon_idxbl);
2362 if( picon_idxbl ) vwindow->change_source(picon_idxbl);
2363 else if( picon_edl ) vwindow->change_source(picon_edl);
2367 int AWindowAssets::selection_changed()
2369 // Show popup window
2371 if( get_button_down() && get_buttonpress() == 3 &&
2372 (item = (AssetPicon*)get_selection(0, 0)) ) {
2373 int folder = mwindow->edl->session->awindow_folder;
2375 case AW_AEFFECT_FOLDER:
2376 case AW_VEFFECT_FOLDER:
2377 case AW_ATRANSITION_FOLDER:
2378 case AW_VTRANSITION_FOLDER:
2379 gui->effectlist_menu->update();
2380 gui->effectlist_menu->activate_menu();
2382 case AW_LABEL_FOLDER:
2383 if( !item->label ) break;
2384 gui->label_menu->activate_menu();
2386 case AW_CLIP_FOLDER:
2387 if( !item->indexable && !item->edl ) break;
2388 gui->clip_menu->update();
2389 gui->clip_menu->activate_menu();
2391 case AW_PROXY_FOLDER:
2392 if( !item->indexable && !item->edl ) break;
2393 gui->proxy_menu->update();
2394 gui->proxy_menu->activate_menu();
2397 if( !item->indexable && !item->edl ) break;
2398 gui->asset_menu->update();
2399 gui->asset_menu->activate_menu();
2403 deactivate_selection();
2405 else if( gui->vicon_drawing && get_button_down() && get_buttonpress() == 1 &&
2406 ( mwindow->edl->session->awindow_folder == AW_MEDIA_FOLDER ||
2407 mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ||
2408 mwindow->edl->session->awindow_folder >= AWINDOW_USER_FOLDERS ) &&
2409 (item = (AssetPicon*)get_selection(0, 0)) != 0 ) {
2411 if( !gui->vicon_thread->vicon ) {
2412 vicon = item->vicon;
2414 gui->vicon_thread->set_view_popup(vicon);
2419 void AWindowAssets::draw_background()
2421 clear_box(0,0,get_w(),get_h(),get_bg_surface());
2422 set_color(BC_WindowBase::get_resources()->audiovideo_color);
2423 set_font(LARGEFONT);
2424 int folder = mwindow->edl->session->awindow_folder;
2425 const char *title = mwindow->edl->get_folder_name(folder);
2426 draw_text(get_w() - get_text_width(LARGEFONT, title) - 4, 30,
2427 title, -1, get_bg_surface());
2430 int AWindowAssets::drag_start_event()
2432 int collect_pluginservers = 0;
2433 int collect_assets = 0, proxy = 0;
2435 if( BC_ListBox::drag_start_event() ) {
2436 switch( mwindow->edl->session->awindow_folder ) {
2437 case AW_AEFFECT_FOLDER:
2438 mwindow->session->current_operation = DRAG_AEFFECT;
2439 collect_pluginservers = 1;
2441 case AW_VEFFECT_FOLDER:
2442 mwindow->session->current_operation = DRAG_VEFFECT;
2443 collect_pluginservers = 1;
2445 case AW_ATRANSITION_FOLDER:
2446 mwindow->session->current_operation = DRAG_ATRANSITION;
2447 collect_pluginservers = 1;
2449 case AW_VTRANSITION_FOLDER:
2450 mwindow->session->current_operation = DRAG_VTRANSITION;
2451 collect_pluginservers = 1;
2453 case AW_LABEL_FOLDER:
2456 case AW_PROXY_FOLDER:
2457 proxy = 1; // fall thru
2458 case AW_MEDIA_FOLDER:
2460 mwindow->session->current_operation = DRAG_ASSET;
2465 if( collect_pluginservers ) {
2467 mwindow->session->drag_pluginservers->remove_all();
2470 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
2471 if( !result ) break;
2473 mwindow->session->drag_pluginservers->append(result->plugin);
2477 if( collect_assets ) {
2478 gui->collect_assets(proxy);
2486 int AWindowAssets::drag_motion_event()
2488 BC_ListBox::drag_motion_event();
2491 mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2492 mwindow->gui->drag_motion();
2493 mwindow->gui->unlock_window();
2495 for( int i = 0; i < mwindow->vwindows.size(); i++ ) {
2496 VWindow *vwindow = mwindow->vwindows.get(i);
2497 if( !vwindow->is_running() ) continue;
2498 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2499 vwindow->gui->drag_motion();
2500 vwindow->gui->unlock_window();
2503 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2504 mwindow->cwindow->gui->drag_motion();
2505 mwindow->cwindow->gui->unlock_window();
2507 lock_window("AWindowAssets::drag_motion_event");
2508 if( mwindow->session->current_operation == DRAG_ASSET &&
2509 gui->folder_list->cursor_above() ) { // highlight user folder
2510 BC_ListBoxItem *item = 0;
2511 int item_no = gui->folder_list->get_cursor_data_item_no(&item);
2512 if( item_no >= 0 ) {
2513 AssetPicon *folder = (AssetPicon *)gui->folders[item_no];
2514 if( folder->foldernum < AWINDOW_USER_FOLDERS ) item_no = -1;
2517 item_no = gui->folder_list->item_to_index(&gui->folders, item);
2518 int folder_xposition = gui->folder_list->get_xposition();
2519 int folder_yposition = gui->folder_list->get_yposition();
2520 gui->folder_list->update(&gui->folders, 0, 0, 1,
2521 folder_xposition, folder_yposition, item_no, 0, 1);
2526 int AWindowAssets::drag_stop_event()
2530 result = gui->drag_stop();
2535 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2536 result = mwindow->gui->drag_stop();
2537 mwindow->gui->unlock_window();
2541 for( int i = 0; !result && i < mwindow->vwindows.size(); i++ ) {
2542 VWindow *vwindow = mwindow->vwindows.get(i);
2543 if( !vwindow ) continue;
2544 if( !vwindow->is_running() ) continue;
2545 if( vwindow->gui->is_hidden() ) continue;
2546 vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2547 if( vwindow->gui->cursor_above() &&
2548 vwindow->gui->get_cursor_over_window() ) {
2549 result = vwindow->gui->drag_stop();
2551 vwindow->gui->unlock_window();
2556 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
2557 result = mwindow->cwindow->gui->drag_stop();
2558 mwindow->cwindow->gui->unlock_window();
2561 lock_window("AWindowAssets::drag_stop_event");
2563 result = gui->folder_list->drag_stop();
2568 get_drag_popup()->set_animation(0);
2570 BC_ListBox::drag_stop_event();
2571 // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
2572 mwindow->session->current_operation = ::NO_OPERATION;
2577 int AWindowAssets::column_resize_event()
2579 mwindow->edl->session->asset_columns[0] = get_column_width(0);
2580 mwindow->edl->session->asset_columns[1] = get_column_width(1);
2584 int AWindowAssets::focus_in_event()
2586 int ret = BC_ListBox::focus_in_event();
2587 gui->start_vicon_drawing();
2591 int AWindowAssets::focus_out_event()
2593 gui->stop_vicon_drawing();
2594 return BC_ListBox::focus_out_event();
2597 int AWindowAssets::cursor_enter_event()
2599 int ret = BC_ListBox::cursor_enter_event();
2600 gui->start_vicon_drawing();
2604 int AWindowAssets::cursor_leave_event()
2606 gui->stop_vicon_drawing();
2607 return BC_ListBox::cursor_leave_event();
2610 void AWindowAssets::update_vicon_area()
2612 int x0 = 0, x1 = get_w();
2613 int y0 = get_title_h();
2615 if( is_highlighted() ) {
2616 x0 += LISTBOX_BORDER; x1 -= LISTBOX_BORDER;
2617 y0 += LISTBOX_BORDER; y1 -= LISTBOX_BORDER;
2619 gui->vicon_thread->set_drawing_area(x0,y0, x1,y1);
2622 int AWindowAssets::mouse_over_event(int no)
2624 if( gui->vicon_thread->viewing &&
2625 no >= 0 && no < gui->displayed_assets[0].size() ) {
2626 AssetPicon *picon = (AssetPicon *)gui->displayed_assets[0][no];
2627 VIcon *vicon = picon->vicon;
2628 picon->gui->vicon_thread->set_view_popup(vicon);
2634 AWindowSearchTextBox::AWindowSearchTextBox(AWindowSearchText *search_text, int x, int y, int w)
2635 : BC_TextBox(x, y, w, 1, "")
2637 this->search_text = search_text;
2640 int AWindowSearchTextBox::handle_event()
2642 return search_text->handle_event();
2645 AWindowSearchText::AWindowSearchText(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2647 this->mwindow = mwindow;
2653 void AWindowSearchText::create_objects()
2655 int x1 = x, y1 = y, margin = 10;
2656 gui->add_subwindow(text_title = new BC_Title(x1, y1, _("Search:")));
2657 x1 += text_title->get_w() + margin;
2658 int w1 = gui->get_w() - x1 - 2*margin;
2659 gui->add_subwindow(text_box = new AWindowSearchTextBox(this, x1, y1, w1));
2662 int AWindowSearchText::handle_event()
2664 gui->async_update_assets();
2668 int AWindowSearchText::get_w()
2670 return text_box->get_w() + text_title->get_w() + 10;
2673 int AWindowSearchText::get_h()
2675 return bmax(text_box->get_h(),text_title->get_h());
2678 void AWindowSearchText::reposition_window(int x, int y, int w)
2680 int x1 = x, y1 = y, margin = 10;
2681 text_title->reposition_window(x1, y1);
2682 x1 += text_title->get_w() + margin;
2683 int w1 = gui->get_w() - x1 - 2*margin;
2684 text_box->reposition_window(x1, y1, w1);
2687 const char *AWindowSearchText::get_text()
2689 return text_box->get_text();
2692 void AWindowSearchText::clear()
2694 text_box->update("");
2697 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2698 : BC_Button(x, y, mwindow->theme->deletedisk_data)
2700 this->mwindow = mwindow;
2702 set_tooltip(_("Delete asset from disk"));
2705 int AWindowDeleteDisk::handle_event()
2710 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2711 : BC_Button(x, y, mwindow->theme->deleteproject_data)
2713 this->mwindow = mwindow;
2715 set_tooltip(_("Delete asset from project"));
2718 int AWindowDeleteProject::handle_event()
2723 // AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2724 // : BC_Button(x, y, mwindow->theme->infoasset_data)
2726 // this->mwindow = mwindow;
2728 // set_tooltip(_("Edit information on asset"));
2731 // int AWindowInfo::handle_event()
2733 // int cur_x, cur_y;
2734 // gui->get_abs_cursor(cur_x, cur_y, 0);
2735 // gui->awindow->asset_edit->edit_asset(gui->selected_asset(), cur_x, cur_y);
2739 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2740 : BC_Button(x, y, mwindow->theme->redrawindex_data)
2742 this->mwindow = mwindow;
2744 set_tooltip(_("Redraw index"));
2747 int AWindowRedrawIndex::handle_event()
2752 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2753 : BC_Button(x, y, mwindow->theme->pasteasset_data)
2755 this->mwindow = mwindow;
2757 set_tooltip(_("Paste asset on recordable tracks"));
2760 int AWindowPaste::handle_event()
2765 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2766 : BC_Button(x, y, mwindow->theme->appendasset_data)
2768 this->mwindow = mwindow;
2770 set_tooltip(_("Append asset in new tracks"));
2773 int AWindowAppend::handle_event()
2778 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
2779 : BC_Button(x, y, mwindow->theme->viewasset_data)
2781 this->mwindow = mwindow;
2783 set_tooltip(_("View asset"));
2786 int AWindowView::handle_event()
2791 AddTools::AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, const char *title)
2792 : BC_PopupMenu(x, y, BC_Title::calculate_w(gui, title, MEDIUMFONT)+8, title, -1, 0, 4)
2794 this->mwindow = mwindow;
2798 void AddTools::create_objects()
2801 add_item(new AddPluginItem(this, "ffmpeg", PLUGIN_FFMPEG_ID));
2802 vis |= 1 << PLUGIN_FFMPEG_ID;
2803 add_item(new AddPluginItem(this, "ladspa", PLUGIN_LADSPA_ID));
2804 vis |= 1 << PLUGIN_LADSPA_ID;
2806 add_item(new AddPluginItem(this, "lv2", PLUGIN_LV2_ID));
2807 vis |= 1 << PLUGIN_LV2_ID;
2809 for( int i=0; i<MWindow::plugindb->size(); ++i ) {
2810 PluginServer *plugin = MWindow::plugindb->get(i);
2811 if( !plugin->audio && !plugin->video ) continue;
2812 int idx = plugin->dir_idx;
2813 uint32_t msk = 1 << idx;
2814 if( (msk & vis) != 0 ) continue;
2816 char parent[BCTEXTLEN];
2817 strcpy(parent, plugin->path);
2818 char *bp = strrchr(parent, '/');
2819 if( bp ) { *bp = 0; bp = strrchr(parent, '/'); }
2820 if( !bp ) bp = parent; else ++bp;
2821 add_item(new AddPluginItem(this, bp, idx));
2826 // plugin_dirs list from toplevel makefile include plugin_defs
2831 N_("audio_transitions")
2838 N_("video_transitions")
2841 AddPluginItem::AddPluginItem(AddTools *menu, char const *text, int idx)
2842 : BC_MenuItem(_(text))
2846 uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2847 int chk = (msk & vis) ? 1 : 0;
2851 int AddPluginItem::handle_event()
2853 int chk = get_checked() ^ 1;
2855 uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
2856 menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
2857 menu->gui->update_effects();
2858 menu->gui->save_defaults(menu->mwindow->defaults);
2859 menu->gui->async_update_assets();
2863 AVIconDrawing::AVIconDrawing(AWindowGUI *agui, int x, int y, VFrame **images)
2864 : BC_Toggle(x, y, images, agui->vicon_drawing)
2867 set_tooltip(_("Preview"));
2870 void AVIconDrawing::calculate_geometry(AWindowGUI *agui, VFrame **images, int *ww, int *hh)
2872 int text_line = -1, toggle_x = -1, toggle_y = -1;
2873 int text_x = -1, text_y = -1, text_w = -1, text_h = -1;
2874 BC_Toggle::calculate_extents(agui, images, 1,
2875 &text_line, ww, hh, &toggle_x, &toggle_y,
2876 &text_x, &text_y, &text_w, &text_h, "", MEDIUMFONT);
2879 AVIconDrawing::~AVIconDrawing()
2883 int AVIconDrawing::handle_event()
2885 agui->vicon_drawing = get_value();
2886 if( agui->vicon_drawing )
2887 agui->start_vicon_drawing();
2889 agui->stop_vicon_drawing();
2894 AWindowListFormat::AWindowListFormat(MWindow *mwindow, AWindowGUI *gui)
2895 : BC_MenuItem("","v",'v')
2897 this->mwindow = mwindow;
2901 int AWindowListFormat::handle_event()
2903 return gui->cycle_assetlist_format();
2906 void AWindowListFormat::update()
2908 EDLSession *session = mwindow->edl->session;
2909 const char *text = 0;
2910 switch( session->assetlist_format ) {
2912 text = _("Display icons");
2915 text = _("Display icons packed");
2917 case ASSETS_ICONS_PACKED:
2918 text = _("Display icon list");
2920 case ASSETS_ICON_LIST:
2921 text = _("Display text");
2927 AWindowListSort::AWindowListSort(MWindow *mwindow, AWindowGUI *gui)
2928 : BC_MenuItem(_("Sort items"))
2930 this->mwindow = mwindow;
2934 int AWindowListSort::handle_event()