repair lock problem with mixer undo (last chkin)
authorGood Guy <good1.2guy@gmail.com>
Sat, 30 Dec 2017 21:10:29 +0000 (14:10 -0700)
committerGood Guy <good1.2guy@gmail.com>
Sat, 30 Dec 2017 21:10:29 +0000 (14:10 -0700)
cinelerra-5.1/cinelerra/mainundo.C
cinelerra-5.1/cinelerra/mainundo.h
cinelerra-5.1/cinelerra/mwindowedit.C
cinelerra-5.1/cinelerra/undostack.C
cinelerra-5.1/cinelerra/undostack.h
cinelerra-5.1/cinelerra/undostack.inc

index 7890343dd1870b41eb23ea1aea56ccbf79299b99..bd048c10de5fa84fcc816206386b8079b753192c 100644 (file)
@@ -164,122 +164,88 @@ void MainUndo::update_undo_after(const char *description,
 }
 
 
-int MainUndo::undo()
+UndoStackItem *MainUndo::next_undo()
 {
-       UndoStackItem *current = undo_stack->current;
-       char after_description[BCTEXTLEN];
-       after_description[0] = 0;
+       return undo_stack->get_current_undo();
+}
 
-       mwindow->undo_commercial();
+UndoStackItem *MainUndo::next_redo()
+{
+       return undo_stack->get_current_redo();
+}
 
-//printf("MainUndo::undo 1\n");
-//dump();
+int MainUndo::undo_load_flags()
+{
+       UndoStackItem *item = next_undo();
+       return item ? item->get_flags() : 0;
+}
 
-// Rewind to an after entry
-       if(current && !(undo_stack->number_of(current) % 2))
-       {
-               current = PREVIOUS;
-       }
+int MainUndo::redo_load_flags()
+{
+       UndoStackItem *item = next_redo();
+       return item ? item->get_flags() : 0;
+}
 
-// Rewind to a before entry
-       if(current && (undo_stack->number_of(current) % 2))
-       {
-               strcpy(after_description, current->get_description());
-               current = PREVIOUS;
-       }
 
