importtemplate.engine.api#we need direct access to the module to inject data in the provided structures. but we also need the functions directly. next line:
returnnewData,linkedContentBlocks,self._duration[:]#mutable. the api uses the list directly as well because we want to undo/restore the old original list, which may be content linked.
elifnotself.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.
logger.info("CC Block merge aborted: not all content link blocks-pairs are next to each other")
returnFalse
#Test complete without exit. All blocks can be paired up.
block.deleteHiddenItems()
@ -521,11 +519,11 @@ class GraphTrackCC(object):
forpos,iteminnextBlock.data.items():
assertnotpos+block.durationinblock.data#this includes pos==0, if not deleted above.
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)
self.deleteBlock(secondBlock)
returnstartDurationToReturnForUndo
@ -637,7 +635,7 @@ class GraphTrackCC(object):
result.append(exportDictItem)
typeString="interpolated"#The next items in userItemAndInterpolatedItemsPositions are interpolated items. Reset once we leave the local forLoop.
#numbers from 0-15 which represent the midi channels all CCs are sent to. Only replaced by a new tuple by the user directly.
#numbers from 0-15 which represent the midi channels all CCs are sent to. Only replaced by a new tuple by the user directly.
ifself.parentTrack.ccChannels:
forchannelinself.parentTrack.ccChannels:
blob=cbox.Pattern.serialize_event(exportDictItem["position"],0xB0+channel,self.cc,ccValue)#position, status byte+channel, controller number, controller value #TODO use channel of the parent note track at that moment in time.
@ -648,11 +646,11 @@ class GraphTrackCC(object):
#Prepare data for the next block.
sumOfBlocksDurationsWithoutCurrent+=block.duration#the naming is only true until the last iteration. Then all blocks, even the current one, are in the sum and can be used below.
sumOfBlockDurations=sumOfBlocksDurationsWithoutCurrent#Choose the correct name. Explicit is better than implicit.
#TODO: A bit wasteful. Optimisation? Did really a content linked block change?
result=set()
forblockinself.blocks:
forlinkedBlockinblock.linkedContentBlocks:
result.add(linkedBlock.parentGraphTrack)
assertresult#at least this very track
assertlen(result)<=len(self.parentTrack.parentData.tracks)#For now we assume that blocks cannot be linked across CCs. This can be removed after we tested it for a while and the time comes for cross-CC links
forlinkedBlockinblock.linkedContentBlocks:
result.add(linkedBlock.parentGraphTrack)
assertresult#at least this very track
assertlen(result)<=len(self.parentTrack.parentData.tracks)#For now we assume that blocks cannot be linked across CCs. This can be removed after we tested it for a while and the time comes for cross-CC links