opencv lib path fix, ub18 fixes
[goodguy/history.git] / cinelerra-5.1 / cinelerra / awindowgui.C
index 688869130b686fecd21c32db35dc2897ac9d2119..f33b9cbc1eb3f96eecdb44677167f7904aaa55da 100644 (file)
@@ -19,6 +19,7 @@
  *
  */
 
+#include "arender.h"
 #include "asset.h"
 #include "assetedit.h"
 #include "assetpopup.h"
@@ -32,6 +33,7 @@
 #include "cache.h"
 #include "cstrdup.h"
 #include "clip.h"
+#include "clipedls.h"
 #include "clippopup.h"
 #include "cursors.h"
 #include "cwindowgui.h"
 #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"
 
@@ -416,6 +423,33 @@ void AssetPicon::reset()
        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;
@@ -428,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;
@@ -514,6 +552,7 @@ void AssetPicon::create_objects()
                                        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");
@@ -575,9 +614,119 @@ 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; i<MAX_CHANNELS; ++i )
+                                               samples[i] = i<channels ? new Samples(bfrsz) : 0;
+                                       open_render_engine(edl, 1);
+                                       render_audio(0, samples, bfrsz);
+                                       close_render_engine();
+                                       gui->lock_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; i<channels; ++i ) delete samples[i];
+                                       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( plugin ) {
@@ -687,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;
@@ -714,14 +864,6 @@ AWindowGUI::~AWindowGUI()
        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;
@@ -914,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();
@@ -923,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();
@@ -1164,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();
@@ -1280,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; i<mwindow->edl->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;
                        }
@@ -1298,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
@@ -1316,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;
                        }
                }
 
@@ -1336,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; i<mwindow->edl->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; j<assets.total && !exists; ++j ) {
                        AssetPicon *picon = (AssetPicon*)assets.values[j];
 
-                       if( picon->id == 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);
                }
@@ -1430,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;
+               }
        }
 }
 
@@ -1620,7 +1813,6 @@ int AWindowGUI::drag_motion()
 int AWindowGUI::drag_stop()
 {
        if( get_hidden() ) return 0;
-
        return 0;
 }
 
@@ -1814,8 +2006,11 @@ int AWindowAssets::button_press_event()
                        gui->cliplist_menu->update();
                        gui->cliplist_menu->activate_menu();
                        break;
-               case AW_MEDIA_FOLDER:
                case AW_PROXY_FOLDER:
+                       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;
@@ -1872,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();
@@ -1910,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 ) {
@@ -1933,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;
@@ -1952,7 +2156,7 @@ int AWindowAssets::drag_start_event()
                }
 
                if( collect_assets ) {
-                       gui->collect_assets();
+                       gui->collect_assets(proxy);
                }
 
                return 1;
@@ -2028,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;
 }