add ids to auto/labels, fix awdw gui deadlock, fix fourier bfr bug, fix cache critica...
authorGood Guy <[email protected]>
Thu, 3 Sep 2020 01:16:24 +0000 (19:16 -0600)
committerGood Guy <[email protected]>
Thu, 3 Sep 2020 01:16:24 +0000 (19:16 -0600)
15 files changed:
cinelerra-5.1/cinelerra/auto.C
cinelerra-5.1/cinelerra/auto.h
cinelerra-5.1/cinelerra/autos.C
cinelerra-5.1/cinelerra/autos.h
cinelerra-5.1/cinelerra/awindowgui.C
cinelerra-5.1/cinelerra/edits.C
cinelerra-5.1/cinelerra/edits.h
cinelerra-5.1/cinelerra/fourier.C
cinelerra-5.1/cinelerra/labels.C
cinelerra-5.1/cinelerra/labels.h
cinelerra-5.1/cinelerra/mwindow.C
cinelerra-5.1/cinelerra/mwindowedit.C
cinelerra-5.1/cinelerra/playbackengine.C
cinelerra-5.1/cinelerra/playbackengine.h
cinelerra-5.1/cinelerra/tracks.C

index 4171fa83d18338a46897ff2877852550279ab9ca..03d4aa016eb5d72b67122f79554e0f9ae8aad314 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "auto.h"
 #include "autos.h"
+#include "edl.h"
 #include "filexml.h"
 
 Auto::Auto()
@@ -29,10 +30,11 @@ Auto::Auto()
        this->edl = 0;
        this->autos = 0;
        position = 0;
-       skip = 0;
        WIDTH = xS(10);
        HEIGHT = yS(10);
        is_default = 0;
+       id = EDL::next_id();
+       orig_id = id;
 }
 
 Auto::Auto(EDL *edl, Autos *autos)
@@ -41,10 +43,11 @@ Auto::Auto(EDL *edl, Autos *autos)
        this->edl = edl;
        this->autos = autos;
        position = 0;
-       skip = 0;
        WIDTH = xS(10);
        HEIGHT = yS(10);
        is_default = 0;
+       id = EDL::next_id();
+       orig_id = id;
 }
 
 Auto& Auto::operator=(Auto& that)
@@ -66,6 +69,7 @@ void Auto::copy(int64_t start, int64_t end, FileXML *file, int default_only)
 
 void Auto::copy_from(Auto *that)
 {
+       this->orig_id = orig_id;
        this->position = that->position;
 }
 
index f91451ef03b19d8b54344ccbf6231396b55a090f..6330952459a3c14262598ecfe2cc86d0b328f1e6 100644 (file)
@@ -57,10 +57,9 @@ public:
 
        virtual void get_caption(char *string) {};
 
-
-       int skip;       // if added by selection event for moves
        EDL *edl;
        Autos *autos;
+       int id, orig_id;
        int WIDTH, HEIGHT;
 // Units native to the track
        int is_default;
index a2914d82e274573704b6f1332e3039b8e24b4cc9..a48afbb508531f1abc99c477dbf9a6a46f853df5 100644 (file)
@@ -274,6 +274,12 @@ Auto* Autos::get_auto_at_position(double position)
        return 0;
 }
 
