#Find sequential content-linked blocks to convert them into lilypond voltas
last=set()
currentFirstBlockInARow=None
repeatCounter=0
blockRepeatIndex={}#block : int
blockRepeatTotal={}#first block : int. This is not the same as len(set(block.linkedContentBlocksInScore())) because the latter is all links in total, while we only want the consecutive count. Only the first block of a row is in here.
#TODO: Contentlink -> Volta conversion is currently deactivated for multi-track. Too many lilypond problems
#As long as blockRepeatTotal exists and is empty export will treat each block as standalone, so everything works
#The commented-out code does not show the number of repeats, and more importantly, places the same repeats in all staffs, even if they do not exist there.
#This is not compatible with real-life music where one instrument plays the same part twice, but the second one has a different version the 2nd time.
#If we ever find a lilypond way to only set synchronized repeats this can get activated for more tracks.
codeActivated=len(self.parentData.tracks)==1
codeActivated=False#TODO: NO! Too fragile
forblockinself.blocks:#in order
links=set(block.linkedContentBlocksInScore())#it's a generator
iflinks:
ifcodeActivatedandlinks==last:
#This is not the first one in a row.
repeatCounter+=1
blockRepeatTotal[currentFirstBlockInARow]+=1
else:
#This is the first one in a row. Reset.
repeatCounter=0
currentFirstBlockInARow=block
blockRepeatTotal[currentFirstBlockInARow]=1
last=links
blockRepeatIndex[block]=repeatCounter#0 for standalone blocks. Each block one entry
#Another round through the blocks to generate data
lyData=""
forblockinself.blocks:
ifblockinblockRepeatTotal:
l=blockRepeatTotal[block]
ifl>1:
assertblockRepeatIndex[block]==0
lyData+=f"\n\\repeat volta {l}"+block.lilypond(carryLilypondRanges)#the lilypond block includes music expression { }
else:
#No voltas. We could do \repeat volta 1 but that would be ugly lilypond.
lyData+=block.lilypond(carryLilypondRanges)
else:
# A linked block in a row.
# do NOT export any content linked block that is not the first in a row.