add haupauge-1657 dual usb capture support, add deinterlace to recordmonitor, asset...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mwindow.C
index 546444fe2bbd6b053ca1450298e2e4fc3ecdd9ad..39c996433da4473abcbfeea39961dcfe64d6dc64 100644 (file)
@@ -27,6 +27,7 @@
 #include "awindowgui.h"
 #include "awindow.h"
 #include "batchrender.h"
+#include "bccmodels.h"
 #include "bcdisplayinfo.h"
 #include "bcprogressbox.h"
 #include "bcsignals.h"
@@ -40,9 +41,9 @@
 #include "channelinfo.h"
 #include "clip.h"
 #include "clipedls.h"
-#include "bccmodels.h"
 #include "commercials.h"
 #include "confirmsave.h"
+#include "convert.h"
 #include "cplayback.h"
 #include "ctimebar.h"
 #include "cwindowgui.h"
@@ -179,7 +180,6 @@ extern "C"
 
 }
 
-
 extern long cin_timezone;
 
 ArrayList<PluginServer*>* MWindow::plugindb = 0;
@@ -225,6 +225,7 @@ MWindow::MWindow()
        create_bd = 0;
        create_dvd = 0;
        batch_render = 0;
+       convert_render = 0;
        render = 0;
        edl = 0;
        gui = 0;
@@ -265,6 +266,7 @@ MWindow::~MWindow()
        delete create_dvd;      create_dvd = 0;
        delete shuttle;         shuttle = 0;
        delete batch_render;    batch_render = 0;
+       delete convert_render;  convert_render = 0;
        delete render;          render = 0;
        delete mixers_align;    mixers_align = 0;
        commit_commercial();
@@ -361,7 +363,6 @@ MWindow::~MWindow()
        colormodels.remove_all_objects();
        interlace_project_modes.remove_all_objects();
        interlace_asset_modes.remove_all_objects();
-       interlace_asset_fixmethods.remove_all_objects();
        sighandler->terminate();
        delete sighandler;
        delete run_lock;
@@ -939,14 +940,7 @@ void MWindow::init_preferences()
 {
        preferences = new Preferences;
        preferences->load_defaults(defaults);
-       const char *lv2_path = getenv("LV2_PATH");
-       if( lv2_path && strcmp(lv2_path, preferences->lv2_path) ) {
-               strncpy(preferences->lv2_path, lv2_path, sizeof(preferences->lv2_path));
-               remove_plugin_index();
-       }
-       else if( !lv2_path && preferences->lv2_path[0] ) {
-               File::setenv_path("LV2_PATH",preferences->lv2_path, 0);
-       }
+       File::setenv_path("LV2_PATH",preferences->lv2_path, 1);
        session = new MainSession(this);
        session->load_defaults(defaults);
        // set x11_host, screens, window_config
@@ -1189,8 +1183,12 @@ ZWindow *MWindow::get_mixer(Mixer *&mixer)
        zwindows_lock->lock("MWindow::get_mixer");
        if( !mixer ) mixer = edl->mixers.new_mixer();
        ZWindow *zwindow = 0;
-       for( int i=0; !zwindow && i<zwindows.size(); ++i )
-               if( zwindows[i]->idx < 0 ) zwindow = zwindows[i];
+       for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
+               ZWindow *zwdw = zwindows[i];
+               if( zwdw->running() ) continue;
+               if( zwdw->idx >= 0 ) continue;
+               zwindow = zwindows[i];
+       }
        if( !zwindow )
                zwindows.append(zwindow = new ZWindow(this));
        zwindow->idx = mixer->idx;
@@ -1313,17 +1311,17 @@ void MWindow::stop_mixers()
        }
 }
 
