re/open mixer window fixes
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mwindow.C
index 63522d6872690e155ccc96e351a6e4dc02eb53db..7f502d10de5b430e42ad77c45693491ffca78dc8 100644 (file)
@@ -301,6 +301,7 @@ MWindow::~MWindow()
        gui->del_keyboard_listener(
                (int (BC_WindowBase::*)(BC_WindowBase *))
                &MWindowGUI::keyboard_listener);
+       reset_caches();
 #if 0
 // release the hounds
        if( awindow && awindow->gui ) awindow->gui->close(0);
@@ -329,7 +330,6 @@ MWindow::~MWindow()
        gui->close(0);
        join();
 #endif
-       reset_caches();
        dead_plugins->remove_all_objects();
 // must delete theme before destroying plugindb
 //  theme destructor will be deleted by delete_plugins
@@ -1210,10 +1210,23 @@ ZWindow *MWindow::get_mixer(Mixer *&mixer)
        return zwindow;
 }
 
-void MWindow::del_mixer(ZWindow *zwindow)
+ZWindow *MWindow::get_mixer(int idx)
 {
-       zwindows_lock->lock("MWindow::del_mixer 0");
-       edl->mixers.del_mixer(zwindow->idx);
+       ZWindow *zwindow = 0;
+       zwindows_lock->lock("MWindow::get_mixer");
+       for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
+               ZWindow *zwdw = zwindows[i];
+               if( !zwdw->running() ) continue;
+               if( zwdw->idx != idx ) continue;
+               zwindow = zwindows[i];
+       }
+       zwindows_lock->unlock();
+       return zwindow;
+}
+
+void MWindow::close_mixer(ZWindow *zwindow)
+{
+       zwindows_lock->lock("MWindow::close_mixer 0");
        if( session->selected_zwindow >= 0 ) {
                int i = zwindows.number_of(zwindow);
                if( i >= 0 && i < session->selected_zwindow )
@@ -1222,7 +1235,7 @@ void MWindow::del_mixer(ZWindow *zwindow)
                        session->selected_zwindow = -1;
        }
        zwindows_lock->unlock();
-       gui->lock_window("MWindow::del_mixer 1");
+       gui->lock_window("MWindow::close_mixer 1");
        gui->update_mixers(0, -1);
        gui->unlock_window();
 }
@@ -2261,27 +2274,7 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
        if(got_indexes) mainindexes->start_build();
 
 // Open plugin GUIs
-       Track *track = edl->tracks->first;
-       while( track ) {
-               for( int j = 0; j < track->plugin_set.size(); j++ ) {
-                       PluginSet *plugins = track->plugin_set[j];
-                       Plugin *plugin = plugins->get_first_plugin();
-
-                       while(plugin) {
-                               if( load_mode == LOADMODE_REPLACE ||
-                                   load_mode == LOADMODE_REPLACE_CONCATENATE ) {
-                                       if( plugin->plugin_type == PLUGIN_STANDALONE &&
-                                           plugin->show ) {
-                                               show_plugin(plugin);
-                                       }
-                               }
-
-                               plugin = (Plugin*)plugin->next;
-                       }
-               }
-
-               track = track->next;
-       }
+       show_plugins();
 
        // opening new session
        if( ( load_mode == LOADMODE_REPLACE ||
@@ -3101,7 +3094,6 @@ void MWindow::set_auto_keyframes(int value)
        gui->mbuttons->edit_panel->keyframe->update(value);
        gui->flush();
        cwindow->gui->lock_window("MWindow::set_auto_keyframes");
-       cwindow->gui->edit_panel->keyframe->update(value);
        cwindow->gui->flush();
        cwindow->gui->unlock_window();
 }
@@ -3112,7 +3104,6 @@ void MWindow::set_span_keyframes(int 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();
 }
@@ -3772,6 +3763,7 @@ void MWindow::update_project(int load_mode)
 
                for( int i=0; i<edl->mixers.size(); ++i ) {
                        Mixer *mixer = edl->mixers[i];
+                       if( !mixer->show ) continue;
                        ZWindow *zwindow = get_mixer(mixer);
                        zwindow->set_title(mixer->title);
                        zwindow->start();
@@ -3801,7 +3793,7 @@ void MWindow::update_project(int load_mode)
        if(debug) PRINT_TRACE
 }
 
-void MWindow::stack_push(EDL *new_edl, Indexable *idxbl)
+void MWindow::stack_push(EDL *new_edl, Indexable *idxbl, Edit *edit)
 {
        int got_indexes = 0;
        for( int i=0; i<new_edl->nested_edls.size(); ++i ) {
@@ -3823,10 +3815,13 @@ void MWindow::stack_push(EDL *new_edl, Indexable *idxbl)
        gui->lock_window("MWindow::stack_push");
        if( stack.size() < 9 ) {
                save_backup();
+               hide_plugins();
                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;
                item.idxbl = idxbl;
                item.mtime = 0;
@@ -3845,6 +3840,7 @@ void MWindow::stack_push(EDL *new_edl, Indexable *idxbl)
                update_project(LOADMODE_REPLACE);
        }
        gui->unlock_window();
+       show_plugins();
 }
 
 void MWindow::stack_pop()
@@ -3852,11 +3848,23 @@ void MWindow::stack_pop()
        if( !stack.size() ) return;
 // writes on config_path/backup%d.xml
        save_backup();
+       hide_plugins();
 // already have gui lock
        StackItem &item = stack.last();
 // 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;
+               }
+       }
        edl->remove_user();
        edl = item.edl;
        delete undo;