+Auto* Autos::get_auto(int id)
+{
+       Auto *current = first;
+       while( current && current->orig_id != id ) current = NEXT;
+       return current;
+}
 
 Auto* Autos::get_auto_for_editing(double position, int create)
 {
index ee53f63a9c21494b90afbe426229d6f378331232..dcb997d8b76f8e5744843bfe7f3aa303ccc07849 100644 (file)
@@ -61,6 +61,7 @@ public:
        int auto_exists_for_editing(double position);
 // Returns auto at exact position, null if non-existent. ignores autokeyframming and align on frames
        Auto* get_auto_at_position(double position = -1);
+       Auto* get_auto(int id);
 
 // Get keyframe for editing with creation
 // create: <0: always new keyframe, =0: no new keyframe, >0: auto keyframe
index 4688e7bc04cead9a205e6a0fd67288640dc10b25..c9a9a898ec33ba473d1690df138d127f541a7a24 100644 (file)
@@ -945,6 +945,11 @@ void AssetPicon::create_objects()
                if( asset->video_data ) {
                        if( mwindow->preferences->use_thumbnails ) {
                                gui->unlock_window();
+                               char string[BCTEXTLEN];
+                               sprintf(string, _("Reading %s"), name);
+                               mwindow->gui->lock_window("AssetPicon::create_objects");
+                               mwindow->gui->show_message(string);
+                               mwindow->gui->unlock_window();
                                File *file = mwindow->video_cache->check_out(asset,
                                        mwindow->edl,
                                        1);
@@ -968,11 +973,6 @@ void AssetPicon::create_objects()
                                                        asset->width, asset->height,
                                                        BC_RGB888, -1);
                                        }
-                                       { char string[BCTEXTLEN];
-                                       sprintf(string, _("Reading %s"), name);
-                                       mwindow->gui->lock_window("AssetPicon::create_objects");
-                                       mwindow->gui->show_message(string);
-                                       mwindow->gui->unlock_window(); }
                                        file->read_frame(gui->temp_picon);
                                        mwindow->video_cache->check_in(asset);
 
index cec86c847d449255a2441fcd0fa8070becc54697..71dd3b18e293ad41af189f0d9f161ceb1f010822 100644 (file)
@@ -560,6 +560,13 @@ Edit* Edits::editof(int64_t position, int direction, int use_nudge)
        return 0;     // return 0 on failure
 }
 
+Edit* Edits::get_edit(int id)
+{
+       Edit *current = first;
+       while( current && current->orig_id != id ) current = NEXT;
+       return current;
+}
+
 Edit* Edits::get_playable_edit(int64_t position, int use_nudge)
 {
        Edit *current;
index bd73e4e79d7b352de75775951e7f984370e65428..5550cb5572e8fb935d7f4b7d2dad9d23d7edb3d2 100644 (file)
@@ -109,6 +109,7 @@ public:
 // ==================================== accounting
 
        Edit* editof(int64_t position, int direction, int use_nudge);
+       Edit* get_edit(int id);
 // Return an edit if position is over an edit and the edit has a source file
        Edit* get_playable_edit(int64_t position, int use_nudge);
 //     int64_t total_length();
index f78a45bd1e092a990864e9efd716a88cd430d954..7f52fe0c8e4c1a5f5d4e886fd8ab30dc3afe32fa 100644 (file)
@@ -429,9 +429,11 @@ int CrossfadeFFT::process_buffer(int64_t output_sample,
        }
 
        input_buffer->set_offset(input_size);
-       result = read_samples(input_sample, need_samples-input_size, input_buffer);
+       if( need_samples > input_size ) {
+               result = read_samples(input_sample, need_samples-input_size, input_buffer);
+               input_sample += step * (need_samples - input_size);
+       }
        input_buffer->set_offset(0);
-       input_sample += step * (need_samples - input_size);
        input_size = need_samples;
 
 
index 211b8767ff75db8f39965ea6a8247e2bec1cb543..ad3626bf13608f1c7b3bac7c217d6b66fa82d41c 100644 (file)
@@ -272,7 +272,9 @@ void Labels::copy_from(Labels *labels)
 
        for(Label *current = labels->first; current; current = NEXT)
        {
-               append(new Label(edl, this, current->position, current->textstr));
+               Label *new_label = new Label(edl, this, current->position, current->textstr);
+               new_label->orig_id = current->orig_id;
+               append(new_label);
        }
 }
 
@@ -460,6 +462,13 @@ Label* Labels::next_label(double position)
        return current;
 }
 
+Label* Labels::get_label(int id)
+{
+       Label *current = first;
+       while( current && current->orig_id != id ) current = NEXT;
+       return current;
+}
+
 int Labels::insert(double start, double length)
 {      // shift every label including the first one back
        Label *current;
@@ -541,6 +550,8 @@ Label* Labels::label_of(double position)
 Label::Label()
  : ListItem<Label>()
 {
+       id = EDL::next_id();
+       orig_id = id;
 }
 
 Label::Label(EDL *edl, Labels *labels, double position, const char *textstr)
@@ -550,6 +561,8 @@ Label::Label(EDL *edl, Labels *labels, double position, const char *textstr)
        this->labels = labels;
        this->position = position;
        strcpy(this->textstr, textstr ? textstr : "");
+       id = EDL::next_id();
+       orig_id = id;
 }
 
 
