def set_tempi(score): curr_tempo = None for c in iterate(score).by_class((Container,)): tempo = to_abjad.get_named_annotation(c, 'tempo') if tempo and not tempo == curr_tempo: fst = next(topleveltools.iterate(c).by_class((Chord, Rest))) attach(Tempo((1,4), tempo), fst) if tempo: curr_tempo = tempo
def annotate_containers(score): fns = { 'section_container': add_staff_markup } for c in iterate(score).by_class((Container, Voice)): score_id_ann = to_abjad.get_named_annotation(c, 'score_id') if score_id_ann: fn = fns.get(score_id_ann) if fn: fn(c)
def apply_pulse(group): if (isinstance(group[0], Chord)): notation = to_abjad.get_named_annotation(group[0], 'notation') # Make an iterator from 'pattern' which can be used for all # groups. pattern = itertools.cycle(notation['pattern']) for event in group: total_duration = event.written_duration pulse = create_pulse( notation['subdivisions'], pattern, event.written_pitches, total_duration, ) selection = select(event) mutate(selection).replace(pulse)
def main(): parser = argparse.ArgumentParser() parser.add_argument('--input', dest='input') parser.add_argument('--output', dest='output') args = parser.parse_args() with open(args.input, 'r') as infile: score = json.load(infile) # TODO: score overrides template = create_score_objects() score = to_abjad.Score(score) sections = score.to_abjad() apply_score_overrides(template.score) for section in sections: for staff_container in section: score.apply_spanners(staff_container) interpret_spanners(staff_container) annotate_containers(staff_container) for i, section in enumerate(sections): for staff_container in section: container_name = to_abjad.get_named_annotation(staff_container, 'name') template.staves[container_name].append(staff_container) set_tempi(template.score) hide_superfluous_time_signatures(template.staves) apply_accidentals(template.score) with open('/tmp/score.txt', 'w') as outfile: for s in midi_output.export_as_qlist(template.score): outfile.write(s) outfile.write('\n') lilypond_file = make_lilypond_file( template.score, title='Test', author='Anonymous', ) persist(lilypond_file).as_ly(args.output)
def notation_grouper(x): try: ann = to_abjad.get_named_annotation(x, 'notation').get('type') return ann except: return None
def add_staff_markup(staff): fst = next(topleveltools.iterate(staff).by_class((Chord, Rest))) text = to_abjad.get_named_annotation(staff, 'notation') attach(Markup(text, direction=Up), fst) attach(indicatortools.BarLine('||'), staff[-1])