"""Source-derived ending geometry, independent of instrument composition.""" import copy import fractions import generator.model BARS = 3 def template(source): result = copy.deepcopy(source[-1]) # An ending is three full bars in the final active meter, never a pickup. for change in result.get('attributes', []): for key in ('meter', 'key', 'clef', 'transpose', 'staff_details'): if key in change: result[key] = copy.deepcopy(change[key]) result.update(duration=generator.model.rational(generator.model.meter_length(result['meter'])), implicit=False, attributes=[], harmonies=[], voices=[], tempos=[], section_label='') result['time_signature'] = generator.model.meter_label(result['meter']) return result def duration(source): return BARS * generator.model.fraction(template(source)['duration']) if source else fractions.Fraction()