X-Git-Url: https://cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fawindowgui.C;h=e8701eaa0f4be841bdc5d98c4368967a0c75ad33;hb=b2dfd8318ea57bbe38e2c61ffd8cda30fb7465c3;hp=2ef637964754a6f119ea87ef384379e7e39aff65;hpb=b64142b983e53a7f0bfe8422efc3bb4f4ebb897c;p=goodguy%2Fcinelerra.git diff --git a/cinelerra-5.1/cinelerra/awindowgui.C b/cinelerra-5.1/cinelerra/awindowgui.C index 2ef63796..e8701eaa 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,11 +302,152 @@ 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; } +AssetVIconThread::AssetVIconThread(AWindowAssets *asset_list) + : VIconThread(asset_list) +{ + popup_dragging = 0; +} + +AssetVIconThread::~AssetVIconThread() +{ +} + +int AssetVIconThread::popup_button_press(int x, int y) +{ + if( !view_win || !view_win->is_event_win() ) return 0; + if( !vicon || vicon->playing_audio >= 0 ) return 0; + popup_dragging = 0; + int view_w = view_win->get_w(), view_h = view_win->get_h(); + AssetVIcon *vicon = (AssetVIcon *)this->vicon; + AssetPicon *picon = vicon->picon; + 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; + } + if( y >= view_h-VIEW_POPUP_BAR_H ) { + popup_dragging = 1; + if( !view_win->ctrl_down() ) + return popup_cursor_motion(x, y); + 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 / view_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"); + edl->local_session->set_selectionstart(pos); + edl->local_session->set_selectionend(pos); + mwindow->find_cursor(); + edl->local_session->set_selectionstart(start); + edl->local_session->set_selectionend(end); + mwindow->zoom_sample(edl->local_session->zoom_sample); + mwindow->gui->unlock_window(); + return 1; + } + return 0; +} + +int AssetVIconThread::popup_button_release(int x, int y) +{ + if( !view_win || !view_win->is_event_win() ) return 0; + if( !vicon || vicon->playing_audio >= 0 ) return 0; + popup_dragging = 0; + return 1; +} + +int AssetVIconThread::popup_cursor_motion(int x, int y) +{ + if( !view_win || !view_win->is_event_win() ) return 0; + if( !vicon || vicon->playing_audio >= 0 ) return 0; + if( !view_win->get_button_down() || view_win->get_buttonpress() != 1 || + view_win->ctrl_down() || view_win->alt_down() || view_win->shift_down() ) + return 0; + AssetVIcon *vicon = (AssetVIcon *)this->vicon; + MWindow *mwindow = vicon->picon->mwindow; + EDL *edl = mwindow->edl; + if( popup_dragging ) { + double total_length = edl->tracks->total_length(); + int view_w = view_win->get_w(); + 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 +592,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; } @@ -1117,7 +1262,7 @@ void AWindowGUI::create_objects() y1 += dy; h1 -= dy; add_subwindow(asset_list = new AWindowAssets(mwindow, this, x1, y1, w1, h1)); - vicon_thread = new VIconThread(asset_list); + vicon_thread = new AssetVIconThread(asset_list); asset_list->update_vicon_area(); vicon_thread->start(); vicon_audio = new AssetVIconAudio(this); @@ -1488,6 +1633,15 @@ int AWindowGUI::keypress_event() mwindow->session->drag_clips); lock_window("AWindowGUI::keypress_event 2"); return 1; + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + if( shift_down() && ctrl_down() ) { + resend_event(mwindow->gui); + return 1; + } + break; } return 0; } @@ -2284,6 +2438,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() @@ -2402,7 +2557,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 ) && @@ -2411,11 +2567,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; + AssetVIconThread *vt = (AssetVIconThread *)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()); @@ -2603,7 +2827,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(); } @@ -2625,7 +2851,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; } @@ -2937,3 +3166,51 @@ int AWindowListSort::handle_event() return 1; } +AssetSelectUsedItem::AssetSelectUsedItem(AssetSelectUsed *select_used, const char *text, int action) + : BC_MenuItem(text) +{ + this->select_used = select_used; + this->action = action; +} + +int AssetSelectUsedItem::handle_event() +{ + MWindow *mwindow = select_used->mwindow; + AWindowGUI *gui = select_used->gui; + AWindowAssets *asset_list = gui->asset_list; + ArrayList *data = gui->displayed_assets; + + switch( action ) { + case SELECT_ALL: + case SELECT_NONE: + asset_list->set_all_selected(data, action==SELECT_ALL ? 1 : 0); + break; + case SELECT_USED: + case SELECT_UNUSED: + asset_list->set_all_selected(data, 0); + for( int i = 0; i < data->total; i++ ) { + AssetPicon *picon = (AssetPicon*)data->values[i]; + Indexable *idxbl = picon->indexable ? picon->indexable : + picon->edl ? picon->edl->get_proxy_asset() : 0; + int used = idxbl && mwindow->edl->in_use(idxbl) ? 1 : 0; + asset_list->set_selected(data, i, action==SELECT_USED ? used : !used); + } + break; + } + + int asset_xposition = asset_list->get_xposition(); + int asset_yposition = asset_list->get_yposition(); + asset_list->update(gui->displayed_assets, gui->asset_titles, + mwindow->edl->session->asset_columns, ASSET_COLUMNS, + asset_xposition, asset_yposition, -1, 0); + asset_list->center_selection(); + return 1; +} + +AssetSelectUsed::AssetSelectUsed(MWindow *mwindow, AWindowGUI *gui) + : BC_MenuItem(_("Select")) +{ + this->mwindow = mwindow; + this->gui = gui; +} +