From 330dfe3b52f9b7b61ecf03a847ad870dbb21903d Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Tue, 1 May 2018 07:53:44 -0400 Subject: [PATCH 1/3] Retain track parameters during add/remove track Previously, actionAddTrackAbove()/Below() would always create the new track at the very top of the layer stack (above all existing tracks), then walk the list of those tracks' clips and slide them up one layer. This caused _track_-level parameters (name, lock status) to be left behind (in the case of lock status) or intentionally discarded (in the case of track-name, which was blanked on all tracks which were moved). Lock status was thus left behind on the "wrong track", relative to the clips that track previously contained. With this new code, the list of _tracks_ is walked during an add operation, starting from the topmost track, and each track is moved upwards one layer (with all of its properties intact). As each track is moved, all of the clips on that track are pushed up along with it. Then, a new track is created and slotted into the space vacated by the lowermost moved track. This method preserves all track parameters, because each track's data in the project file is the _same_ after being moved as it was before. Only the layer numbers change. All of the label-blanking code was removed from both add methods, as well as from the renumbering (in the other direction) performed during actionRemoveTrack(). --- src/windows/main_window.py | 43 +++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/windows/main_window.py b/src/windows/main_window.py index 4b7884cda6..2c1bf5cdcd 100644 --- a/src/windows/main_window.py +++ b/src/windows/main_window.py @@ -901,22 +901,29 @@ def actionAddTrackAbove_trigger(self, event): existing_track = Track.get(id=selected_layer_id) selected_layer_number = int(existing_track.data["number"]) - # Create new track - track = Track() - track.data = {"number": max_track_number, "y": 0, "label": "", "lock": False} - track.save() + # log.info("Adding track above #{} (id {})".format(selected_layer_number, selected_layer_id)) - # Loop through all clips on higher layers, and move to new layer (in reverse order) - for existing_layer in list(reversed(range(selected_layer_number + 1, max_track_number))): - existing_track.data["label"] = "" + # Loop through tracks above insert point (in descending order), renumbering layers + for existing_layer in list(reversed(range(selected_layer_number+1, max_track_number))): + existing_track = Track.get(number=existing_layer) + # log.info("Renumbering track id {} from {} to {}".format(existing_track.data["id"], existing_layer, existing_layer+1)) + existing_track.data["number"] = existing_layer + 1 existing_track.save() + # Loop through clips for track, moving up to new layer for clip in Clip.filter(layer=existing_layer): + # log.info("Moving clip id {} from layer {} to {}".format(clip.data["id"], int(clip.data["layer"]), int(clip.data["layer"])+1)) clip.data["layer"] = int(clip.data["layer"]) + 1 clip.save() + # Create new track at vacated layer + track = Track() + track.data = {"number": selected_layer_number+1, "y": 0, "label": "", "lock": False} + track.save() + # log.info("Created new track id {} at layer number {}".format(track.data["id"], track.data["number"])) + def actionAddTrackBelow_trigger(self, event): - log.info("actionAddTrackAbove_trigger") + log.info("actionAddTrackBelow_trigger") # Get # of tracks max_track_number = len(get_app().project.get(["layers"])) @@ -926,20 +933,27 @@ def actionAddTrackBelow_trigger(self, event): existing_track = Track.get(id=selected_layer_id) selected_layer_number = int(existing_track.data["number"]) - # Create new track - track = Track() - track.data = {"number": max_track_number, "y": 0, "label": "", "lock": False} - track.save() + # log.info("Adding track below #{} (id {})".format(selected_layer_number, selected_layer_id)) - # Loop through all clips on higher layers, and move to new layer (in reverse order) + # Loop through tracks from insert point up (in descending order), renumbering layers for existing_layer in list(reversed(range(selected_layer_number, max_track_number))): - existing_track.data["label"] = "" + existing_track = Track.get(number=existing_layer) + # log.info("Renumbering track id {} from {} to {}".format(existing_track.data["id"], existing_layer, existing_layer+1)) + existing_track.data["number"] = existing_layer + 1 existing_track.save() + # Loop through clips for track, moving up to new layer for clip in Clip.filter(layer=existing_layer): + # log.info("Moving clip id {} from layer {} to {}".format(clip.data["id"], int(clip.data["layer"]), int(clip.data["layer"])+1)) clip.data["layer"] = int(clip.data["layer"]) + 1 clip.save() + # Create new track at vacated layer + track = Track() + track.data = {"number": selected_layer_number, "y": 0, "label": "", "lock": False} + track.save() + # log.info("Created new track id {} at layer number {}".format(track.data["id"], track.data["number"])) + def actionArrowTool_trigger(self, event): log.info("actionArrowTool_trigger") @@ -1438,7 +1452,6 @@ def actionRemoveTrack_trigger(self, event): # Update existing layer # track = Track.get(number=existing_layer) track.data["number"] = existing_layer - 1 - track.data["label"] = "" track.save() for clip in Clip.filter(layer=existing_layer): From a16ca11a8ed0f16d3642f5ba0f8f23fdcb9201eb Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Tue, 1 May 2018 10:34:37 -0400 Subject: [PATCH 2/3] Correct a cut-and-paste wrong comment --- src/windows/main_window.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows/main_window.py b/src/windows/main_window.py index 2c1bf5cdcd..461c080e4f 100644 --- a/src/windows/main_window.py +++ b/src/windows/main_window.py @@ -885,7 +885,7 @@ def actionAddTrack_trigger(self, event): # Get # of tracks track_number = len(get_app().project.get(["layers"])) - # Look for existing Marker + # Create new track above existing layer(s) track = Track() track.data = {"number": track_number, "y": 0, "label": "", "lock": False} track.save() From 82784fdeea9a0f001835957fcb5391000b9d2b9b Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 2 May 2018 23:56:06 -0400 Subject: [PATCH 3/3] Also update transition layer on track add/remove Transitions are also positioned vertically on the timeline by layer number, so they have to be updated as well when tracks are added/removed. --- src/windows/main_window.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/windows/main_window.py b/src/windows/main_window.py index 461c080e4f..6d325cd29d 100644 --- a/src/windows/main_window.py +++ b/src/windows/main_window.py @@ -910,12 +910,17 @@ def actionAddTrackAbove_trigger(self, event): existing_track.data["number"] = existing_layer + 1 existing_track.save() - # Loop through clips for track, moving up to new layer + # Loop through clips and transitions for track, moving up to new layer for clip in Clip.filter(layer=existing_layer): # log.info("Moving clip id {} from layer {} to {}".format(clip.data["id"], int(clip.data["layer"]), int(clip.data["layer"])+1)) clip.data["layer"] = int(clip.data["layer"]) + 1 clip.save() + for trans in Transition.filter(layer=existing_layer): + # log.info("Moving transition id {} from layer {} to {}".format(trans.data["id"], int(trans.data["layer"]), int(trans.data["layer"])+1)) + trans.data["layer"] = int(trans.data["layer"]) + 1 + trans.save() + # Create new track at vacated layer track = Track() track.data = {"number": selected_layer_number+1, "y": 0, "label": "", "lock": False} @@ -942,12 +947,17 @@ def actionAddTrackBelow_trigger(self, event): existing_track.data["number"] = existing_layer + 1 existing_track.save() - # Loop through clips for track, moving up to new layer + # Loop through clips and transitions for track, moving up to new layer for clip in Clip.filter(layer=existing_layer): # log.info("Moving clip id {} from layer {} to {}".format(clip.data["id"], int(clip.data["layer"]), int(clip.data["layer"])+1)) clip.data["layer"] = int(clip.data["layer"]) + 1 clip.save() + for trans in Transition.filter(layer=existing_layer): + # log.info("Moving transition id {} from layer {} to {}".format(trans.data["id"], int(trans.data["layer"]), int(trans.data["layer"])+1)) + trans.data["layer"] = int(trans.data["layer"]) + 1 + trans.save() + # Create new track at vacated layer track = Track() track.data = {"number": selected_layer_number, "y": 0, "label": "", "lock": False} @@ -1447,9 +1457,9 @@ def actionRemoveTrack_trigger(self, event): # Remove track selected_track.delete() - # Loop through all tracks, and renumber (to keep thing in numerical order) + # Loop through all layers above, and renumber elements (to keep thing in numerical order) for existing_layer in list(range(selected_track_number + 1, max_track_number)): - # Update existing layer # + # Update existing layer number track = Track.get(number=existing_layer) track.data["number"] = existing_layer - 1 track.save() @@ -1458,6 +1468,11 @@ def actionRemoveTrack_trigger(self, event): clip.data["layer"] = int(clip.data["layer"]) - 1 clip.save() + for trans in Transition.filter(layer=existing_layer): + trans.data["layer"] = int(trans.data["layer"]) - 1 + trans.save() + + # Clear selected track self.selected_tracks = []