Browse Source

fix CC block split/merge and undo

master
Nils 5 years ago
parent
commit
22d2104b85
  1. 14
      engine/api.py
  2. 19
      engine/ccsubtrack.py

14
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:

19
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

Loading…
Cancel
Save