-void MWindow::close_mixers(int destroy)
+void MWindow::close_mixers(int result)
 {
        ArrayList<ZWindow*> closed;
        zwindows_lock->lock("MWindow::close_mixers");
        for( int i=zwindows.size(); --i>=0; ) {
                ZWindow *zwindow = zwindows[i];
                if( zwindow->idx < 0 ) continue;
-               zwindow->destroy = destroy;
+               zwindow->idx = -1;
                ZWindowGUI *zgui = zwindow->zgui;
                zgui->lock_window("MWindow::select_zwindow 0");
-               zgui->set_done(0);
+               zgui->set_done(result);
                zgui->unlock_window();
                closed.append(zwindow);
        }
@@ -1339,7 +1337,7 @@ ZWindow *MWindow::create_mixer(Indexable *indexable, double position)
        ArrayList<Indexable*> new_assets;
        new_assets.append(indexable);
        Track *track = edl->tracks->last;
-       load_assets(&new_assets, position, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
+       load_assets(&new_assets, position, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 1);
        track = !track ? edl->tracks->first : track->next;
        Mixer *mixer = 0;
        ZWindow *zwindow = get_mixer(mixer);
@@ -1456,7 +1454,7 @@ void MWindow::tile_mixers()
        int bw = lt + BC_DisplayInfo::get_right_border();  // borders
        int bh = top + BC_DisplayInfo::get_bottom_border();
        int zx = 0, zy = 0;  // window origins
-       int mw = 10+10, mh = 10+10; // canvas margins
+       int mw = xS(10+10), mh = yS(10+10); // canvas margins
        int rsz = 0, n = 0, dz = 0;
        int ow = edl->session->output_w, oh = edl->session->output_h;
        for( int i=0; i<zwindows.size(); ++i ) {
@@ -1468,7 +1466,7 @@ void MWindow::tile_mixers()
                int mx = x2 - zw, my = y2 - zh;
                if( xx > mx ) xx = mx;
                if( yy > my ) yy = my;
-               xx += lt + dz;  yy += top + dz;
+               xx += lt + xS(dz);  yy += top + yS(dz);
                zwindow->reposition(xx,yy, ww,hh);
                if( zwindow->running() ) {
                        ZWindowGUI *gui = (ZWindowGUI *)zwindow->get_gui();
@@ -1533,9 +1531,6 @@ void MWindow::init_menus()
 #define ILACEASSETMODELISTADD(x) ilacemode_to_text(string, x); \
                            interlace_asset_modes.append(new InterlacemodeItem(string, x));
 
-#define ILACEFIXMETHODLISTADD(x) ilacefixmethod_to_text(string, x); \
-                           interlace_asset_fixmethods.append(new InterlacefixmethodItem(string, x));
-
        // Interlacing Modes
        ILACEASSETMODELISTADD(ILACE_MODE_UNDETECTED); // Not included in the list for the project options.
 
@@ -1548,11 +1543,6 @@ void MWindow::init_menus()
        ILACEASSETMODELISTADD(ILACE_MODE_NOTINTERLACED);
        ILACEPROJECTMODELISTADD(ILACE_MODE_NOTINTERLACED);
 
-       // Interlacing Fixing Methods
-       ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
-       ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
-       ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
-
        mixers_align = new MixersAlign(this);
 }
 
@@ -2201,6 +2191,8 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
                edl->local_session->loop_playback = 0;
                edl->local_session->set_selectionstart(0);
                edl->local_session->set_selectionend(0);
+               edl->local_session->unset_inpoint();
+               edl->local_session-> unset_outpoint();
                set_brender_active(0, 0);
                fit_selection();
                goto_start();
@@ -2284,9 +2276,8 @@ int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
        Asset *format_asset = new Asset;
        format_asset->format = FILE_FFMPEG;
        format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0);
-       ProxyRender proxy_render(this, format_asset);
        int new_scale = edl->session->proxy_scale;
-       int use_scaler = edl->session->proxy_use_scaler;
+       ProxyRender proxy_render(this, format_asset, new_scale);
 
        for( int i=0; i<new_idxbls.size(); ++i ) {
                Indexable *orig = new_idxbls.get(i);
@@ -2303,8 +2294,7 @@ int MWindow::render_proxy(ArrayList<Indexable *> &new_idxbls)
 // render needed proxies
        int result = proxy_render.create_needed_proxies(new_scale);
        if( !result ) {
-               add_proxy(use_scaler,
-                       &proxy_render.orig_idxbls, &proxy_render.orig_proxies);
+               add_proxy(&proxy_render.orig_idxbls, &proxy_render.orig_proxies);
        }
        format_asset->remove_user();
        return !result ? proxy_render.needed_proxies.size() : -1;
@@ -2353,7 +2343,9 @@ int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
        edl->Garbage::add_user();
        save_backup();
        undo_before(_("proxy"), this);
-       ProxyRender proxy_render(this, asset);
+       int asset_scale = new_scale == 1 ? 0 :
+                       !new_use_scaler ? 1 : new_scale;
+       ProxyRender proxy_render(this, asset, asset_scale);
 
 // revert project to original size from current size
 // remove all session proxy assets at the at the current proxy_scale
@@ -2644,7 +2636,7 @@ void MWindow::create_objects(int want_gui,
 
        if(debug) printf("MWindow::create_objects %d total_time=%d\n", __LINE__, (int)timer.get_difference());
 
-       plugin_guis = new ArrayList<PluginServer*>;
+       plugin_guis = new PluginGUIs(this);
        dead_plugins = new ArrayList<PluginServer*>;
        keyframe_threads = new ArrayList<KeyFrameThread*>;
 
@@ -2718,7 +2710,9 @@ void MWindow::create_objects(int want_gui,
        gui->show_window();
        gui->raise_window();
        gui->unlock_window();
-
+       cwindow->gui->lock_window("MWindow::create_objects 1");
+       cwindow->gui->tool_panel->raise_tool();
+       cwindow->gui->unlock_window();
        if(debug) PRINT_TRACE
 
        if(preferences->use_tipwindow)
@@ -2737,6 +2731,12 @@ void MWindow::create_objects(int want_gui,
        BC_WindowBase::get_resources()->vframe_shm = 1;
 }
 
+int MWindow::uses_opengl()
+{
+       if( !playback_3d || !playback_3d->running() ) return 0;
+       PlaybackConfig *playback_config = edl->session->playback_config;
+       return playback_config->vconfig->driver == PLAYBACK_X11_GL ? 1 : 0;
+}
 
 void MWindow::show_splash()
 {
@@ -2990,6 +2990,17 @@ void MWindow::set_auto_keyframes(int value)
        cwindow->gui->unlock_window();
 }
 
+void MWindow::set_span_keyframes(int value)
+{
+       edl->session->span_keyframes = value;
+       gui->mbuttons->edit_panel->span_keyframe->update(value);
+       gui->flush();
+       cwindow->gui->lock_window("MWindow::set_span_keyframes");
+       cwindow->gui->edit_panel->span_keyframe->update(value);
+       cwindow->gui->flush();
+       cwindow->gui->unlock_window();
+}
+
 void MWindow::set_auto_visibility(Autos *autos, int value)
 {
        if( autos->type == Autos::AUTOMATION_TYPE_PLUGIN )
@@ -3161,9 +3172,6 @@ void MWindow::show_keyframe_gui(Plugin *plugin)
 }
 
 
-
-
-
 void MWindow::show_plugin(Plugin *plugin)
 {
        int done = 0;
@@ -3213,6 +3221,8 @@ SET_TRACE
                }
        }
        plugin_gui_lock->unlock();
+// update show/gui_id
+       sync_parameters(CHANGE_PARAMS);
 //printf("MWindow::show_plugin %d\n", __LINE__);
 SET_TRACE
 //sleep(1);
@@ -3244,6 +3254,8 @@ void MWindow::hide_plugin(Plugin *plugin, int lock)
                }
        }
        if(lock) plugin_gui_lock->unlock();
+// update show/gui_id
+       sync_parameters(CHANGE_PARAMS);
 }
 
 void MWindow::delete_plugin(PluginServer *plugin)
@@ -3419,7 +3431,6 @@ void MWindow::update_plugin_guis(int do_keyframe_guis)
                                }
 
                                if(!got_it) plugin->show = 0;
