Browse Source

Better remove empty blocks. Now works for practically empty tracks. Cosmetic bug still present when removing content linked blocks and then do undo

master
Nils 6 years ago
parent
commit
0a69dcc8dd
  1. 1
      engine/api.py
  2. 11
      engine/main.py

1
engine/api.py

@ -772,6 +772,7 @@ def deleteCurrentBlock():
def deleteEmptyBlocks():
"""whole score"""
dictOfTrackIdsWithListOfBlockIds = session.data.removeEmptyBlocks()
#We keep everything in dictOfTrackIdsWithListOfBlockIds. Empty blocks have been removed from this data.
if dictOfTrackIdsWithListOfBlockIds and all(l for l in dictOfTrackIdsWithListOfBlockIds.values()):
rearrangeBlocksInMultipleTracks(dictOfTrackIdsWithListOfBlockIds) #handles undo and callbacks for redrawing
callbacks._setCursor()

11
engine/main.py

@ -1023,11 +1023,18 @@ class Data(template.engine.sequencer.Score):
#for trId, track in Track.allTracks.items():
for track in list(self.hiddenTracks.keys()) + self.tracks:
if len(track.blocks) <= 1:
continue #next track
#Get all blocks and then remove those with no content.
trId = id(track)
listOfBlockIds = track.asListOfBlockIds()
listOfBlockIds = track.asListOfBlockIds()
for block in track.blocks:
if not block.data and len(track.blocks) > 1:
if not block.data:
listOfBlockIds.remove(id(block))
#Maybe the track was empty. In this case we add one of the blocks again. Otherwise follow up functions will not act.
if not listOfBlockIds:
listOfBlockIds.append(id(block))
dictOfTrackIdsWithListOfBlockIds[trId] = listOfBlockIds
return dictOfTrackIdsWithListOfBlockIds

Loading…
Cancel
Save