From 2292a9b260b7c5f0ee85280823ef760910ace931 Mon Sep 17 00:00:00 2001 From: Good Guy Date: Sun, 2 Dec 2018 18:22:26 -0700 Subject: [PATCH] map media vicon popup --- cinelerra-5.1/cinelerra/awindowgui.C | 185 +++++++++++++++++++++++++-- cinelerra-5.1/cinelerra/awindowgui.h | 12 +- cinelerra-5.1/configure.ac | 2 +- cinelerra-5.1/guicast/vicon.C | 40 ++++-- cinelerra-5.1/guicast/vicon.h | 14 +- 5 files changed, 224 insertions(+), 29 deletions(-) diff --git a/cinelerra-5.1/cinelerra/awindowgui.C b/cinelerra-5.1/cinelerra/awindowgui.C index 38dad86b..30ae58b3 100644 --- a/cinelerra-5.1/cinelerra/awindowgui.C +++ b/cinelerra-5.1/cinelerra/awindowgui.C @@ -40,6 +40,8 @@ #include "cursors.h" #include "cwindowgui.h" #include "cwindow.h" +#include "edits.h" +#include "edit.h" #include "edl.h" #include "edlsession.h" #include "effectlist.h" @@ -63,6 +65,7 @@ #include "samples.h" #include "theme.h" #include "tracks.h" +#include "track.h" #include "transportque.h" #include "vframe.h" #include "vicon.h" @@ -291,6 +294,7 @@ void AssetVIconAudio::stop(int wait) void AssetVIcon::start_audio() { + if( playing_audio < 0 ) return; picon->gui->vicon_audio->stop(0); playing_audio = 1; picon->gui->vicon_audio->start(this); @@ -298,10 +302,90 @@ void AssetVIcon::start_audio() void AssetVIcon::stop_audio() { - picon->gui->vicon_audio->stop(0); + if( playing_audio > 0 ) + picon->gui->vicon_audio->stop(0); playing_audio = 0; } +int AssetVIcon::popup_button_press(int x, int y) +{ + if( playing_audio >= 0 ) return 0; + VIconThread *vt = picon->gui->vicon_thread; + ViewPopup *view_win = vt->view_win; + if( !view_win || !view_win->is_event_win() ) return 0; + int view_w = view_win->get_w(), view_h = view_win->get_h(); + MWindow *mwindow = picon->mwindow; + EDL *edl = mwindow->edl; + if( y < VIEW_POPUP_BAR_H ) { + 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 / view_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(end); + vwindow->update_position(CHANGE_NONE, 0, 1, 0); + return 1; + } + return y < view_h-VIEW_POPUP_BAR_H ? 0 : popup_cursor_motion(x, y); +} + +int AssetVIcon::popup_cursor_motion(int x, int y) +{ + if( playing_audio >= 0 ) return 0; + VIconThread *vt = picon->gui->vicon_thread; + ViewPopup *view_win = (ViewPopup *)vt->view_win; + if( !view_win || !view_win->is_event_win() || + !view_win->get_button_down() ) return 0; + int view_w = view_win->get_w(), view_h = view_win->get_h(); + MWindow *mwindow = picon->mwindow; + EDL *edl = mwindow->edl; + if( y >= view_h-VIEW_POPUP_BAR_H ) { + double total_length = edl->tracks->total_length(); + double pos = x * total_length / view_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; +} + AWindowFolderItem::AWindowFolderItem() : BC_ListBoxItem() @@ -447,14 +531,14 @@ void AssetPicon::draw_hue_bar(VFrame *frame, double duration) } } -void AssetPicon::draw_wave(VFrame *frame, double *dp, int len, int base_color, int line_color) +void AssetPicon::draw_wave(VFrame *frame, double *dp, int len, + int base_color, int line_color, int x, int y, int w, int h) { - int w = frame->get_w(), h = frame->get_h(); - int h1 = h-1, h2 = h/2, y = h2; + int h1 = h-1, h2 = h/2, iy = h2; int rgb_color = frame->pixel_rgb; - for( int x=0,x1=0,x2=0; xpixel_rgb = line_color; - frame->draw_line(x,y1, x,y2); + frame->draw_line(ix+x,y1+y, ix+x,y2+y); frame->pixel_rgb = base_color; - frame->draw_line(x,y, x,y0); - y = y0; + frame->draw_line(ix+x,iy+y, ix+x,y0+y); + iy = y0; } frame->pixel_rgb = rgb_color; } @@ -2293,6 +2377,7 @@ AWindowAssets::AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, in this->gui = gui; set_drag_scroll(0); set_scroll_stretch(1, 1); + draw_func = 0; } AWindowAssets::~AWindowAssets() @@ -2411,7 +2496,8 @@ int AWindowAssets::selection_changed() deactivate_selection(); } - else if( gui->vicon_drawing && get_button_down() && get_buttonpress() == 1 && + else if( gui->vicon_drawing && get_button_down() && + ( get_buttonpress() == 1 || get_buttonpress() == 2 ) && ( mwindow->edl->session->awindow_folder == AW_MEDIA_FOLDER || mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER || mwindow->edl->session->awindow_folder >= AWINDOW_USER_FOLDERS ) && @@ -2420,11 +2506,79 @@ int AWindowAssets::selection_changed() if( !gui->vicon_thread->vicon ) { vicon = item->vicon; } - gui->vicon_thread->set_view_popup(vicon); + if( vicon && get_buttonpress() == 2 ) { + vicon->playing_audio = -1; + draw_func = AWindowAssets::draw_vframe; + } + else + draw_func = 0; + gui->vicon_thread->set_view_popup(vicon, draw_func); } return 1; } +void AWindowAssets::draw_vframe(BC_WindowBase *wdw, VFrame *vframe) +{ + int y1 = VIEW_POPUP_BAR_H; + int y2 = wdw->get_h()-VIEW_POPUP_BAR_H; + wdw->set_color(BLACK); + wdw->draw_box(0,0,wdw->get_w(),wdw->get_h()); + wdw->draw_vframe(vframe, 0,y1, wdw->get_w(),y2-y1); + ViewPopup *view_popup = (ViewPopup *)wdw; + VIconThread *vt = view_popup->vt; + AssetVIcon *vicon = (AssetVIcon *)vt->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 ) { + 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 = wdw->get_w() / idxbl_length; + int ex1 = pos1 * xscale, ex2 = pos2 * xscale; + wdw->set_color(WHITE); + wdw->draw_box(ex1,0, ex2-ex1,y1); + wdw->set_color(BLACK); + wdw->draw_line(ex1,0, ex1,y1); + wdw->draw_line(ex2,0, ex2,y1); + pos1 = track->from_units(edit->startproject); + pos2 = track->from_units(edit->startproject + edit->length); + xscale = wdw->get_w() / total_length; + int px1 = pos1 * xscale, px2 = pos2 * xscale; + wdw->set_color(RED); + wdw->draw_box(px1,y2, px2-px1,wdw->get_h()-y2); + wdw->set_color(BLACK); + wdw->draw_line(px1,y2, px1,wdw->get_h()-1); + wdw->draw_line(px2,y2, px2,wdw->get_h()-1); + + wdw->set_color(YELLOW); + wdw->draw_line(ex1,y1, px1,y2); + wdw->draw_line(ex2,y1, px2,y2); + } + } + } +} + void AWindowAssets::draw_background() { clear_box(0,0,get_w(),get_h(),get_bg_surface()); @@ -2612,7 +2766,9 @@ int AWindowAssets::cursor_enter_event() int AWindowAssets::cursor_leave_event() { - gui->stop_vicon_drawing(); + VIcon *vicon = gui->vicon_thread->vicon; + if( vicon && vicon->playing_audio >= 0 ) + gui->stop_vicon_drawing(); return BC_ListBox::cursor_leave_event(); } @@ -2634,7 +2790,10 @@ int AWindowAssets::mouse_over_event(int no) no >= 0 && no < gui->displayed_assets[0].size() ) { AssetPicon *picon = (AssetPicon *)gui->displayed_assets[0][no]; VIcon *vicon = picon->vicon; - picon->gui->vicon_thread->set_view_popup(vicon); + if( gui->vicon_thread->vicon && + gui->vicon_thread->vicon->playing_audio < 0 ) + vicon->playing_audio = -1; + picon->gui->vicon_thread->set_view_popup(vicon, draw_func); } return 0; } diff --git a/cinelerra-5.1/cinelerra/awindowgui.h b/cinelerra-5.1/cinelerra/awindowgui.h index 93d6fa27..b936647f 100644 --- a/cinelerra-5.1/cinelerra/awindowgui.h +++ b/cinelerra-5.1/cinelerra/awindowgui.h @@ -53,6 +53,7 @@ #define SELECT_USED 1 #define SELECT_UNUSED 2 #define SELECT_NONE 3 +#define VIEW_POPUP_BAR_H 15 class AWindowFolderItem : public BC_ListBoxItem { @@ -82,7 +83,12 @@ public: void reset(); static void draw_hue_bar(VFrame *frame, double t); static void draw_wave(VFrame *frame, double *dp, int len, - int base_color, int line_color); + int base_color, int line_color, int x, int y, int w, int h); + static void draw_wave(VFrame *frame, double *dp, int len, + int base_color, int line_color, int x=0, int y=0) { + draw_wave(frame, dp, len, base_color, line_color, + x,y,frame->get_w(),frame->get_h()); + } void open_render_engine(EDL *edl, int is_audio); void close_render_engine(); void render_video(int64_t pos, VFrame *vfrm); @@ -149,6 +155,8 @@ public: void load_audio(); void start_audio(); void stop_audio(); + int popup_button_press(int x, int y); + int popup_cursor_motion(int x, int y); AssetVIcon(AssetPicon *picon, int w, int h, double framerate, int64_t length); ~AssetVIcon(); @@ -346,6 +354,8 @@ public: int cursor_leave_event(); void update_vicon_area(); int mouse_over_event(int no); + static VIconDrawVFrame draw_vframe; + VIconDrawVFrame *draw_func; MWindow *mwindow; AWindowGUI *gui; diff --git a/cinelerra-5.1/configure.ac b/cinelerra-5.1/configure.ac index ab04c5ed..0bc0a38c 100644 --- a/cinelerra-5.1/configure.ac +++ b/cinelerra-5.1/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ([2.69]) -AC_INIT([cinelerra], [5.1], [mail@lists.cinelerra-cv.org]) +AC_INIT([cinelerra], [5.1], [mail@lists.cinelerra-gg.org]) AM_INIT_AUTOMAKE([foreign]) AM_PROG_AS diff --git a/cinelerra-5.1/guicast/vicon.C b/cinelerra-5.1/guicast/vicon.C index e9a23f4a..119b6344 100644 --- a/cinelerra-5.1/guicast/vicon.C +++ b/cinelerra-5.1/guicast/vicon.C @@ -141,7 +141,7 @@ void VIconThread:: stop_drawing() { wdw->lock_window("VIconThread::stop_drawing"); - set_view_popup(0); + close_view_popup(); if( !interrupted ) interrupted = 1; stop_age = timer->get_difference(); @@ -151,7 +151,7 @@ stop_drawing() int VIconThread::keypress_event(int key) { if( key != ESC ) return 0; - set_view_popup(0); + close_view_popup(); return 1; } @@ -172,6 +172,18 @@ int ViewPopup::keypress_event() return vt->keypress_event(key); } +int ViewPopup::button_press_event() +{ + return !vt->vicon ? 0 : + vt->vicon->popup_button_press(get_cursor_x(), get_cursor_y()); +} +int ViewPopup::cursor_motion_event() +{ + return !vt->vicon ? 0 : + vt->vicon->popup_cursor_motion(get_cursor_x(), get_cursor_y()); +} + + ViewPopup::ViewPopup(VIconThread *vt, VFrame *frame, int x, int y, int w, int h) : BC_Popup(vt->wdw, x, y, w, h, BLACK) { @@ -183,12 +195,6 @@ ViewPopup::~ViewPopup() vt->wdw->set_active_subwindow(0); } -void ViewPopup::draw_vframe(VFrame *frame) -{ - if( !frame ) return; - BC_WindowBase::draw_vframe(frame, 0,0, get_w(),get_h()); -} - ViewPopup *VIconThread::new_view_window(VFrame *frame) { BC_WindowBase *parent = wdw->get_parent(); @@ -231,9 +237,21 @@ int VIconThread::del_vicon(VIcon *vicon) return 1; } -void VIconThread::set_view_popup(VIcon *vicon) +void VIconThread::draw_vframe(BC_WindowBase *wdw, VFrame *frame) +{ + if( !wdw || !frame ) return; + wdw->draw_vframe(frame, 0,0, wdw->get_w(),wdw->get_h()); +} + +void VIconThread::set_view_popup(VIcon *vicon, VIconDrawVFrame *draw_vfrm) { this->vicon = vicon; + this->draw_vfrm = vicon && !draw_vfrm ? VIconThread::draw_vframe : draw_vfrm; +} + +void VIconThread::close_view_popup() +{ + set_view_popup(0); } int VIconThread:: @@ -281,7 +299,7 @@ draw(VIcon *vicon) img_dirty = 1; } if( draw_win ) { - view_win->draw_vframe(vicon->frame()); + draw_vfrm(view_win, vicon->frame()); win_dirty = 1; } return 1; @@ -316,7 +334,7 @@ run() draw(next); if( !next->seq_no ) { next->cycle_start = now; - if( next->playing_audio ) + if( next->playing_audio > 0 ) next->start_audio(); } int64_t ref_no = (now - next->cycle_start) / 1000. * refresh_rate; diff --git a/cinelerra-5.1/guicast/vicon.h b/cinelerra-5.1/guicast/vicon.h index 274051fa..bab38462 100644 --- a/cinelerra-5.1/guicast/vicon.h +++ b/cinelerra-5.1/guicast/vicon.h @@ -9,11 +9,14 @@ #include "vicon.inc" #include "vframe.h" +typedef void VIconDrawVFrame(BC_WindowBase *wdw, VFrame *frame); + class ViewPopup : public BC_Popup { public: VIconThread *vt; int keypress_event(); - void draw_vframe(VFrame *frame); + int button_press_event(); + int cursor_motion_event(); ViewPopup(VIconThread *vt, VFrame *frame, int x, int y, int w, int h); ~ViewPopup(); @@ -56,6 +59,8 @@ public: virtual void load_audio() {} virtual void start_audio() {} virtual void stop_audio() {} + virtual int popup_button_press(int x, int y) { return 0; } + virtual int popup_cursor_motion(int x, int y) { return 0; } void add_image(VFrame *frm, int ww, int hh, int vcmdl); void draw_vframe(VIconThread *vt, BC_WindowBase *wdw, int x, int y); @@ -96,13 +101,16 @@ public: void remove_vicon(int i); int keypress_event(int key); void set_drawing_area(int x0, int y0, int x1, int y1); - void set_view_popup(VIcon *vicon); + void set_view_popup(VIcon *vicon, VIconDrawVFrame *draw_vfrm=0); + void close_view_popup(); void hide_vicons(int v=1); - ViewPopup *new_view_window(VFrame *frame); + virtual bool visible(VIcon *vicon, int x, int y); virtual void drawing_started() {} virtual void drawing_stopped() {} + static VIconDrawVFrame draw_vframe; + VIconDrawVFrame *draw_vfrm; VIconThread(BC_WindowBase *wdw, int vw=4*VICON_WIDTH, int vh=4*VICON_HEIGHT); ~VIconThread(); -- 2.26.2