fix audio big btn replay, new proj path, proxy fix, updated Features5
[goodguy/history.git] / cinelerra-5.1 / cinelerra / mwindow.C
index 4245e8725cb4f6ffed21178d9887bf0d478175a5..6ad64376e6b3e47839d20d5adae6fdd49d495d3a 100644 (file)
@@ -230,6 +230,7 @@ MWindow::MWindow()
        restart_status = 0;
        screens = 1;
        in_destructor = 0;
+       speed_edl = 0;
 }
 
 
@@ -251,7 +252,7 @@ MWindow::~MWindow()
        commit_commercial();
        if( commercials && !commercials->remove_user() ) commercials = 0;
        close_mixers();
-
+       if( speed_edl ) { speed_edl->remove_user();  speed_edl = 0; }
 // Save defaults for open plugins
        plugin_gui_lock->lock("MWindow::~MWindow");
        for(int i = 0; i < plugin_guis->size(); i++) {
@@ -470,6 +471,7 @@ void MWindow::init_defaults(BC_Hash* &defaults, char *config_path)
        else
                create_defaults_path(path, CONFIG_FILE);
 
+       delete defaults;
        defaults = new BC_Hash(path);
        defaults->load();
 }
@@ -745,18 +747,17 @@ void MWindow::add_plugins(ArrayList<PluginServer*> &plugins)
 
 void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *lang)
 {
-       const char *cfg_path = File::get_cindat_path();
-       char msg_path[BCTEXTLEN];  int txt = 0;
+       const char *dat_path = File::get_cindat_path();
+       char msg_path[BCTEXTLEN];
        FILE *fp = 0;
        if( BC_Resources::language[0] ) {
                snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.%s",
-                       cfg_path, lang);
+                       dat_path, lang);
                fp = fopen(msg_path, "r");
        }
        if( !fp ) {
-               txt = 1;
                snprintf(msg_path, sizeof(msg_path), "%s/info/plugins.txt",
-                       cfg_path);
+                       dat_path);
                fp = fopen(msg_path, "r");
        }
        if( !fp ) return;
