From 22d2104b8539fe9b66dc002d84f3f5aece9c73f5 Mon Sep 17 00:00:00 2001 From: Nils <> Date: Sun, 5 May 2019 01:25:31 +0200 Subject: [PATCH] fix CC block split/merge and undo --- engine/api.py | 14 +++++++++----- engine/ccsubtrack.py | 19 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/engine/api.py b/engine/api.py index ca987f8..5d27622 100644 --- a/engine/api.py +++ b/engine/api.py @@ -1974,7 +1974,7 @@ def deleteCCBlock(graphBlockId): def extendLastCCBlockToTrackLength(trId, cc): ccTrack = session.data.trackById(trId).ccGraphTracks[cc] lastCCBlock = ccTrack.blocks[-1] - _CCUndoCreater(trId, cc, "Exten last CC Block to Track length") + _CCUndoCreater(trId, cc, "Extend last CC Block to Track length") lastCCBlock.extendToTrackLength(ccTrack) callbacks._updateGraphTrackCC(trId, cc) @@ -1986,8 +1986,10 @@ def splitCCBlock(graphBlockId, positionInTicksRelativeToBlock): success = ccTrack.splitGraphBlock(graphBlock, positionInTicksRelativeToBlock) if success: description = "Split CC Block" - session.history.register(lambda: _lazyCCUndoRedo(trId, cc, oldData, description), descriptionString=description) - callbacks._updateGraphTrackCC(trId, cc) + session.history.register(lambda: _lazyCCUndoRedo(trId, cc, oldData, description), descriptionString=description) + callbacks._historyChanged() + callbacks._updateGraphTrackCC(trId, cc) + def mergeWithNextGraphBlock(graphBlockId): trId, cc, graphBlock = session.data.graphBlockById(graphBlockId) @@ -1996,8 +1998,9 @@ def mergeWithNextGraphBlock(graphBlockId): positionForSplit = ccTrack.mergeWithNextGraphBlock(graphBlock) if positionForSplit: description = "Split CC Block" - session.history.register(lambda: _lazyCCUndoRedo(trId, cc, oldData, description), descriptionString=description) - callbacks._updateGraphTrackCC(trId, cc) + session.history.register(lambda: _lazyCCUndoRedo(trId, cc, oldData, description), descriptionString=description) + callbacks._historyChanged() + callbacks._updateGraphTrackCC(trId, cc) ##CC Blocks and User Points @@ -2375,6 +2378,7 @@ def _reorderChords(functionToGenerateChordOrder, descriptionString): originalOrder.append((data, index, chord)) for chord in track: + data = next(bl for bl in chord.parentBlocks).data #just take any block. data is shared between all of them. Content linked data was removed from the selection data.remove(chord) for data, index, chord in originalOrder: diff --git a/engine/ccsubtrack.py b/engine/ccsubtrack.py index 22529b8..044e34e 100644 --- a/engine/ccsubtrack.py +++ b/engine/ccsubtrack.py @@ -469,13 +469,13 @@ class GraphTrackCC(object): block = graphBlock if len(self.blocks) == 1: - #print ("only one block in the track") + logging.info("CC Block merge aborted: only one block in the track") return False blockIndex = self.blocks.index(block) if blockIndex+1 == len(self.blocks): - #print ("not for the last block") + logging.info("CC Block merge aborted: not for the last block") return False nextIndex = blockIndex + 1 @@ -505,16 +505,16 @@ class GraphTrackCC(object): #Further testing required: for firstBlock, secondBlock in zip(block.linkedContentBlocksInScore(), nextBlock.linkedContentBlocksInScore()): if firstBlock.data is secondBlock.data: #content link of itself in succession. Very common usecase, but not compatible with merging. - #print ("content link follows itself") + logging.info("CC Block merge aborted: content link follows itself") return False elif not self.blocks.index(firstBlock) + 1 == self.blocks.index(secondBlock): #all first blocks must be followed directly by a content link of the second block. linkedContentBlocksInScore() returns a blocklist in order so we can compare. - #print ("not all blocks-pairs are next to each other") + logging.info("CC Block merge aborted: not all content link blocks-pairs are next to each other") return False - + #Test complete without exit. All blocks can be paired up. - #print ("Test complete. Merging begins") block.deleteHiddenItems() + nextBlock.deleteHiddenItems() if firstBlock_endingValue == nextBlock_startingValue: #remove redundancy del nextBlock.data[0] @@ -522,6 +522,13 @@ class GraphTrackCC(object): for pos, item in nextBlock.data.items(): assert not pos + block.duration in block.data #this includes pos==0, if not deleted above. block.data[pos + block.duration] = item + + newFirstBlockDuration = block.duration+nextBlock.duration + for firstBlock, secondBlock in zip(block.linkedContentBlocksInScore(), nextBlock.linkedContentBlocksInScore()): + firstBlock._duration = [newFirstBlockDuration,] #Duration is content linked. if we use the setter it will create the wrong sum. Force the new duration instead. + self.deleteBlock(secondBlock) + + return startDurationToReturnForUndo def deleteBlock(self, graphBlock): """at least one block. If you want to delete the track