apply sge motion plugin mods
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mwindow.C
index 03e013099b61f2a919bdc33e52dc58e96b8eb19c..bb04335f118e6b85f9bac7a95ad323fa65c5ce93 100644 (file)
@@ -303,7 +303,7 @@ MWindow::~MWindow()
        gui->del_keyboard_listener(
                (int (BC_WindowBase::*)(BC_WindowBase *))
                &MWindowGUI::keyboard_listener);
-       reset_caches();
+       reset_caches(0);
 #if 0
 // release the hounds
        if( awindow && awindow->gui ) awindow->gui->close(0);
@@ -506,6 +506,13 @@ void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
 
 void MWindow::check_language()
 {
+       char pref_locale[BCSTRLEN];
+       strcpy(pref_locale, DEFAULT_LOCALE);
+       defaults->get("LOCALE",pref_locale);
+// set LANGUAGE if pref locale != sys
+       if( strcmp(pref_locale, DEFAULT_LOCALE) )
+               setenv("LANGUAGE", pref_locale, 1);
+
        char curr_lang[BCTEXTLEN]; curr_lang[0] = 0;
        const char *env_lang = getenv("LANGUAGE");
        if( !env_lang ) env_lang = getenv("LC_ALL");
@@ -2673,12 +2680,12 @@ void MWindow::create_objects(int want_gui,
        init_3d();
 
        if(debug) PRINT_TRACE
-       show_splash();
 
        if(debug) PRINT_TRACE
        default_standard = default_std();
        init_defaults(defaults, config_path);
        check_language();
+       show_splash();
        init_preferences();
        if(splash_window)
                splash_window->update_status(_("Initializing Plugins"));
@@ -2961,6 +2968,7 @@ void MWindow::show_cwindow()
 {
        session->show_cwindow = 1;
        cwindow->show_window();
+       cwindow->gui->tool_panel->raise_tool();
        gui->mainmenu->show_cwindow->set_checked(1);
 }
 
@@ -3734,8 +3742,7 @@ void MWindow::update_project(int load_mode)
        if( load_mode == LOADMODE_REPLACE ||
            load_mode == LOADMODE_REPLACE_CONCATENATE ) {
                edl->session->timecode_offset = 0;
-               delete gui->keyvalue_popup;
-               gui->keyvalue_popup = 0;
+               gui->close_keyvalue_popup();
                gui->load_panes();
        }
 
@@ -3807,7 +3814,7 @@ void MWindow::update_project(int load_mode)
        if(debug) PRINT_TRACE
 }
 
-void MWindow::stack_push(EDL *new_edl, Indexable *idxbl, Edit *edit)
+void MWindow::stack_push(EDL *new_edl, Indexable *idxbl)
 {
        int got_indexes = 0;
        for( int i=0; i<new_edl->nested_edls.size(); ++i ) {
@@ -3833,7 +3840,6 @@ void MWindow::stack_push(EDL *new_edl, Indexable *idxbl, Edit *edit)
                undo_before();
                StackItem &item = stack.append();
                item.edl = edl;
-               item.edit = edit;
                item.new_edl = new_edl;
                item.duration = new_edl->tracks->total_length();
                item.undo = undo;
@@ -3868,29 +3874,44 @@ void MWindow::stack_pop()
 // session edl replaced, overwrite and save clip data
        if( item.new_edl != edl )
                item.new_edl->overwrite_clip(edl);
-       Edit *edit = item.edit;
-// resize the referring edit if the edl duration changed
-       if( edit ) {
-               double duration = item.new_edl->tracks->total_length();
-               double dt = duration - item.duration;
-               if( fabs(dt) > 1e-4 ) {
-                       int64_t du = edit->track->to_units(dt,0);
-                       if( (edit->length+=du) < 0 )
-                               edit->length = 0;
+       Indexable *idxbl = item.idxbl;
+       if( idxbl && idxbl->is_asset && item.mtime ) {
+               Asset *asset = (Asset *)idxbl;
+               if( asset->format == FILE_REF ) {
+                       char *path = asset->path;
+                       struct stat st;
+                       if( stat(path, &st) || item.mtime == st.st_mtime ) {
+                               int cw = xS(250), ch = yS(150), px, py;
+                               gui->get_pop_cursor(px, py);
+                               px -= cw/2;  py -= ch/2;
+                               ConfirmRefWindow confirm(this, path, px, py, cw, ch);
+                               confirm.create_objects();
+                               int result = confirm.run_window();
+                               if( !result ) {
+                                       FileXML file;
+                                       item.new_edl->save_xml(&file, path);
+                                       file.terminate_string();
+                                       if(file.write_to_file(path))
+                                               eprintf(_("Cant write FileREF: %s"), path);
+                               }
+                       }
                }
        }
        edl->remove_user();
        edl = item.edl;
        delete undo;
        undo = item.undo;
-       Indexable *idxbl = item.idxbl;
-       int64_t mtime = item.mtime;
        stack.remove();
        if( idxbl ) {
+// resize the indexable edits if the new_edl duration changed
+               double duration = item.new_edl->tracks->total_length();
+               double dt = duration - item.duration;
+               if( fabs(dt) > 1e-4 )
+                       edl->tracks->update_idxbl_length(idxbl->id, dt);
                gui->unlock_window();
                gui->resource_thread->close_indexable(idxbl);
                remove_from_caches(idxbl);
-               remove_indexfile(idxbl);
+               IndexFile::delete_index_files(preferences, idxbl);
                mainindexes->add_indexable(idxbl);
                mainindexes->start_build();
                awindow->gui->async_update_assets();
@@ -3901,17 +3922,6 @@ void MWindow::stack_pop()
        undo_after(_("open edl"), LOAD_ALL);
        show_plugins();
        gui->stack_button->update();
-       if( mtime && idxbl && idxbl->is_asset ) {
-               struct stat st;
-               Asset *asset = (Asset *)idxbl;
-               if( asset->format == FILE_REF && !stat(asset->path, &st) &&
-                   item.mtime == st.st_mtime ) {
-                       char text[BCTEXTLEN];
-                       snprintf(text, sizeof(text),
-                                _("Warning: Asset not updated: %s"), asset->path);
-                       show_warning(&preferences->warn_stack, text);
-               }
-       }
 }
 
 int MWindow::save(EDL *edl, char *filename, int stat)
@@ -4079,18 +4089,18 @@ void MWindow::update_preferences(Preferences *prefs)
        if( prefs != preferences )
                preferences->copy_from(prefs);
        if( cwindow->playback_engine )
-               cwindow->playback_engine->preferences->copy_from(prefs);
+               cwindow->playback_engine->update_preferences(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);
+                       vwindow->playback_engine->update_preferences(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);
+                       zwindow->zgui->playback_engine->update_preferences(prefs);
        }
 }
 
@@ -4109,11 +4119,8 @@ void MWindow::update_vwindow()
 void MWindow::remove_indexfile(Indexable *indexable)
 {
        if( !indexable->is_asset ) return;
-       Asset *asset = (Asset *)indexable;
 // Erase file
-       IndexFile::delete_index(preferences, asset, ".toc");
-       IndexFile::delete_index(preferences, asset, ".idx");
-       IndexFile::delete_index(preferences, asset, ".mkr");
+       IndexFile::delete_index_files(preferences, indexable);
 }
 
 void MWindow::rebuild_indices()
@@ -4468,31 +4475,24 @@ int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
        return 0;
 }
 
-void MWindow::reset_caches()
+void MWindow::reset_caches(int locked)
 {
-       int locked  = gui->get_window_lock();
        if( locked ) gui->unlock_window();
        awindow->gui->stop_vicon_drawing(1);
-       frame_cache->remove_all();
-       wave_cache->remove_all();
-       audio_cache->remove_all();
-       video_cache->remove_all();
-       if( cwindow->playback_engine ) {
-               if( cwindow->playback_engine->audio_cache )
-                       cwindow->playback_engine->audio_cache->remove_all();
-               if( cwindow->playback_engine->video_cache )
-                       cwindow->playback_engine->video_cache->remove_all();
-       }
+       if( cwindow->playback_engine )
+               cwindow->playback_engine->create_cache();
        for(int i = 0; i < vwindows.size(); i++) {
                VWindow *vwindow = vwindows[i];
                if( !vwindow->is_running() ) continue;
                if( !vwindow->playback_engine ) continue;
-               if( vwindow->playback_engine->audio_cache )
-                       vwindow->playback_engine->audio_cache->remove_all();
-               if( vwindow->playback_engine->video_cache )
-                       vwindow->playback_engine->video_cache->remove_all();
+               vwindow->playback_engine->create_cache();
        }
-       if( locked ) gui->lock_window("MWindow::reset_caches");
+       gui->lock_window("MWindow::reset_caches");
+       frame_cache->remove_all();
+       wave_cache->remove_all();
+       audio_cache->remove_all();
+       video_cache->remove_all();
+       if( !locked ) gui->unlock_window();
 }
 
 void MWindow::remove_from_caches(Indexable *idxbl)
@@ -5177,3 +5177,33 @@ void DrawTrackMovement::run()
        mwindow->gui->unlock_window();
 }
 
+
+ConfirmRefWindow::ConfirmRefWindow(MWindow *mwindow, char *path,
+               int px, int py, int cw, int ch)
+ : BC_Window(_(PROGRAM_NAME ": Confirm update"), px, py, cw, ch, cw, ch)
+{
+       this->mwindow = mwindow;
+       this->path = path;
+}
+
+ConfirmRefWindow::~ConfirmRefWindow()
+{
+}
+
+void ConfirmRefWindow::create_objects()
+{
+       lock_window("ConfirmRefWindow::create_objects()");
+       int x = xS(10), y = yS(10), pad = yS(5);
+       BC_Title *title;
+       add_subwindow(title = new BC_Title(x, y, _("FileREF not updated:")));
+       y += title->get_h() + pad;
+       BC_TextBox *text_box;
+       add_subwindow(text_box = new BC_TextBox(x,y, get_w()-2*x, 1, path));
+       y += text_box->get_h() + 2*pad;
+       add_subwindow(title = new BC_Title(x, y, _("Save file ref changes?")));
+       add_subwindow(new BC_OKButton(this));
+       add_subwindow(new BC_CancelButton(this));
+       show_window();
+       unlock_window();
+}
+