@@ -775,9 +776,8 @@ void MWindow::init_plugin_tips(ArrayList<PluginServer*> &plugins, const char *la
                if( done ) {
                        if( tp > text && *--tp == '\n' ) *tp = 0;
                        if( title[0] ) {
-                               tp = !txt ? title : _(title);
                                int idx = plugins.size();
-                               while( --idx>=0 && strcmp(plugins[idx]->title, tp) );
+                               while( --idx>=0 && strcmp(plugins[idx]->title, title) );
                                if( idx >= 0 ) {
                                        delete [] plugins[idx]->tip;
                                        plugins[idx]->tip = cstrdup(text);
@@ -1288,35 +1288,53 @@ void MWindow::close_mixers()
        }
 }
 
+ZWindow *MWindow::create_mixer(Indexable *indexable)
+{
+       ArrayList<Indexable*> new_assets;
+       new_assets.append(indexable);
+       Track *track = edl->tracks->last;
+       load_assets(&new_assets, 0, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
+       track = !track ? edl->tracks->first : track->next;
+       Mixer *mixer = 0;
+       ZWindow *zwindow = get_mixer(mixer);
+       while( track ) {
+               track->play = track->record = 0;
+               if( track->data_type == TRACK_VIDEO ) {
+                       sprintf(track->title, _("Mixer %d"), zwindow->idx);
+               }
+               mixer->mixer_ids.append(track->get_mixer_id());
+               track = track->next;
+       }
+       if(  indexable->is_asset ) {
+               char *path = indexable->path;
+               char *tp = strrchr(path, '/');
+               if( !tp ) tp = path; else ++tp;
+               zwindow->set_title(tp);
+       }
+       else {
+               char *title = ((EDL*)indexable)->local_session->clip_title;
+               zwindow->set_title(title);
+       }
+       return zwindow;
+}
+
 void MWindow::create_mixers()
 {
-       if( !session->drag_assets->size() ) return;
+       if( !session->drag_assets->size() &&
+           !session->drag_clips->size() ) return;
        undo->update_undo_before();
 
        select_zwindow(0);
        ArrayList<ZWindow *>new_mixers;
 
-       for( int i=0; i<session->drag_assets->total; ++i ) {
-               Indexable *indexable = session->drag_assets->values[i];
-               ArrayList<Indexable*> new_assets;
-               new_assets.append(indexable);
-               Track *track = edl->tracks->last;
-               load_assets(&new_assets, -1, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
-               track = !track ? edl->tracks->first : track->next;
-               Mixer *mixer = 0;
-               ZWindow *zwindow = get_mixer(mixer);
-               while( track ) {
-                       track->play = track->record = 0;
-                       if( track->data_type == TRACK_VIDEO ) {
-                               sprintf(track->title, _("Mixer %d"), zwindow->idx);
-                       }
-                       mixer->mixer_ids.append(track->get_mixer_id());
-                       track = track->next;
-               }
-               char *path = indexable->path;
-               char *tp = strrchr(path, '/');
-               if( !tp ) tp = path; else ++tp;
-               zwindow->set_title(tp);
+       for( int i=0; i<session->drag_assets->size(); ++i ) {
+               Indexable *indexable = session->drag_assets->get(i);
+               ZWindow *zwindow = create_mixer(indexable);
+               new_mixers.append(zwindow);
+       }
+       for( int i=0; i<session->drag_clips->size(); ++i ) {
+               Indexable *indexable = (Indexable*)session->drag_clips->get(i);
+               ZWindow *zwindow = create_mixer(indexable);
                new_mixers.append(zwindow);
        }
 
@@ -1941,11 +1959,10 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
 // Load temporary EDL for nesting.
                                EDL *nested_edl = new EDL;
                                nested_edl->create_objects();
-                               nested_edl->set_path(filenames->get(i));
                                nested_edl->load_xml(&xml_file, LOAD_ALL);
 //printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
-                               new_edl->to_nested(nested_edl);
-                               new_edl->local_session->set_clip_path(nested_edl);
+                               new_edl->create_nested(nested_edl);
+                               new_edl->set_path(filenames->get(i));
                                nested_edl->Garbage::remove_user();
                        }
                        else {
@@ -2247,32 +2264,37 @@ void MWindow::test_plugins(EDL *new_edl, char *path)
 }
 
 
-void MWindow::init_shm()
+void MWindow::init_shm(const char *pfn, int64_t min)
 {
+       int64_t result = 0;
 // Fix shared memory
-       FILE *fd = fopen("/proc/sys/kernel/shmmax", "w");
-       if(fd) {
-               fprintf(fd, "0x7fffffff");
+       FILE *fd = fopen(pfn, "r");
+       if( fd ) {
+               fscanf(fd, "%jd", &result);
                fclose(fd);
+               if( result >= min ) return;
        }
-       fd = 0;
 
-       fd = fopen("/proc/sys/kernel/shmmax", "r");
-       if(!fd) {
-               MainError::show_error("MWindow::init_shm: couldn't open /proc/sys/kernel/shmmax for reading.\n");
+       fd = fopen(pfn, "w");
+       if( !fd ) return;
+       fprintf(fd, "0x%jx", min);
+       fclose(fd);
+
+       fd = fopen(pfn, "r");
+       if( !fd ) {
+               eprintf(_("MWindow::init_shm: couldn't open %s for reading.\n"), pfn);
                return;
        }
 
-       int64_t result = 0;
        fscanf(fd, "%jd", &result);
        fclose(fd);
-       fd = 0;
-       if(result < 0x7fffffff) {
-               eprintf(_("MWindow::init_shm: /proc/sys/kernel/shmmax is %p.\n"
+       if( result < min ) {
+               eprintf(_("MWindow::init_shm: %s is %p.\n"
                        "you probably need to be root, or:\n"
-                       "as root, run: echo 0x7fffffff > /proc/sys/kernel/shmmax\n"
+                       "as root, run: echo 0x%jx > %s\n"
                        "before trying to start cinelerra.\n"
-                       "It should be at least 0x7fffffff for Cinelerra.\n"), (void *)result);
+                       "It should be at least 0x%jx for Cinelerra.\n"),
+                       pfn, (void *)result, min, pfn, min);
        }
 }
 
@@ -2457,7 +2479,8 @@ void MWindow::create_objects(int want_gui,
                &MWindowGUI::keyboard_listener);
 
        hide_splash();
-       init_shm();
+       init_shm("/proc/sys/kernel/shmmax", 0x7fffffff);
+       init_shm("/proc/sys/kernel/shmmni", 0x4000);
        if(debug) PRINT_TRACE
 
        BC_WindowBase::get_resources()->vframe_shm = 1;
@@ -3333,9 +3356,12 @@ void MWindow::save_backup()
        FileXML file;
        edl->optimize();
        edl->set_path(session->filename);
-       char backup_path[BCTEXTLEN];
+       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);
+       rename(backup_path, backup_path1);
        edl->save_xml(&file, backup_path);
        file.terminate_string();
        FileSystem fs;
@@ -3372,6 +3398,29 @@ void MWindow::load_backup()
        save_backup();
 }
 
+
+void MWindow::save_undo_data()
+{
+       char perpetual_path[BCTEXTLEN];
+       snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
+               File::get_config_path(), PERPETUAL_FILE);
+       FILE *fp = fopen(perpetual_path,"w");
+       if( !fp ) return;
+       undo->save(fp);
+       fclose(fp);
+}
+
+void MWindow::load_undo_data()
+{
+       char perpetual_path[BCTEXTLEN];
+       snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
+               File::get_config_path(), PERPETUAL_FILE);
+       FILE *fp = fopen(perpetual_path,"r");
+       if( !fp ) return;
+       undo->load(fp);
+       fclose(fp);
+}
+
 static inline int gcd(int m, int n)
 {
        int r;