Skip to content

Commit

Permalink
Merge pull request #1546 from ferdnyc/track-names
Browse files Browse the repository at this point in the history
Retain track parameters during add/remove track
  • Loading branch information
DylanC authored May 6, 2018
2 parents e93e5f7 + 82784fd commit 0e89e3e
Showing 1 changed file with 46 additions and 18 deletions.
64 changes: 46 additions & 18 deletions src/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -901,22 +901,34 @@ 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 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}
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"]))
Expand All @@ -926,20 +938,32 @@ 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 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}
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")

Expand Down Expand Up @@ -1433,18 +1457,22 @@ 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.data["label"] = ""
track.save()

for clip in Clip.filter(layer=existing_layer):
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 = []

Expand Down

0 comments on commit 0e89e3e

Please sign in to comment.