@@ -3866,6 +3874,7 @@ void MWindow::stack_pop()
        stack.remove();
        if( idxbl ) {
                gui->unlock_window();
+               gui->resource_thread->close_indexable(idxbl);
                remove_from_caches(idxbl);
                remove_indexfile(idxbl);
                mainindexes->add_indexable(idxbl);
@@ -3876,6 +3885,7 @@ void MWindow::stack_pop()
        strcpy(session->filename, edl->path);
        update_project(LOADMODE_REPLACE);
        undo_after(_("open edl"), LOAD_ALL);
+       show_plugins();
        gui->stack_button->update();
        if( mtime && idxbl && idxbl->is_asset ) {
                struct stat st;
@@ -3890,6 +3900,77 @@ void MWindow::stack_pop()
        }
 }
 
+int MWindow::save(EDL *edl, char *filename, int stat)
+{
+       FileXML file;
+       edl->save_xml(&file, filename);
+       file.terminate_string();
+       if( file.write_to_file(filename) ) {
+               eprintf(_("Couldn't open %s"), filename);
+               return 1;
+       }
+       if( stat ) {
+               char string[BCTEXTLEN];
+               char *filename = stack.size() ?
+                       stack[0].edl->path : session->filename;
+               sprintf(string, _("\"%s\" %jdC written"),
+                        filename, file.length());
+               gui->lock_window("SaveAs::run");
+               gui->show_message(string);
+               gui->unlock_window();
+       }
+       return 0;
+}
+
+int MWindow::save(int save_as)
+{
+       char new_path[BCTEXTLEN];  new_path[0] = 0;
+       char *path = stack.size() ? stack[0].edl->path : session->filename;
+       if( save_as || !path[0] ) {
+               if( ConfirmSave::get_save_path(this, new_path) )
+                       return 1;
+               if( stack.size() ) {
+                       strcpy(path, new_path);
+                       set_titlebar(new_path);
+               }
+               else
+                       set_filename(new_path);
+               gui->mainmenu->add_load(new_path);
+               path = new_path;
+       }
+       for( int i=stack.size(); --i>=0;  ) {
+               StackItem &item = stack[i];
+               Indexable *idxbl = item.idxbl;
+               if( idxbl->is_asset ) {
+                       Asset *asset = (Asset *)idxbl;
+                       if( asset->format == FILE_REF ) {
+                               if( save(item.new_edl, asset->path, 0) )
+                                       return 1;
+                       }
+               }
+               else if( item.new_edl != item.idxbl )
+                       item.new_edl->overwrite_clip((EDL*)item.idxbl);
+       }
+       EDL *new_edl = stack.size() ? stack[0].edl : edl;
+       save(new_edl, path, 1);
+       return 0;
+}
+
+void MWindow::show_plugins()
+{
+       for( Track *track=edl->tracks->first; track; track=track->next ) {
+               for( int i=0; i<track->plugin_set.size(); ++i ) {
+                       PluginSet *plugins = track->plugin_set[i];
+                       Plugin *plugin = plugins->get_first_plugin();
+                       for( ; plugin; plugin=(Plugin*)plugin->next ) {
+                               if( plugin->plugin_type == PLUGIN_STANDALONE &&
+                                   plugin->show )
+                                       show_plugin(plugin);
+                       }
+               }
+       }
+}
+
 void MWindow::clip_to_media()
 {
        if( edl->session->proxy_scale != 1 ) {
@@ -3897,6 +3978,7 @@ void MWindow::clip_to_media()
                return;
        }
        undo_before();
+       awindow->gui->stop_vicon_drawing();
        int clips_total = session->drag_clips->total;
        for( int i=0; i<clips_total; ++i ) {
                EDL *clip = session->drag_clips->values[i];
@@ -4373,6 +4455,7 @@ int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
 
 void MWindow::reset_caches()
 {
+       awindow->gui->stop_vicon_drawing();
        frame_cache->remove_all();
        wave_cache->remove_all();
        audio_cache->remove_all();
@@ -4396,6 +4479,7 @@ void MWindow::reset_caches()
 
 void MWindow::remove_from_caches(Indexable *idxbl)
 {
+       awindow->gui->stop_vicon_drawing();
        frame_cache->remove_item(idxbl);
        wave_cache->remove_item(idxbl);
        if( gui->render_engine &&
@@ -4403,11 +4487,7 @@ void MWindow::remove_from_caches(Indexable *idxbl)
                delete gui->render_engine;
                gui->render_engine = 0;
        }
-       if( gui->resource_thread->render_engine_id == idxbl->id ) {
-               gui->resource_thread->render_engine_id = -1;
-               delete gui->resource_thread->render_engine;
-               gui->resource_thread->render_engine = 0;
-       }
+       gui->resource_thread->close_indexable(idxbl);
        if( !idxbl->is_asset ) return;
        Asset *asset = (Asset *)idxbl;
        audio_cache->delete_entry(asset);
@@ -4433,12 +4513,13 @@ void MWindow::remove_from_caches(Indexable *idxbl)
                if( zwindow->zgui->playback_engine->video_cache )
                        zwindow->zgui->playback_engine->video_cache->delete_entry(asset);
        }
+       awindow->gui->start_vicon_drawing();
 }
 
 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();
+       awindow->gui->stop_vicon_drawing();
 
 // Remove from VWindow.
        if( drag_clips ) {
@@ -4593,6 +4674,14 @@ void MWindow::dump_exe(FILE *fp)
        fprintf(fp, "\n");
 }
 
+void MWindow::dump_caches(FILE *fp)
+{
+       fprintf(fp, "audio cache: ");
+       audio_cache->dump(fp);
+       fprintf(fp, "video cache: ");
+       video_cache->dump(fp);
+}
+
 void MWindow::trap_hook(FILE *fp, void *vp)
 {
        MWindow *mwindow = (MWindow *)vp;
@@ -4604,6 +4693,8 @@ void MWindow::trap_hook(FILE *fp, void *vp)
        mwindow->dump_undo(fp);
        fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp);
        mwindow->dump_exe(fp);
+       fprintf(fp, "\nCACHES:\n");
+       mwindow->dump_caches(fp);
 }
 
 
@@ -4724,32 +4815,25 @@ int MWindow::set_filename(const char *filename)
                strcpy(session->filename, filename);
        if( filename != edl->path )
                strcpy(edl->path, filename);
+       return set_titlebar(filename);
+}
 
