add ids to auto/labels, fix awdw gui deadlock, fix fourier bfr bug, fix cache critica...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mwindow.C
index 702bd8a7c6fde6bb0aaa68bbe0354f74b607efd2..8319bfbdead591e94afdb0a1e3ae7f79c87b36d2 100644 (file)
@@ -349,8 +349,9 @@ MWindow::~MWindow()
        delete gui;             gui = 0;
        delete mainindexes;     mainindexes = 0;
        delete mainprogress;    mainprogress = 0;
-       delete audio_cache;     audio_cache = 0;  // delete the cache after the assets
-       delete video_cache;     video_cache = 0;  // delete the cache after the assets
+ // delete the caches after the assets
+       if( audio_cache ) { audio_cache->remove_user();  audio_cache = 0; }
+       if( video_cache ) { video_cache->remove_user();  video_cache = 0; }
        delete frame_cache;     frame_cache = 0;
        delete wave_cache;      wave_cache = 0;
        delete plugin_guis;     plugin_guis = 0;
@@ -505,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");
@@ -2283,6 +2291,8 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
 // Start examining next batch of index files
        if(got_indexes) mainindexes->start_build();
 
+// reload renderengine edl or the plugin guis will flip out
+       sync_parameters(CHANGE_ALL);
 // Open plugin GUIs
        show_plugins();
 
@@ -2670,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"));
@@ -2958,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);
 }
 
@@ -3730,8 +3741,8 @@ void MWindow::update_project(int load_mode)
 
        if( load_mode == LOADMODE_REPLACE ||
            load_mode == LOADMODE_REPLACE_CONCATENATE ) {
-               delete gui->keyvalue_popup;
-               gui->keyvalue_popup = 0;
+               edl->session->timecode_offset = 0;
+               gui->close_keyvalue_popup();
                gui->load_panes();
        }
 
@@ -3803,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 ) {
@@ -3829,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;
@@ -3864,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();
@@ -3897,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)
@@ -3951,6 +3965,7 @@ int MWindow::save(int save_as)
        for( int i=stack.size(); --i>=0;  ) {
                StackItem &item = stack[i];
                Indexable *idxbl = item.idxbl;
+               if( !idxbl ) continue;
                if( idxbl->is_asset ) {
                        Asset *asset = (Asset *)idxbl;
                        if( asset->format == FILE_REF ) {
@@ -3958,8 +3973,8 @@ int MWindow::save(int save_as)
                                        return 1;
                        }
                }
-               else if( item.new_edl != item.idxbl )
-                       item.new_edl->overwrite_clip((EDL*)item.idxbl);
+               else if( item.new_edl != idxbl )
+                       item.new_edl->overwrite_clip((EDL*)idxbl);
        }
        EDL *new_edl = stack.size() ? stack[0].edl : edl;
        save(new_edl, path, 1);
@@ -4104,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,26 +4480,20 @@ void MWindow::reset_caches()
        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)
@@ -4778,31 +4784,30 @@ int MWindow::interrupt_indexes()
 
 void MWindow::next_time_format()
 {
-       switch(edl->session->time_format)
-       {
-               case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
-               case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
-               case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
-               case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
-               case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
-               case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
-               case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
+       switch( edl->session->time_format ) {
+       case TIME_HMS:          edl->session->time_format = TIME_HMSF;         break;
+       case TIME_HMSF:         edl->session->time_format = TIME_TIMECODE;     break;
+       case TIME_TIMECODE:     edl->session->time_format = TIME_FRAMES;       break;
+       case TIME_FRAMES:       edl->session->time_format = TIME_SAMPLES;      break;
+       case TIME_SAMPLES:      edl->session->time_format = TIME_SAMPLES_HEX;  break;
+       case TIME_SAMPLES_HEX:  edl->session->time_format = TIME_SECONDS;      break;
+       case TIME_SECONDS:      edl->session->time_format = TIME_FEET_FRAMES;  break;
+       case TIME_FEET_FRAMES:  edl->session->time_format = TIME_HMS;          break;
        }
-
        time_format_common();
 }
 
 void MWindow::prev_time_format()
 {
-       switch(edl->session->time_format)
-       {
-               case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
-               case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
-               case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
-               case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
-               case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
-               case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
-               case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
+       switch( edl->session->time_format ) {
+       case TIME_HMS:          edl->session->time_format = TIME_FEET_FRAMES;  break;
+       case TIME_HMSF:         edl->session->time_format = TIME_HMS;          break;
+       case TIME_TIMECODE:     edl->session->time_format = TIME_HMSF;         break;
+       case TIME_FRAMES:       edl->session->time_format = TIME_TIMECODE;     break;
+       case TIME_SAMPLES:      edl->session->time_format = TIME_FRAMES;       break;
+       case TIME_SAMPLES_HEX:  edl->session->time_format = TIME_SAMPLES;      break;
+       case TIME_SECONDS:      edl->session->time_format = TIME_SAMPLES_HEX;  break;
+       case TIME_FEET_FRAMES:  edl->session->time_format = TIME_SECONDS;      break;
        }
 
        time_format_common();
@@ -5173,3 +5178,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();
+}
+