+int MainUndo::undo()
+{
+       mwindow->undo_commercial();
+
+       UndoStackItem *current = next_undo();
 // Now have an even number
-       if(current)
-       {
+       if( current ) {
                undo_stack->current = current;
 // Set the redo text to the current description
-               if(mwindow->gui)
-                       mwindow->gui->mainmenu->redo->update_caption(
-                               after_description);
-
+               if( mwindow->gui ) {
+                       UndoStackItem *next = NEXT;
+                       mwindow->gui->mainmenu->redo->
+                               update_caption(next ? next->get_description() : "");
+               }
                FileXML file;
                char *current_data = current->get_data();
-               if(current_data)
-               {
+               if( current_data ) {
                        file.read_from_string(current_data);
                        load_from_undo(&file, current->get_flags());
 //printf("MainUndo::undo %d %s\n", __LINE__, current->get_filename());
                        mwindow->set_filename(current->get_filename());
                        delete [] current_data;
 
-// move current entry back one step
-                       undo_stack->pull();
-
-
-                       if(mwindow->gui)
-                       {
+                       if( mwindow->gui ) {
 // Now update the menu with the after entry
-                               current = PREVIOUS;
-// Must be a previous entry to perform undo
-                               if(current)
-                                       mwindow->gui->mainmenu->undo->update_caption(
-                                               current->get_description());
-                               else
-                                       mwindow->gui->mainmenu->undo->update_caption("");
+                               UndoStackItem *prev = PREVIOUS;
+                               mwindow->gui->mainmenu->undo->
+                                       update_caption(prev ? prev->get_description() : "");
                        }
                }
        }
 
-
-//dump();
        reset_creators();
        mwindow->reset_caches();
        return 0;
 }
 
+
 int MainUndo::redo()
 {
-       UndoStackItem *current = undo_stack->current;
-//printf("MainUndo::redo 1\n");
-//dump();
-
-// Get 1st entry
-       if(!current) current = undo_stack->first;
-
-// Advance to a before entry
-       if(current && (undo_stack->number_of(current) % 2))
-       {
-               current = NEXT;
-       }
-
-// Advance to an after entry
-       if(current && !(undo_stack->number_of(current) % 2))
-       {
-               current = NEXT;
-       }
-
-       if(current)
-       {
-               FileXML file;
-               char *current_data = current->get_data();
+       UndoStackItem *current = next_redo();
+       if( current ) {
                undo_stack->current = current;
-
-               if(current_data)
-               {
+               char *current_data = current->get_data();
+               if( current_data ) {
+                       FileXML file;
                        mwindow->set_filename(current->get_filename());
                        file.read_from_string(current_data);
                        load_from_undo(&file, current->get_flags());
                        delete [] current_data;
 
-                       if(mwindow->gui)
-                       {
+                       if( mwindow->gui ) {
 // Update menu
-                               mwindow->gui->mainmenu->undo->update_caption(current->get_description());
-
+                               mwindow->gui->mainmenu->undo->
+                                       update_caption(current->get_description());
 // Get next after entry
-                               current = NEXT;
-                               if(current)
-                                       current = NEXT;
-
-                               if(current)
-                                       mwindow->gui->mainmenu->redo->update_caption(current->get_description());
-                               else
-                                       mwindow->gui->mainmenu->redo->update_caption("");
+                               if( (current=NEXT) ) current = NEXT;
+                               mwindow->gui->mainmenu->redo->
+                                       update_caption(current ? current->get_description() : "");
                        }
                }
        }
index 8b5af5adeaa5a40e0cc5c99deec8016119d426a4..a0d3006dc02d1cab1c49d736cec9ae70d0c3aa11 100644 (file)
@@ -37,9 +37,6 @@ public:
        MainUndo(MWindow *mwindow);
        ~MainUndo();
 
-
-
-
 // For tweeking operations:
 // If a pair of update_undo_before and update_undo_after are called
 // within a certain time limit and the creator is nonzero and equal,
@@ -56,6 +53,9 @@ public:
        int undo();
        int redo();
 
+// load_flags for the next undo/redo stack item
+       int undo_load_flags();
+       int redo_load_flags();
        void dump(FILE *fp=stdout);
 private:
 // Entry point for all update commands
@@ -69,9 +69,8 @@ private:
 // compression more efficient.
 // So even numbers are before and odd numbers are after
        UndoStack *undo_stack;
-
-
-
+       UndoStackItem *next_undo();
+       UndoStackItem *next_redo();
 
 // loads undo from the stringfile to the project
        int load_undo_before(FileXML *file, uint32_t load_flags);
index c569c9204b085b0d9aa7dc2ff61ea2024b4e8c5c..ad7d729fd681616a0dc1cd9ffbdde47f918d240e 100644 (file)
@@ -1862,6 +1862,8 @@ void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
 {
        calling_window_gui->unlock_window();
        stop_playback(0);
+       if( undo->redo_load_flags() & LOAD_SESSION )
+               close_mixers();
 
        cwindow->gui->lock_window("MWindow::redo_entry 1");
        for( int i = 0; i < vwindows.size(); i++ ) {
@@ -2174,6 +2176,8 @@ void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
 {
        calling_window_gui->unlock_window();
        stop_playback(0);
+       if( undo->undo_load_flags() & LOAD_SESSION )
+               close_mixers();
 
        cwindow->gui->lock_window("MWindow::undo_entry 1");
        for( int i = 0; i < vwindows.size(); i++ ) {
index acc6544f010dd0467b2150b206fd1b38d08a3221..de738b84d3c6f7cf4be51666d53fe12430f6f401 100644 (file)
@@ -35,6 +35,23 @@ UndoStack::~UndoStack()
 {
 }
 
+UndoStackItem *UndoStack::get_current_undo()
+{
+       UndoStackItem *item = current;
+       if( item && !(number_of(item) % 2) ) item = item->previous;
+       if( item &&  (number_of(item) % 2) ) item = item->previous;
+       return item;
+}
+
+UndoStackItem *UndoStack::get_current_redo()
+{
+       UndoStackItem *item = current ? current : first;
+       if( item &&  (number_of(item) % 2) ) item = item->next;
+       if( item && !(number_of(item) % 2) ) item = item->next;
+       return item;
+}
+
+
 UndoStackItem* UndoStack::push()
 {
 // current is only 0 if before first undo
@@ -76,11 +93,6 @@ UndoStackItem* UndoStack::push()
        return current;
 }
 
-void UndoStack::pull()
-{
-       if(current) current = PREVIOUS;
-}
-
 UndoStackItem* UndoStack::pull_next()
 {
 // use first entry if none
index 5893c4cac68a026171e65729e8d27d934c84c07e..f54cb0da34de7fe9392da8c6cfccf6e274e056ca 100644 (file)
@@ -95,16 +95,16 @@ public:
        UndoStack();
        ~UndoStack();
 
+// get current undo/redo stack item
+       UndoStackItem *get_current_undo();
+       UndoStackItem *get_current_redo();
+
 // Create a new undo entry and put on the stack.
 // The current pointer points to the new entry.
 // delete future undos if in the middle
 // delete undos older than UNDOLEVELS if last
        UndoStackItem* push();
 
-// move to the previous undo entry
-       void pull();
-
-
 // move to the next undo entry for a redo
        UndoStackItem* pull_next();
 
index 90010f47169f57b19e30369eff789327e2dcf020..2d4dd68d5c5bf498dffd634f1a9b39c069476cb1 100644 (file)
@@ -22,6 +22,7 @@
 #ifndef UNDOSTACK_INC
 #define UNDOSTACK_INC
 
+class UndoStackItem;
 class UndoStack;
 
 #endif