+ if( playing_audio > 0 ) {
+ picon->gui->vicon_audio->stop(0);
+ playing_audio = 0;
+ }
+}
+
+AssetViewPopup::AssetViewPopup(VIconThread *vt, int draw_mode,
+ int x, int y, int w, int h)
+ : ViewPopup(vt, x, y, w, h)
+{
+ this->draw_mode = draw_mode;
+ this->bar_h = (VIEW_POPUP_BAR_H * h) / 200;
+ dragging = 0;
+}
+
+AssetViewPopup::~AssetViewPopup()
+{
+}
+
+int AssetViewPopup::reposition_window(int x, int y, int w, int h)
+{
+ this->bar_h = (VIEW_POPUP_BAR_H * h) / 200;
+ return ViewPopup::reposition_window(x, y, w, h);
+}
+
+int AssetViewPopup::button_press_event()
+{
+ if( !is_event_win() ) return 0;
+ AssetVIconThread *avt = (AssetVIconThread *)vt;
+ if( !avt->vicon ) return 0;
+
+ int dir = 1;
+ switch( get_buttonpress() ) {
+ case LEFT_BUTTON:
+ break;
+ case MIDDLE_BUTTON:
+ avt->set_view_popup(0);
+ return 1;
+ case WHEEL_DOWN:
+ dir = -1; // fall thru
+ case WHEEL_UP:
+ switch( draw_mode ) {
+ case ASSET_VIEW_MEDIA:
+ case ASSET_VIEW_MEDIA_MAP:
+ avt->zoom_scale(dir);
+ return 1;
+ } // fall thru
+ default:
+ return 0;
+ }
+
+ int x = get_cursor_x(), y = get_cursor_y();
+ AssetVIcon *vicon = (AssetVIcon *)avt->vicon;
+ AssetPicon *picon = vicon->picon;
+ MWindow *mwindow = picon->mwindow;
+ EDL *edl = mwindow->edl;
+ dragging = 0;
+ if( y < get_h()/2 ) {
+ Indexable *idxbl =
+ picon->indexable ? picon->indexable :
+ picon->edl ? picon->edl : 0;
+ if( !idxbl ) return 0;
+ double sample_rate = idxbl->get_sample_rate();
+ double audio_length = sample_rate > 0 && idxbl->have_audio() ?
+ idxbl->get_audio_samples() / sample_rate : 0;
+ double frame_rate = idxbl->get_frame_rate();
+ double video_length = frame_rate > 0 && idxbl->have_video() ?
+ idxbl->get_video_frames() / frame_rate : 0;
+ double idxbl_length = bmax(audio_length, video_length);
+ double pos = x * idxbl_length / get_w();
+ double start = 0, end = idxbl_length;
+ double lt = DBL_MAX, rt = DBL_MAX;
+ for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
+ for( Edit *edit=track->edits->first; edit!=0; edit=edit->next ) {
+ Indexable *indexable = (Indexable *)edit->asset;
+ if( !indexable ) indexable = (Indexable *)edit->nested_edl;
+ if( !indexable ) continue;
+ if( indexable->id == idxbl->id ||
+ (!indexable->is_asset == !idxbl->is_asset &&
+ !strcmp(indexable->path, idxbl->path)) ) {
+ double start_pos = track->from_units(edit->startsource);
+ double end_pos = track->from_units(edit->startsource + edit->length);
+ double dlt = pos - start_pos, drt = end_pos - pos;
+ if( dlt >= 0 && dlt < lt ) { lt = dlt; start = start_pos; }
+ else if( dlt < 0 && -dlt < rt ) { rt = -dlt; end = start_pos; }
+ if( drt >= 0 && drt < rt ) { rt = drt; end = end_pos; }
+ else if( drt < 0 && -drt < lt ) { lt = -drt; start = end_pos; }
+ }
+ }
+ }
+ mwindow->gui->lock_window("AssetVIcon::popup_button_press");
+ VWindow *vwindow = mwindow->get_viewer(1, 0);
+ vwindow->change_source(idxbl);
+ mwindow->gui->unlock_window();
+ EDL *vedl = vwindow->get_edl();
+ vedl->set_inpoint(start);
+ vedl->set_outpoint(end);
+ vedl->local_session->set_selectionstart(start);
+ vedl->local_session->set_selectionend(start);
+ vwindow->gui->lock_window("AssetViewPopup::button_press_event");
+ vwindow->update_position();
+ vwindow->gui->unlock_window();
+ return 1;
+ }
+ else {
+ dragging = 1;
+ if( !ctrl_down() && !shift_down() )
+ return cursor_motion_event();
+ Indexable *idxbl =
+ picon->indexable ? picon->indexable :
+ picon->edl ? picon->edl : 0;
+ if( !idxbl ) return 0;
+ double total_length = mwindow->edl->tracks->total_length();
+ double pos = x * total_length / get_w();
+ double start = 0, end = total_length;
+ double lt = DBL_MAX, rt = DBL_MAX;
+ for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
+ for( Edit *edit=track->edits->first; edit!=0; edit=edit->next ) {
+ Indexable *indexable = (Indexable *)edit->asset;
+ if( !indexable ) indexable = (Indexable *)edit->nested_edl;
+ if( !indexable ) continue;
+ if( indexable->id == idxbl->id ||
+ (!indexable->is_asset == !idxbl->is_asset &&
+ !strcmp(indexable->path, idxbl->path)) ) {
+ double start_pos = track->from_units(edit->startproject);
+ double end_pos = track->from_units(edit->startproject + edit->length);
+ double dlt = pos - start_pos, drt = end_pos - pos;
+ if( dlt >= 0 && dlt < lt ) { lt = dlt; start = start_pos; }
+ else if( dlt < 0 && -dlt < rt ) { rt = -dlt; end = start_pos; }
+ if( drt >= 0 && drt < rt ) { rt = drt; end = end_pos; }
+ else if( drt < 0 && -drt < lt ) { lt = -drt; start = end_pos; }
+ }
+ }
+ }
+ mwindow->gui->lock_window("AssetVIcon::popup_button_press");
+ mwindow->select_point(start);
+ edl->local_session->set_selectionstart(start);
+ edl->local_session->set_selectionend(!shift_down() ? start : end);
+ mwindow->zoom_sample(edl->local_session->zoom_sample);
+ mwindow->gui->unlock_window();
+ return 1;
+ }
+ return 0;
+}
+
+int AssetViewPopup::button_release_event()
+{
+ if( !is_event_win() ) return 0;
+ dragging = 0;
+ return 1;
+}
+
+int AssetViewPopup::cursor_motion_event()
+{
+ AssetVIconThread *avt = (AssetVIconThread *)vt;
+ AssetVIcon *vicon = (AssetVIcon *)avt->vicon;
+ if( vicon && dragging && is_event_win() &&
+ get_button_down() && get_buttonpress() == LEFT_BUTTON &&
+ !ctrl_down() && !alt_down() && !shift_down() ) {
+ switch( draw_mode ) {
+ case ASSET_VIEW_MEDIA_MAP:
+ case ASSET_VIEW_FULL:
+ MWindow *mwindow = vicon->picon->mwindow;
+ EDL *edl = mwindow->edl;
+ int x = get_cursor_x();
+ double total_length = edl->tracks->total_length();
+ double pos = x * total_length / get_w();
+ mwindow->gui->lock_window("AssetVIcon::popup_cursor_motion");
+ mwindow->select_point(pos);
+ mwindow->zoom_sample(edl->local_session->zoom_sample);
+ mwindow->gui->unlock_window();
+ return 1;
+ }
+ }
+ return 0;
+}
+
+void AssetViewPopup::draw_vframe(VFrame *vframe)
+{
+ switch( draw_mode ) {
+ case ASSET_VIEW_MEDIA:
+ case ASSET_VIEW_ICON:
+ ViewPopup::draw_vframe(vframe);
+ case ASSET_VIEW_NONE:
+ default:
+ return;
+ case ASSET_VIEW_MEDIA_MAP:
+ case ASSET_VIEW_FULL:
+ break;
+ }
+ set_color(BLACK);
+ draw_box(0,0,get_w(),get_h());
+ int y1 = bar_h;
+ int y2 = get_h()-bar_h;
+ BC_WindowBase::draw_vframe(vframe, 0,y1, get_w(),y2-y1);
+ AssetVIconThread *avt = (AssetVIconThread *)vt;
+ AssetVIcon *vicon = (AssetVIcon *)avt->vicon;
+ AssetPicon *picon = (AssetPicon *)vicon->picon;
+ Indexable *idxbl =
+ picon->indexable ? picon->indexable :
+ picon->edl ? picon->edl : 0;
+ if( !idxbl ) return;
+ double sample_rate = idxbl->get_sample_rate();
+ double audio_length = sample_rate > 0 && idxbl->have_audio() ?
+ idxbl->get_audio_samples() / sample_rate : 0;
+ double frame_rate = idxbl->get_frame_rate();
+ double video_length = frame_rate > 0 && idxbl->have_video() ?
+ idxbl->get_video_frames() / frame_rate : 0;
+ double idxbl_length = bmax(audio_length, video_length);
+ if( !idxbl_length ) idxbl_length = 1;
+
+ EDL *edl = picon->mwindow->edl;
+ double total_length = edl->tracks->total_length();
+ if( !total_length ) total_length = 1;
+ for( Track *track=edl->tracks->first; track!=0; track=track->next ) {
+ if( !track->record ) continue;
+ for( Edit *edit=track->edits->first; edit!=0; edit=edit->next ) {
+ Indexable *indexable = (Indexable *)edit->asset;
+ if( !indexable ) indexable = (Indexable *)edit->nested_edl;
+ if( !indexable ) continue;
+ if( indexable->id == idxbl->id ||
+ (!indexable->is_asset == !idxbl->is_asset &&
+ !strcmp(indexable->path, idxbl->path)) ) {
+ double pos1 = track->from_units(edit->startsource);
+ double pos2 = track->from_units(edit->startsource + edit->length);
+ double xscale = get_w() / idxbl_length;
+ int ex1 = pos1 * xscale, ex2 = pos2 * xscale;
+ set_color(WHITE);
+ draw_box(ex1,0, ex2-ex1,y1);
+ set_color(BLACK);
+ draw_line(ex1,0, ex1,y1);
+ draw_line(ex2,0, ex2,y1);
+ pos1 = track->from_units(edit->startproject);
+ pos2 = track->from_units(edit->startproject + edit->length);
+ xscale = get_w() / total_length;
+ int px1 = pos1 * xscale, px2 = pos2 * xscale;
+ set_color(RED);
+ draw_box(px1,y2, px2-px1,get_h()-y2);
+ set_color(BLACK);
+ draw_line(px1,y2, px1,get_h()-1);
+ draw_line(px2,y2, px2,get_h()-1);
+
+ set_color(YELLOW);
+ draw_line(ex1,y1, px1,y2);
+ draw_line(ex2,y1, px2,y2);
+ }
+ }
+ }
+}
+
+int AssetViewPopup::keypress_event()
+{
+ int result = 0;
+ AssetVIconThread *avt = (AssetVIconThread *)vt;
+ switch( avt->draw_mode ) {
+ case ASSET_VIEW_MEDIA_MAP:
+ switch( get_keypress() ) {
+ case 'f':
+ case 'F':
+ avt->draw_mode = ASSET_VIEW_FULL;
+ result = 1;
+ }
+ break;
+ case ASSET_VIEW_FULL:
+ avt->draw_mode = ASSET_VIEW_MEDIA_MAP;
+ result = 1;
+ }
+ if( result ) // zero change for refresh
+ avt->zoom_scale(0);
+ return ViewPopup::keypress_event();
+}
+
+
+AssetVIconThread::AssetVIconThread(AWindowGUI *gui, Preferences *preferences)
+ : VIconThread(gui->asset_list, preferences->vicon_size * 16/9, preferences->vicon_size,
+ 4*preferences->awindow_picon_h * 16/9, 4*preferences->awindow_picon_h)
+{
+ this->gui = gui;
+ draw_mode = ASSET_VIEW_NONE;
+ int vicon_cmodel = BC_RGB8;
+ switch( preferences->vicon_color_mode ) {
+ case VICON_COLOR_MODE_LOW: vicon_cmodel = BC_RGB8; break;
+ case VICON_COLOR_MODE_MED: vicon_cmodel = BC_RGB565; break;
+ case VICON_COLOR_MODE_HIGH: vicon_cmodel = BC_RGB888; break;
+ }
+ this->vicon_cmodel = vicon_cmodel;
+ this->draw_lock = new Mutex("AssetVIconThread::draw_lock");
+}
+
+AssetVIconThread::~AssetVIconThread()
+{
+ delete draw_lock;
+}
+
+void AssetVIconThread::drawing_started()
+{
+ draw_lock->lock("AssetVIconThread::drawing_started");
+}
+
+void AssetVIconThread::drawing_stopped()
+{
+ draw_lock->unlock();
+}
+
+void AssetVIconThread::set_view_popup(AssetVIcon *v, int draw_mode)
+{
+ gui->stop_vicon_drawing();
+ this->draw_mode = draw_mode;
+ set_view_popup(v);
+ gui->start_vicon_drawing();
+}
+
+void AssetVIconThread::set_view_popup(AssetVIcon *v)
+{
+ if( !v ) draw_mode = ASSET_VIEW_NONE;
+ VIconThread::set_view_popup(v);
+}
+
+ViewPopup *AssetVIconThread::new_view_window(ViewPopup *vpopup)
+{
+ BC_WindowBase *parent = wdw->get_parent();
+ int rx = 0, ry = 0, rw = 0, rh = 0;
+ if( draw_mode != ASSET_VIEW_FULL ) {
+ XineramaScreenInfo *info = parent->get_xinerama_info(-1);
+ int cx = info ? info->x_org + info->width/2 : parent->get_root_w(0)/2;
+ int cy = info ? info->y_org + info->height/2 : parent->get_root_h(0)/2;
+ int vx = viewing->get_vx(), vy = viewing->get_vy();
+ wdw->get_root_coordinates(vx, vy, &rx, &ry);
+ rx += (rx >= cx ? -view_w+viewing->w/4 : viewing->w-viewing->w/4);
+ ry += (ry >= cy ? -view_h+viewing->h/4 : viewing->h-viewing->h/4);
+ rw = view_w; rh = view_h;
+ }
+ else
+ parent->get_fullscreen_geometry(rx, ry, rw, rh);
+ AssetViewPopup *av_popup = (AssetViewPopup *)vpopup;
+ if( av_popup )
+ av_popup->reposition_window(rx, ry, rw, rh);
+ else
+ av_popup = new AssetViewPopup(this, draw_mode, rx, ry, rw, rh);
+ int playing_audio = gui->play_off ? -1 : 0;
+ if( !playing_audio ) {
+ switch( draw_mode ) {
+ case ASSET_VIEW_NONE:
+ case ASSET_VIEW_ICON:
+ case ASSET_VIEW_MEDIA_MAP:
+ case ASSET_VIEW_FULL:
+ playing_audio = -1;
+ break;
+ case ASSET_VIEW_MEDIA:
+ switch( gui->vicon_drawing ) {
+ case AVICON_SRC_TARGET:
+ case AVICON_NO_PLAY:
+ playing_audio = -1;
+ break;
+ }
+ }
+ }
+ vicon->playing_audio = playing_audio;
+ wdw->set_active_subwindow(av_popup);
+ return av_popup;
+}
+
+void AssetVIconThread::close_view_popup()
+{
+ stop_drawing();
+ drawing_started(); // waits for draw lock
+ drawing_stopped();