-       if(gui)
-       {
-               if(filename[0] == 0)
-               {
-                       gui->set_title(PROGRAM_NAME);
-               }
-               else
-               {
-                       FileSystem dir;
-                       char string[BCTEXTLEN], string2[BCTEXTLEN];
-                       dir.extract_name(string, filename);
-                       sprintf(string2, PROGRAM_NAME ": %s", string);
-                       gui->set_title(string2);
-               }
+int MWindow::set_titlebar(const char *filename)
+{
+       if( !gui ) return 0;
+       if( filename[0] ) {
+               FileSystem dir;
+               char string[BCTEXTLEN], string2[BCTEXTLEN];
+               dir.extract_name(string, filename);
+               sprintf(string2, PROGRAM_NAME ": %s", string);
+               gui->set_title(string2);
        }
+       else
+               gui->set_title(PROGRAM_NAME);
        return 0;
 }
 
 
-
-
-
-
-
-
 int MWindow::set_loop_boundaries()
 {
        double start = edl->local_session->get_selectionstart();
@@ -5037,3 +5121,17 @@ PatchGUI *MWindow::get_patchgui(Track *track)
         return patchgui;
 }
 
+int MWindow::get_cpus(int out_w, int out_h)
+{
+       if( !out_w ) out_w = edl->session->output_w;
+       if( !out_h ) out_h = edl->session->output_h;
+       int cpus = out_w*out_h/0x80000 + 1;
+       if( cpus > preferences->processors )
+               cpus = preferences->processors;
+       return cpus;
+}
+int MWindow::get_cpus()
+{
+       return get_cpus(edl->session->output_w, edl->session->output_h);
+}
+