reload plugin btn in prefs, speed gang fader tweaks
[goodguy/history.git] / cinelerra-5.1 / cinelerra / mwindow.C
index b0f829bbd7adaeac2f738600d7bb63c74126930c..7d871c9652126768e7e3d1612aaaaaa23fcde9ec 100644 (file)
@@ -28,6 +28,7 @@
 #include "awindow.h"
 #include "batchrender.h"
 #include "bcdisplayinfo.h"
+#include "bcprogressbox.h"
 #include "bcsignals.h"
 #include "bctimer.h"
 #include "bctrace.h"
@@ -98,6 +99,7 @@
 #include "removefile.h"
 #include "render.h"
 #include "resourcethread.h"
+#include "savefile.inc"
 #include "samplescroll.h"
 #include "sha1.h"
 #include "sighandler.h"
@@ -1839,7 +1841,7 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
                char string[BCTEXTLEN];
 
                new_edl->create_objects();
-               new_edl->copy_session(edl);
+               new_edl->copy_session(edl, -1);
                new_file->set_program(edl->session->program_no);
 
                sprintf(string, _("Loading %s"), new_asset->path);
@@ -2004,7 +2006,8 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
                                result = 1;
                                break;
                        }
-                       if( strcmp(cin_version, CINELERRA_VERSION) ) {
+                       if( strcmp(cin_version, CINELERRA_VERSION) &&
+                           strcmp(cin_version, "5.1") ) {
                                char string[BCTEXTLEN];
                                snprintf(string, sizeof(string),
                                         _("Warning: XML from cinelerra version %s\n"
@@ -2175,7 +2178,7 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
                edl->session->proxy_auto_scale = 0;
                edl->session->proxy_beep = 0;
                edl->local_session->preview_start = 0;
-               edl->local_session->preview_end = 0;
+               edl->local_session->preview_end = -1;
                edl->local_session->loop_playback = 0;
                edl->local_session->set_selectionstart(0);
                edl->local_session->set_selectionend(0);
@@ -2878,12 +2881,6 @@ void MWindow::toggle_loop_playback()
        sync_parameters(CHANGE_PARAMS);
 }
 
-//void MWindow::set_titles(int value)
-//{
-//     edl->session->show_titles = value;
-//     trackmovement(edl->local_session->track_start);
-//}
-
 void MWindow::set_screens(int value)
 {
        screens = value;
@@ -2953,6 +2950,19 @@ void MWindow::toggle_editing_mode()
                set_editing_mode(EDITING_ARROW, 0, 1);
 }
 
+void MWindow::toggle_camera_xyz()
+{
+       gwindow->gui->lock_window("MWindow::toggle_camera_xyz");
+       gwindow->gui->toggle_camera_xyz();
+       gwindow->gui->unlock_window();
+}
+
+void MWindow::toggle_projector_xyz()
+{
+       gwindow->gui->lock_window("MWindow::toggle_projector_xyz");
+       gwindow->gui->toggle_projector_xyz();
+       gwindow->gui->unlock_window();
+}
 
 void MWindow::set_labels_follow_edits(int value)
 {
@@ -3463,9 +3473,10 @@ void MWindow::update_project(int load_mode)
 
        if(debug) PRINT_TRACE
 
-       if(load_mode == LOADMODE_REPLACE ||
-               load_mode == LOADMODE_REPLACE_CONCATENATE)
-       {
+       if( load_mode == LOADMODE_REPLACE ||
+           load_mode == LOADMODE_REPLACE_CONCATENATE ) {
+               delete gui->keyvalue_popup;
+               gui->keyvalue_popup = 0;
                gui->load_panes();
        }
 
@@ -3629,6 +3640,8 @@ void MWindow::load_backup()
 
 void MWindow::save_undo_data()
 {
+       undo->update_undo_before();
+       undo->update_undo_after(_("perpetual session"), LOAD_ALL);
        char perpetual_path[BCTEXTLEN];
        snprintf(perpetual_path, sizeof(perpetual_path), "%s/%s",
                File::get_config_path(), PERPETUAL_FILE);
@@ -3649,6 +3662,187 @@ void MWindow::load_undo_data()
        fclose(fp);
 }
 
+
+int MWindow::copy_target(const char *path, const char *target)
+{
+       int ifd = ::open(path, O_RDONLY);
+       if( ifd < 0 ) {
+               eprintf("Cannot open asset: %s", path);
+               return 1;
+       }
+       int ret = 0;
+       int ofd = ::open(target, O_CREAT+O_TRUNC+O_WRONLY, 0777);
+       if( ofd >= 0 ) {
+               struct stat st;
+               int64_t total_bytes = !fstat(ifd, &st) ? st.st_size : 0;
+               char progress_title[BCTEXTLEN];
+               sprintf(progress_title, _("Copying: %s\n"), target);
+               BC_ProgressBox progress(-1, -1, progress_title, total_bytes);
+
+               int64_t count = 0, len = -1;
+               int bfrsz = 0x100000;
+               uint8_t *bfr = new uint8_t[bfrsz];
+               while( (len=::read(ifd, bfr, bfrsz)) > 0 ) {
+                       if( len != ::write(ofd, bfr, len) ) {
+                               eprintf("Error writing: %s", target);
+                               break;
+                       }
+                       if( progress.is_cancelled() ) {
+                               ret = 1;
+                               break;
+                       }
+                       progress.update(count += len, 1);
+               }
+               delete [] bfr;
+               ::close(ofd);
+
+               progress.stop_progress();
+               if( len < 0 ) {
+                       eprintf("Error reading: %s", path);
+                       ret = 1;
+               }
+       }
+       else
+               eprintf("Cannot create asset target: %s", target);
+       ::close(ifd);
+       return ret;
+}
+
+int MWindow::link_target(const char *real_path, const char *link_path, int relative)
+{
+       char target[BCTEXTLEN];
+       if( relative ) {
+               const char *bp = real_path, *cp = bp;
+               const char *lp = link_path, *np = lp;
+               char *tp = target, *ep = tp+sizeof(target)-1, lch;
+               while( *lp && *bp && (lch=*lp++) == *bp++ ) {
+                       if( lch == '/' ) { np = lp;  cp = bp; }
+               }
+               while( tp<ep && *np ) {
+                       if( *np++ != '/' ) continue;
+                       *tp++ = '.';  *tp++ = '.';  *tp++ = '/';
+               }
+               while( tp<ep && *cp ) *tp++ = *cp++;
+               *tp = 0;
+       }
+       else
+               strcpy(target, real_path);
+       if( symlink(target, link_path) ) {
+               eprintf("Cannot create symlink: %s", link_path);
+               return 1;
+       }
+       return 0;
+}
+
+void MWindow::save_project(const char *dir, int save_mode, int overwrite, int reload)
+{
+       char dir_path[BCTEXTLEN];
+       strcpy(dir_path, dir);
+       FileSystem fs;
+       fs.complete_path(dir_path);
+
+       struct stat st;
+       if( !stat(dir_path, &st) ) {
+               if( !S_ISDIR(st.st_mode) ) {
+                       eprintf("Path exists and is not a directory\n%s", dir_path);
+                       return;
+               }
+       }
+       else {
+               if( mkdir(dir_path, S_IRWXU | S_IRWXG | S_IRWXO) ) {
+                       eprintf("Cannot create directory\n%s", dir_path);
+                       return;
+               }
+       }
+       char *real_dir = realpath(dir_path, 0);
+       strcpy(dir_path, real_dir);
+       free(real_dir);
+
+       EDL *save_edl = new EDL;
+       save_edl->create_objects();
+       save_edl->copy_all(edl);
+
+       char progress_title[BCTEXTLEN];
+       sprintf(progress_title, _("Saving to %s:\n"), dir);
+       int total_assets = save_edl->assets->total();
+       MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
+       int ret = 0;
+       Asset *current = save_edl->assets->first;
+       for( int i=0; !ret && current; ++i, current=NEXT ) {
+               char *path = current->path;
+               if( ::stat(path, &st) ) {
+                       eprintf("Asset not found: %s", path);
+                       continue;
+               }
+               char *real_path = realpath(path, 0);
+               const char *cp = strrchr(path, '/'), *bp = !cp ? path : cp+1;
+               char link_path[BCTEXTLEN];
+               snprintf(link_path, sizeof(link_path), "%s/%s", dir_path, bp);
+               int skip = 0;
+               if( strcmp(real_path, link_path) ) {
+                       if( !::lstat(link_path, &st) ) {
+                               if( overwrite )
+                                       ::remove(link_path);
+                               else
+                                       skip = 1;
+                       }
+               }
+               else {
+                       eprintf("copy/link to self, skippped: %s", path);
+                       skip = 1;
+               }
+               if( !skip ) {
+                       if( save_mode == SAVE_PROJECT_COPY ) {
+                               if( copy_target(real_path, link_path) )
+                                       ret = 1;
+                       }
+                       else {
+                               link_target(real_path, link_path,
+                                       save_mode == SAVE_PROJECT_RELLINK ? 1 : 0);
+                       }
+               }
+               free(real_path);
+               strcpy(path, link_path);
+
+               if( progress->is_cancelled() ) break;
+               progress->update(i);
+       }
+
+       progress->stop_progress();
+       delete progress;
+
+       char *cp = strrchr(dir_path,'/');
+       char *bp = cp ? cp+1 : dir_path;
+       char filename[BCTEXTLEN];
+       snprintf(filename, sizeof(filename), "%s/%s.xml", dir_path, bp);
+       save_edl->set_path(filename);
+       FileXML file;
+       save_edl->save_xml(&file, filename);
+       file.terminate_string();
+
+       if( !file.write_to_file(filename) ) {
+               char string[BCTEXTLEN];
+               sprintf(string, _("\"%s\" %dC written"), filename, (int)strlen(file.string()));
+               gui->lock_window("SaveProject::run 2");
+               gui->show_message(string);
+               gui->unlock_window();
+               gui->mainmenu->add_load(filename);
+       }
+       else
+               eprintf(_("Couldn't open %s."), filename);
+
+       save_edl->remove_user();
+
+       if( reload ) {
+               gui->lock_window("MWindow::save_project");
+               ArrayList<char*> filenames;
+               filenames.append(filename);
+               load_filenames(&filenames, LOADMODE_REPLACE);
+               gui->unlock_window();
+       }
+}
+
+
 static inline int gcd(int m, int n)
 {
        int r;