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 "bcdisplayinfo.h"
34 #include "bcsignals.h"
36 #include "binfolder.h"
41 #include "clippopup.h"
43 #include "cwindowgui.h"
48 #include "edlsession.h"
49 #include "effectlist.h"
51 #include "filesystem.h"
52 #include "folderlistmenu.h"
53 #include "indexable.h"
57 #include "labelpopup.h"
58 #include "localsession.h"
59 #include "mainerror.h"
61 #include "mainsession.h"
62 #include "mwindowgui.h"
64 #include "preferences.h"
66 #include "proxypopup.h"
67 #include "renderengine.h"
72 #include "transportque.h"
76 #include "vwindowgui.h"
79 #include "data/lad_picon_png.h"
80 #include "data/ff_audio_png.h"
81 #include "data/ff_video_png.h"
88 const char *AWindowGUI::folder_names[] =
92 N_("Audio Transitions"),
93 N_("Video Transitions"),
100 const char *AVIconDrawing::avicon_names[] =
108 AssetVIcon::AssetVIcon(AssetPicon *picon, int w, int h, double framerate, int64_t length)
109 : VIcon(w, h, framerate), Garbage("AssetVIcon")
112 this->length = length;
117 AssetVIcon::~AssetVIcon()
119 if( picon->gui->vicon_thread->solo == this )
120 picon->gui->vicon_thread->solo = 0;
121 picon->gui->vicon_thread->del_vicon(this);
125 VFrame *AssetVIcon::frame()
127 if( broken ) return 0;
128 AssetVIconThread *avt = picon->gui->vicon_thread;
129 Indexable *idxbl = picon->indexable;
130 Asset *asset = idxbl && idxbl->is_asset ? (Asset *)idxbl : 0;
131 if( !asset ) return vframes()>0 ? (VFrame*)*images[0] : 0;
132 if( !asset->video_data && audio_data && audio_size && length > 0 ) {
133 if( !temp ) temp = new VFrame(0, -1, w, h, BC_RGB888, -1);
135 int sample_rate = asset->get_sample_rate();
136 int64_t audio_samples = asset->get_audio_samples();
137 double duration = (double)audio_samples / sample_rate;
138 picon->draw_hue_bar(temp, duration);
139 int secs = length / frame_rate + 0.5;
140 if( !secs ) secs = 1;
141 int bfrsz = VICON_SAMPLE_RATE;
142 int samples = audio_size/sizeof(vicon_audio_t);
143 double line_pos = (double)seq_no/(length-1);
144 int audio_pos = samples * line_pos * (secs-1)/secs;
145 vicon_audio_t *audio_data = ((vicon_audio_t *)this->audio_data) + audio_pos;
146 static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
147 double data[bfrsz], sample_scale = 1./mx;
148 int len = samples - audio_pos;
149 if( len > bfrsz ) len = bfrsz;
151 while( i < len ) data[i++] = *audio_data++ * sample_scale;
152 while( i < bfrsz ) data[i++] = 0;
153 picon->draw_wave(temp, data, bfrsz, RED, GREEN);
154 int x = (w-1) * line_pos;
155 temp->pixel_rgb = RED;
156 temp->draw_line(x,0, x,h);
159 int vw = avt->vw, vh = avt->vh, vicon_cmodel = avt->vicon_cmodel;
160 if( !asset->video_data ) {
162 temp = new VFrame(0, -1, vw, vh, BC_RGB888, -1);
167 if( seq_no >= images.size() ) {
168 MWindow *mwindow = picon->mwindow;
169 if( temp && (temp->get_w() != asset->width || temp->get_h() != asset->height) ) {
170 delete temp; temp = 0;
173 temp = new VFrame(0, -1, asset->width, asset->height, BC_RGB888, -1);
174 File *file = mwindow->video_cache->check_out(asset, mwindow->edl, 1);
175 if( !file ) { broken = 1; return 0; }
177 while( file && seq_no >= images.size() && !avt->interrupted ) {
178 int64_t pos = images.size() / picon->gui->vicon_thread->refresh_rate * frame_rate;
179 file->set_video_position(pos,0);
181 if( file->read_frame(temp) ) temp->clear_frame();
182 add_image(temp, vw, vh, vicon_cmodel);
183 mwindow->video_cache->check_in(asset);
184 if( timer.get_difference() > 500 ) return 0;
186 file = mwindow->video_cache->check_out(asset, mwindow->edl, 0);
187 for( int retries=10; !file && --retries>=0; usleep(1000) ) {
188 if( avt->interrupted ) return 0;
189 file = mwindow->video_cache->check_out(asset, mwindow->edl, 0);
191 if( !file ) return 0;
193 mwindow->video_cache->check_in(asset);
195 if( seq_no >= images.size() ) return 0;
196 return *images[seq_no];
199 int64_t AssetVIcon::set_seq_no(int64_t no)
201 if( no >= length ) no = 0;
205 int AssetVIcon::get_vx()
207 BC_ListBox *lbox = picon->gui->asset_list;
208 return lbox->get_icon_x(picon);
210 int AssetVIcon::get_vy()
212 BC_ListBox *lbox = picon->gui->asset_list;
213 return lbox->get_icon_y(picon);
216 void AssetVIcon::load_audio()
218 MWindow *mwindow = picon->mwindow;
219 Asset *asset = (Asset *)picon->indexable;
220 File *file = mwindow->audio_cache->check_out(asset, mwindow->edl, 1);
221 int channels = asset->get_audio_channels();
222 if( channels > 2 ) channels = 2;
223 int sample_rate = asset->get_sample_rate();
224 int bfrsz = sample_rate;
225 Samples samples(bfrsz);
226 double time_scale = (double)sample_rate / VICON_SAMPLE_RATE;
227 vicon_audio_t *audio_data = (vicon_audio_t *)this->audio_data;
228 static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
229 double sample_scale = (double)mx / channels;
230 int audio_pos = 0, audio_len = audio_size/sizeof(vicon_audio_t);
231 while( audio_pos < audio_len ) {
232 int64_t pos = audio_pos * time_scale;
233 for( int ch=0; ch<channels; ++ch ) {
234 file->set_channel(ch);
235 file->set_audio_position(pos);
236 file->read_samples(&samples, bfrsz);
237 double *data = samples.get_data();
238 for( int64_t k=audio_pos; k<audio_len; ++k ) {
239 int i = k * time_scale - pos;
240 if( i >= bfrsz ) break;
241 int v = audio_data[k] + data[i] * sample_scale;
242 audio_data[k] = CLIP(v, -mx,mx);
245 audio_pos = (pos + bfrsz) / time_scale;
247 mwindow->audio_cache->check_in(asset);
251 AssetVIconAudio::AssetVIconAudio(AWindowGUI *gui)
255 audio = new AudioDevice(gui->mwindow);
259 AssetVIconAudio::~AssetVIconAudio()
264 void AssetVIconAudio::run()
267 int64_t bfrsz = VICON_SAMPLE_RATE;
268 MWindow *mwindow = gui->mwindow;
269 EDL *edl = mwindow->edl;
270 EDLSession *session = edl->session;
271 AudioOutConfig *aconfig = session->playback_config->aconfig;
272 audio->open_output(aconfig, VICON_SAMPLE_RATE, bfrsz, channels, 0);
273 audio->start_playback();
274 double out0[bfrsz], out1[bfrsz], *out[2] = { out0, out1 };
275 vicon_audio_t *audio_data = (vicon_audio_t *)vicon->audio_data;
276 static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1;
278 int audio_len = vicon->audio_size/sizeof(vicon_audio_t);
279 while( !interrupted ) {
280 int len = audio_len - audio_pos;
281 if( len <= 0 ) break;
282 if( len > bfrsz ) len = bfrsz;
284 for( int i=0; i<len; ++i,++k )
285 out0[i] = out1[i] = (double)audio_data[k] / mx;
287 audio->write_buffer(out, channels, len);
291 audio->set_last_buffer();
292 audio->stop_audio(interrupted ? 0 : 1);
296 void AssetVIconAudio::start(AssetVIcon *vicon)
298 if( running() ) return;
300 double pos = vicon->length > 0 ? (double)vicon->seq_no/vicon->length : 0;
301 int audio_len = vicon->audio_size/sizeof(vicon_audio_t);
302 audio_pos = pos * audio_len;
307 void AssetVIconAudio::stop(int wait)
309 if( running() && !interrupted ) {
311 audio->stop_audio(wait);
315 vicon->playing_audio = 0;
320 void AssetVIcon::start_audio()
322 if( playing_audio < 0 ) return;
323 picon->gui->vicon_audio->stop(0);
325 picon->gui->vicon_audio->start(this);
328 void AssetVIcon::stop_audio()
330 if( playing_audio > 0 ) {
331 picon->gui->vicon_audio->stop(0);
336 AssetViewPopup::AssetViewPopup(VIconThread *vt, int draw_mode,
337 int x, int y, int w, int h)
338 : ViewPopup(vt, x, y, w, h)
340 this->draw_mode = draw_mode;
341 this->bar_h = (VIEW_POPUP_BAR_H * h) / 200;
345 AssetViewPopup::~AssetViewPopup()
349 int AssetViewPopup::reposition_window(int x, int y, int w, int h)
351 this->bar_h = (VIEW_POPUP_BAR_H * h) / 200;
352 return ViewPopup::reposition_window(x, y, w, h);
355 int AssetViewPopup::button_press_event()
357 if( !is_event_win() ) return 0;
358 AssetVIconThread *avt = (AssetVIconThread *)vt;
359 if( !avt->vicon ) return 0;
362 switch( get_buttonpress() ) {
366 avt->set_view_popup(0);
369 dir = -1; // fall thru
371 switch( draw_mode ) {
372 case ASSET_VIEW_MEDIA:
373 case ASSET_VIEW_MEDIA_MAP:
374 avt->zoom_scale(dir);
381 int x = get_cursor_x(), y = get_cursor_y();
382 AssetVIcon *vicon = (AssetVIcon *)avt->vicon;
383 AssetPicon *picon = vicon->picon;
384 MWindow *mwindow = picon->mwindow;
385 EDL *edl = mwindow->edl;
387 if( y < get_h()/2 ) {
389 picon->indexable ? picon->indexable :
390 picon->edl ? picon->edl : 0;
391 if( !idxbl ) return 0;
392 double sample_rate = idxbl->get_sample_rate();
393 double audio_length = sample_rate > 0 && idxbl->have_audio() ?
394 idxbl->get_audio_samples() / sample_rate : 0;
395 double frame_rate = idxbl->get_frame_rate();
396 double video_length = frame_rate > 0 && idxbl->have_video() ?
397 idxbl->get_video_frames() / frame_rate : 0;
398 double idxbl_length = bmax(audio_length, video_length);
399 double pos = x * idxbl_length / get_w();
400 double start = 0, end = idxbl_length;
401 double lt = DBL_MAX, rt = DBL_MAX;
402 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
403 for( Edit *edit=track->edits->first; edit!=0; edit=edit->next ) {
404 Indexable *indexable = (Indexable *)edit->asset;
405 if( !indexable ) indexable = (Indexable *)edit->nested_edl;
406 if( !indexable ) continue;
407 if( indexable->id == idxbl->id ||
408 (!indexable->is_asset == !idxbl->is_asset &&
409 !strcmp(indexable->path, idxbl->path)) ) {
410 double start_pos = track->from_units(edit->startsource);
411 double end_pos = track->from_units(edit->startsource + edit->length);
412 double dlt = pos - start_pos, drt = end_pos - pos;
413 if( dlt >= 0 && dlt < lt ) { lt = dlt; start = start_pos; }
414 else if( dlt < 0 && -dlt < rt ) { rt = -dlt; end = start_pos; }
415 if( drt >= 0 && drt < rt ) { rt = drt; end = end_pos; }
416 else if( drt < 0 && -drt < lt ) { lt = -drt; start = end_pos; }
420 mwindow->gui->lock_window("AssetVIcon::popup_button_press");
421 VWindow *vwindow = mwindow->get_viewer(1, 0);
422 vwindow->change_source(idxbl);
423 mwindow->gui->unlock_window();
424 EDL *vedl = vwindow->get_edl();
425 vedl->set_inpoint(start);
426 vedl->set_outpoint(end);
427 vedl->local_session->set_selectionstart(start);
428 vedl->local_session->set_selectionend(start);
429 vwindow->gui->lock_window("AssetViewPopup::button_press_event");
430 vwindow->update_position();
431 vwindow->gui->unlock_window();
436 if( !ctrl_down() && !shift_down() )
437 return cursor_motion_event();
439 picon->indexable ? picon->indexable :
440 picon->edl ? picon->edl : 0;
441 if( !idxbl ) return 0;
442 double total_length = mwindow->edl->tracks->total_length();
443 double pos = x * total_length / get_w();
444 double start = 0, end = total_length;
445 double lt = DBL_MAX, rt = DBL_MAX;
446 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
447 for( Edit *edit=track->edits->first; edit!=0; edit=edit->next ) {
448 Indexable *indexable = (Indexable *)edit->asset;
449 if( !indexable ) indexable = (Indexable *)edit->nested_edl;
450 if( !indexable ) continue;
451 if( indexable->id == idxbl->id ||
452 (!indexable->is_asset == !idxbl->is_asset &&
453 !strcmp(indexable->path, idxbl->path)) ) {
454 double start_pos = track->from_units(edit->startproject);
455 double end_pos = track->from_units(edit->startproject + edit->length);
456 double dlt = pos - start_pos, drt = end_pos - pos;
457 if( dlt >= 0 && dlt < lt ) { lt = dlt; start = start_pos; }
458 else if( dlt < 0 && -dlt < rt ) { rt = -dlt; end = start_pos; }
459 if( drt >= 0 && drt < rt ) { rt = drt; end = end_pos; }
460 else if( drt < 0 && -drt < lt ) { lt = -drt; start = end_pos; }
464 mwindow->gui->lock_window("AssetVIcon::popup_button_press");
465 mwindow->select_point(start);
466 edl->local_session->set_selectionstart(start);
467 edl->local_session->set_selectionend(!shift_down() ? start : end);
468 mwindow->zoom_sample(edl->local_session->zoom_sample);
469 mwindow->gui->unlock_window();
475 int AssetViewPopup::button_release_event()
477 if( !is_event_win() ) return 0;
482 int AssetViewPopup::cursor_motion_event()
484 AssetVIconThread *avt = (AssetVIconThread *)vt;
485 AssetVIcon *vicon = (AssetVIcon *)avt->vicon;
486 if( vicon && dragging && is_event_win() &&
487 get_button_down() && get_buttonpress() == LEFT_BUTTON &&
488 !ctrl_down() && !alt_down() && !shift_down() ) {
489 switch( draw_mode ) {
490 case ASSET_VIEW_MEDIA_MAP:
491 case ASSET_VIEW_FULL:
492 MWindow *mwindow = vicon->picon->mwindow;
493 EDL *edl = mwindow->edl;
494 int x = get_cursor_x();
495 double total_length = edl->tracks->total_length();
496 double pos = x * total_length / get_w();
497 mwindow->gui->lock_window("AssetVIcon::popup_cursor_motion");
498 mwindow->select_point(pos);
499 mwindow->zoom_sample(edl->local_session->zoom_sample);
500 mwindow->gui->unlock_window();
507 void AssetViewPopup::draw_vframe(VFrame *vframe)
509 switch( draw_mode ) {
510 case ASSET_VIEW_MEDIA:
511 case ASSET_VIEW_ICON:
512 ViewPopup::draw_vframe(vframe);
513 case ASSET_VIEW_NONE:
516 case ASSET_VIEW_MEDIA_MAP:
517 case ASSET_VIEW_FULL:
521 draw_box(0,0,get_w(),get_h());
523 int y2 = get_h()-bar_h;
524 BC_WindowBase::draw_vframe(vframe, 0,y1, get_w(),y2-y1);
525 AssetVIconThread *avt = (AssetVIconThread *)vt;
526 AssetVIcon *vicon = (AssetVIcon *)avt->vicon;
527 AssetPicon *picon = (AssetPicon *)vicon->picon;
529 picon->indexable ? picon->indexable :
530 picon->edl ? picon->edl : 0;
532 double sample_rate = idxbl->get_sample_rate();
533 double audio_length = sample_rate > 0 && idxbl->have_audio() ?
534 idxbl->get_audio_samples() / sample_rate : 0;
535 double frame_rate = idxbl->get_frame_rate();
536 double video_length = frame_rate > 0 && idxbl->have_video() ?
537 idxbl->get_video_frames() / frame_rate : 0;
538 double idxbl_length = bmax(audio_length, video_length);
539 if( !idxbl_length ) idxbl_length = 1;
541 EDL *edl = picon->mwindow->edl;
542 double total_length = edl->tracks->total_length();
543 if( !total_length ) total_length = 1;
544 for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
545 if( !track->is_armed() ) continue;
546 for( Edit *edit=track->edits->first; edit!=0; edit=edit->next ) {
547 Indexable *indexable = (Indexable *)edit->asset;
548 if( !indexable ) indexable = (Indexable *)edit->nested_edl;
549 if( !indexable ) continue;
550 if( indexable->id == idxbl->id ||
551 (!indexable->is_asset == !idxbl->is_asset &&
552 !strcmp(indexable->path, idxbl->path)) ) {
553 double pos1 = track->from_units(edit->startsource);
554 double pos2 = track->from_units(edit->startsource + edit->length);
555 double xscale = get_w() / idxbl_length;
556 int ex1 = pos1 * xscale, ex2 = pos2 * xscale;
558 draw_box(ex1,0, ex2-ex1,y1);
560 draw_line(ex1,0, ex1,y1);
561 draw_line(ex2,0, ex2,y1);
562 pos1 = track->from_units(edit->startproject);
563 pos2 = track->from_units(edit->startproject + edit->length);
564 xscale = get_w() / total_length;
565 int px1 = pos1 * xscale, px2 = pos2 * xscale;
567 draw_box(px1,y2, px2-px1,get_h()-y2);
569 draw_line(px1,y2, px1,get_h()-1);
570 draw_line(px2,y2, px2,get_h()-1);
573 draw_line(ex1,y1, px1,y2);
574 draw_line(ex2,y1, px2,y2);
580 int AssetViewPopup::keypress_event()
583 AssetVIconThread *avt = (AssetVIconThread *)vt;
584 switch( avt->draw_mode ) {
585 case ASSET_VIEW_MEDIA_MAP:
586 switch( get_keypress() ) {
589 avt->draw_mode = ASSET_VIEW_FULL;
593 case ASSET_VIEW_FULL:
594 avt->draw_mode = ASSET_VIEW_MEDIA_MAP;
597 if( result ) // zero change for refresh
599 return ViewPopup::keypress_event();
603 AssetVIconThread::AssetVIconThread(AWindowGUI *gui, Preferences *preferences)
604 : VIconThread(gui->asset_list, preferences->vicon_size * 16/9, preferences->vicon_size,
605 4*preferences->awindow_picon_h * 16/9, 4*preferences->awindow_picon_h)
608 draw_mode = ASSET_VIEW_NONE;
609 int vicon_cmodel = BC_RGB8;
610 switch( preferences->vicon_color_mode ) {
611 case VICON_COLOR_MODE_LOW: vicon_cmodel = BC_RGB8; break;
612 case VICON_COLOR_MODE_MED: vicon_cmodel = BC_RGB565; break;
613 case VICON_COLOR_MODE_HIGH: vicon_cmodel = BC_RGB888; break;
615 this->vicon_cmodel = vicon_cmodel;
618 AssetVIconThread::~AssetVIconThread()
622 void AssetVIconThread::set_view_popup(AssetVIcon *v, int draw_mode)
624 gui->stop_vicon_drawing();
625 this->draw_mode = draw_mode;
627 gui->start_vicon_drawing();
630 void AssetVIconThread::set_view_popup(AssetVIcon *v)
632 if( !v ) draw_mode = ASSET_VIEW_NONE;
633 VIconThread::set_view_popup(v);
636 ViewPopup *AssetVIconThread::new_view_window(ViewPopup *vpopup)
638 BC_WindowBase *parent = wdw->get_parent();
639 int rx = 0, ry = 0, rw = 0, rh = 0;
640 if( draw_mode != ASSET_VIEW_FULL ) {
641 XineramaScreenInfo *info = parent->get_xinerama_info(-1);
642 int cx = info ? info->x_org + info->width/2 : parent->get_root_w(0)/2;
643 int cy = info ? info->y_org + info->height/2 : parent->get_root_h(0)/2;
644 int vx = viewing->get_vx(), vy = viewing->get_vy();
645 wdw->get_root_coordinates(vx, vy, &rx, &ry);
646 rx += (rx >= cx ? -view_w+viewing->w/4 : viewing->w-viewing->w/4);
647 ry += (ry >= cy ? -view_h+viewing->h/4 : viewing->h-viewing->h/4);
648 rw = view_w; rh = view_h;
651 parent->get_fullscreen_geometry(rx, ry, rw, rh);
652 AssetViewPopup *av_popup = (AssetViewPopup *)vpopup;
654 av_popup->reposition_window(rx, ry, rw, rh);
656 av_popup = new AssetViewPopup(this, draw_mode, rx, ry, rw, rh);
657 int playing_audio = gui->play_off ? -1 : 0;
658 if( !playing_audio ) {
659 switch( draw_mode ) {
660 case ASSET_VIEW_NONE:
661 case ASSET_VIEW_ICON:
662 case ASSET_VIEW_MEDIA_MAP:
663 case ASSET_VIEW_FULL:
666 case ASSET_VIEW_MEDIA:
667 switch( gui->vicon_drawing ) {
668 case AVICON_SRC_TARGET:
675 vicon->playing_audio = playing_audio;
676 wdw->set_active_subwindow(av_popup);
680 void AssetVIconThread::stop_vicon_drawing(int wait)
683 gui->lock_window("AssetVIconThread::stop_vicon_drawing");
684 gui->unlock_window();
688 AWindowFolderItem::AWindowFolderItem()
694 AWindowFolderItem::AWindowFolderItem(const char *text, int color)
695 : BC_ListBoxItem(text, color)
700 AWindowFolderItem::AWindowFolderItem(const char *text, BC_Pixmap *icon, int color)
701 : BC_ListBoxItem(text, icon, color)
706 AssetPicon *AWindowFolderItem::get_picon()
708 AWindowFolderItem *item = this;
709 while( item->parent ) { item = (AWindowFolderItem*)item->parent; }
710 return (AssetPicon*)item;
713 int AWindowFolderSubItems::matches(const char *text)
715 int i = names.size();
716 while( --i >= 0 && strcmp(names[i], text) );
718 ArrayList<BC_ListBoxItem *> *sublist = get_sublist();
719 i = sublist ? sublist->size() : 0;
721 AWindowFolderSubItems *item = (AWindowFolderSubItems *)sublist->get(i);
722 if( item->matches(text) ) break;
725 return i >= 0 ? 1 : 0;
729 AssetPicon::AssetPicon(MWindow *mwindow,
730 AWindowGUI *gui, Indexable *indexable)
731 : AWindowFolderItem()
734 this->mwindow = mwindow;
736 this->indexable = indexable;
737 indexable->add_user();
738 this->id = indexable->id;
741 AssetPicon::AssetPicon(MWindow *mwindow,
742 AWindowGUI *gui, EDL *edl)
743 : AWindowFolderItem()
746 this->mwindow = mwindow;
753 AssetPicon::AssetPicon(MWindow *mwindow,
754 AWindowGUI *gui, int folder, int persist)
755 : AWindowFolderItem(_(AWindowGUI::folder_names[folder]),
756 folder>=0 && folder<AWINDOW_FOLDERS ?
757 gui->folder_icons[folder] : gui->folder_icon)
761 this->mwindow = mwindow;
763 persistent = persist;
766 AssetPicon::AssetPicon(MWindow *mwindow,
767 AWindowGUI *gui, int folder, const char *title)
768 : AWindowFolderItem(title, gui->folder_icon)
772 this->mwindow = mwindow;
777 AssetPicon::AssetPicon(MWindow *mwindow,
778 AWindowGUI *gui, PluginServer *plugin)
779 : AWindowFolderItem()
782 this->mwindow = mwindow;
784 this->plugin = plugin;
787 AssetPicon::AssetPicon(MWindow *mwindow,
788 AWindowGUI *gui, Label *label)
789 : AWindowFolderItem()
792 this->mwindow = mwindow;
800 AssetPicon::~AssetPicon()
802 if( vicon ) vicon->remove_user();
804 if( indexable ) indexable->remove_user();
805 if( edl ) edl->remove_user();
806 if( icon && !gui->protected_pixmap(icon) ) {
808 if( !plugin ) delete icon_vframe;
812 void AssetPicon::draw_hue_bar(VFrame *frame, double duration)
814 float t = duration > 1 ? (log(duration) / log(3600.f)) : 0;
816 float h = 300 * t, s = 1., v = 1.;
817 float r, g, b; // duration, 0..1hr == hue red..magenta
818 HSV::hsv_to_rgb(r,g,b, h,s,v);
819 int ih = frame->get_h()/8, iw = frame->get_w();
820 int ir = r * 256; CLAMP(ir, 0,255);
821 int ig = g * 256; CLAMP(ig, 0,255);
822 int ib = b * 256; CLAMP(ib, 0,255);
823 unsigned char **rows = frame->get_rows();
824 for( int y=0; y<ih; ++y ) {
825 unsigned char *rp = rows[y];
826 for( int x=0; x<iw; rp+=3,++x ) {
827 rp[0] = ir; rp[1] = ig; rp[2] = ib;
832 void AssetPicon::draw_wave(VFrame *frame, double *dp, int len,
833 int base_color, int line_color, int x, int y, int w, int h)
835 int h1 = h-1, h2 = h/2, iy = h2;
836 int rgb_color = frame->pixel_rgb;
837 for( int ix=0,x1=0,x2=0; ix<w; ++ix,x1=x2 ) {
838 double min = *dp, max = min;
839 x2 = (len * (ix+1))/w;
840 for( int i=x1; i<x2; ++i ) {
841 double value = *dp++;
842 if( value < min ) min = value;
843 if( value > max ) max = value;
845 int ctr = (min + max) / 2;
846 int y0 = (int)(h2 - ctr*h2); CLAMP(y0, 0,h1);
847 int y1 = (int)(h2 - min*h2); CLAMP(y1, 0,h1);
848 int y2 = (int)(h2 - max*h2); CLAMP(y2, 0,h1);
849 frame->pixel_rgb = line_color;
850 frame->draw_line(ix+x,y1+y, ix+x,y2+y);
851 frame->pixel_rgb = base_color;
852 frame->draw_line(ix+x,iy+y, ix+x,y0+y);
855 frame->pixel_rgb = rgb_color;
858 void AssetPicon::reset()
866 foldernum = AW_NO_FOLDER;
881 void AssetPicon::open_render_engine(EDL *edl, int is_audio)
883 TransportCommand command;
884 command.command = is_audio ? NORMAL_FWD : CURRENT_FRAME;
885 command.get_edl()->copy_all(edl);
886 command.change_type = CHANGE_ALL;
887 command.realtime = 0;
888 render_engine = new RenderEngine(0, mwindow->preferences, 0, 0);
889 render_engine->set_vcache(mwindow->video_cache);
890 render_engine->set_acache(mwindow->audio_cache);
891 render_engine->arm_command(&command);
893 void AssetPicon::close_render_engine()
895 delete render_engine; render_engine = 0;
897 void AssetPicon::render_video(int64_t pos, VFrame *vfrm)
899 if( !render_engine || !render_engine->vrender ) return;
900 render_engine->vrender->process_buffer(vfrm, pos, 0);
902 void AssetPicon::render_audio(int64_t pos, Samples **samples, int len)
904 if( !render_engine || !render_engine->arender ) return;
905 render_engine->arender->process_buffer(samples, len, pos);
908 void AssetPicon::create_objects()
911 char name[BCTEXTLEN];
912 int pixmap_w, pixmap_h;
914 int picon_h = mwindow->preferences->awindow_picon_h;
915 pixmap_h = picon_h * BC_WindowBase::get_resources()->icon_scale;
921 if( this->indexable ) {
923 if( this->indexable->is_asset ) {
924 asset = (Asset *)indexable;
925 if( asset->format == FILE_REF ) {
926 cp += sprintf(cp, "ref:");
927 set_color(get_color() ^ 0x5599CC);
931 edl = (EDL *)indexable;
932 cp += sprintf(cp, "edl:");
933 // set_color(get_color() ^ 0xCC9955);
935 fs.extract_name(cp, indexable->path);
938 else if( this->edl ) {
940 strcpy(name, edl->local_session->clip_title);
946 if( asset->video_data ) {
947 if( mwindow->preferences->use_thumbnails ) {
948 gui->unlock_window();
949 char string[BCTEXTLEN];
950 sprintf(string, _("Reading %s"), name);
951 mwindow->gui->lock_window("AssetPicon::create_objects");
952 mwindow->gui->show_message(string);
953 mwindow->gui->unlock_window();
954 File *file = mwindow->video_cache->check_out(asset,
959 int height = asset->height > 0 ? asset->height : 1;
960 pixmap_w = pixmap_h * asset->width / height;
963 file->set_video_position(0, 0);
965 if( gui->temp_picon &&
966 (gui->temp_picon->get_w() != asset->width ||
967 gui->temp_picon->get_h() != asset->height) ) {
968 delete gui->temp_picon;
972 if( !gui->temp_picon ) {
973 gui->temp_picon = new VFrame(0, -1,
974 asset->width, asset->height,
977 file->read_frame(gui->temp_picon);
978 mwindow->video_cache->check_in(asset);
980 gui->lock_window("AssetPicon::create_objects 0");
981 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
982 icon->draw_vframe(gui->temp_picon,
983 0, 0, pixmap_w, pixmap_h, 0, 0);
984 icon_vframe = new VFrame(0,
985 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
986 icon_vframe->transfer_from(gui->temp_picon);
987 if( asset->folder_no == AW_MEDIA_FOLDER ||
988 asset->folder_no == AW_PROXY_FOLDER ) {
990 double framerate = asset->get_frame_rate();
991 if( !framerate ) framerate = VICON_RATE;
992 int64_t frames = asset->get_video_frames();
993 double secs = frames / framerate;
994 if( secs > 5 ) secs = 5;
995 int64_t length = secs * gui->vicon_thread->refresh_rate;
996 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, framerate, length);
997 if( asset->audio_data && secs > 0 ) {
998 gui->unlock_window();
999 int audio_len = VICON_SAMPLE_RATE*secs+0.5;
1000 vicon->init_audio(audio_len*sizeof(vicon_audio_t));
1001 vicon->load_audio();
1002 gui->lock_window("AssetPicon::create_objects 1");
1004 gui->vicon_thread->add_vicon(vicon);
1008 eprintf("Unable to open %s\nin asset: %s",asset->path, get_text());
1009 gui->lock_window("AssetPicon::create_objects 2");
1010 icon = gui->video_icon;
1011 icon_vframe = gui->video_vframe;
1015 icon = gui->video_icon;
1016 icon_vframe = gui->video_vframe;
1020 if( asset->audio_data ) {
1021 if( mwindow->preferences->use_thumbnails ) {
1022 gui->unlock_window();
1023 File *file = mwindow->audio_cache->check_out(asset,
1027 pixmap_w = pixmap_h * 16/9;
1028 icon_vframe = new VFrame(0,
1029 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
1030 icon_vframe->clear_frame();
1031 { char string[BCTEXTLEN];
1032 sprintf(string, _("Reading %s"), name);
1033 mwindow->gui->lock_window("AssetPicon::create_objects 3");
1034 mwindow->gui->show_message(string);
1035 mwindow->gui->unlock_window(); }
1036 int sample_rate = asset->get_sample_rate();
1037 int channels = asset->get_audio_channels();
1038 if( channels > 2 ) channels = 2;
1039 int64_t audio_samples = asset->get_audio_samples();
1040 double duration = (double)audio_samples / sample_rate;
1041 draw_hue_bar(icon_vframe, duration);
1042 int bfrsz = sample_rate;
1043 Samples samples(bfrsz);
1044 static int line_colors[2] = { GREEN, YELLOW };
1045 static int base_colors[2] = { RED, PINK };
1046 for( int i=channels; --i>=0; ) {
1047 file->set_channel(i);
1048 file->set_audio_position(0);
1049 file->read_samples(&samples, bfrsz);
1050 draw_wave(icon_vframe, samples.get_data(), bfrsz,
1051 base_colors[i], line_colors[i]);
1053 mwindow->audio_cache->check_in(asset);
1054 if( asset->folder_no == AW_MEDIA_FOLDER ) {
1055 double secs = duration;
1056 if( secs > 5 ) secs = 5;
1057 double refresh_rate = gui->vicon_thread->refresh_rate;
1058 int64_t length = secs * refresh_rate;
1059 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, refresh_rate, length);
1060 int audio_len = VICON_SAMPLE_RATE*secs+0.5;
1061 vicon->init_audio(audio_len*sizeof(vicon_audio_t));
1062 vicon->load_audio();
1063 gui->vicon_thread->add_vicon(vicon);
1065 gui->lock_window("AssetPicon::create_objects 4");
1066 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
1067 icon->draw_vframe(icon_vframe,
1068 0, 0, pixmap_w, pixmap_h, 0, 0);
1071 eprintf("Unable to open %s\nin asset: %s",asset->path, get_text());
1072 gui->lock_window("AssetPicon::create_objects 5");
1073 icon = gui->audio_icon;
1074 icon_vframe = gui->audio_vframe;
1078 icon = gui->audio_icon;
1079 icon_vframe = gui->audio_vframe;
1084 comments_time = !stat(asset->path, &st) ? st.st_mtime : 0;
1085 comments_rate = asset->get_frame_rate();
1086 comments_ffmt = asset->format == FILE_FFMPEG ? '=' : '-';
1087 comments_type = asset->format == FILE_FFMPEG ?
1088 asset->vcodec : File::formattostr(asset->format);
1091 if( edl->tracks->playable_video_tracks() ) {
1092 if( mwindow->preferences->use_thumbnails ) {
1093 gui->unlock_window();
1094 AssetVIconThread *avt = gui->vicon_thread;
1095 char clip_icon_path[BCTEXTLEN];
1096 char *clip_icon = edl->local_session->clip_icon;
1098 if( is_clip && clip_icon[0] ) {
1099 snprintf(clip_icon_path, sizeof(clip_icon_path),
1100 "%s/%s", File::get_config_path(), clip_icon);
1101 vframe = VFramePng::vframe_png(clip_icon_path);
1104 ( vframe->get_w() != avt->vw || vframe->get_h() != avt->vh ) ) {
1105 delete vframe; vframe = 0;
1107 int edl_h = edl->get_h(), edl_w = edl->get_w();
1108 int height = edl_h > 0 ? edl_h : 1;
1109 int width = edl_w > 0 ? edl_w : 1;
1110 int color_model = edl->session->color_model;
1112 //printf("render clip: %s\n", name);
1113 VFrame::get_temp(gui->temp_picon, width, height, color_model);
1114 char string[BCTEXTLEN];
1115 sprintf(string, _("Rendering %s"), name);
1116 mwindow->gui->lock_window("AssetPicon::create_objects");
1117 mwindow->gui->show_message(string);
1118 mwindow->gui->unlock_window();
1119 open_render_engine(edl, 0);
1120 render_video(0, gui->temp_picon);
1121 close_render_engine();
1122 vframe = new VFrame(avt->vw, avt->vh, BC_RGB888);
1123 vframe->transfer_from(gui->temp_picon);
1124 if( this->edl && clip_icon[0] )
1125 vframe->write_png(clip_icon_path);
1127 pixmap_w = pixmap_h * width / height;
1128 vicon = new AssetVIcon(this, pixmap_w, pixmap_h, VICON_RATE, 1);
1129 vicon->add_image(vframe, avt->vw, avt->vh, avt->vicon_cmodel);
1130 icon_vframe = new VFrame(pixmap_w, pixmap_h, BC_RGB888);
1131 icon_vframe->transfer_from(vframe);
1133 gui->lock_window("AssetPicon::create_objects 0");
1134 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
1135 icon->draw_vframe(icon_vframe,
1136 0, 0, pixmap_w, pixmap_h, 0, 0);
1138 else if( is_clip ) {
1139 icon = gui->clip_icon;
1140 icon_vframe = gui->clip_vframe;
1143 icon = gui->video_icon;
1144 icon_vframe = gui->video_vframe;
1148 if( edl->tracks->playable_audio_tracks() ) {
1149 if( mwindow->preferences->use_thumbnails ) {
1150 gui->unlock_window();
1151 char clip_icon_path[BCTEXTLEN];
1152 char *clip_icon = edl->local_session->clip_icon;
1153 if( is_clip && clip_icon[0] ) {
1154 snprintf(clip_icon_path, sizeof(clip_icon_path),
1155 "%s/%s", File::get_config_path(), clip_icon);
1156 icon_vframe = VFramePng::vframe_png(clip_icon_path);
1158 if( !icon_vframe ) {
1159 pixmap_w = pixmap_h * 16/9;
1160 icon_vframe = new VFrame(0,
1161 -1, pixmap_w, pixmap_h, BC_RGB888, -1);
1162 icon_vframe->clear_frame();
1163 char string[BCTEXTLEN];
1164 sprintf(string, _("Rendering %s"), name);
1165 mwindow->gui->lock_window("AssetPicon::create_objects 3");
1166 mwindow->gui->show_message(string);
1167 mwindow->gui->unlock_window();
1168 int sample_rate = edl->get_sample_rate();
1169 int channels = edl->get_audio_channels();
1170 if( channels > 2 ) channels = 2;
1171 int64_t audio_samples = edl->get_audio_samples();
1172 double duration = (double)audio_samples / sample_rate;
1173 draw_hue_bar(icon_vframe, duration);
1174 Samples *samples[MAX_CHANNELS];
1175 int bfrsz = sample_rate;
1176 for( int i=0; i<MAX_CHANNELS; ++i )
1177 samples[i] = i<channels ? new Samples(bfrsz) : 0;
1178 open_render_engine(edl, 1);
1179 render_audio(0, samples, bfrsz);
1180 close_render_engine();
1181 gui->lock_window("AssetPicon::create_objects 4");
1182 static int line_colors[2] = { GREEN, YELLOW };
1183 static int base_colors[2] = { RED, PINK };
1184 for( int i=channels; --i>=0; ) {
1185 draw_wave(icon_vframe, samples[i]->get_data(), bfrsz,
1186 base_colors[i], line_colors[i]);
1188 for( int i=0; i<channels; ++i ) delete samples[i];
1189 if( is_clip && clip_icon[0] )
1190 icon_vframe->write_png(clip_icon_path);
1193 pixmap_w = icon_vframe->get_w();
1194 pixmap_h = icon_vframe->get_h();
1196 icon = new BC_Pixmap(gui, pixmap_w, pixmap_h);
1197 icon->draw_vframe(icon_vframe,
1198 0, 0, pixmap_w, pixmap_h, 0, 0);
1200 else if( !indexable ) {
1201 icon = gui->clip_icon;
1202 icon_vframe = gui->clip_vframe;
1205 icon = gui->audio_icon;
1206 icon_vframe = gui->audio_vframe;
1211 strcpy(name, _(plugin->title));
1213 icon_vframe = plugin->get_picon();
1215 icon = gui->create_pixmap(icon_vframe);
1216 else if( plugin->audio ) {
1217 if( plugin->transition ) {
1218 icon = gui->atransition_icon;
1219 icon_vframe = gui->atransition_vframe;
1221 else if( plugin->is_ffmpeg() ) {
1222 icon = gui->ff_aud_icon;
1223 icon_vframe = gui->ff_aud_vframe;
1225 else if( plugin->is_ladspa() ) {
1226 icon = gui->ladspa_icon;
1227 icon_vframe = gui->ladspa_vframe;
1230 icon = gui->aeffect_icon;
1231 icon_vframe = gui->aeffect_vframe;
1234 else if( plugin->video ) {
1235 if( plugin->transition ) {
1236 icon = gui->vtransition_icon;
1237 icon_vframe = gui->vtransition_vframe;
1239 else if( plugin->is_ffmpeg() ) {
1240 icon = gui->ff_vid_icon;
1241 icon_vframe = gui->ff_vid_vframe;
1244 icon = gui->veffect_icon;
1245 icon_vframe = gui->veffect_vframe;
1252 mwindow->edl->session->time_format,
1253 mwindow->edl->session->sample_rate,
1254 mwindow->edl->session->frame_rate,
1255 mwindow->edl->session->frames_per_foot);
1257 icon = gui->label_icon;
1258 icon_vframe = gui->label_vframe;
1261 icon = gui->file_icon;
1262 icon_vframe = BC_WindowBase::get_resources()->type_to_icon[ICON_UNKNOWN];
1265 set_icon_vframe(icon_vframe);
1268 AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow)
1269 : BC_Window(_(PROGRAM_NAME ": Resources"),
1270 mwindow->session->awindow_x, mwindow->session->awindow_y,
1271 mwindow->session->awindow_w, mwindow->session->awindow_h,
1272 xS(100), yS(100), 1, 1, 1)
1274 this->mwindow = mwindow;
1275 this->awindow = awindow;
1277 file_vframe = 0; file_icon = 0;
1278 folder_vframe = 0; folder_icon = 0;
1279 audio_vframe = 0; audio_icon = 0;
1280 video_vframe = 0; video_icon = 0;
1281 label_vframe = 0; label_icon = 0;
1283 aeffect_folder_vframe = 0; aeffect_folder_icon = 0;
1284 atransition_folder_vframe = 0; atransition_folder_icon = 0;
1285 clip_folder_vframe = 0; clip_folder_icon = 0;
1286 label_folder_vframe = 0; label_folder_icon = 0;
1287 media_folder_vframe = 0; media_folder_icon = 0;
1288 proxy_folder_vframe = 0; proxy_folder_icon = 0;
1289 veffect_folder_vframe = 0; veffect_folder_icon = 0;
1290 vtransition_folder_vframe = 0; vtransition_folder_icon = 0;
1292 ladspa_vframe = 0; ladspa_icon = 0;
1293 ff_aud_vframe = 0; ff_aud_icon = 0;
1294 ff_vid_vframe = 0; ff_vid_icon = 0;
1296 clip_vframe = 0; clip_icon = 0;
1297 atransition_vframe = 0; atransition_icon = 0;
1298 vtransition_vframe = 0; vtransition_icon = 0;
1299 aeffect_vframe = 0; aeffect_icon = 0;
1300 veffect_vframe = 0; veffect_icon = 0;
1302 plugin_visibility = ((uint64_t)1<<(8*sizeof(uint64_t)-1))-1;
1304 effectlist_menu = 0;
1309 folderlist_menu = 0;
1312 allow_iconlisting = 1;
1316 vicon_drawing = AVICON_FULL_PLAY;
1319 displayed_folder = AW_NO_FOLDER;
1320 new_folder_thread = 0;
1321 modify_folder_thread = 0;
1322 folder_lock = new Mutex("AWindowGUI::folder_lock");
1325 AWindowGUI::~AWindowGUI()
1327 assets.remove_all_objects();
1328 folders.remove_all_objects();
1329 aeffects.remove_all_objects();
1330 veffects.remove_all_objects();
1331 atransitions.remove_all_objects();
1332 vtransitions.remove_all_objects();
1333 labellist.remove_all_objects();
1334 displayed_assets[1].remove_all_objects();
1336 delete new_folder_thread;
1337 delete modify_folder_thread;
1338 delete vicon_thread;
1343 delete remove_plugin;
1345 delete file_vframe; delete file_icon;
1346 delete folder_vframe; delete folder_icon;
1347 delete audio_vframe; delete audio_icon;
1348 delete video_vframe; delete video_icon;
1349 delete label_vframe; delete label_icon;
1350 delete clip_vframe; delete clip_icon;
1351 delete aeffect_folder_vframe; delete aeffect_folder_icon;
1352 delete atransition_folder_vframe; delete atransition_folder_icon;
1353 delete veffect_folder_vframe; delete veffect_folder_icon;
1354 delete vtransition_folder_vframe; delete vtransition_folder_icon;
1355 delete clip_folder_vframe; delete clip_folder_icon;
1356 delete label_folder_vframe; delete label_folder_icon;
1357 delete media_folder_vframe; delete media_folder_icon;
1358 delete proxy_folder_vframe; delete proxy_folder_icon;
1359 delete ladspa_vframe; delete ladspa_icon;
1360 delete ff_aud_vframe; delete ff_aud_icon;
1361 delete ff_vid_vframe; delete ff_vid_icon;
1362 delete atransition_vframe; delete atransition_icon;
1363 delete vtransition_vframe; delete vtransition_icon;
1364 delete aeffect_vframe; delete aeffect_icon;
1365 delete veffect_vframe; delete veffect_icon;
1369 bool AWindowGUI::protected_pixmap(BC_Pixmap *icon)
1371 return icon == file_icon ||
1372 icon == folder_icon ||
1373 icon == audio_icon ||
1374 icon == video_icon ||
1375 icon == clip_icon ||
1376 icon == label_icon ||
1377 icon == vtransition_icon ||
1378 icon == atransition_icon ||
1379 icon == veffect_icon ||
1380 icon == aeffect_icon ||
1381 icon == ladspa_icon ||
1382 icon == ff_aud_icon ||
1383 icon == ff_vid_icon ||
1384 icon == aeffect_folder_icon ||
1385 icon == veffect_folder_icon ||
1386 icon == atransition_folder_icon ||
1387 icon == vtransition_folder_icon ||
1388 icon == label_folder_icon ||
1389 icon == clip_folder_icon ||
1390 icon == media_folder_icon ||
1391 icon == proxy_folder_icon;
1394 VFrame *AWindowGUI::get_picon(const char *name, const char *plugin_icons)
1396 char png_path[BCTEXTLEN];
1397 char *pp = png_path, *ep = pp + sizeof(png_path)-1;
1398 snprintf(pp, ep-pp, "%s/picon/%s/%s.png",
1399 File::get_plugin_path(), plugin_icons, name);
1400 if( access(png_path, R_OK) ) return 0;
1401 return VFramePng::vframe_png(png_path,0,0);
1404 VFrame *AWindowGUI::get_picon(const char *name)
1406 VFrame *vframe = get_picon(name, mwindow->preferences->plugin_icons);
1408 char png_name[BCSTRLEN], *pp = png_name, *ep = pp + sizeof(png_name)-1;
1409 snprintf(pp, ep-pp, "%s.png", name);
1410 unsigned char *data = mwindow->theme->get_image_data(png_name);
1411 if( data ) vframe = new VFramePng(data, 0.);
1416 void AWindowGUI::resource_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, int idx)
1418 vfrm = get_picon(fn);
1419 if( !vfrm ) vfrm = BC_WindowBase::get_resources()->type_to_icon[idx];
1420 icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
1422 void AWindowGUI::theme_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn)
1424 vfrm = get_picon(fn);
1425 if( !vfrm ) vfrm = mwindow->theme->get_image(fn);
1426 icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
1428 void AWindowGUI::plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, unsigned char *png)
1430 vfrm = get_picon(fn);
1431 if( !vfrm ) vfrm = new VFramePng(png);
1432 icon = new BC_Pixmap(this, vfrm, PIXMAP_ALPHA);
1435 void AWindowGUI::create_objects()
1437 int ys5 = yS(5), ys10 = yS(10);
1438 lock_window("AWindowGUI::create_objects");
1439 asset_titles[0] = C_("Title");
1440 asset_titles[1] = _("Comments");
1442 set_icon(mwindow->theme->get_image("awindow_icon"));
1444 resource_icon(file_vframe, file_icon, "film_icon", ICON_UNKNOWN);
1445 resource_icon(folder_vframe, folder_icon, "folder_icon", ICON_FOLDER);
1446 resource_icon(audio_vframe, audio_icon, "audio_icon", ICON_SOUND);
1447 resource_icon(video_vframe, video_icon, "video_icon", ICON_FILM);
1448 resource_icon(label_vframe, label_icon, "label_icon", ICON_LABEL);
1450 theme_icon(aeffect_folder_vframe, aeffect_folder_icon, "aeffect_folder");
1451 theme_icon(atransition_folder_vframe, atransition_folder_icon, "atransition_folder");
1452 theme_icon(clip_folder_vframe, clip_folder_icon, "clip_folder");
1453 theme_icon(label_folder_vframe, label_folder_icon, "label_folder");
1454 theme_icon(media_folder_vframe, media_folder_icon, "media_folder");
1455 theme_icon(proxy_folder_vframe, proxy_folder_icon, "proxy_folder");
1456 theme_icon(veffect_folder_vframe, veffect_folder_icon, "veffect_folder");
1457 theme_icon(vtransition_folder_vframe, vtransition_folder_icon, "vtransition_folder");
1459 folder_icons[AW_AEFFECT_FOLDER] = aeffect_folder_icon;
1460 folder_icons[AW_VEFFECT_FOLDER] = veffect_folder_icon;
1461 folder_icons[AW_ATRANSITION_FOLDER] = atransition_folder_icon;
1462 folder_icons[AW_VTRANSITION_FOLDER] = vtransition_folder_icon;
1463 folder_icons[AW_LABEL_FOLDER] = label_folder_icon;
1464 folder_icons[AW_CLIP_FOLDER] = clip_folder_icon;
1465 folder_icons[AW_MEDIA_FOLDER] = media_folder_icon;
1466 folder_icons[AW_PROXY_FOLDER] = proxy_folder_icon;
1468 theme_icon(clip_vframe, clip_icon, "clip_icon");
1469 theme_icon(atransition_vframe, atransition_icon, "atransition_icon");
1470 theme_icon(vtransition_vframe, vtransition_icon, "vtransition_icon");
1471 theme_icon(aeffect_vframe, aeffect_icon, "aeffect_icon");
1472 theme_icon(veffect_vframe, veffect_icon, "veffect_icon");
1474 plugin_icon(ladspa_vframe, ladspa_icon, "lad_picon", lad_picon_png);
1475 plugin_icon(ff_aud_vframe, ff_aud_icon, "ff_audio", ff_audio_png);
1476 plugin_icon(ff_vid_vframe, ff_vid_icon, "ff_video", ff_video_png);
1477 folder_lock->lock("AWindowGUI::create_objects");
1478 // Mandatory folders
1479 folders.append(new AssetPicon(mwindow, this, AW_AEFFECT_FOLDER, 1));
1480 folders.append(new AssetPicon(mwindow, this, AW_VEFFECT_FOLDER, 1));
1481 folders.append(new AssetPicon(mwindow, this, AW_ATRANSITION_FOLDER, 1));
1482 folders.append(new AssetPicon(mwindow, this, AW_VTRANSITION_FOLDER, 1));
1483 folders.append(new AssetPicon(mwindow, this, AW_LABEL_FOLDER, 1));
1484 folders.append(new AssetPicon(mwindow, this, AW_CLIP_FOLDER, 1));
1485 folders.append(new AssetPicon(mwindow, this, AW_PROXY_FOLDER, 1));
1486 folders.append(new AssetPicon(mwindow, this, AW_MEDIA_FOLDER, 1));
1488 create_label_folder();
1489 folder_lock->unlock();
1491 mwindow->theme->get_awindow_sizes(this);
1492 load_defaults(mwindow->defaults);
1493 new_folder_thread = new NewFolderThread(this);
1494 modify_folder_thread = new ModifyFolderThread(this);
1496 int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1497 int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1498 search_text = new AWindowSearchText(mwindow, this, x1, y1+ys5);
1499 search_text->create_objects();
1500 int dy = search_text->get_h() + ys10;
1502 add_subwindow(asset_list = new AWindowAssets(mwindow, this, x1, y1, w1, h1));
1504 vicon_thread = new AssetVIconThread(this, mwindow->preferences);
1505 asset_list->update_vicon_area();
1506 vicon_thread->start();
1507 vicon_audio = new AssetVIconAudio(this);
1509 add_subwindow(divider = new AWindowDivider(mwindow, this,
1510 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1511 mwindow->theme->adivider_w, mwindow->theme->adivider_h));
1513 divider->set_cursor(HSEPARATE_CURSOR, 0, 0);
1515 int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1516 int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1517 int n = sizeof(AVIconDrawing::avicon_names)/sizeof(AVIconDrawing::avicon_names[0]);
1518 int tw = 0; const char **av_names = AVIconDrawing::avicon_names;
1519 for( int i=0; i<n; ++i ) {
1520 int nw = get_text_width(MEDIUMFONT, _(av_names[i]));
1521 if( tw < nw ) tw = nw;
1523 int pw = BC_PopupMenu::calculate_w(xS(16), tw, 1);
1524 const char *text = _(AVIconDrawing::avicon_names[vicon_drawing]);
1525 add_subwindow(avicon_drawing = new AVIconDrawing(this, fw, fy, pw, text));
1526 avicon_drawing->create_objects();
1527 add_subwindow(add_tools = new AddTools(mwindow, this, fx, fy, _("Visibility")));
1528 add_tools->create_objects();
1529 fy += add_tools->get_h(); fh -= add_tools->get_h();
1530 add_subwindow(folder_list = new AWindowFolders(mwindow,
1531 this, fx, fy, fw, fh));
1533 folder_list->load_expanders();
1535 //int x = mwindow->theme->abuttons_x;
1536 //int y = mwindow->theme->abuttons_y;
1538 add_subwindow(asset_menu = new AssetPopup(mwindow, this));
1539 asset_menu->create_objects();
1540 add_subwindow(clip_menu = new ClipPopup(mwindow, this));
1541 clip_menu->create_objects();
1542 add_subwindow(label_menu = new LabelPopup(mwindow, this));
1543 label_menu->create_objects();
1544 add_subwindow(proxy_menu = new ProxyPopup(mwindow, this));
1545 proxy_menu->create_objects();
1547 add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this));
1548 effectlist_menu->create_objects();
1549 add_subwindow(assetlist_menu = new AssetListMenu(mwindow, this));
1550 assetlist_menu->create_objects();
1551 add_subwindow(cliplist_menu = new ClipListMenu(mwindow, this));
1552 cliplist_menu->create_objects();
1553 add_subwindow(labellist_menu = new LabelListMenu(mwindow, this));
1554 labellist_menu->create_objects();
1555 add_subwindow(proxylist_menu = new ProxyListMenu(mwindow, this));
1556 proxylist_menu->create_objects();
1558 add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this));
1559 folderlist_menu->create_objects();
1561 create_custom_xatoms();
1565 int AWindowGUI::resize_event(int w, int h)
1567 mwindow->session->awindow_x = get_x();
1568 mwindow->session->awindow_y = get_y();
1569 mwindow->session->awindow_w = w;
1570 mwindow->session->awindow_h = h;
1572 mwindow->theme->get_awindow_sizes(this);
1573 mwindow->theme->draw_awindow_bg(this);
1574 reposition_objects();
1576 // int x = mwindow->theme->abuttons_x;
1577 // int y = mwindow->theme->abuttons_y;
1578 // new_bin->reposition_window(x, y);
1579 // x += new_bin->get_w();
1580 // delete_bin->reposition_window(x, y);
1581 // x += delete_bin->get_w();
1582 // rename_bin->reposition_window(x, y);
1583 // x += rename_bin->get_w();
1584 // delete_disk->reposition_window(x, y);
1585 // x += delete_disk->get_w();
1586 // delete_project->reposition_window(x, y);
1587 // x += delete_project->get_w();
1588 // info->reposition_window(x, y);
1589 // x += info->get_w();
1590 // redraw_index->reposition_window(x, y);
1591 // x += redraw_index->get_w();
1592 // paste->reposition_window(x, y);
1593 // x += paste->get_w();
1594 // append->reposition_window(x, y);
1595 // x += append->get_w();
1596 // view->reposition_window(x, y);
1598 BC_WindowBase::resize_event(w, h);
1599 asset_list->update_vicon_area();
1603 int AWindowGUI::translation_event()
1605 mwindow->session->awindow_x = get_x();
1606 mwindow->session->awindow_y = get_y();
1610 void AWindowGUI::reposition_objects()
1612 int ys5 = yS(5), ys10 = yS(10);
1613 int x1 = mwindow->theme->alist_x, y1 = mwindow->theme->alist_y;
1614 int w1 = mwindow->theme->alist_w, h1 = mwindow->theme->alist_h;
1615 search_text->reposition_window(x1, y1+ys5, w1);
1616 int dy = search_text->get_h() + ys10;
1618 asset_list->reposition_window(x1, y1, w1, h1);
1619 divider->reposition_window(
1620 mwindow->theme->adivider_x, mwindow->theme->adivider_y,
1621 mwindow->theme->adivider_w, mwindow->theme->adivider_h);
1622 int fx = mwindow->theme->afolders_x, fy = mwindow->theme->afolders_y;
1623 int fw = mwindow->theme->afolders_w, fh = mwindow->theme->afolders_h;
1624 add_tools->resize_event(fw-avicon_w, add_tools->get_h());
1625 avicon_drawing->reposition_window(fw-avicon_drawing->get_w(), fy);
1626 fy += add_tools->get_h(); fh -= add_tools->get_h();
1627 folder_list->reposition_window(fx, fy, fw, fh);
1630 int AWindowGUI::save_defaults(BC_Hash *defaults)
1632 defaults->update("PLUGIN_VISIBILTY", plugin_visibility);
1633 defaults->update("VICON_DRAWING", vicon_drawing);
1634 defaults->update("TIP_INFO", tip_info);
1638 int AWindowGUI::load_defaults(BC_Hash *defaults)
1640 plugin_visibility = defaults->get("PLUGIN_VISIBILTY", plugin_visibility);
1641 vicon_drawing = defaults->get("VICON_DRAWING", vicon_drawing);
1642 tip_info = defaults->get("TIP_INFO", tip_info);
1646 int AWindowGUI::close_event()
1649 mwindow->session->show_awindow = 0;
1652 mwindow->gui->lock_window("AWindowGUI::close_event");
1653 mwindow->gui->mainmenu->show_awindow->set_checked(0);
1654 mwindow->gui->unlock_window();
1656 lock_window("AWindowGUI::close_event");
1657 save_defaults(mwindow->defaults);
1658 mwindow->save_defaults();
1662 int AWindowGUI::start_vicon_drawing()
1664 if( play_off ) return stop_vicon_drawing();
1665 if( !vicon_thread->interrupted ) return 1;
1666 switch( vicon_drawing ) {
1667 case AVICON_FULL_PLAY: // all vicons, viewing, target
1669 case AVICON_MOUSE_OVER: // one vicon, viewing, target
1670 if( vicon_thread->solo ) break;
1672 case AVICON_SRC_TARGET: // no vicons, no view, target
1673 case AVICON_NO_PLAY: // no vicons, no view, no target
1676 if( mwindow->edl->session->awindow_folder == AW_MEDIA_FOLDER ||
1677 mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ||
1678 mwindow->edl->session->awindow_folder == AW_CLIP_FOLDER ||
1679 mwindow->edl->session->awindow_folder >= AWINDOW_USER_FOLDERS ) {
1680 switch( mwindow->edl->session->assetlist_format ) {
1682 case ASSETS_ICONS_PACKED:
1683 case ASSETS_ICON_LIST:
1684 asset_list->update_vicon_area();
1685 vicon_thread->start_drawing();
1694 int AWindowGUI::stop_vicon_drawing(int wait)
1696 vicon_thread->stop_vicon_drawing(wait);
1701 VFrame *AssetPicon::get_vicon_frame()
1703 if( !vicon ) return 0;
1704 if( gui->vicon_thread->interrupted ) return 0;
1705 VFrame *frame = vicon->frame();
1706 if( !frame ) return 0;
1708 vicon_frame = new VFrame(vicon->w, vicon->h, frame->get_color_model());
1709 vicon_frame->transfer_from(frame);
1713 int AWindowGUI::cycle_assetlist_format()
1715 EDLSession *session = mwindow->edl->session;
1716 int format = ASSETS_TEXT;
1717 if( allow_iconlisting ) {
1718 switch( session->assetlist_format ) {
1720 format = ASSETS_ICONS;
1723 format = ASSETS_ICONS_PACKED;
1725 case ASSETS_ICONS_PACKED:
1726 format = ASSETS_ICON_LIST;
1728 case ASSETS_ICON_LIST:
1729 format = ASSETS_TEXT;
1733 stop_vicon_drawing();
1734 session->assetlist_format = format;
1735 asset_list->update_format(session->assetlist_format, 0);
1736 async_update_assets();
1737 start_vicon_drawing();
1741 void AWindowGUI::hide_tip_info()
1743 asset_list->hide_tooltip();
1747 AWindowRemovePluginGUI::
1748 AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
1749 int x, int y, PluginServer *plugin)
1750 : BC_Window(_(PROGRAM_NAME ": Remove plugin"), x,y,
1751 xS(500),yS(200), xS(50), yS(50),
1754 this->awindow = awindow;
1755 this->thread = thread;
1756 this->plugin = plugin;
1757 VFrame *vframe = plugin->get_picon();
1758 icon = vframe ? create_pixmap(vframe) : 0;
1759 plugin_list.append(new BC_ListBoxItem(plugin->title, icon));
1762 AWindowRemovePluginGUI::
1763 ~AWindowRemovePluginGUI()
1765 if( !awindow->gui->protected_pixmap(icon) )
1767 plugin_list.remove_all();
1770 void AWindowRemovePluginGUI::create_objects()
1772 int xs10 = xS(10), xs20 = xS(20);
1773 int ys5 = yS(5), ys10 = yS(10);
1774 lock_window("AWindowRemovePluginGUI::create_objects");
1775 BC_Button *ok_button = new BC_OKButton(this);
1776 add_subwindow(ok_button);
1777 BC_Button *cancel_button = new BC_CancelButton(this);
1778 add_subwindow(cancel_button);
1779 int x = xs10, y = ys10;
1780 BC_Title *title = new BC_Title(x, y, _("remove plugin?"));
1781 add_subwindow(title);
1782 y += title->get_h() + ys5;
1783 list = new BC_ListBox(x, y,
1784 get_w() - xs20, ok_button->get_y() - y - ys5, LISTBOX_TEXT, &plugin_list,
1785 0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0);
1786 add_subwindow(list);
1791 int AWindowRemovePlugin::remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder)
1794 for( int i=0; i<folder.size(); ) {
1795 AssetPicon *picon = (AssetPicon *)folder[i];
1796 if( picon->plugin == plugin ) {
1797 folder.remove_object_number(i);
1806 void AWindowRemovePlugin::handle_close_event(int result)
1809 printf(_("remove %s\n"), plugin->path);
1810 awindow->gui->lock_window("AWindowRemovePlugin::handle_close_event");
1811 ArrayList<BC_ListBoxItem*> *folder =
1812 plugin->audio ? plugin->transition ?
1813 &awindow->gui->atransitions :
1814 &awindow->gui->aeffects :
1815 plugin->video ? plugin->transition ?
1816 &awindow->gui->vtransitions :
1817 &awindow->gui->veffects :
1819 if( folder ) remove_plugin(plugin, *folder);
1820 MWindow *mwindow = awindow->mwindow;
1821 awindow->gui->unlock_window();
1822 char plugin_path[BCTEXTLEN];
1823 strcpy(plugin_path, plugin->path);
1824 mwindow->plugindb->remove(plugin);
1825 remove(plugin_path);
1826 char index_path[BCTEXTLEN];
1827 mwindow->create_defaults_path(index_path, PLUGIN_FILE);
1829 char picon_path[BCTEXTLEN];
1831 snprintf(picon_path, sizeof(picon_path), "%s/picon",
1832 File::get_plugin_path());
1833 char png_name[BCSTRLEN], png_path[BCTEXTLEN];
1834 plugin->get_plugin_png_name(png_name);
1835 fs.update(picon_path);
1836 for( int i=0; i<fs.dir_list.total; ++i ) {
1837 char *fs_path = fs.dir_list[i]->path;
1838 if( !fs.is_dir(fs_path) ) continue;
1839 snprintf(png_path, sizeof(picon_path), "%s/%s",
1843 delete plugin; plugin = 0;
1844 awindow->gui->async_update_assets();
1848 AWindowRemovePlugin::
1849 AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin)
1852 this->awindow = awindow;
1853 this->plugin = plugin;
1856 AWindowRemovePlugin::
1857 ~AWindowRemovePlugin()
1862 BC_Window* AWindowRemovePlugin::new_gui()
1864 int x = awindow->gui->get_abs_cursor_x(0);
1865 int y = awindow->gui->get_abs_cursor_y(0);
1866 AWindowRemovePluginGUI *gui = new AWindowRemovePluginGUI(awindow, this, x, y, plugin);
1867 gui->create_objects();
1871 int AWindowGUI::keypress_event()
1873 switch( get_keypress() ) {
1881 tip_info = !tip_info ? 1 : 0;
1882 if( !tip_info ) hide_tip_info();
1885 if( !ctrl_down() && !shift_down() ) {
1886 assetlist_menu->load_file->handle_event();
1891 return cycle_assetlist_format();
1893 if( shift_down() && ctrl_down() ) {
1894 PluginServer* plugin = selected_plugin();
1895 if( !plugin ) break;
1896 remove_plugin = new AWindowRemovePlugin(awindow, plugin);
1898 remove_plugin->start();
1899 lock_window("AWindowGUI::keypress_event 1");
1903 if( shift_down() ) {
1904 mwindow->awindow->asset_remove->start();
1908 mwindow->remove_assets_from_project(1, 1, 1,
1909 mwindow->session->drag_assets,
1910 mwindow->session->drag_clips);
1911 lock_window("AWindowGUI::keypress_event 2");
1917 if( shift_down() && ctrl_down() ) {
1918 resend_event(mwindow->gui);
1928 int AWindowGUI::create_custom_xatoms()
1930 UpdateAssetsXAtom = create_xatom("CWINDOWGUI_UPDATE_ASSETS");
1933 int AWindowGUI::receive_custom_xatoms(xatom_event *event)
1935 if( event->message_type == UpdateAssetsXAtom ) {
1942 void AWindowGUI::async_update_assets()
1945 event.message_type = UpdateAssetsXAtom;
1946 send_custom_xatom(&event);
1950 void AWindowGUI::update_folder_list()
1952 for( int i = 0; i < folders.total; i++ ) {
1953 AssetPicon *picon = (AssetPicon*)folders.values[i];
1957 // Search assets for folders
1958 for( int i = 0; i < mwindow->edl->folders.total; i++ ) {
1959 BinFolder *bin_folder = mwindow->edl->folders[i];
1962 for( int j = 0; j < folders.total; j++ ) {
1963 AssetPicon *picon = (AssetPicon*)folders[j];
1964 if( !strcasecmp(picon->get_text(), bin_folder->title) ) {
1972 const char *title = bin_folder->title;
1973 int folder = bin_folder->awindow_folder;
1974 AssetPicon *picon = new AssetPicon(mwindow, this, folder, title);
1975 picon->create_objects();
1976 folders.append(picon);
1980 // Delete unused non-persistent folders
1981 int do_autoplace = 0;
1982 for( int i=folders.total; --i>=0; ) {
1983 AssetPicon *picon = (AssetPicon*)folders.values[i];
1984 if( !picon->in_use && !picon->persistent ) {
1986 folders.remove_number(i);
1991 folder_list->set_autoplacement(&folders, 0, 1);
1994 void AWindowGUI::create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
1995 int do_audio, int do_video, int is_realtime, int is_transition)
1997 ArrayList<PluginServer*> plugin_list;
1998 // Get pointers to plugindb entries
1999 mwindow->search_plugindb(do_audio, do_video, is_realtime, is_transition,
2002 for( int i = 0; i < plugin_list.total; i++ ) {
2003 PluginServer *server = plugin_list.values[i];
2004 int visible = plugin_visibility & (1<<server->dir_idx);
2005 if( !visible ) continue;
2006 // Create new listitem
2007 AssetPicon *picon = new AssetPicon(mwindow, this, server);
2008 picon->create_objects();
2009 output->append(picon);
2013 void AWindowGUI::create_label_folder()
2016 for( current = mwindow->edl->labels->first; current; current = NEXT ) {
2017 AssetPicon *picon = new AssetPicon(mwindow, this, current);
2018 picon->create_objects();
2019 labellist.append(picon);
2024 void AWindowGUI::update_asset_list()
2026 ArrayList<AssetPicon *> new_assets;
2027 for( int i = 0; i < assets.total; i++ ) {
2028 AssetPicon *picon = (AssetPicon*)assets.values[i];
2032 mwindow->gui->lock_window("AWindowGUI::update_asset_list");
2033 // Synchronize EDL clips
2034 for( int i=0; i<mwindow->edl->clips.size(); ++i ) {
2037 // Look for clip in existing listitems
2038 for( int j = 0; j < assets.total && !exists; j++ ) {
2039 AssetPicon *picon = (AssetPicon*)assets.values[j];
2041 if( picon->id == mwindow->edl->clips[i]->id ) {
2042 picon->edl = mwindow->edl->clips[i];
2043 picon->set_text(mwindow->edl->clips[i]->local_session->clip_title);
2049 // Create new listitem
2051 AssetPicon *picon = new AssetPicon(mwindow,
2052 this, mwindow->edl->clips[i]);
2053 new_assets.append(picon);
2057 // Synchronize EDL assets
2058 for( Asset *current=mwindow->edl->assets->first; current; current=NEXT ) {
2061 // Look for asset in existing listitems
2062 for( int j = 0; j < assets.total && !exists; j++ ) {
2063 AssetPicon *picon = (AssetPicon*)assets.values[j];
2065 if( picon->id == current->id ) {
2066 picon->indexable = current;
2072 // Create new listitem
2074 AssetPicon *picon = new AssetPicon(mwindow,
2076 new_assets.append(picon);
2077 if( current->width > ASSET_MAX_WIDTH || current->height > ASSET_MAX_HEIGHT ) {
2078 eprintf(_("Warning: %s\n"
2079 " dimensions %dx%d exceed asset maximum limits %dx%d\n"),
2080 current->path, current->width, current->height,
2081 ASSET_MAX_WIDTH, ASSET_MAX_HEIGHT);
2083 else if( mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
2084 int texture_limit = BC_DisplayInfo::get_gl_max_texture_size();
2085 if( texture_limit >= 0 &&
2086 (current->width >= texture_limit || current->height >= texture_limit) ) {
2087 eprintf(_("Warning: %s\n"
2088 " dimensions %dx%d exceed OpenGL texture limit %d\n"),
2089 current->path, current->width, current->height, texture_limit);
2095 // Synchronize nested EDLs
2096 for( int i=0; i<mwindow->edl->nested_edls.size(); ++i ) {
2098 EDL *nested_edl = mwindow->edl->nested_edls[i];
2100 // Look for asset in existing listitems
2101 for( int j=0; j<assets.total && !exists; ++j ) {
2102 AssetPicon *picon = (AssetPicon*)assets.values[j];
2104 if( picon->id == nested_edl->id ) {
2105 picon->indexable = nested_edl;
2111 // Create new listitem
2113 AssetPicon *picon = new AssetPicon(mwindow,
2114 this, (Indexable*)nested_edl);
2115 new_assets.append(picon);
2118 mwindow->gui->unlock_window();
2120 for( int i=0; i<new_assets.size(); ++i ) {
2121 AssetPicon *picon = new_assets[i];
2122 picon->create_objects();
2123 if( picon->indexable )
2124 picon->foldernum = AW_MEDIA_FOLDER;
2125 else if( picon->edl )
2126 picon->foldernum = AW_CLIP_FOLDER;
2127 assets.append(picon);
2130 mwindow->gui->lock_window();
2131 mwindow->gui->default_message();
2132 mwindow->gui->unlock_window();
2134 for( int i = assets.size() - 1; i >= 0; i-- ) {
2135 AssetPicon *picon = (AssetPicon*)assets.get(i);
2136 if( !picon->in_use ) {
2138 assets.remove_number(i);
2141 if( picon->indexable && picon->indexable->is_asset ) {
2142 Asset *asset = (Asset *)picon->indexable;
2144 picon->comments_time = !stat(asset->path, &st) ? st.st_mtime : 0;
2145 picon->comments_rate = asset->get_frame_rate();
2146 picon->comments_ffmt = asset->format == FILE_FFMPEG ? '=' : '-';
2147 picon->comments_type = asset->format == FILE_FFMPEG ?
2148 asset->vcodec : File::formattostr(asset->format);
2153 void AWindowGUI::update_picon(Indexable *indexable)
2156 for( int i = 0; i < assets.total; i++ ) {
2157 AssetPicon *picon = (AssetPicon*)assets.values[i];
2158 if( picon->indexable == indexable ||
2159 picon->edl == (EDL *)indexable ) {
2160 char name[BCTEXTLEN];
2162 fs.extract_name(name, indexable->path);
2163 picon->set_text(name);
2164 vicon = picon->vicon;
2169 stop_vicon_drawing();
2170 vicon->clear_images();
2171 vicon->reset(indexable->get_frame_rate());
2172 start_vicon_drawing();
2176 void AWindowGUI::sort_assets()
2178 folder_lock->lock("AWindowGUI::sort_assets");
2179 switch( mwindow->edl->session->awindow_folder ) {
2180 case AW_AEFFECT_FOLDER:
2181 sort_picons(&aeffects);
2183 case AW_VEFFECT_FOLDER:
2184 sort_picons(&veffects);
2186 case AW_ATRANSITION_FOLDER:
2187 sort_picons(&atransitions);
2189 case AW_VTRANSITION_FOLDER:
2190 sort_picons(&vtransitions);
2192 case AW_LABEL_FOLDER:
2193 sort_picons(&labellist);
2196 sort_picons(&assets);
2200 asset_list->update_format(asset_list->get_format(), 0);
2201 folder_lock->unlock();
2205 void AWindowGUI::sort_folders()
2207 folder_lock->lock("AWindowGUI::update_assets");
2208 // folder_list->collapse_recursive(&folders, 0);
2209 folder_list->set_autoplacement(&folders, 0, 1);
2210 sort_picons(&folders);
2211 folder_list->update_format(folder_list->get_format(), 0);
2212 folder_lock->unlock();
2216 EDL *AWindowGUI::collect_proxy(Asset *proxy_asset)
2218 char path[BCTEXTLEN];
2219 int proxy_scale = mwindow->edl->session->proxy_scale;
2220 ProxyRender::from_proxy_path(path, proxy_asset, proxy_scale);
2221 Indexable *unproxy_idxbl =
2222 proxy_asset->proxy_edl ?
2223 (Indexable *) mwindow->edl->get_nested_edl(path) :
2224 (Indexable *) mwindow->edl->assets->get_asset(path);
2225 if( !unproxy_idxbl || !unproxy_idxbl->get_video_layers() ) return 0;
2226 // make a clip from proxy video tracks and unproxy audio tracks
2227 EDL *proxy_edl = new EDL(mwindow->edl);
2228 proxy_edl->create_objects();
2229 proxy_edl->set_path(proxy_asset->path);
2230 FileSystem fs; fs.extract_name(path, proxy_asset->path);
2231 strcpy(proxy_edl->local_session->clip_title, path);
2232 strcpy(proxy_edl->local_session->clip_notes, _("Proxy clip"));
2233 proxy_edl->session->video_tracks = proxy_asset->layers;
2234 proxy_edl->session->audio_tracks = unproxy_idxbl->get_audio_channels();
2235 proxy_edl->create_default_tracks();
2236 double length = proxy_asset->frame_rate > 0 ?
2237 ( proxy_asset->video_length >= 0 ?
2238 ( proxy_asset->video_length / proxy_asset->frame_rate ) :
2239 ( proxy_edl->session->si_useduration ?
2240 proxy_edl->session->si_duration :
2241 1.0 / proxy_asset->frame_rate ) ) :
2242 1.0 / proxy_edl->session->frame_rate;
2243 Track *current = proxy_edl->tracks->first;
2244 for( int vtrack=0; current; current=NEXT ) {
2245 if( current->data_type != TRACK_VIDEO ) continue;
2246 current->insert_asset(proxy_asset, 0, length, 0, vtrack++);
2248 int64_t samples = unproxy_idxbl->get_audio_samples();
2249 int sample_rate = unproxy_idxbl->get_sample_rate();
2250 length = sample_rate > 0 ? (double)samples / sample_rate : 0;
2251 current = proxy_edl->tracks->first;
2252 for( int atrack=0; current; current=NEXT ) {
2253 if( current->data_type != TRACK_AUDIO ) continue;
2254 Asset *asset = unproxy_idxbl->is_asset ? (Asset *)unproxy_idxbl : 0;
2255 EDL *nested_edl = unproxy_idxbl->is_asset ? 0 : (EDL *)unproxy_idxbl;
2256 current->insert_asset(asset, nested_edl, length, 0, atrack++);
2258 proxy_edl->folder_no = AW_PROXY_FOLDER;
2263 void AWindowGUI::collect_assets(int proxy)
2265 mwindow->session->drag_assets->remove_all();
2266 mwindow->session->drag_clips->remove_all();
2267 int i = 0; AssetPicon *result;
2268 while( (result = (AssetPicon*)asset_list->get_selection(0, i++)) != 0 ) {
2269 Indexable *indexable = result->indexable;
2270 if( proxy && indexable && indexable->is_asset &&
2271 indexable->folder_no == AW_PROXY_FOLDER ) {
2272 EDL *drag_edl = collect_proxy((Asset*)indexable);
2273 if( drag_edl ) mwindow->session->drag_clips->append(drag_edl);
2277 mwindow->session->drag_assets->append(indexable);
2281 mwindow->session->drag_clips->append(result->edl);
2287 void AWindowGUI::copy_picons(AssetPicon *picon, ArrayList<BC_ListBoxItem*> *src)
2289 // Remove current pointers
2290 ArrayList<BC_ListBoxItem*> *dst = displayed_assets;
2291 dst[0].remove_all();
2292 dst[1].remove_all_objects();
2294 AWindowFolderSubItems *sub_items = picon ? picon->sub_items : 0;
2295 int folder = mwindow->edl->session->awindow_folder;
2296 BinFolder *bin_folder = folder < AWINDOW_USER_FOLDERS ? 0 :
2297 mwindow->edl->get_folder(folder);
2299 // Create new pointers
2300 for( int i = 0; i < src->total; i++ ) {
2301 int visible = folder >= AW_CLIP_FOLDER ? 0 : 1;
2302 picon = (AssetPicon*)src->values[i];
2303 picon->sort_key = -1;
2304 if( !visible && bin_folder ) {
2305 Indexable *idxbl = bin_folder->is_clips ? (Indexable *)picon->edl :
2306 picon->indexable ? picon->indexable :
2307 picon->edl ? picon->edl->get_proxy_asset() : 0;
2309 picon->sort_key = mwindow->edl->folders.matches_indexable(folder, idxbl);
2310 if( picon->sort_key < 0 ) continue;
2314 if( !visible && picon->indexable && picon->indexable->folder_no == folder )
2316 if( !visible && picon->edl && picon->edl->folder_no == folder )
2318 if( visible && sub_items ) {
2319 if( !sub_items->matches(picon->get_text()) )
2323 const char *text = search_text->get_text();
2324 if( text && text[0] )
2325 visible = bstrcasestr(picon->get_text(), text) ? 1 : 0;
2327 if( visible && picon->vicon && picon->vicon->hidden )
2328 picon->vicon->hidden = 0;
2330 BC_ListBoxItem *item2, *item1;
2331 dst[0].append(item1 = picon);
2333 dst[1].append(item2 = new BC_ListBoxItem(picon->edl->local_session->clip_notes));
2336 dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr));
2337 else if( picon->comments_time ) {
2338 char date_time[BCSTRLEN];
2339 struct tm stm; localtime_r(&picon->comments_time, &stm);
2340 sprintf(date_time,"%04d.%02d.%02d %02d:%02d:%02d @%0.2f %c%s",
2341 stm.tm_year+1900, stm.tm_mon+1, stm.tm_mday,
2342 stm.tm_hour, stm.tm_min, stm.tm_sec,
2343 picon->comments_rate, picon->comments_ffmt,
2344 picon->comments_type);
2345 dst[1].append(item2 = new BC_ListBoxItem(date_time));
2348 dst[1].append(item2 = new BC_ListBoxItem(""));
2349 item1->set_autoplace_text(1); item1->set_autoplace_icon(1);
2350 item2->set_autoplace_text(1); item2->set_autoplace_icon(1);
2355 void AWindowGUI::sort_picons(ArrayList<BC_ListBoxItem*> *src)
2357 int done = 0, changed = 0;
2360 for( int i=0; i<src->total-1; ++i ) {
2361 AssetPicon *item1 = (AssetPicon *)src->values[i];
2362 AssetPicon *item2 = (AssetPicon *)src->values[i + 1];
2363 double v = item2->sort_key - item1->sort_key;
2364 if( v > 0 ) continue;
2366 const char *cp1 = item1->get_text();
2367 const char *bp1 = strrchr(cp1, '/');
2368 if( bp1 ) cp1 = bp1 + 1;
2369 const char *cp2 = item2->get_text();
2370 const char *bp2 = strrchr(cp2, '/');
2371 if( bp2 ) cp2 = bp2 + 1;
2372 if( strcmp(cp2, cp1) >= 0 ) continue;
2374 src->values[i + 1] = item1;
2375 src->values[i] = item2;
2376 done = 0; changed = 1;
2380 for( int i=0; i<src->total; ++i ) {
2381 AssetPicon *item = (AssetPicon *)src->values[i];
2382 item->set_autoplace_icon(1);
2383 item->set_autoplace_text(1);
2388 void AWindowGUI::filter_displayed_assets()
2390 //allow_iconlisting = 1;
2391 asset_titles[0] = C_("Title");
2392 asset_titles[1] = _("Comments");
2393 AssetPicon *picon = 0;
2394 int selected_folder = mwindow->edl->session->awindow_folder;
2395 // Ensure the current folder icon is highlighted
2396 for( int i = 0; i < folders.total; i++ ) {
2397 AssetPicon *folder_item = (AssetPicon *)folders.values[i];
2398 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
2399 folder_item->set_selected(selected);
2400 if( selected ) picon = folder_item;
2403 ArrayList<BC_ListBoxItem*> *src = &assets;
2404 switch( selected_folder ) {
2405 case AW_AEFFECT_FOLDER: src = &aeffects; break;
2406 case AW_VEFFECT_FOLDER: src = &veffects; break;
2407 case AW_ATRANSITION_FOLDER: src = &atransitions; break;
2408 case AW_VTRANSITION_FOLDER: src = &vtransitions; break;
2409 case AW_LABEL_FOLDER: src = &labellist;
2410 asset_titles[0] = _("Time Stamps");
2411 asset_titles[1] = C_("Title");
2412 //allow_iconlisting = 0;
2415 copy_picons(picon, src);
2419 void AWindowGUI::update_assets()
2421 stop_vicon_drawing();
2422 folder_lock->lock("AWindowGUI::update_assets");
2423 update_folder_list();
2424 update_asset_list();
2425 labellist.remove_all_objects();
2426 create_label_folder();
2428 if( displayed_folder != mwindow->edl->session->awindow_folder )
2429 search_text->clear();
2430 vicon_thread->hide_vicons();
2431 filter_displayed_assets();
2432 folder_lock->unlock();
2434 if( mwindow->edl->session->folderlist_format != folder_list->get_format() ) {
2435 folder_list->update_format(mwindow->edl->session->folderlist_format, 0);
2437 int folder_xposition = folder_list->get_xposition();
2438 int folder_yposition = folder_list->get_yposition();
2439 folder_list->update(&folders, 0, 0, 1, folder_xposition, folder_yposition, -1);
2441 if( mwindow->edl->session->assetlist_format != asset_list->get_format() ) {
2442 asset_list->update_format(mwindow->edl->session->assetlist_format, 0);
2444 int asset_xposition = asset_list->get_xposition();
2445 int asset_yposition = asset_list->get_yposition();
2446 if( displayed_folder != mwindow->edl->session->awindow_folder ) {
2447 displayed_folder = mwindow->edl->session->awindow_folder;
2448 asset_xposition = asset_yposition = 0;
2450 asset_list->update(displayed_assets, asset_titles,
2451 mwindow->edl->session->asset_columns, ASSET_COLUMNS,
2452 asset_xposition, asset_yposition, -1, 0);
2453 asset_list->center_selection();
2456 start_vicon_drawing();
2460 void AWindowGUI::update_effects()
2462 aeffects.remove_all_objects();
2463 create_persistent_folder(&aeffects, 1, 0, 1, 0);
2464 veffects.remove_all_objects();
2465 create_persistent_folder(&veffects, 0, 1, 1, 0);
2466 atransitions.remove_all_objects();
2467 create_persistent_folder(&atransitions, 1, 0, 0, 1);
2468 vtransitions.remove_all_objects();
2469 create_persistent_folder(&vtransitions, 0, 1, 0, 1);
2472 int AWindowGUI::drag_motion()
2474 if( get_hidden() ) return 0;
2480 int AWindowGUI::drag_stop()
2482 if( get_hidden() ) return 0;
2486 Indexable* AWindowGUI::selected_asset()
2488 AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
2489 return picon ? picon->indexable : 0;
2492 PluginServer* AWindowGUI::selected_plugin()
2494 AssetPicon *picon = (AssetPicon*)asset_list->get_selection(0, 0);
2495 return picon ? picon->plugin : 0;
2498 AssetPicon* AWindowGUI::selected_folder()
2500 AssetPicon *picon = (AssetPicon*)folder_list->get_selection(0, 0);
2511 AWindowDivider::AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
2512 : BC_SubWindow(x, y, w, h)
2514 this->mwindow = mwindow;
2517 AWindowDivider::~AWindowDivider()
2521 int AWindowDivider::button_press_event()
2523 if( is_event_win() && cursor_inside() ) {
2524 mwindow->session->current_operation = DRAG_PARTITION;
2530 int AWindowDivider::cursor_motion_event()
2532 if( mwindow->session->current_operation == DRAG_PARTITION ) {
2534 int wmax = mwindow->session->awindow_w - mwindow->theme->adivider_w - wmin;
2535 int fw = gui->get_relative_cursor_x();
2536 if( fw > wmax ) fw = wmax;
2537 if( fw < wmin ) fw = wmin;
2538 mwindow->session->afolders_w = fw;
2539 mwindow->theme->get_awindow_sizes(gui);
2540 gui->reposition_objects();
2546 int AWindowDivider::button_release_event()
2548 if( mwindow->session->current_operation == DRAG_PARTITION ) {
2549 mwindow->session->current_operation = NO_OPERATION;
2560 AWindowFolders::AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
2561 : BC_ListBox(x, y, w, h,
2562 mwindow->edl->session->folderlist_format == FOLDERS_ICONS ?
2563 LISTBOX_ICONS : LISTBOX_TEXT,
2564 &gui->folders, // Each column has an ArrayList of BC_ListBoxItems.
2565 0, // Titles for columns. Set to 0 for no titles
2566 0, // width of each column
2567 1, // Total columns.
2568 0, // Pixel of top of window.
2569 0, // If this listbox is a popup window
2570 LISTBOX_SINGLE, // Select one item or multiple items
2571 ICON_TOP, // Position of icon relative to text of each item
2574 this->mwindow = mwindow;
2581 AWindowFolders::~AWindowFolders()
2585 int AWindowFolders::selection_changed()
2587 AWindowFolderItem *item0 = (AWindowFolderItem*)get_selection(0, 0);
2588 AWindowFolderItem *item1 = (AWindowFolderItem*)get_selection(0, 1);
2589 // prefer expanded entry
2590 AWindowFolderItem *item = item1 ? item1 : item0;
2591 if( item0 && item1 && last_item0 == item0 && last_item1 == item1 ) {
2592 item1->set_selected(0);
2599 AssetPicon *picon = item->get_picon();
2600 picon->sub_items = (AWindowFolderSubItems*)(!item->parent ? 0 : item);
2602 gui->stop_vicon_drawing();
2604 if( get_button_down() && get_buttonpress() == RIGHT_BUTTON ) {
2605 gui->folderlist_menu->update_titles();
2606 gui->folderlist_menu->activate_menu();
2609 mwindow->edl->session->awindow_folder = picon->foldernum;
2610 gui->asset_list->draw_background();
2611 gui->async_update_assets();
2613 gui->start_vicon_drawing();
2618 int AWindowFolders::button_press_event()
2620 gui->hide_tip_info();
2621 int result = BC_ListBox::button_press_event();
2624 if( get_buttonpress() == RIGHT_BUTTON &&
2625 is_event_win() && cursor_inside() ) {
2626 gui->folderlist_menu->update_titles();
2627 gui->folderlist_menu->activate_menu();
2635 int AWindowFolders::drag_stop()
2638 if( get_hidden() ) return 0;
2639 if( mwindow->session->current_operation == DRAG_ASSET &&
2640 gui->folder_list->cursor_above() ) { // check user folder
2641 int item_no = gui->folder_list->get_cursor_data_item_no();
2642 AssetPicon *picon = (AssetPicon *)(item_no < 0 ? 0 : gui->folders[item_no]);
2643 if( picon && picon->foldernum >= AWINDOW_USER_FOLDERS ) {
2644 BinFolder *folder = mwindow->edl->get_folder(picon->foldernum);
2645 ArrayList<Indexable *> *drags = folder->is_clips ?
2646 ((ArrayList<Indexable *> *)mwindow->session->drag_clips) :
2647 ((ArrayList<Indexable *> *)mwindow->session->drag_assets);
2648 if( folder && drags && !folder->add_patterns(drags, shift_down()) )
2650 mwindow->session->current_operation = ::NO_OPERATION;
2657 AWindowFolderSubItems::AWindowFolderSubItems(AWindowFolderItem *parent, const char *text)
2658 : AWindowFolderItem(text)
2660 this->parent = parent;
2663 int AWindowFolders::load_expanders()
2665 char expanders_path[BCTEXTLEN];
2666 mwindow->create_defaults_path(expanders_path, EXPANDERS_FILE);
2667 FILE *fp = fopen(expanders_path, "r");
2669 snprintf(expanders_path, sizeof(expanders_path), "%s/%s",
2670 File::get_cindat_path(), EXPANDERS_FILE);
2671 char *cp = strrchr(expanders_path,'.');
2672 if( cp ) strcpy(cp+1, mwindow->cin_lang);
2673 fp = fopen(expanders_path, "r");
2676 snprintf(expanders_path, sizeof(expanders_path), "%s/%s",
2677 File::get_cindat_path(), EXPANDERS_FILE);
2678 fp = fopen(expanders_path, "r");
2681 const char tab = '\t';
2682 char line[BCTEXTLEN]; line[0] = 0;
2683 AWindowFolderItem *item = 0, *parent;
2684 AWindowFolderSubItems *sub_items = 0;
2686 while( fgets(line,sizeof(line),fp) ) {
2687 if( line[0] == '#' ) continue;
2688 int i = strlen(line);
2689 if( i > 0 && line[i-1] == '\n' ) line[--i] = 0;
2690 if( i == 0 ) continue;
2692 for( char *cp=line; *cp==tab; ++cp ) ++i;
2694 int i = gui->folders.size();
2696 AssetPicon *folder = (AssetPicon *)gui->folders[i];
2697 if( !strcmp(folder->get_text(),_(line)) ) break;
2699 item = (AWindowFolderItem*)(i >= 0 ? gui->folders[i] : 0);
2704 if( i > k+1 ) continue;
2706 if( line[i] != '-' && sub_items ) {
2707 sub_items->names.append(cstrdup(_(&line[i])));
2715 item = item->parent;
2718 parent = item->parent;
2720 ArrayList<BC_ListBoxItem*> *sublist = parent->get_sublist();
2721 if( !sublist ) sublist = parent->new_sublist(1);
2722 sub_items = new AWindowFolderSubItems(parent, &line[i]);
2723 sublist->append(item = sub_items);
2730 AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h)
2731 : BC_ListBox(x, y, w, h, !gui->allow_iconlisting ? LISTBOX_TEXT :
2732 mwindow->edl->session->assetlist_format == ASSETS_ICONS ? LISTBOX_ICONS :
2733 mwindow->edl->session->assetlist_format == ASSETS_ICONS_PACKED ? LISTBOX_ICONS_PACKED :
2734 mwindow->edl->session->assetlist_format == ASSETS_ICON_LIST ? LISTBOX_ICON_LIST :
2736 &gui->assets, // Each column has an ArrayList of BC_ListBoxItems.
2737 gui->asset_titles,// Titles for columns. Set to 0 for no titles
2738 mwindow->edl->session->asset_columns, // width of each column
2739 1, // Total columns.
2740 0, // Pixel of top of window.
2741 0, // If this listbox is a popup window
2742 LISTBOX_MULTIPLE, // Select one item or multiple items
2743 ICON_TOP, // Position of icon relative to text of each item
2744 -1) // Allow drags, require shift for scrolling
2746 this->mwindow = mwindow;
2748 this->info_tip = -1;
2750 set_scroll_stretch(1, 1);
2753 AWindowAssets::~AWindowAssets()
2757 int AWindowAssets::button_press_event()
2760 AssetVIconThread *avt = gui->vicon_thread;
2761 if( avt->draw_mode != ASSET_VIEW_NONE && is_event_win() ) {
2762 int dir = 1, button = get_buttonpress();
2764 case WHEEL_DOWN: dir = -1; // fall thru
2766 int x = get_cursor_x(), y = get_cursor_y();
2767 if( avt->cursor_inside(x, y) && avt->view_win )
2768 avt->zoom_scale(dir);
2773 int result = BC_ListBox::button_press_event();
2775 if( !result && get_buttonpress() == RIGHT_BUTTON &&
2776 is_event_win() && cursor_inside() ) {
2777 BC_ListBox::deactivate_selection();
2778 int folder = mwindow->edl->session->awindow_folder;
2780 case AW_AEFFECT_FOLDER:
2781 case AW_VEFFECT_FOLDER:
2782 case AW_ATRANSITION_FOLDER:
2783 case AW_VTRANSITION_FOLDER:
2784 gui->effectlist_menu->update();
2785 gui->effectlist_menu->activate_menu();
2787 case AW_LABEL_FOLDER:
2788 gui->labellist_menu->update();
2789 gui->labellist_menu->activate_menu();
2791 case AW_CLIP_FOLDER:
2792 gui->cliplist_menu->update();
2793 gui->cliplist_menu->activate_menu();
2795 case AW_PROXY_FOLDER:
2796 gui->proxylist_menu->update();
2797 gui->proxylist_menu->activate_menu();
2800 case AW_MEDIA_FOLDER: {
2801 int shots = folder==AW_MEDIA_FOLDER || folder>=AWINDOW_USER_FOLDERS;
2802 gui->assetlist_menu->update_titles(shots);
2803 gui->assetlist_menu->activate_menu();
2813 int AWindowAssets::handle_event()
2815 AssetPicon *asset_picon = (AssetPicon *)get_selection(0, 0);
2816 if( !asset_picon ) return 0;
2817 Indexable *picon_idxbl = asset_picon->indexable;
2818 EDL *picon_edl = asset_picon->edl;
2820 VWindow *vwindow = 0;
2821 switch( mwindow->edl->session->awindow_folder ) {
2822 case AW_AEFFECT_FOLDER:
2823 case AW_VEFFECT_FOLDER:
2824 case AW_ATRANSITION_FOLDER:
2825 case AW_VTRANSITION_FOLDER: return 1;
2826 case AW_PROXY_FOLDER:
2827 proxy = 1; // fall thru
2829 if( mwindow->vwindows.size() > DEFAULT_VWINDOW )
2830 vwindow = mwindow->vwindows.get(DEFAULT_VWINDOW);
2833 if( !vwindow || !vwindow->is_running() ) return 1;
2834 if( proxy && picon_idxbl && picon_idxbl->is_asset ) {
2835 picon_edl = gui->collect_proxy((Asset*)picon_idxbl);
2839 if( picon_idxbl ) vwindow->change_source(picon_idxbl);
2840 else if( picon_edl ) vwindow->change_source(picon_edl);
2844 int AWindowAssets::selection_changed()
2846 // Show popup window
2848 int folder = mwindow->edl->session->awindow_folder;
2849 if( get_button_down() && get_buttonpress() == RIGHT_BUTTON &&
2850 (item = (AssetPicon*)get_selection(0, 0)) ) {
2852 case AW_AEFFECT_FOLDER:
2853 case AW_VEFFECT_FOLDER:
2854 case AW_ATRANSITION_FOLDER:
2855 case AW_VTRANSITION_FOLDER:
2856 gui->effectlist_menu->update();
2857 gui->effectlist_menu->activate_menu();
2859 case AW_LABEL_FOLDER:
2860 if( !item->label ) break;
2861 gui->label_menu->activate_menu();
2863 case AW_CLIP_FOLDER:
2864 if( !item->indexable && !item->edl ) break;
2865 gui->clip_menu->update();
2866 gui->clip_menu->activate_menu();
2868 case AW_PROXY_FOLDER:
2869 if( !item->indexable && !item->edl ) break;
2870 gui->proxy_menu->update();
2871 gui->proxy_menu->activate_menu();
2874 if( !item->indexable && !item->edl ) break;
2875 gui->asset_menu->update();
2876 gui->asset_menu->activate_menu();
2880 deactivate_selection();
2882 else if( get_button_down() && !gui->play_off &&
2883 mwindow->edl->session->assetlist_format != ASSETS_TEXT ) {
2884 item = (AssetPicon*)get_selection(0, 0);
2885 if( item && !get_selection(0, 1) ) {
2887 case AW_MEDIA_FOLDER:
2888 case AW_PROXY_FOLDER:
2889 case AWINDOW_USER_FOLDERS:
2890 if( get_buttonpress() == LEFT_BUTTON ||
2891 get_buttonpress() == MIDDLE_BUTTON ) {
2892 AssetVIcon *vicon = 0;
2893 AssetVIconThread *avt = gui->vicon_thread;
2894 if( !avt->vicon && gui->vicon_drawing != AVICON_NO_PLAY )
2895 vicon = item->vicon;
2896 int draw_mode = !vicon ?
2898 get_buttonpress() == MIDDLE_BUTTON ?
2899 ASSET_VIEW_MEDIA_MAP : ASSET_VIEW_MEDIA;
2900 avt->set_view_popup(vicon, draw_mode);
2903 case AW_CLIP_FOLDER:
2904 if( get_buttonpress() == LEFT_BUTTON ) {
2905 AssetVIcon *vicon = 0;
2906 AssetVIconThread *avt = gui->vicon_thread;
2907 if( !avt->vicon && gui->vicon_drawing != AVICON_NO_PLAY )
2908 vicon = item->vicon;
2909 gui->vicon_thread->set_view_popup(vicon, ASSET_VIEW_ICON);
2915 gui->vicon_thread->set_view_popup(0);
2916 if( gui->vicon_drawing != AVICON_FULL_PLAY )
2917 gui->stop_vicon_drawing();
2923 void AWindowAssets::draw_background()
2925 clear_box(0,0,get_w(),get_h(),get_bg_surface());
2926 set_color(BC_WindowBase::get_resources()->audiovideo_color);
2927 set_font(LARGEFONT);
2928 int folder = mwindow->edl->session->awindow_folder;
2929 const char *title = mwindow->edl->get_folder_name(folder);
2930 draw_text(get_w() - get_text_width(LARGEFONT, title) - xS(4), yS(30),
2931 title, -1, get_bg_surface());
2934 int AWindowAssets::drag_start_event()
2936 gui->vicon_thread->set_view_popup(0);
2937 int collect_pluginservers = 0;
2938 int collect_assets = 0, proxy = 0;
2940 if( BC_ListBox::drag_start_event() ) {
2941 switch( mwindow->edl->session->awindow_folder ) {
2942 case AW_AEFFECT_FOLDER:
2943 mwindow->session->current_operation = DRAG_AEFFECT;
2944 collect_pluginservers = 1;
2946 case AW_VEFFECT_FOLDER:
2947 mwindow->session->current_operation = DRAG_VEFFECT;
2948 collect_pluginservers = 1;
2950 case AW_ATRANSITION_FOLDER:
2951 mwindow->session->current_operation = DRAG_ATRANSITION;
2952 collect_pluginservers = 1;
2954 case AW_VTRANSITION_FOLDER:
2955 mwindow->session->current_operation = DRAG_VTRANSITION;
2956 collect_pluginservers = 1;
2958 case AW_LABEL_FOLDER:
2961 case AW_PROXY_FOLDER:
2962 proxy = 1; // fall thru
2963 case AW_MEDIA_FOLDER:
2965 mwindow->session->current_operation = DRAG_ASSET;
2970 if( collect_pluginservers ) {
2972 mwindow->session->drag_pluginservers->remove_all();
2975 AssetPicon *result = (AssetPicon*)get_selection(0, i++);
2976 if( !result ) break;
2978 mwindow->session->drag_pluginservers->append(result->plugin);
2982 if( collect_assets ) {
2983 gui->collect_assets(proxy);
2991 int AWindowAssets::drag_motion_event()
2993 BC_ListBox::drag_motion_event();
2996 mwindow->gui->lock_window("AWindowAssets::drag_motion_event");
2997 mwindow->gui->drag_motion();
2998 mwindow->gui->unlock_window();
3000 for( int i = 0; i < mwindow->vwindows.size(); i++ ) {
3001 VWindow *vwindow = mwindow->vwindows.get(i);
3002 if( !vwindow->is_running() ) continue;
3003 vwindow->gui->lock_window("AWindowAssets::drag_motion_event");
3004 vwindow->gui->drag_motion();
3005 vwindow->gui->unlock_window();
3008 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_motion_event");
3009 mwindow->cwindow->gui->drag_motion();
3010 mwindow->cwindow->gui->unlock_window();
3012 lock_window("AWindowAssets::drag_motion_event");
3013 if( mwindow->session->current_operation == DRAG_ASSET &&
3014 gui->folder_list->cursor_above() ) { // highlight user folder
3015 BC_ListBoxItem *item = 0;
3016 int item_no = gui->folder_list->get_cursor_data_item_no(&item);
3017 if( item_no >= 0 ) {
3018 AssetPicon *folder = (AssetPicon *)gui->folders[item_no];
3019 if( folder->foldernum < AWINDOW_USER_FOLDERS ) item_no = -1;
3022 item_no = gui->folder_list->item_to_index(&gui->folders, item);
3023 int folder_xposition = gui->folder_list->get_xposition();
3024 int folder_yposition = gui->folder_list->get_yposition();
3025 gui->folder_list->update(&gui->folders, 0, 0, 1,
3026 folder_xposition, folder_yposition, item_no, 0, 1);
3031 int AWindowAssets::drag_stop_event()
3035 result = gui->drag_stop();
3040 mwindow->gui->lock_window("AWindowAssets::drag_stop_event");
3041 result = mwindow->gui->drag_stop();
3042 mwindow->gui->unlock_window();
3046 for( int i = 0; !result && i < mwindow->vwindows.size(); i++ ) {
3047 VWindow *vwindow = mwindow->vwindows.get(i);
3048 if( !vwindow ) continue;
3049 if( !vwindow->is_running() ) continue;
3050 if( vwindow->gui->is_hidden() ) continue;
3051 vwindow->gui->lock_window("AWindowAssets::drag_stop_event");
3052 if( vwindow->gui->cursor_above() &&
3053 vwindow->gui->get_cursor_over_window() ) {
3054 result = vwindow->gui->drag_stop();
3056 vwindow->gui->unlock_window();
3061 mwindow->cwindow->gui->lock_window("AWindowAssets::drag_stop_event");
3062 result = mwindow->cwindow->gui->drag_stop();
3063 mwindow->cwindow->gui->unlock_window();
3066 lock_window("AWindowAssets::drag_stop_event");
3068 result = gui->folder_list->drag_stop();
3073 get_drag_popup()->set_animation(0);
3075 BC_ListBox::drag_stop_event();
3076 // since NO_OPERATION is also defined in listbox, we have to reach for global scope...
3077 mwindow->session->current_operation = ::NO_OPERATION;
3082 int AWindowAssets::column_resize_event()
3084 mwindow->edl->session->asset_columns[0] = get_column_width(0);
3085 mwindow->edl->session->asset_columns[1] = get_column_width(1);
3089 int AWindowAssets::cursor_enter_event()
3091 int ret = BC_ListBox::cursor_enter_event();
3092 switch( gui->vicon_drawing ) {
3093 case AVICON_FULL_PLAY:
3094 gui->start_vicon_drawing();
3096 case AVICON_MOUSE_OVER:
3097 case AVICON_SRC_TARGET:
3098 case AVICON_NO_PLAY:
3105 int AWindowAssets::cursor_leave_event()
3108 if( !is_event_win() ) return 0;
3109 if( !gui->vicon_thread->viewing )
3110 gui->stop_vicon_drawing();
3111 return BC_ListBox::cursor_leave_event();
3114 int AWindowAssets::focus_out_event()
3116 gui->stop_vicon_drawing();
3117 gui->vicon_thread->set_view_popup(0);
3118 return BC_ListBox::focus_out_event();
3121 void AWindowAssets::update_vicon_area()
3123 int x0 = 0, x1 = get_w();
3124 int y0 = get_title_h();
3126 if( is_highlighted() ) {
3127 x0 += LISTBOX_BORDER; x1 -= LISTBOX_BORDER;
3128 y0 += LISTBOX_BORDER; y1 -= LISTBOX_BORDER;
3130 gui->vicon_thread->set_drawing_area(x0,y0, x1,y1);
3133 int AWindowAssets::mouse_over_event(int no)
3135 AssetPicon *picon = no >= 0 && no < gui->displayed_assets[0].size() ?
3136 (AssetPicon *)gui->displayed_assets[0][no] : 0;
3137 AssetVIcon *vicon = !picon ? 0 : picon->vicon;
3138 switch( gui->vicon_drawing ) {
3139 case AVICON_FULL_PLAY:
3140 gui->vicon_thread->solo = 0;
3141 if( vicon && gui->vicon_thread->viewing )
3142 gui->vicon_thread->set_view_popup(vicon);
3144 case AVICON_MOUSE_OVER:
3146 gui->vicon_thread->solo = vicon;
3147 gui->start_vicon_drawing();
3149 case AVICON_SRC_TARGET:
3151 if( gui->vicon_thread->viewing )
3152 gui->vicon_thread->set_view_popup(vicon);
3154 case AVICON_NO_PLAY:
3158 if( no < 0 && info_tip >= 0 ) {
3161 if( gui->tip_info && no >= 0 &&
3162 info_tip != no && picon && picon->plugin ) {
3163 const char *info = picon->plugin->tip;
3164 if( !info ) info = _("No info available");
3165 show_tip_info(info, no);
3170 void AWindowAssets::show_tip_info(const char *info, int no)
3172 int tw = get_text_width(MEDIUMFONT, info) + TOOLTIP_MARGIN * 2;
3173 int th = get_text_height(MEDIUMFONT, info) + TOOLTIP_MARGIN * 2;
3174 int tx = get_w() - (tw + xS(28));
3175 int ty = get_h() - (th + yS(28));
3176 show_tooltip(info, tx, ty, tw, th);
3180 void AWindowAssets::hide_tip_info()
3187 AWindowSearchTextBox::AWindowSearchTextBox(AWindowSearchText *search_text, int x, int y, int w)
3188 : BC_TextBox(x, y, w, 1, "")
3190 this->search_text = search_text;
3193 int AWindowSearchTextBox::handle_event()
3195 return search_text->handle_event();
3198 AWindowSearchText::AWindowSearchText(MWindow *mwindow, AWindowGUI *gui, int x, int y)
3200 this->mwindow = mwindow;
3206 void AWindowSearchText::create_objects()
3210 gui->add_subwindow(text_title = new BC_Title(x1, y1, _("Search:")));
3211 x1 += text_title->get_w() + xs10;
3212 int w1 = gui->get_w() - x1 - 2*xs10;
3213 gui->add_subwindow(text_box = new AWindowSearchTextBox(this, x1, y1, w1));
3216 int AWindowSearchText::handle_event()
3218 gui->async_update_assets();
3222 int AWindowSearchText::get_w()
3224 return text_box->get_w() + text_title->get_w() + xS(10);
3227 int AWindowSearchText::get_h()
3229 return bmax(text_box->get_h(),text_title->get_h());
3232 void AWindowSearchText::reposition_window(int x, int y, int w)
3236 text_title->reposition_window(x1, y1);
3237 x1 += text_title->get_w() + xs10;
3238 int w1 = gui->get_w() - x1 - 2*xs10;
3239 text_box->reposition_window(x1, y1, w1);
3242 const char *AWindowSearchText::get_text()
3244 return text_box->get_text();
3247 void AWindowSearchText::clear()
3249 text_box->update("");
3252 AWindowDeleteDisk::AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y)
3253 : BC_Button(x, y, mwindow->theme->deletedisk_data)
3255 this->mwindow = mwindow;
3257 set_tooltip(_("Delete asset from disk"));
3260 int AWindowDeleteDisk::handle_event()
3265 AWindowDeleteProject::AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y)
3266 : BC_Button(x, y, mwindow->theme->deleteproject_data)
3268 this->mwindow = mwindow;
3270 set_tooltip(_("Delete asset from project"));
3273 int AWindowDeleteProject::handle_event()
3278 // AWindowInfo::AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y)
3279 // : BC_Button(x, y, mwindow->theme->infoasset_data)
3281 // this->mwindow = mwindow;
3283 // set_tooltip(_("Edit information on asset"));
3286 // int AWindowInfo::handle_event()
3288 // int cur_x, cur_y;
3289 // gui->get_abs_cursor(cur_x, cur_y, 0);
3290 // gui->awindow->asset_edit->edit_asset(gui->selected_asset(), cur_x, cur_y);
3294 AWindowRedrawIndex::AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y)
3295 : BC_Button(x, y, mwindow->theme->redrawindex_data)
3297 this->mwindow = mwindow;
3299 set_tooltip(_("Redraw index"));
3302 int AWindowRedrawIndex::handle_event()
3307 AWindowPaste::AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y)
3308 : BC_Button(x, y, mwindow->theme->pasteasset_data)
3310 this->mwindow = mwindow;
3312 set_tooltip(_("Paste asset on recordable tracks"));
3315 int AWindowPaste::handle_event()
3320 AWindowAppend::AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y)
3321 : BC_Button(x, y, mwindow->theme->appendasset_data)
3323 this->mwindow = mwindow;
3325 set_tooltip(_("Append asset in new tracks"));
3328 int AWindowAppend::handle_event()
3333 AWindowView::AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y)
3334 : BC_Button(x, y, mwindow->theme->viewasset_data)
3336 this->mwindow = mwindow;
3338 set_tooltip(_("View asset"));
3341 int AWindowView::handle_event()
3346 AddTools::AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, const char *title)
3347 : BC_PopupMenu(x, y, title, -1, 0)
3349 this->mwindow = mwindow;
3353 void AddTools::create_objects()
3356 add_item(new AddPluginItem(this, "ffmpeg", PLUGIN_FFMPEG_ID));
3357 vis |= 1 << PLUGIN_FFMPEG_ID;
3358 add_item(new AddPluginItem(this, "ladspa", PLUGIN_LADSPA_ID));
3359 vis |= 1 << PLUGIN_LADSPA_ID;
3361 add_item(new AddPluginItem(this, "lv2", PLUGIN_LV2_ID));
3362 vis |= 1 << PLUGIN_LV2_ID;
3364 for( int i=0; i<MWindow::plugindb->size(); ++i ) {
3365 PluginServer *plugin = MWindow::plugindb->get(i);
3366 if( !plugin->audio && !plugin->video ) continue;
3367 int idx = plugin->dir_idx;
3368 uint32_t msk = 1 << idx;
3369 if( (msk & vis) != 0 ) continue;
3371 char parent[BCTEXTLEN];
3372 strcpy(parent, plugin->path);
3373 char *bp = strrchr(parent, '/');
3374 if( bp ) { *bp = 0; bp = strrchr(parent, '/'); }
3375 if( !bp ) bp = parent; else ++bp;
3376 add_item(new AddPluginItem(this, bp, idx));
3381 // plugin_dirs list from toplevel makefile include plugin_defs
3386 N_("audio_transitions")
3393 N_("video_transitions")
3396 AddPluginItem::AddPluginItem(AddTools *menu, char const *text, int idx)
3397 : BC_MenuItem(_(text))
3401 uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
3402 int chk = (msk & vis) ? 1 : 0;
3406 int AddPluginItem::handle_event()
3408 int chk = get_checked() ^ 1;
3410 uint64_t msk = (uint64_t)1 << idx, vis = menu->gui->plugin_visibility;
3411 menu->gui->plugin_visibility = chk ? vis | msk : vis & ~msk;
3412 menu->gui->update_effects();
3413 menu->gui->save_defaults(menu->mwindow->defaults);
3414 menu->gui->async_update_assets();
3418 AVIconDrawingItem::AVIconDrawingItem(AVIconDrawing *avicon, const char *text, int id)
3421 this->avicon = avicon;
3425 int AVIconDrawingItem::handle_event()
3427 for( int i=0; i<AVICON_PLAY_MODES; ++i ) {
3428 AVIconDrawingItem *item = (AVIconDrawingItem *) avicon->get_item(i);
3429 item->set_checked(id == i);
3431 AWindowGUI *agui = avicon->agui;
3433 avicon->set_text(get_text());
3434 agui->stop_vicon_drawing();
3435 agui->vicon_thread->set_view_popup(0);
3436 agui->vicon_thread->solo = 0;
3437 agui->vicon_drawing = id;
3438 agui->start_vicon_drawing();
3442 int AVIconDrawing::draw_face(int dx, int color)
3444 int ret = BC_PopupMenu::draw_face(dx, color);
3445 if( agui->play_off && agui->vicon_drawing != AVICON_NO_PLAY ) {
3446 int lx = get_margin(), ly = get_h()/2;
3447 draw_line(lx,ly, get_w()-2*lx,ly);
3452 AVIconDrawing::AVIconDrawing(AWindowGUI *agui, int x, int y, int w, const char *text)
3453 : BC_PopupMenu(x-w, y, w, text, 1, 0, 4)
3458 AVIconDrawing::~AVIconDrawing()
3462 void AVIconDrawing::create_objects()
3464 AVIconDrawingItem *item;
3465 for( int i=0; i<AVICON_PLAY_MODES; ++i ) {
3466 add_item(item = new AVIconDrawingItem(this, avicon_names[i], i));
3467 item->set_checked(agui->vicon_drawing == i);
3471 int AVIconDrawing::button_press_event()
3473 if( !is_event_win() ) return 0;
3474 if( get_buttonpress() == MIDDLE_BUTTON ) {
3475 agui->play_off = !agui->play_off ? 1 : 0;
3478 agui->start_vicon_drawing();
3481 return BC_PopupMenu::button_press_event();
3484 AWindowListFormat::AWindowListFormat(MWindow *mwindow, AWindowGUI *gui)
3485 : BC_MenuItem("","v",'v')
3487 this->mwindow = mwindow;
3491 int AWindowListFormat::handle_event()
3493 return gui->cycle_assetlist_format();
3496 void AWindowListFormat::update()
3498 EDLSession *session = mwindow->edl->session;
3499 const char *text = 0;
3500 switch( session->assetlist_format ) {
3502 text = _("Display icons");
3505 text = _("Display icons packed");
3507 case ASSETS_ICONS_PACKED:
3508 text = _("Display icon list");
3510 case ASSETS_ICON_LIST:
3511 text = _("Display text");
3517 AWindowListSort::AWindowListSort(MWindow *mwindow, AWindowGUI *gui)
3518 : BC_MenuItem(_("Sort items"))
3520 this->mwindow = mwindow;
3524 int AWindowListSort::handle_event()
3530 AssetSelectUsedItem::AssetSelectUsedItem(AssetSelectUsed *select_used, const char *text, int action)
3533 this->select_used = select_used;
3534 this->action = action;
3537 int AssetSelectUsedItem::handle_event()
3539 MWindow *mwindow = select_used->mwindow;
3540 AWindowGUI *gui = select_used->gui;
3541 AWindowAssets *asset_list = gui->asset_list;
3542 ArrayList<BC_ListBoxItem*> *data = gui->displayed_assets;
3547 asset_list->set_all_selected(data, action==SELECT_ALL ? 1 : 0);
3551 asset_list->set_all_selected(data, 0);
3552 for( int i = 0; i < data->total; i++ ) {
3553 AssetPicon *picon = (AssetPicon*)data->values[i];
3554 Indexable *idxbl = picon->indexable ? picon->indexable :
3555 picon->edl ? picon->edl->get_proxy_asset() : 0;
3556 int used = idxbl && mwindow->edl->in_use(idxbl) ? 1 : 0;
3557 asset_list->set_selected(data, i, action==SELECT_USED ? used : !used);
3562 int asset_xposition = asset_list->get_xposition();
3563 int asset_yposition = asset_list->get_yposition();
3564 asset_list->update(gui->displayed_assets, gui->asset_titles,
3565 mwindow->edl->session->asset_columns, ASSET_COLUMNS,
3566 asset_xposition, asset_yposition, -1, 0);
3567 asset_list->center_selection();
3571 AssetSelectUsed::AssetSelectUsed(MWindow *mwindow, AWindowGUI *gui)
3572 : BC_MenuItem(_("Select"))
3574 this->mwindow = mwindow;