X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fawindowgui.C;h=f33b9cbc1eb3f96eecdb44677167f7904aaa55da;hp=d2777c93a74edb902295233ccc6e12da7735ba86;hb=eecf057a9d6b8c8cffc7d0001bff89bc9cac7b05;hpb=48c313de28fe6d39d9431dbe2dca6ffb176541ff diff --git a/cinelerra-5.1/cinelerra/awindowgui.C b/cinelerra-5.1/cinelerra/awindowgui.C index d2777c93..f33b9cbc 100644 --- a/cinelerra-5.1/cinelerra/awindowgui.C +++ b/cinelerra-5.1/cinelerra/awindowgui.C @@ -19,10 +19,12 @@ * */ +#include "arender.h" #include "asset.h" #include "assetedit.h" #include "assetpopup.h" #include "assets.h" +#include "audiodevice.h" #include "awindowgui.h" #include "awindow.h" #include "bccmodels.h" @@ -31,6 +33,7 @@ #include "cache.h" #include "cstrdup.h" #include "clip.h" +#include "clipedls.h" #include "clippopup.h" #include "cursors.h" #include "cwindowgui.h" @@ -51,12 +54,18 @@ #include "mainsession.h" #include "mwindowgui.h" #include "mwindow.h" -#include "nestededls.h" #include "newfolder.h" #include "preferences.h" +#include "proxy.h" +#include "proxypopup.h" +#include "renderengine.h" +#include "samples.h" #include "theme.h" +#include "tracks.h" +#include "transportque.h" #include "vframe.h" #include "vicon.h" +#include "vrender.h" #include "vwindowgui.h" #include "vwindow.h" @@ -97,23 +106,50 @@ AssetVIcon::~AssetVIcon() VFrame *AssetVIcon::frame() { + Asset *asset = (Asset *)picon->indexable; + if( !asset->video_data && audio_data && audio_size && length > 0 ) { + if( !temp ) temp = new VFrame(0, -1, vw, vh, BC_RGB888, -1); + temp->clear_frame(); + int sample_rate = asset->get_sample_rate(); + int64_t audio_samples = asset->get_audio_samples(); + double duration = (double)audio_samples / sample_rate; + picon->draw_hue_bar(temp, duration); + int secs = length / frame_rate + 0.5; + if( !secs ) secs = 1; + int bfrsz = VICON_SAMPLE_RATE; + int samples = audio_size/sizeof(vicon_audio_t); + double line_pos = (double)seq_no/(length-1); + int audio_pos = samples * line_pos * (secs-1)/secs; + vicon_audio_t *audio_data = ((vicon_audio_t *)this->audio_data) + audio_pos; + static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1; + double data[bfrsz], sample_scale = 1./mx; + int len = samples - audio_pos; + if( len > bfrsz ) len = bfrsz; + int i = 0; + while( i < len ) data[i++] = *audio_data++ * sample_scale; + while( i < bfrsz ) data[i++] = 0; + picon->draw_wave(temp, data, bfrsz, RED, GREEN); + int x = (vw-1) * line_pos; + temp->pixel_rgb = RED; + temp->draw_line(x,0, x,vh); + return temp; + } if( seq_no >= images.size() ) { MWindow *mwindow = picon->mwindow; - Asset *asset = (Asset *)picon->indexable; File *file = mwindow->video_cache->check_out(asset, mwindow->edl, 1); if( !file ) return 0; if( temp && (temp->get_w() != asset->width || temp->get_h() != asset->height) ) { delete temp; temp = 0; } if( !temp ) - temp = new VFrame(asset->width, asset->height, BC_RGB888, 0); + temp = new VFrame(0, -1, asset->width, asset->height, BC_RGB888, -1); int ww = picon->gui->vicon_thread->view_w; int hh = picon->gui->vicon_thread->view_h; while( seq_no >= images.size() ) { file->set_layer(0); int64_t pos = images.size() / picon->gui->vicon_thread->refresh_rate * frame_rate; file->set_video_position(pos,0); - file->read_frame(temp); + if( file->read_frame(temp) ) temp->clear_frame(); add_image(temp, ww, hh, BC_RGB8); } mwindow->video_cache->check_in(asset); @@ -138,6 +174,120 @@ int AssetVIcon::get_vy() return lbox->get_item_y(picon) + lbox->get_title_h(); } +void AssetVIcon::load_audio() +{ + MWindow *mwindow = picon->mwindow; + Asset *asset = (Asset *)picon->indexable; + File *file = mwindow->audio_cache->check_out(asset, mwindow->edl, 1); + int channels = asset->get_audio_channels(); + if( channels > 2 ) channels = 2; + int sample_rate = asset->get_sample_rate(); + int bfrsz = sample_rate; + Samples samples(bfrsz); + double time_scale = (double)sample_rate / VICON_SAMPLE_RATE; + vicon_audio_t *audio_data = (vicon_audio_t *)this->audio_data; + static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1; + double sample_scale = (double)mx / channels; + int audio_pos = 0, audio_len = audio_size/sizeof(vicon_audio_t); + while( audio_pos < audio_len ) { + int64_t pos = audio_pos * time_scale; + for( int ch=0; chset_channel(ch); + file->set_audio_position(pos); + file->read_samples(&samples, bfrsz); + double *data = samples.get_data(); + for( int64_t k=audio_pos; k= bfrsz ) break; + int v = audio_data[k] + data[i] * sample_scale; + audio_data[k] = CLIP(v, -mx,mx); + } + } + audio_pos = (pos + bfrsz) / time_scale; + } + mwindow->audio_cache->check_in(asset); +} + + +AssetVIconAudio::AssetVIconAudio(AWindowGUI *gui) + : Thread(1, 0, 0) +{ + this->gui = gui; + audio = new AudioDevice(gui->mwindow); + interrupted = 0; + vicon = 0; +} +AssetVIconAudio::~AssetVIconAudio() +{ + delete audio; +} + +void AssetVIconAudio::run() +{ + int channels = 2; + int64_t bfrsz = VICON_SAMPLE_RATE; + MWindow *mwindow = gui->mwindow; + EDL *edl = mwindow->edl; + EDLSession *session = edl->session; + AudioOutConfig *aconfig = session->playback_config->aconfig; + audio->open_output(aconfig, VICON_SAMPLE_RATE, bfrsz, channels, 0); + audio->start_playback(); + double out0[bfrsz], out1[bfrsz], *out[2] = { out0, out1 }; + vicon_audio_t *audio_data = (vicon_audio_t *)vicon->audio_data; + static const int mx = (1<<(8*sizeof(*audio_data)-1)) - 1; + + int audio_len = vicon->audio_size/sizeof(vicon_audio_t); + while( !interrupted ) { + int len = audio_len - audio_pos; + if( len <= 0 ) break; + if( len > bfrsz ) len = bfrsz; + int k = audio_pos; + for( int i=0; iwrite_buffer(out, channels, len); + } + + if( !interrupted ) + audio->set_last_buffer(); + audio->stop_audio(interrupted ? 0 : 1); + audio->close_all(); +} + +void AssetVIconAudio::start(AssetVIcon *vicon) +{ + if( running() ) return; + interrupted = 0; + audio_pos = 0; + this->vicon = vicon; + Thread::start(); +} + +void AssetVIconAudio::stop(int wait) +{ + if( running() && !interrupted ) { + interrupted = 1; + audio->stop_audio(wait); + } + Thread::join(); + if( vicon ) { + vicon->playing_audio = 0; + vicon = 0; + } +} + +void AssetVIcon::start_audio() +{ + picon->gui->vicon_audio->stop(0); + playing_audio = 1; + picon->gui->vicon_audio->start(this); +} + +void AssetVIcon::stop_audio() +{ + picon->gui->vicon_audio->stop(0); + playing_audio = 0; +} AssetPicon::AssetPicon(MWindow *mwindow, AWindowGUI *gui, Indexable *indexable) @@ -211,6 +361,52 @@ AssetPicon::~AssetPicon() } } +void AssetPicon::draw_hue_bar(VFrame *frame, double duration) +{ + float t = duration > 1 ? (log(duration) / log(3600.f)) : 0; + if( t > 1 ) t = 1; + float h = 300 * t, s = 1., v = 1.; + float r, g, b; // duration, 0..1hr == hue red..magenta + HSV::hsv_to_rgb(r,g,b, h,s,v); + int ih = frame->get_h()/8, iw = frame->get_w(); + int ir = r * 256; CLAMP(ir, 0,255); + int ig = g * 256; CLAMP(ig, 0,255); + int ib = b * 256; CLAMP(ib, 0,255); + unsigned char **rows = frame->get_rows(); + for( int y=0; yget_w(), h = frame->get_h(); + int h1 = h-1, h2 = h/2, y = h2; + int rgb_color = frame->pixel_rgb; + for( int x=0,x1=0,x2=0; x max ) max = value; + } + int ctr = (min + max) / 2; + int y0 = (int)(h2 - ctr*h2); CLAMP(y0, 0,h1); + int y1 = (int)(h2 - min*h2); CLAMP(y1, 0,h1); + int y2 = (int)(h2 - max*h2); CLAMP(y2, 0,h1); + frame->pixel_rgb = line_color; + frame->draw_line(x,y1, x,y2); + frame->pixel_rgb = base_color; + frame->draw_line(x,y, x,y0); + y = y0; + } + frame->pixel_rgb = rgb_color; +} + void AssetPicon::reset() { plugin = 0; @@ -222,10 +418,38 @@ void AssetPicon::reset() icon_vframe = 0; vicon = 0; in_use = 1; + mtime = 0; id = 0; persistent = 0; } +void AssetPicon::open_render_engine(EDL *edl, int is_audio) +{ + TransportCommand command; + command.command = is_audio ? NORMAL_FWD : CURRENT_FRAME; + command.get_edl()->copy_all(edl); + command.change_type = CHANGE_ALL; + command.realtime = 0; + render_engine = new RenderEngine(0, mwindow->preferences, 0, 0); + render_engine->set_vcache(mwindow->video_cache); + render_engine->set_acache(mwindow->audio_cache); + render_engine->arm_command(&command); +} +void AssetPicon::close_render_engine() +{ + delete render_engine; render_engine = 0; +} +void AssetPicon::render_video(int64_t pos, VFrame *vfrm) +{ + if( !render_engine || !render_engine->vrender ) return; + render_engine->vrender->process_buffer(vfrm, pos, 0); +} +void AssetPicon::render_audio(int64_t pos, Samples **samples, int len) +{ + if( !render_engine || !render_engine->arender ) return; + render_engine->arender->process_buffer(samples, len, pos); +} + void AssetPicon::create_objects() { FileSystem fs; @@ -238,6 +462,10 @@ void AssetPicon::create_objects() fs.extract_name(name, indexable->path); set_text(name); } + else if( edl ) { + set_text(strcpy(name, edl->local_session->clip_title)); + set_text(name); + } if( indexable && indexable->is_asset ) { Asset *asset = (Asset*)indexable; @@ -275,7 +503,7 @@ void AssetPicon::create_objects() file->read_frame(gui->temp_picon); mwindow->video_cache->check_in(asset); - gui->lock_window("AssetPicon::create_objects 1"); + gui->lock_window("AssetPicon::create_objects 0"); icon = new BC_Pixmap(gui, pixmap_w, pixmap_h); icon->draw_vframe(gui->temp_picon, 0, 0, pixmap_w, pixmap_h, 0, 0); @@ -291,6 +519,13 @@ void AssetPicon::create_objects() if( secs > 5 ) secs = 5; int64_t length = secs * gui->vicon_thread->refresh_rate; vicon = new AssetVIcon(this, pixmap_w, pixmap_h, framerate, length); + if( asset->audio_data && secs > 0 ) { + gui->unlock_window(); + int audio_len = VICON_SAMPLE_RATE*secs+0.5; + vicon->init_audio(audio_len*sizeof(vicon_audio_t)); + vicon->load_audio(); + gui->lock_window("AssetPicon::create_objects 1"); + } gui->vicon_thread->add_vicon(vicon); } @@ -308,10 +543,69 @@ void AssetPicon::create_objects() } else if( asset->audio_data ) { - icon = gui->audio_icon; - icon_vframe = gui->audio_vframe; - } + if( mwindow->preferences->use_thumbnails ) { + gui->unlock_window(); + File *file = mwindow->audio_cache->check_out(asset, + mwindow->edl, + 1); + if( file ) { + pixmap_w = pixmap_h * 16/9; + icon_vframe = new VFrame(0, + -1, pixmap_w, pixmap_h, BC_RGB888, -1); + icon_vframe->clear_frame(); + { char string[BCTEXTLEN]; + sprintf(string, _("Reading %s"), name); + mwindow->gui->lock_window("AssetPicon::create_objects 3"); + mwindow->gui->show_message(string); + mwindow->gui->unlock_window(); } + int sample_rate = asset->get_sample_rate(); + int channels = asset->get_audio_channels(); + if( channels > 2 ) channels = 2; + int64_t audio_samples = asset->get_audio_samples(); + double duration = (double)audio_samples / sample_rate; + draw_hue_bar(icon_vframe, duration); + int bfrsz = sample_rate; + Samples samples(bfrsz); + static int line_colors[2] = { GREEN, YELLOW }; + static int base_colors[2] = { RED, PINK }; + for( int i=channels; --i>=0; ) { + file->set_channel(i); + file->set_audio_position(0); + file->read_samples(&samples, bfrsz); + draw_wave(icon_vframe, samples.get_data(), bfrsz, + base_colors[i], line_colors[i]); + } + mwindow->audio_cache->check_in(asset); + if( asset->awindow_folder == AW_MEDIA_FOLDER ) { + double secs = duration; + if( secs > 5 ) secs = 5; + double refresh_rate = gui->vicon_thread->refresh_rate; + int64_t length = secs * refresh_rate; + vicon = new AssetVIcon(this, pixmap_w, pixmap_h, refresh_rate, length); + int audio_len = VICON_SAMPLE_RATE*secs+0.5; + vicon->init_audio(audio_len*sizeof(vicon_audio_t)); + vicon->load_audio(); + gui->vicon_thread->add_vicon(vicon); + } + gui->lock_window("AssetPicon::create_objects 4"); + icon = new BC_Pixmap(gui, pixmap_w, pixmap_h); + icon->draw_vframe(icon_vframe, + 0, 0, pixmap_w, pixmap_h, 0, 0); + } + else { + gui->lock_window("AssetPicon::create_objects 5"); + icon = gui->audio_icon; + icon_vframe = gui->audio_vframe; + } + } + else { + icon = gui->audio_icon; + icon_vframe = gui->audio_vframe; + } + } + struct stat st; + mtime = !stat(asset->path, &st) ? st.st_mtime : 0; } else if( indexable && !indexable->is_asset ) { @@ -320,13 +614,123 @@ void AssetPicon::create_objects() } else if( edl ) { - set_text(strcpy(name, edl->local_session->clip_title)); - icon = gui->clip_icon; - icon_vframe = gui->clip_vframe; + if( edl->tracks->playable_video_tracks() ) { + if( mwindow->preferences->use_thumbnails ) { + gui->unlock_window(); + char clip_icon_path[BCTEXTLEN]; + char *clip_icon = edl->local_session->clip_icon; + if( clip_icon[0] ) { + snprintf(clip_icon_path, sizeof(clip_icon_path), + "%s/%s", File::get_config_path(), clip_icon); + icon_vframe = VFramePng::vframe_png(clip_icon_path); + } + if( !icon_vframe ) { +//printf("render clip: %s\n", name); + int edl_h = edl->get_h(), edl_w = edl->get_w(); + int height = edl_h > 0 ? edl_h : 1; + int width = edl_w > 0 ? edl_w : 1; + int color_model = edl->session->color_model; + pixmap_w = pixmap_h * width / height; + + if( gui->temp_picon && + (gui->temp_picon->get_color_model() != color_model || + gui->temp_picon->get_w() != width || + gui->temp_picon->get_h() != height) ) { + delete gui->temp_picon; gui->temp_picon = 0; + } + + if( !gui->temp_picon ) { + gui->temp_picon = new VFrame(0, -1, + width, height, color_model, -1); + } + char string[BCTEXTLEN]; + sprintf(string, _("Rendering %s"), name); + mwindow->gui->lock_window("AssetPicon::create_objects"); + mwindow->gui->show_message(string); + mwindow->gui->unlock_window(); + open_render_engine(edl, 0); + render_video(0, gui->temp_picon); + close_render_engine(); + gui->lock_window("AssetPicon::create_objects 0"); + icon_vframe = new VFrame(0, + -1, pixmap_w, pixmap_h, BC_RGB888, -1); + icon_vframe->transfer_from(gui->temp_picon); + if( clip_icon[0] ) icon_vframe->write_png(clip_icon_path); + } + else { + pixmap_w = icon_vframe->get_w(); + pixmap_h = icon_vframe->get_h(); + } + icon = new BC_Pixmap(gui, pixmap_w, pixmap_h); + icon->draw_vframe(icon_vframe, + 0, 0, pixmap_w, pixmap_h, 0, 0); + } + else { + icon = gui->clip_icon; + icon_vframe = gui->clip_vframe; + } + } + else + if( edl->tracks->playable_audio_tracks() ) { + if( mwindow->preferences->use_thumbnails ) { + gui->unlock_window(); + char clip_icon_path[BCTEXTLEN]; + char *clip_icon = edl->local_session->clip_icon; + if( clip_icon[0] ) { + snprintf(clip_icon_path, sizeof(clip_icon_path), + "%s/%s", File::get_config_path(), clip_icon); + icon_vframe = VFramePng::vframe_png(clip_icon_path); + } + if( !icon_vframe ) { + pixmap_w = pixmap_h * 16/9; + icon_vframe = new VFrame(0, + -1, pixmap_w, pixmap_h, BC_RGB888, -1); + icon_vframe->clear_frame(); + char string[BCTEXTLEN]; + sprintf(string, _("Rendering %s"), name); + mwindow->gui->lock_window("AssetPicon::create_objects 3"); + mwindow->gui->show_message(string); + mwindow->gui->unlock_window(); + int sample_rate = edl->get_sample_rate(); + int channels = edl->get_audio_channels(); + if( channels > 2 ) channels = 2; + int64_t audio_samples = edl->get_audio_samples(); + double duration = (double)audio_samples / sample_rate; + draw_hue_bar(icon_vframe, duration); + Samples *samples[MAX_CHANNELS]; + int bfrsz = sample_rate; + for( int i=0; ilock_window("AssetPicon::create_objects 4"); + static int line_colors[2] = { GREEN, YELLOW }; + static int base_colors[2] = { RED, PINK }; + for( int i=channels; --i>=0; ) { + draw_wave(icon_vframe, samples[i]->get_data(), bfrsz, + base_colors[i], line_colors[i]); + } + for( int i=0; iwrite_png(clip_icon_path); + } + else { + pixmap_w = icon_vframe->get_w(); + pixmap_h = icon_vframe->get_h(); + } + icon = new BC_Pixmap(gui, pixmap_w, pixmap_h); + icon->draw_vframe(icon_vframe, + 0, 0, pixmap_w, pixmap_h, 0, 0); + } + else { + icon = gui->clip_icon; + icon_vframe = gui->clip_vframe; + } + } } else if( plugin ) { - strcpy(name, plugin->title); + strcpy(name, _(plugin->title)); set_text(name); icon_vframe = plugin->get_picon(); if( icon_vframe ) @@ -432,6 +836,7 @@ AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow) effectlist_menu = 0; assetlist_menu = 0; cliplist_menu = 0; + proxylist_menu = 0; labellist_menu = 0; folderlist_menu = 0; temp_picon = 0; @@ -439,6 +844,7 @@ AWindowGUI::AWindowGUI(MWindow *mwindow, AWindow *awindow) allow_iconlisting = 1; remove_plugin = 0; vicon_thread = 0; + vicon_audio = 0; vicon_drawing = 1; displayed_folder = AW_NO_FOLDER; } @@ -455,16 +861,9 @@ AWindowGUI::~AWindowGUI() displayed_assets[1].remove_all_objects(); delete vicon_thread; + delete vicon_audio; delete newfolder_thread; - delete asset_menu; - delete clip_menu; - delete label_menu; - delete effectlist_menu; - delete assetlist_menu; - delete cliplist_menu; - delete labellist_menu; - delete folderlist_menu; delete search_text; delete temp_picon; delete remove_plugin; @@ -625,6 +1024,7 @@ void AWindowGUI::create_objects() vicon_thread = new VIconThread(asset_list); vicon_thread->start(); + vicon_audio = new AssetVIconAudio(this); add_subwindow(divider = new AWindowDivider(mwindow, this, mwindow->theme->adivider_x, mwindow->theme->adivider_y, @@ -656,6 +1056,8 @@ void AWindowGUI::create_objects() clip_menu->create_objects(); add_subwindow(label_menu = new LabelPopup(mwindow, this)); label_menu->create_objects(); + add_subwindow(proxy_menu = new ProxyPopup(mwindow, this)); + proxy_menu->create_objects(); add_subwindow(effectlist_menu = new EffectListMenu(mwindow, this)); effectlist_menu->create_objects(); @@ -665,6 +1067,8 @@ void AWindowGUI::create_objects() cliplist_menu->create_objects(); add_subwindow(labellist_menu = new LabelListMenu(mwindow, this)); labellist_menu->create_objects(); + add_subwindow(proxylist_menu = new ProxyListMenu(mwindow, this)); + proxylist_menu->create_objects(); add_subwindow(folderlist_menu = new FolderListMenu(mwindow, this)); folderlist_menu->create_objects(); @@ -906,6 +1310,12 @@ int AWindowGUI::keypress_event() return 1; } break; + case 'o': + if( !ctrl_down() && !shift_down() ) { + assetlist_menu->load_file->handle_event(); + return 1; + } + break; case DELETE: if( shift_down() ) { PluginServer* plugin = selected_plugin(); @@ -1022,16 +1432,16 @@ void AWindowGUI::update_asset_list() } // Synchronize EDL clips - for( int i = 0; i < mwindow->edl->clips.total; i++ ) { + for( int i=0; iedl->clips.size(); ++i ) { int exists = 0; // Look for clip in existing listitems for( int j = 0; j < assets.total && !exists; j++ ) { AssetPicon *picon = (AssetPicon*)assets.values[j]; - if( picon->id == mwindow->edl->clips.values[i]->id ) { - picon->edl = mwindow->edl->clips.values[i]; - picon->set_text(mwindow->edl->clips.values[i]->local_session->clip_title); + if( picon->id == mwindow->edl->clips[i]->id ) { + picon->edl = mwindow->edl->clips[i]; + picon->set_text(mwindow->edl->clips[i]->local_session->clip_title); exists = 1; picon->in_use = 1; } @@ -1040,16 +1450,14 @@ void AWindowGUI::update_asset_list() // Create new listitem if( !exists ) { AssetPicon *picon = new AssetPicon(mwindow, - this, mwindow->edl->clips.values[i]); + this, mwindow->edl->clips[i]); picon->create_objects(); assets.append(picon); } } // Synchronize EDL assets - for( Asset *current = mwindow->edl->assets->first; - current; - current = NEXT ) { + for( Asset *current=mwindow->edl->assets->first; current; current=NEXT ) { int exists = 0; // Look for asset in existing listitems @@ -1058,9 +1466,8 @@ void AWindowGUI::update_asset_list() if( picon->id == current->id ) { picon->indexable = current; - exists = 1; picon->in_use = 1; - break; + exists = 1; } } @@ -1078,26 +1485,25 @@ void AWindowGUI::update_asset_list() mwindow->gui->unlock_window(); // Synchronize nested EDLs - for( int i = 0; i < mwindow->edl->nested_edls->size(); i++ ) { + for( int i=0; iedl->nested_edls.size(); ++i ) { int exists = 0; - Indexable *indexable = mwindow->edl->nested_edls->get(i); + EDL *nested_edl = mwindow->edl->nested_edls[i]; // Look for asset in existing listitems - for( int j = 0; j < assets.total && !exists; j++ ) { + for( int j=0; jid == indexable->id ) { - picon->indexable = indexable; - exists = 1; + if( picon->id == nested_edl->id ) { + picon->indexable = nested_edl; picon->in_use = 1; - break; + exists = 1; } } // Create new listitem if( !exists ) { AssetPicon *picon = new AssetPicon(mwindow, - this, indexable); + this, (Indexable*)nested_edl); picon->create_objects(); assets.append(picon); } @@ -1108,7 +1514,11 @@ void AWindowGUI::update_asset_list() if( !picon->in_use ) { delete picon; assets.remove_number(i); + continue; } + if( !picon->indexable || !picon->indexable->is_asset ) continue; + struct stat st; + picon->mtime = !stat(picon->indexable->path, &st) ? st.st_mtime : 0; } } @@ -1135,7 +1545,7 @@ void AWindowGUI::update_picon(Indexable *indexable) } } -void AWindowGUI::sort_assets() +void AWindowGUI::sort_assets(int use_mtime) { switch( mwindow->edl->session->awindow_folder ) { case AW_AEFFECT_FOLDER: @@ -1154,7 +1564,7 @@ void AWindowGUI::sort_assets() sort_picons(&labellist); break; default: - sort_picons(&assets); + sort_picons(&assets, use_mtime); } // reset xyposition asset_list->update_format(asset_list->get_format(), 0); @@ -1168,18 +1578,63 @@ void AWindowGUI::sort_folders() update_assets(); } -void AWindowGUI::collect_assets() +EDL *AWindowGUI::collect_proxy(Indexable *indexable) +{ + Asset *proxy_asset = (Asset *)indexable; + char path[BCTEXTLEN]; + int proxy_scale = mwindow->edl->session->proxy_scale; + ProxyRender::from_proxy_path(path, proxy_asset, proxy_scale); + Asset *unproxy_asset = mwindow->edl->assets->get_asset(path); + if( !unproxy_asset || !unproxy_asset->channels ) return 0; +// make a clip from proxy video tracks and unproxy audio tracks + EDL *proxy_edl = new EDL(mwindow->edl); + proxy_edl->create_objects(); + FileSystem fs; fs.extract_name(path, proxy_asset->path); + proxy_edl->set_path(path); + strcpy(proxy_edl->local_session->clip_title, path); + strcpy(proxy_edl->local_session->clip_notes, _("Proxy clip")); + proxy_edl->session->video_tracks = proxy_asset->layers; + proxy_edl->session->audio_tracks = unproxy_asset->channels; + proxy_edl->create_default_tracks(); + double length = proxy_asset->frame_rate > 0 ? + (double)proxy_asset->video_length / proxy_asset->frame_rate : + 1.0 / mwindow->edl->session->frame_rate; + Track *current = proxy_edl->tracks->first; + for( int vtrack=0; current; current=NEXT ) { + if( current->data_type != TRACK_VIDEO ) continue; + current->insert_asset(proxy_asset, 0, length, 0, vtrack++); + } + length = (double)unproxy_asset->audio_length / unproxy_asset->sample_rate; + current = proxy_edl->tracks->first; + for( int atrack=0; current; current=NEXT ) { + if( current->data_type != TRACK_AUDIO ) continue; + current->insert_asset(unproxy_asset, 0, length, 0, atrack++); + } + return proxy_edl; +} + + +void AWindowGUI::collect_assets(int proxy) { - int i = 0; mwindow->session->drag_assets->remove_all(); mwindow->session->drag_clips->remove_all(); - while(1) - { - AssetPicon *result = (AssetPicon*)asset_list->get_selection(0, i++); - if( !result ) break; - - if( result->indexable ) mwindow->session->drag_assets->append(result->indexable); - if( result->edl ) mwindow->session->drag_clips->append(result->edl); + mwindow->session->clear_drag_proxy(); + int i = 0; AssetPicon *result; + while( (result = (AssetPicon*)asset_list->get_selection(0, i++)) != 0 ) { + Indexable *indexable = result->indexable; EDL *drag_edl; + if( proxy && (drag_edl=collect_proxy(indexable)) ) { + mwindow->session->drag_clips->append(drag_edl); + mwindow->session->drag_proxy->append(drag_edl); + continue; + } + if( indexable ) { + mwindow->session->drag_assets->append(indexable); + continue; + } + if( result->edl ) { + mwindow->session->drag_clips->append(result->edl); + continue; + } } } @@ -1207,6 +1662,14 @@ void AWindowGUI::copy_picons(ArrayList *dst, else if( picon->label && picon->label->textstr ) dst[1].append(item2 = new BC_ListBoxItem(picon->label->textstr)); + else if( picon->mtime ) { + char date_time[BCSTRLEN]; + struct tm stm; localtime_r(&picon->mtime, &stm); + sprintf(date_time,"%04d.%02d.%02d %02d:%02d:%02d", + stm.tm_year+1900, stm.tm_mon+1, stm.tm_mday, + stm.tm_hour, stm.tm_min, stm.tm_sec); + dst[1].append(item2 = new BC_ListBoxItem(date_time)); + } else dst[1].append(item2 = new BC_ListBoxItem("")); item1->set_autoplace_text(1); item1->set_autoplace_icon(1); @@ -1215,26 +1678,29 @@ void AWindowGUI::copy_picons(ArrayList *dst, } } -void AWindowGUI::sort_picons(ArrayList *src) +void AWindowGUI::sort_picons(ArrayList *src, int use_mtime) { - int done = 0; - while(!done) - { + int done = 0, changed = 0; + while( !done ) { done = 1; - for( int i = 0; i < src->total - 1; i++ ) { - BC_ListBoxItem *item1 = src->values[i]; - BC_ListBoxItem *item2 = src->values[i + 1]; - item1->set_autoplace_icon(1); - item2->set_autoplace_icon(1); - item1->set_autoplace_text(1); - item2->set_autoplace_text(1); - if( strcmp(item1->get_text(), item2->get_text()) > 0 ) { + for( int i=0; itotal-1; ++i ) { + AssetPicon *item1 = (AssetPicon *)src->values[i]; + AssetPicon *item2 = (AssetPicon *)src->values[i + 1]; + if( use_mtime ? item1->mtime > item2->mtime : + strcmp(item1->get_text(), item2->get_text()) > 0 ) { src->values[i + 1] = item1; src->values[i] = item2; - done = 0; + done = 0; changed = 1; } } } + if( changed ) { + for( int i=0; itotal; ++i ) { + AssetPicon *item = (AssetPicon *)src->values[i]; + item->set_autoplace_icon(1); + item->set_autoplace_text(1); + } + } } @@ -1347,7 +1813,6 @@ int AWindowGUI::drag_motion() int AWindowGUI::drag_stop() { if( get_hidden() ) return 0; - return 0; } @@ -1541,9 +2006,12 @@ int AWindowAssets::button_press_event() gui->cliplist_menu->update(); gui->cliplist_menu->activate_menu(); break; - case AW_MEDIA_FOLDER: case AW_PROXY_FOLDER: - gui->assetlist_menu->update_titles(); + gui->proxylist_menu->update(); + gui->proxylist_menu->activate_menu(); + break; + case AW_MEDIA_FOLDER: + gui->assetlist_menu->update_titles(folder==AW_MEDIA_FOLDER); gui->assetlist_menu->activate_menu(); break; } @@ -1568,12 +2036,10 @@ int AWindowAssets::handle_event() mwindow->vwindows.get(DEFAULT_VWINDOW) : 0; if( !vwindow || !vwindow->is_running() ) return 1; - vwindow->gui->lock_window("AWindowAssets::handle_event"); if( asset_picon->indexable ) vwindow->change_source(asset_picon->indexable); else if( asset_picon->edl ) vwindow->change_source(asset_picon->edl); - vwindow->gui->unlock_window(); return 1; } @@ -1601,6 +2067,11 @@ int AWindowAssets::selection_changed() gui->clip_menu->update(); gui->clip_menu->activate_menu(); break; + case AW_PROXY_FOLDER: + if( !item->indexable && !item->edl ) break; + gui->proxy_menu->update(); + gui->proxy_menu->activate_menu(); + break; default: if( !item->indexable && !item->edl ) break; gui->asset_menu->update(); @@ -1611,7 +2082,8 @@ int AWindowAssets::selection_changed() BC_ListBox::deactivate_selection(); return 1; } - else if( get_button_down() && get_buttonpress() == 1 && + else if( gui->vicon_drawing && + get_button_down() && get_buttonpress() == 1 && (item = (AssetPicon*)get_selection(0, 0)) ) { VIcon *vicon = 0; if( !gui->vicon_thread->viewing ) { @@ -1638,7 +2110,7 @@ void AWindowAssets::draw_background() int AWindowAssets::drag_start_event() { int collect_pluginservers = 0; - int collect_assets = 0; + int collect_assets = 0, proxy = 0; if( BC_ListBox::drag_start_event() ) { switch( mwindow->edl->session->awindow_folder ) { @@ -1661,6 +2133,10 @@ int AWindowAssets::drag_start_event() case AW_LABEL_FOLDER: // do nothing! break; + case AW_PROXY_FOLDER: + proxy = 1; + // fall thru + case AW_MEDIA_FOLDER: default: mwindow->session->current_operation = DRAG_ASSET; collect_assets = 1; @@ -1680,7 +2156,7 @@ int AWindowAssets::drag_start_event() } if( collect_assets ) { - gui->collect_assets(); + gui->collect_assets(proxy); } return 1; @@ -1756,6 +2232,8 @@ int AWindowAssets::drag_stop_event() BC_ListBox::drag_stop_event(); // since NO_OPERATION is also defined in listbox, we have to reach for global scope... mwindow->session->current_operation = ::NO_OPERATION; + mwindow->session->clear_drag_proxy(); + return 1; } @@ -2122,7 +2600,7 @@ AWindowListSort::AWindowListSort(MWindow *mwindow, AWindowGUI *gui) int AWindowListSort::handle_event() { - gui->sort_assets(); + gui->sort_assets(0); return 1; }