@ -273,10 +273,7 @@ class TrackState(object):
""" TrackState stays not the same for one track but gets recreated, at least in track.head().
This means init is always position 0. """
defaultClef = Clef ( " treble " )
defaultDynamicSignature = DynamicSignature ( " custom " ) #This is the start dynamic value like 'forte', not the DynamicSettingsSignature
defaultMetricalInstruction = MetricalInstruction ( tuple ( ) , isMetrical = False )
defaultKeySignature = KeySignature ( 20 , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] )
def __init__ ( self , track ) :
self . track = track
@ -286,10 +283,9 @@ class TrackState(object):
self . ticksSinceLastMeasureStart = 0 #Only for export.
self . barlines = [ ] #a list of ints/tickpositions. These are the non-editable, non-movable single barlines.
#stacks. There is always one item left in the stack, the default:
self . keySignatures = [ self . defaultKeySignature ] #C Major
#self.clefs = [self.defaultClef]
self . keySignatures = [ track . initialKeySignature ]
self . clefs = [ Clef ( track . initialClefKeyword ) ]
self . metricalInstructions = [ self . default MetricalInstruction] #no barlines, no metrical information.
self . metricalInstructions = [ track . initial MetricalInstruction] #no barlines, no metrical information.
self . dynamicSignatures = [ self . defaultDynamicSignature ]
self . dynamicRamp = None #Not for cursor movement so it is not a stack.
self . EXPORTtiedNoteExportObjectsWaitingForClosing = { } #pitch:noteExportObject . Empty during cursor movement, filled during export.
@ -401,9 +397,8 @@ class Track(object):
#Since version 2.1.0 the initial signature can be set by the user, mostly as a GUI convenience.
#These are used by the track-state init/head
self . initialClefKeyword : str = " treble " #it is much easier to handle the keyword with save/load and setting this value, so we are not using the item.Clef class
#self.initialMetricalInstruction = MetricalInstruction(tuple(), isMetrical = False)
#self.initialKeySignature = KeySignature(20, [0,0,0,0,0,0,0])
self . initialKeySignature = KeySignature ( 20 , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) #C Major
self . initialMetricalInstruction = MetricalInstruction ( tuple ( ) , isMetrical = False )
self . asMetronomeData = None #This track as metronome version. Is always up to date through export.
@ -842,21 +837,36 @@ class Track(object):
This dict begins here . Each track gets its own .
"""
carryLilypondRanges = { } #handed from item to item for ranges such as tuplets. Can act like a stack or simply remember stuff.
#Initial Metrical Instruction
for item in self . blocks [ 0 ] . data [ : 4 ] :
if type ( item ) is MetricalInstruction :
if type ( item ) is MetricalInstruction : #don't use the initial. use the user provided one.
timeSig = " "
break
else :
timeSig = " \\ once \\ override Staff.TimeSignature # ' stencil = ##f \\ cadenzaOn \n "
if self . initialMetricalInstruction . treeOfInstructions :
timeSig = self . initialMetricalInstruction . lilypond ( carryLilypondRanges ) + " \n "
else :
timeSig = " \\ once \\ override Staff.TimeSignature # ' stencil = ##f \\ cadenzaOn \n "
#Initial Clef
for item in self . blocks [ 0 ] . data [ : 4 ] :
if type ( item ) is Clef :
if type ( item ) is Clef : #don't use the initial. use the user provided one.
clef = " "
break
else :
clef = " \\ clef " + self . initialClefKeyword + " \n " #internal clef keywords are the same as lilypond
carryLilypondRanges = { } #handed from item to item for ranges such as tuplets. Can act like a stack or simply remember stuff.
#Initial Key Signature
for item in self . blocks [ 0 ] . data [ : 4 ] :
if type ( item ) is KeySignature : #don't use the initial. use the user provided one.
keySignature = " "
break
else :
keySignature = self . initialKeySignature . lilypond ( carryLilypondRanges ) + " \n "
upbeatLy = " \\ partial {} " . format ( Duration . createByGuessing ( self . upbeatInTicks ) . lilypond ( carryLilypondRanges ) ) if self . upbeatInTicks else " "
@ -911,7 +921,7 @@ class Track(object):
pass
if lyData :
return clef + timeSig + upbeatLy + lyData + " \n "
return clef + keySignature + timeSig + upbeatLy + lyData + " \n "
else :
return " " #Empty track
@ -926,6 +936,8 @@ class Track(object):
" double " : self . double ,
" initialClefKeyword " : self . initialClefKeyword ,
" initialKeySignature " : self . initialKeySignature . serialize ( ) ,
" initialMetricalInstruction " : self . initialMetricalInstruction . serialize ( ) ,
" initialMidiChannel " : self . initialMidiChannel ,
" initialMidiProgram " : self . initialMidiProgram ,
" initialMidiBankMsb " : self . initialMidiBankMsb ,
@ -947,8 +959,8 @@ class Track(object):
self . upbeatInTicks = int ( serializedData [ " upbeatInTicks " ] )
self . blocks = [ Block . instanceFromSerializedData ( block , parentObject = self ) for block in serializedData [ " blocks " ] ]
self . durationSettingsSignature = DurationSettingsSignature . instanceFromSerializedData ( serializedData [ " durationSettingsSignature " ] , parentObject = self )
self . dynamicSettingsSignature = DynamicSettingsSignature . instanceFromSerializedData ( serializedData [ " dynamicSettingsSignature " ] , parentObject = self )
self . durationSettingsSignature = DurationSettingsSignature . instanceFromSerializedData ( serializedData [ " durationSettingsSignature " ] , parentObject = self )
self . dynamicSettingsSignature = DynamicSettingsSignature . instanceFromSerializedData ( serializedData [ " dynamicSettingsSignature " ] , parentObject = self )
self . double = serializedData [ " double " ]
self . initialMidiChannel = serializedData [ " initialMidiChannel " ]
self . initialMidiProgram = serializedData [ " initialMidiProgram " ]
@ -966,6 +978,16 @@ class Track(object):
else :
self . initialClefKeyword = " treble "
if " initialKeySignature " in serializedData :
self . initialKeySignature = KeySignature . instanceFromSerializedData ( serializedData [ " initialKeySignature " ] , parentObject = self )
else :
self . initialKeySignature = KeySignature ( 20 , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) #C Major
if " initialMetricalInstruction " in serializedData :
self . initialMetricalInstruction = MetricalInstruction . instanceFromSerializedData ( serializedData [ " initialMetricalInstruction " ] , parentObject = self )
else :
self . initialMetricalInstruction = MetricalInstruction ( tuple ( ) , isMetrical = False )
self . _processAfterInit ( )
return self
@ -1254,7 +1276,10 @@ class Track(object):
metaData [ " barlines " ] = barlines . keys ( )
metaData [ " duration " ] = self . state . tickindex #tickindex is now at the end, so this is the end duration. This includes Blocks minimumDuration as well since it is included in left/right
metaData [ " beams " ] = resultBeamGroups
metaData [ " initialClef " ] = self . initialClefKeyword
metaData [ " initialClef " ] = self . initialClefKeyword #it is already a string
#the state is at the end, but it doesn't matter for the init-sigs. It will show the wrong tick index, but don't worry.
metaData [ " initialKeySignature " ] = self . initialKeySignature . exportObject ( self . state )
metaData [ " initialMetricalInstruction " ] = self . initialMetricalInstruction . exportObject ( self . state )
#Notes
t = ( midiNotesBinaryCboxData , 0 , self . state . tickindex )