self._minimumInTicks=[0]# if this is bigger than the actual duration-sum of the content this will be used instead. Advice: best used in the form of x*210 (multiple of real base-durations) #is content linked, thats why it is a mutable list of len==1.
self._name=[str(id(self))]#list of len==1 so it is mutable for linked blocks. See @property below
self._minimumInTicks=[0]# if this is bigger than the actual duration-sum of the content this will be used instead. Advice: best used in the form of x*210 (multiple of real base-durations) #is content linked, thats why it is a mutable list of len==1. See @property below
self.linkedContentBlocks=WeakSet()#only new standalone blocks use this empty WeakSet. once you contentLink a block it will be overwritten.
self._secondInit(parentTrack=track)
@ -45,14 +45,28 @@ class Block(object):
self.linkedContentBlocks.add(self)
self.rememberBlock()
@property
defname(self):
"""name must be mutable so it is shared between content link blocks"""
returnself._name[0]
@name.setter
defname(self,name:str):
listId=id(self._name)#just a precaution
self._name.pop()
self._name.append(name)
assertlen(self._name)==1
assertlistId==id(self._name)
@property
defminimumInTicks(self):
"""minimumInTicks must be mutable so it is shared between content link blocks"""
returnself._minimumInTicks[0]
@minimumInTicks.setter
defminimumInTicks(self,newValue):
defminimumInTicks(self,newValue:int):
"""Keep the mutable list at all cost"""
listId=id(self._minimumInTicks)
listId=id(self._minimumInTicks)#just a precaution
self._minimumInTicks.pop()
self._minimumInTicks.append(newValue)
assertlen(self._minimumInTicks)==1
@ -66,16 +80,17 @@ class Block(object):
ifserializedObject["data"]isNone:#Found a content linked block which already has one member of its group in the score
firstBlock=Block.firstBlockWithNewContentDuringDeserializeToObject[serializedObject["contentLinkGroup"]]#block with the same contentGroup. This is the one with the real data.
self.data=firstBlock.data
self._minimumInTicks=firstBlock._minimumInTicks
self._minimumInTicks=firstBlock._minimumInTicks#mutable list
self._name=firstBlock._name#mutable list
self.linkedContentBlocks=firstBlock.linkedContentBlocks#add self to this is in _secondInit
else:#found a stand-alone block or the first one of a content link group
new._minimumInTicks=self._minimumInTicks[:]#it is a mutable value, we make a copy of the list (which has an int inside, which is immutable and copied automatically)
returnnew
defgetUnlinkedData(self):
@ -210,7 +225,7 @@ class Block(object):
new.linkedContentBlocks=self.linkedContentBlocks
new.linkedContentBlocks.add(new)
new.data=self.data#mutable. Will change in all blocks together.
new.name=self.name#immutable. Will change independently but we start with the same name.
new._name=self._name#mutable as well.
new._minimumInTicks=self._minimumInTicks#mutable
#Add the new block to the parentBlocks set but don't delete self from it, as in copy(). The items are now in more than one block simultaniously