index 31015ea43f58d13b853ae31c6ecac9097559177f..e648de5a2ed5b9da44d5aa5824dcde57ebb6120a 100644 (file)
@@ -60,6 +60,7 @@ public:
        char textstr[BCTEXTLEN];
 // Seconds
        double position;
+       int id, orig_id;
 };
 
 class Labels : public List<Label>
@@ -98,6 +99,7 @@ public:
 // Get nearest labels or 0 if start or end of timeline
        Label* prev_label(double position);
        Label* next_label(double position);
+       Label* get_label(int id);
 
        Label* label_of(double position); // first label on or after position
        TimeBar *timebar;
index 4afbd81888f3f67b020d023f8c61dd7d3db5f81e..8319bfbdead591e94afdb0a1e3ae7f79c87b36d2 100644 (file)
@@ -4480,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)
index 7b359ce2d817bb5672049bf4ea03a2c4f6143acd..f75896d73ec01602ef76e31b5560aeecedd103b6 100644 (file)
@@ -2602,56 +2602,46 @@ int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl, int edit_speed)
                        old_speed = (FloatAuto *)old_speed->next;
                        new_speed = (FloatAuto *)new_speed->next;
                }
+               if( !old_speed && !new_speed ) continue;
+               result = 1;
                if( edit_speed ) {
                        Autos *old_autos = old_track->automation->autos[AUTOMATION_SPEED];
                        Autos *new_autos = new_track->automation->autos[AUTOMATION_SPEED];
                        Auto *old_auto = old_autos ? old_autos->first : 0;
-                       Auto *new_auto = new_autos ? new_autos->first : 0;
-                       while( old_auto && new_auto ) {
+                       for( ; old_auto; old_auto=old_auto->next ) {
+                               Auto *new_auto = new_autos->get_auto(old_auto->orig_id);
+                               if( !new_auto ) continue;
                                int64_t auto_pos = old_auto->position;
-                               if( old_speed || new_speed ) {
-                                       double orig_pos = old_speeds->automation_integral(0, auto_pos, PLAY_FORWARD);
-                                       auto_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
-                                       result = 1;
-                               }
+                               double orig_pos = old_speeds->automation_integral(0, auto_pos, PLAY_FORWARD);
+                               auto_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
                                new_auto->position = auto_pos;
-                               old_auto = old_auto->next;
-                               new_auto = new_auto->next;
                        }
                }
                Edit *old_edit = old_track->edits->first;
-               Edit *new_edit = new_track->edits->first;
-               while( old_edit && new_edit ) {
+               for( ; old_edit; old_edit=old_edit->next ) {
+                       Edit *new_edit = new_track->edits->get_edit(old_edit->orig_id);
+                       if( !new_edit ) continue;
                        int64_t edit_start = old_edit->startproject;
                        int64_t edit_end = edit_start + old_edit->length;
-                       if( old_speed || new_speed ) {
-                               double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
-                               double orig_end   = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
-                               edit_start = new_track->frame_align(new_speeds->speed_position(orig_start), 1);
-                               edit_end = new_track->frame_align(new_speeds->speed_position(orig_end), 1);
-                               result = 1;
-                       }
+                       double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
+                       double orig_end   = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
+                       edit_start = new_track->frame_align(new_speeds->speed_position(orig_start), 1);
+                       edit_end = new_track->frame_align(new_speeds->speed_position(orig_end), 1);
                        new_edit->startproject = edit_start;
                        new_edit->length = edit_end - edit_start;
-                       old_edit = old_edit->next;
-                       new_edit = new_edit->next;
                }
                if( first_track && old_track->is_armed() ) {
-                       if( edit_labels ) {
-                               Labels *old_labels = old_edl->labels;
-                               Labels *new_labels = new_edl->labels;
-                               Label *old_label = old_labels ? old_labels->first : 0;
-                               Label *new_label = new_labels ? new_labels->first : 0;
-                               while( old_label && new_label ) {
+                       Labels *old_labels = old_edl->labels;
+                       Labels *new_labels = new_edl->labels;
+                       if( edit_labels && old_labels && new_labels ) {
+                               Label *old_label = old_labels->first;
+                               for( ; old_label; old_label=old_label->next ) {
+                                       Label *new_label = new_labels->get_label(old_label->orig_id);
+                                       if( !new_label ) continue;
                                        int64_t label_pos = old_track->to_units(old_label->position, 1);
-                                       if( old_speed || new_speed ) {
-                                               double orig_pos = old_speeds->automation_integral(0, label_pos, PLAY_FORWARD);
-                                               label_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
-                                               result = 1;
-                                       }
+                                       double orig_pos = old_speeds->automation_integral(0, label_pos, PLAY_FORWARD);
+                                       label_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
                                        new_label->position = new_track->from_units(label_pos);
-                                       old_label = old_label->next;
-                                       new_label = new_label->next;
                                }
                        }
                        first_track = 0;
@@ -2662,59 +2652,54 @@ int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl, int edit_speed)
                        int n = bmin(old_size, new_size);
                        for( int i=0; i<n; ++i ) {
                                PluginSet *old_plugin_set = old_track->plugin_set[i];
-                               Plugin *old_plugin = (Plugin *)(old_plugin_set ? old_plugin_set->first : 0);
+                               if( !old_plugin_set ) continue;
                                PluginSet *new_plugin_set = new_track->plugin_set[i];
-                               Plugin *new_plugin = (Plugin *)(new_plugin_set ? new_plugin_set->first : 0);
-                               while( old_plugin && new_plugin ) {
+                               if( !new_plugin_set ) continue;
+                               Plugin *old_plugin = (Plugin *)old_plugin_set->first;
+                               for( ; old_plugin; old_plugin=(Plugin *)old_plugin->next ) {
+                                       Plugin *new_plugin = (Plugin *)new_plugin_set->get_edit(old_plugin->orig_id);
+                                       if( !new_plugin ) continue;
                                        int64_t plugin_start = old_plugin->startproject;
                                        int64_t plugin_end = plugin_start + old_plugin->length;
-                                       if( old_speed || new_speed ) {
-                                               double orig_start = old_speeds->automation_integral(0, plugin_start, PLAY_FORWARD);
-                                               double orig_end   = old_speeds->automation_integral(0, plugin_end, PLAY_FORWARD);
-                                               plugin_start = new_track->frame_align(new_speeds->speed_position(orig_start), 1);
-                                               plugin_end = new_track->frame_align(new_speeds->speed_position(orig_end), 1);
-                                               result = 1;
-                                       }
+                                       double orig_start = old_speeds->automation_integral(0, plugin_start, PLAY_FORWARD);
+                                       double orig_end   = old_speeds->automation_integral(0, plugin_end, PLAY_FORWARD);
+                                       plugin_start = new_track->frame_align(new_speeds->speed_position(orig_start), 1);
+                                       plugin_end = new_track->frame_align(new_speeds->speed_position(orig_end), 1);
                                        new_plugin->startproject = plugin_start;
                                        new_plugin->length = plugin_end - plugin_start;
                                        if( edit_autos ) {
                                                KeyFrames *old_keyframes = old_plugin->keyframes;
-                                               Auto *old_auto = old_keyframes ? old_keyframes->first : 0;
+                                               if( !old_keyframes ) continue;
                                                KeyFrames *new_keyframes = new_plugin->keyframes;
-                                               Auto *new_auto = new_keyframes ? new_keyframes->first : 0;
-                                               while( old_auto && new_auto ) {
+                                               if( !new_keyframes ) continue;
+                                               Auto *old_auto = old_keyframes->first;
+                                               for( ; old_auto; old_auto=old_auto->next ) {
+                                                       Auto *new_auto = new_keyframes->get_auto(old_auto->orig_id);
+                                                       if( !new_auto ) continue;
                                                        int64_t auto_pos = old_auto->position;
-                                                       if( old_speed || new_speed ) {
-                                                               double orig_pos = old_speeds->automation_integral(0, auto_pos, PLAY_FORWARD);
-                                                               auto_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
-                                                               result = 1;
-                                                       }
+                                                       double orig_pos = old_speeds->automation_integral(0, auto_pos, PLAY_FORWARD);
+                                                       auto_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
                                                        new_auto->position = auto_pos;
                                                        old_auto = old_auto->next;
-                                                       new_auto = new_auto->next;
                                                }
                                        }
-                                       old_plugin = (Plugin *)old_plugin->next;
-                                       new_plugin = (Plugin *)new_plugin->next;
                                }
                        }
                }
                if( edit_autos ) { // speed must be last
                        for( int i=0; i<AUTOMATION_SPEED; ++i ) {
                                Autos *old_autos = old_track->automation->autos[i];
+                               if( !old_autos ) continue;
                                Autos *new_autos = new_track->automation->autos[i];
-                               Auto *old_auto = old_autos ? old_autos->first : 0;
-                               Auto *new_auto = new_autos ? new_autos->first : 0;
-                               while( old_auto && new_auto ) {
+                               if( !new_autos ) continue;
+                               Auto *old_auto = old_autos->first;
+                               for( ; old_auto; old_auto=old_auto->next ) {
+                                       Auto *new_auto = new_autos->get_auto(old_auto->orig_id);
+                                       if( !new_auto ) continue;
                                        int64_t auto_pos = old_auto->position;
-                                       if( old_speed || new_speed ) {
-                                               double orig_pos = old_speeds->automation_integral(0, auto_pos, PLAY_FORWARD);
-                                               auto_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
-                                               result = 1;
-                                       }
+                                       double orig_pos = old_speeds->automation_integral(0, auto_pos, PLAY_FORWARD);
+                                       auto_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
                                        new_auto->position = auto_pos;
-                                       old_auto = old_auto->next;
-                                       new_auto = new_auto->next;
                                }
                        }
                }
index 82bd7bb6587b930b77caa7f4da7673255539b3a3..b15edd62c1636d0de0b135b479d35d97fb4c7071 100644 (file)
@@ -71,6 +71,7 @@ PlaybackEngine::PlaybackEngine(MWindow *mwindow, Canvas *output)
        tracking_done = new Condition(1, "PlaybackEngine::tracking_done");
        pause_lock = new Condition(0, "PlaybackEngine::pause_lock");
        start_lock = new Condition(0, "PlaybackEngine::start_lock");
+       cache_lock = new Mutex("PlaybackEngine::cache_lock");
        input_lock = new Condition(1, "PlaybackEngine::input_lock");
        output_lock = new Condition(0, "PlaybackEngine::output_lock", 1);
 
@@ -93,6 +94,7 @@ PlaybackEngine::~PlaybackEngine()
        delete tracking_done;
        delete pause_lock;
        delete start_lock;
+       delete cache_lock;
        delete renderengine_lock;
        delete command;
        delete next_command;
@@ -164,12 +166,14 @@ void PlaybackEngine::wait_render_engine()
 
 void PlaybackEngine::create_cache()
 {
+       cache_lock->lock("PlaybackEngine::create_cache");
        if( audio_cache )
                audio_cache->remove_user();
        if( video_cache )
                video_cache->remove_user();
        audio_cache = new CICache(preferences);
        video_cache = new CICache(preferences);
+       cache_lock->unlock();
 }
 
 
index ee27ff19a4b55e4ddf1db4250d7655c2f8ddc02f..65935c2bd9d5c8850fcb68aa0c5608b764f5699e 100644 (file)
@@ -106,6 +106,8 @@ public:
        Condition *pause_lock;
 // Wait until thread has started
        Condition *start_lock;
+// Reinit caches
+       Mutex *cache_lock;
 
        MWindow *mwindow;
        Canvas *output;
index 73e7706d3452125bf03a92165eed4174a5373ae3..d8357e2f61d8e865d1eebd62d2b3671de7c5c2f3 100644 (file)
@@ -336,8 +336,7 @@ int Tracks::delete_track(Track *track, int gang)
                gang = edl->session->gang_tracks != GANG_NONE ? 1 : 0;
        Track *nxt = track->next;
        if( gang ) {
-               while( track && !track->master && track->previous )
-                       track = track->previous;
+               track = track->gang_master();
                while( nxt && !nxt->master )
                        nxt = nxt->next;
        }