-
                                plugin = (Plugin*)plugin->next;
                        }
                }
@@ -3433,50 +3444,85 @@ void MWindow::update_plugin_guis(int do_keyframe_guis)
        if(do_keyframe_guis) update_keyframe_guis();
 }
 
-int MWindow::plugin_gui_open(Plugin *plugin)
+void MWindow::stop_plugin_guis()
 {
-       int result = 0;
-       plugin_gui_lock->lock("MWindow::plugin_gui_open");
-       for(int i = 0; i < plugin_guis->total; i++)
-       {
-               if(plugin_guis->get(i)->plugin->identical_location(plugin))
-               {
-                       result = 1;
-                       break;
+// Send new configuration to plugin GUI's
+       plugin_gui_lock->lock("MWindow::stop_plugin_guis");
+
+       for( int i=0; i<plugin_guis->size(); ++i ) {
+               PluginServer *ptr = plugin_guis->get(i);
+               if( edl->tracks->plugin_exists(ptr->plugin) ) {
+                       ptr->render_stop();
                }
        }
+       plugin_gui_lock->unlock(); 
+}
+
+int MWindow::plugin_gui_open(Plugin *plugin)
+{
+       int gui_id = plugin->gui_id;
+       if( gui_id < 0 ) return 0;
+       plugin_gui_lock->lock("MWindow::plugin_gui_open");
+       PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
+       int result = plugin_server ? 1 : 0;
        plugin_gui_lock->unlock();
        return result;
 }
 
+
 void MWindow::render_plugin_gui(void *data, Plugin *plugin)
 {
-       plugin_gui_lock->lock("MWindow::render_plugin_gui");
-       for(int i = 0; i < plugin_guis->total; i++)
-       {
-               if(plugin_guis->get(i)->plugin->identical_location(plugin))
-               {
-                       plugin_guis->get(i)->render_gui(data);
-                       break;
-               }
-       }
+       int gui_id = plugin->gui_id;
+       if( gui_id < 0 ) return;
+       plugin_gui_lock->lock("MWindow::render_plugin_gui 0");
+       PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
+       if( plugin_server )
+               plugin_server->render_gui(data);
        plugin_gui_lock->unlock();
 }
 
 void MWindow::render_plugin_gui(void *data, int size, Plugin *plugin)
 {
-       plugin_gui_lock->lock("MWindow::render_plugin_gui");
-       for(int i = 0; i < plugin_guis->total; i++)
-       {
-               if(plugin_guis->get(i)->plugin->identical_location(plugin))
-               {
-                       plugin_guis->get(i)->render_gui(data, size);
-                       break;
-               }
-       }
+       int gui_id = plugin->gui_id;
+       if( gui_id < 0 ) return;
+       plugin_gui_lock->lock("MWindow::render_plugin_gui 1");
+       PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
+       if( plugin_server )
+               plugin_server->render_gui(data, size);
        plugin_gui_lock->unlock();
 }
 
+void MWindow::reset_plugin_gui_frames(Plugin *plugin)
+{
+       int gui_id = plugin->gui_id;
+       if( gui_id < 0 ) return;
+       plugin_gui_lock->lock("MWindow::reset_plugin_gui_frames");
+       PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
+       if( plugin_server )
+               plugin_server->reset_plugin_gui_frames();
+       plugin_gui_lock->unlock();
+}
+
+void MWindow::render_plugin_gui_frames(PluginClientFrames *frames, Plugin *plugin)
+{
+       int gui_id = plugin->gui_id;
+       if( gui_id < 0 ) return;
+       plugin_gui_lock->lock("MWindow::render_plugin_gui_frames");
+       PluginServer *plugin_server = plugin_guis->gui_server(gui_id);
+       if( plugin_server )
+               plugin_server->render_plugin_gui_frames(frames);
+       plugin_gui_lock->unlock();
+}
+
+double MWindow::get_tracking_position()
+{
+       return edl->local_session->get_selectionstart(1);
+}
+
+int MWindow::get_tracking_direction()
+{
+       return cwindow->playback_engine->get_direction();
+}
 
 void MWindow::update_plugin_states()
 {
@@ -3596,6 +3642,7 @@ if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
 //printf("MWindow::asset_to_edl 4 %s\n", string);
 if(debug) printf("MWindow::asset_to_edl %d\n", __LINE__);
 
+       new_edl->local_session->asset2edl = 1;
        return 0;
 }
 
@@ -3623,9 +3670,7 @@ void MWindow::update_project(int load_mode)
        gui->unlock_window();
        init_brender();
 
-       cwindow->gui->lock_window("MWindow::update_project 1");
        cwindow->update(0, 0, 1, 1, 1);
-       cwindow->gui->unlock_window();
 
        if(debug) PRINT_TRACE
 
@@ -3662,12 +3707,17 @@ void MWindow::update_project(int load_mode)
                        zwindow->set_title(mixer->title);
                        zwindow->start();
                }
+               cwindow->gui->canvas->set_zoom(edl, 0);
        }
        update_vwindow();
 
        if(debug) PRINT_TRACE
        cwindow->gui->lock_window("MWindow::update_project 2");
        cwindow->gui->timebar->update(0);
+       Track *track = cwindow->calculate_affected_track();
+       cwindow->mask_track_id = track ? track->get_id() : -1;
+       cwindow->gui->tool_panel->raise_tool();
+       cwindow->gui->update_canvas(0);
        cwindow->gui->unlock_window();
 
        if(debug) PRINT_TRACE
@@ -3682,6 +3732,145 @@ void MWindow::update_project(int load_mode)
        if(debug) PRINT_TRACE
 }
 
+void MWindow::stack_push(EDL *new_edl)
+{
+// needs gui lock
+       gui->lock_window("MWindow::stack_push");
+       if( stack.size() < 9 ) {
+               undo_before();
+               StackItem &item = stack.append();
+               item.edl = edl;
+               item.new_edl = new_edl;
+               item.undo = undo;
+               edl = new_edl;
+               edl->add_user();
+               strcpy(session->filename, edl->path);
+               undo = new MainUndo(this);
+               gui->stack_button->update();
+               update_project(LOADMODE_REPLACE);
+       }
+       gui->unlock_window();
+}
+
+void MWindow::stack_pop()
+{
+       if( !stack.size() ) return;
+// writes on config_path/backup%d.xml
+       save_backup();
+// already have gui lock
+       forget_nested_edl(edl);
+       StackItem &item = stack.last();
+// session edl replaced, overwrite and save clip data
+       if( item.new_edl != edl )
+               item.new_edl->overwrite_clip(edl);
+       edl->remove_user();
+       edl = item.edl;
+       delete undo;
+       undo = item.undo;
+       stack.remove();
+       strcpy(session->filename, edl->path);
+       update_project(LOADMODE_REPLACE);
+       undo_after(_("open edl"), LOAD_ALL);
+       gui->stack_button->update();
+}
+
+void MWindow::forget_nested_edl(EDL *nested)
+{
+       frame_cache->remove_item(nested);
+       wave_cache->remove_item(nested);
+       if( gui->render_engine &&
+           gui->render_engine_id == nested->id ) {
+               delete gui->render_engine;
+               gui->render_engine = 0;
+       }
+       if( gui->resource_thread->render_engine_id == nested->id ) {
+               gui->resource_thread->render_engine_id = -1;
+               delete gui->resource_thread->render_engine;
+               gui->resource_thread->render_engine = 0;
+       }
+}
+
+void MWindow::clip_to_media()
+{
+       if( edl->session->proxy_scale != 1 ) {
+               eprintf("Nesting not allowed when proxy scale != 1");
+               return;
+       }
+       undo_before();
+       int clips_total = session->drag_clips->total;
+       for( int i=0; i<clips_total; ++i ) {
+               EDL *clip = session->drag_clips->values[i];
+               time_t dt;      time(&dt);
+               struct tm dtm;  localtime_r(&dt, &dtm);
+               char path[BCTEXTLEN], *cp = path, *ep = cp+sizeof(path)-1;
+// path_basename = "Nested_<date>-<time>_<basename>"
+               cp += snprintf(cp, ep-cp, _("Nested_%02d%02d%02d-%02d%02d%02d_"),
+                       dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
+                       dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
+               char *bp = strrchr(clip->local_session->clip_title, '/');
+               bp = bp ? bp+1 : clip->local_session->clip_title;
+               cp += snprintf(cp, ep-cp, "%s", bp);
+               EDL *nested = edl->new_nested_edl(clip, path);
+               edl->clips.remove(clip);
+               clip->remove_user();
+               mainindexes->add_next_asset(0, nested);
+       }
+       undo_after(_("clip2media"), LOAD_ALL);
+       mainindexes->start_build();
+       awindow->gui->async_update_assets();
+}
+
+void MWindow::media_to_clip()
+{
+       undo_before();
+       int assets_total = session->drag_assets->total;
+       for( int i=0; i<assets_total; ++i ) {
+               Indexable *idxbl = session->drag_assets->values[i];
+               if( idxbl->is_asset ) {
+                       eprintf(_("media is not EDL:\n%s"), idxbl->path);
+                       continue;
+               }
+               char clip_title[BCSTRLEN];
+               int name_ok = 0;
+               while( !name_ok ) {
+                       name_ok = 1;
+                       sprintf(clip_title, _("Clip %d"), session->clip_number++);
+                       for( int i=0; name_ok && i<edl->clips.size(); ++i ) {
+                               char *title = edl->clips[i]->local_session->clip_title;
+                               if( !strcasecmp(clip_title, title) ) name_ok = 0;
+                       }
+               }
+               EDL *nested = (EDL *)idxbl;
+               EDL *clip = edl->add_clip(nested);
+               strcpy(clip->local_session->clip_title, clip_title);
+               snprintf(clip->local_session->clip_notes,
+                       sizeof(clip->local_session->clip_notes),
+                       _("From: %s"), nested->path);
+       }
+       undo_after(_("media2clip"), LOAD_ALL);
+       awindow->gui->async_update_assets();
+}
+
+void MWindow::update_preferences(Preferences *prefs)
+{
+       if( prefs != preferences )
+               preferences->copy_from(prefs);
+       if( cwindow->playback_engine )
+               cwindow->playback_engine->preferences->copy_from(prefs);
+       for(int i = 0; i < vwindows.size(); i++) {
+               VWindow *vwindow = vwindows[i];
+               if( !vwindow->is_running() ) continue;
+               if( vwindow->playback_engine )
+                       vwindow->playback_engine->preferences->copy_from(prefs);
+       }
+       for(int i = 0; i < zwindows.size(); i++) {
+               ZWindow *zwindow = zwindows[i];
+               if( !zwindow->is_running() ) continue;
+               if( zwindow->zgui->playback_engine )
+                       zwindow->zgui->playback_engine->preferences->copy_from(prefs);
+       }
+}
+
 void MWindow::update_vwindow()
 {
        for( int i=0; i<vwindows.size(); ++i ) {
@@ -3712,8 +3901,9 @@ void MWindow::rebuild_indices()
 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
                remove_indexfile(indexable);
 // Schedule index build
-               IndexState *index_state = indexable->index_state;
-               index_state->index_status = INDEX_NOTTESTED;
+               indexable->index_state->remove_user();
+               indexable->index_state = new IndexState;
+               IndexFile::delete_index_files(preferences, indexable);
                if( indexable->is_asset ) {
                        Asset *asset = (Asset *)indexable;
                        if( asset->format != FILE_PCM ) {
@@ -3727,28 +3917,36 @@ void MWindow::rebuild_indices()
                }
                mainindexes->add_next_asset(0, indexable);
        }
+// still in render engine
+       sync_parameters(CHANGE_ALL);
+       awindow->gui->async_update_assets();
        mainindexes->start_build();
 }
 
 
+void MWindow::get_backup_path(char *path, int len)
+{
+       char *cp = path, *ep = cp + len-1;
+       cp += snprintf(cp, ep-cp, "%s/", File::get_config_path());
+       int idx = stack.size();
+       cp += snprintf(cp, ep-cp, idx ? BACKUPn_FILE : BACKUP_FILE, idx);
+}
+
 void MWindow::save_backup()
 {
        FileXML file;
        edl->optimize();
        edl->set_path(session->filename);
+
        char backup_path[BCTEXTLEN], backup_path1[BCTEXTLEN];
-       snprintf(backup_path, sizeof(backup_path), "%s/%s",
-               File::get_config_path(), BACKUP_FILE);
-       snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
-               File::get_config_path(), BACKUP_FILE1);
+       get_backup_path(backup_path, sizeof(backup_path));
        rename(backup_path, backup_path1);
        edl->save_xml(&file, backup_path);
        file.terminate_string();
        FileSystem fs;
        fs.complete_path(backup_path);
 
-       if(file.write_to_file(backup_path))
-       {
+       if(file.write_to_file(backup_path)) {
                char string2[256];
                sprintf(string2, _("Couldn't open %s for writing."), backup_path);
                gui->show_message(string2);
@@ -3761,8 +3959,7 @@ void MWindow::load_backup()
        path_list.set_array_delete();
        char *out_path;
        char backup_path[BCTEXTLEN];
-       snprintf(backup_path, sizeof(backup_path), "%s/%s",
-               File::get_config_path(), BACKUP_FILE);
+       get_backup_path(backup_path, sizeof(backup_path));
        FileSystem fs;
        fs.complete_path(backup_path);
 
@@ -4072,47 +4269,60 @@ void MWindow::remove_asset_from_caches(Asset *asset)
                if( vwindow->playback_engine->video_cache )
                        vwindow->playback_engine->video_cache->delete_entry(asset);
        }
+       for(int i = 0; i < zwindows.size(); i++) {
+               ZWindow *zwindow = zwindows[i];
+               if( !zwindow->is_running() ) continue;
+               if( zwindow->zgui->playback_engine->audio_cache )
+                       zwindow->zgui->playback_engine->audio_cache->delete_entry(asset);
+               if( zwindow->zgui->playback_engine->video_cache )
+                       zwindow->zgui->playback_engine->video_cache->delete_entry(asset);
+       }
 }
 
-
-void MWindow::remove_assets_from_project(int push_undo, int redraw,
+void MWindow::remove_assets_from_project(int push_undo, int redraw, int delete_indexes,
                ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
 {
        awindow->gui->close_view_popup();
 
-       for(int i = 0; i < drag_assets->total; i++) {
-               Indexable *indexable = drag_assets->get(i);
-               if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
-       }
-
 // Remove from VWindow.
-       for(int i = 0; i < session->drag_clips->total; i++) {
-               for(int j = 0; j < vwindows.size(); j++) {
-                       VWindow *vwindow = vwindows[j];
-                       if( !vwindow->is_running() ) continue;
-                       if(session->drag_clips->get(i) == vwindow->get_edl()) {
-                               vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
-                               vwindow->delete_source(1, 1);
-                               vwindow->gui->unlock_window();
+       if( drag_clips ) {
+               for(int i = 0; i < drag_clips->total; i++) {
+                       for(int j = 0; j < vwindows.size(); j++) {
+                               VWindow *vwindow = vwindows[j];
+                               if( !vwindow->is_running() ) continue;
+                               if(drag_clips->get(i) == vwindow->get_edl()) {
+                                       vwindow->gui->lock_window("MWindow::remove_assets_from_project 1");
+                                       vwindow->delete_source(1, 1);
+                                       vwindow->gui->unlock_window();
+                               }
                        }
                }
        }
 
-       for(int i = 0; i < drag_assets->size(); i++) {
-               for(int j = 0; j < vwindows.size(); j++) {
-                       VWindow *vwindow = vwindows[j];
-                       if( !vwindow->is_running() ) continue;
-                       if(drag_assets->get(i) == vwindow->get_source()) {
-                               vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
-                               vwindow->delete_source(1, 1);
-                               vwindow->gui->unlock_window();
+       if( drag_assets ) {
+               for(int i = 0; i < drag_assets->size(); i++) {
+                       for(int j = 0; j < vwindows.size(); j++) {
+                               VWindow *vwindow = vwindows[j];
+                               if( !vwindow->is_running() ) continue;
+                               if(drag_assets->get(i) == vwindow->get_source()) {
+                                       vwindow->gui->lock_window("MWindow::remove_assets_from_project 2");
+                                       vwindow->delete_source(1, 1);
+                                       vwindow->gui->unlock_window();
+                               }
                        }
                }
-       }
 
-       for(int i = 0; i < drag_assets->size(); i++) {
-               Indexable *indexable = drag_assets->get(i);
-               remove_indexfile(indexable);
+               for(int i = 0; i < drag_assets->total; i++) {
+                       Indexable *indexable = drag_assets->get(i);
+                       if(indexable->is_asset) remove_asset_from_caches((Asset*)indexable);
+               }
+
+               if( delete_indexes ) {
+                       for(int i = 0; i < drag_assets->size(); i++) {
+                               Indexable *indexable = drag_assets->get(i);
+                               remove_indexfile(indexable);
+                       }
+               }
        }
 
 //printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
@@ -4137,10 +4347,8 @@ void MWindow::remove_assets_from_project(int push_undo, int redraw,
 
 void MWindow::remove_assets_from_disk()
 {
-       remove_assets_from_project(1,
-               1,
-               session->drag_assets,
-               session->drag_clips);
+       remove_assets_from_project(1, 1, 1,
+               session->drag_assets, session->drag_clips);
 
 // Remove from disk
        for(int i = 0; i < session->drag_assets->total; i++)
@@ -4477,7 +4685,7 @@ void MWindow::resync_guis()
        lwindow->gui->panel->set_meters(channels, 1);
        lwindow->gui->flush();
        lwindow->gui->unlock_window();
-
+#ifdef GLx4
 // Warn user
        if(((edl->session->output_w % 4) ||
                (edl->session->output_h % 4)) &&
@@ -4487,7 +4695,7 @@ void MWindow::resync_guis()
                        _("This project's dimensions are not multiples of 4 so\n"
                        "it can't be rendered by OpenGL."));
        }
-
+#endif
 
 // Flash frame
        sync_parameters(CHANGE_ALL);
@@ -4512,8 +4720,10 @@ int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tra
                double framerate = asset->get_frame_rate();
                int width = asset->get_w();
                int height = asset->get_h();
+#ifdef GLx4
                // must be multiple of 4 for opengl
                width = (width+3) & ~3;  height = (height+3) & ~3;
+#endif
                int driver = session->playback_config->vconfig->driver;
                int color_model = file->get_best_colormodel(asset, driver);
 //             color_model = BC_CModels::is_yuv(color_model) ?