def make_two_staff_unordered_cells_score(): cells = manifolds.etc.pitch.unordered_cells_sequence directions = manifolds.etc.pitch.segmentation_series harmonic_walk = sequencetools.flatten_sequence(manifolds.etc.pitch.harmonic_walk) score = Score([]) piano_staff = PianoStaff([]) score.append(piano_staff) treble = Staff([]) treble.accidental.style = "forget" treble.clef.forced = Clef("treble") bass = Staff([]) bass.accidental.style = "forget" bass.clef.forced = Clef("bass") piano_staff.append(treble) piano_staff.append(bass) duration = Fraction(1, 16) for cell_number, cell in enumerate(cells): measure = AnonymousMeasure([]) notes = [Note(pitch, duration) for pitch in cell] measure.extend(notes) rest_measure = clone.unspan([measure])[0] for i, note in enumerate(rest_measure): rest_measure[i] = Rest(note.duration.written) pitches = [note.pitch for note in notes] clef = pitchtools.suggest_clef(pitches) if clef == Clef("treble"): treble.append(measure) bass.append(rest_measure) else: treble.append(rest_measure) bass.append(measure) if 26 < max(cell): octavation = Octavation(measure[:]) octavation.start = 1 if directions[cell_number % 16] == -1: direction = "L" else: direction = "R" field_number = (cell_number + 6) % 8 + 1 center_pitch = harmonic_walk[cell_number % len(harmonic_walk)] chord = Chord(measure[0]) notehead = NoteHead(None, center_pitch) notehead.style = "harmonic" notehead.color = "blue" chord.append(notehead) first_leaf = treble[-1].leaves[0] first_leaf.markup.up.append(str(cell_number)) label = r"\line { %s%s \with-color #blue (%s) }" % (direction, field_number, center_pitch) first_leaf.markup.up.append(label) front, back = Fraction(1, 16), Fraction(1, 32) layout.insert_measure_padding(score, front, back) lengths = manifolds.etc.pitch.harmonic_walk_lengths parts = sequencetools.partition_by_lengths(treble[:], lengths, cyclic=True) for part in parts: if 1 < len(part): bracket = Bracket(part) bracket.staff_padding = None parts = sequencetools.partition_by_lengths(bass[:], lengths, cyclic=True) for part_number, part in enumerate(parts): label = r"\with-color #blue \circle{ %s }" % (part_number + 1) part[0][1].markup.down.append(label) layout.line_break_every_prolated(treble, Fraction(58, 16)) layout.line_break_every_prolated(bass, Fraction(58, 16)) staves = StaffAlignmentOffsets(0, -10) systems = SystemYOffsets(45, 5) positioning = FixedStaffPositioning(systems, staves) layout.apply_fixed_staff_positioning(treble, positioning) score.rest.transparent = True return score
def make_cells_with_prominences_score(): from manifolds.etc.pitch import prominent_section_numbers from manifolds.etc.pitch import sequence_with_prominences as sections from manifolds.etc.pitch._helpers import field_id_to_segmented_field from manifolds.etc.pitch._helpers import section_index_to_polar_value assert len(sections) == 46 score, treble, bass = make_piano_staff() prominence_lengths = _prominence_lengths() duration = Fraction(1, 16) output_cells = [] cell_index_in_score = 0 ## enumerate forty-six separate sections for section_index, section in enumerate(sections): cur_polar_value = section_index_to_polar_value(section_index) next_polar_value = section_index_to_polar_value(section_index + 1) prominence_length = prominence_lengths[section_index] first_prominent_triple = len(section) - prominence_length - 1 cell_number_in_section = 1 first_field_id_in_prominence = None second_field_id_in_prominence = None for triple_index, triple in enumerate(section): section_number = section_index + 1 field_id, middle, cell = triple segmented_field = field_id_to_segmented_field(field_id) cell_number_in_field = segmented_field.index(cell) + 1 if 0 < prominence_length and first_prominent_triple <= triple_index: if cell_number_in_prominence is None: cell_number_in_prominence = 1 first_field_id_in_prominence = field_id else: cell_number_in_prominence += 1 if not field_id == first_field_id_in_prominence: second_field_id_in_prominence = field_id else: cell_number_in_prominence = None measure = AnonymousMeasure([]) notes = [Note(pitch, duration) for pitch in cell] measure.extend(notes) if triple_index + 1 == len(section): measure.barline.kind = '||' if cell_number_in_prominence is not None: measure.notehead.style = 'harmonic' for leaf in measure.leaves: leaf.notehead.color = 'red' rest_measure = clone.unspan([measure])[0] for i, note in enumerate(rest_measure): rest_measure[i] = Rest(note.duration.written) pitches = [note.pitch for note in notes] cell_clef = pitchtools.suggest_clef(pitches) if cell_clef == Clef('treble'): treble.append(measure) bass.append(rest_measure) else: treble.append(rest_measure) bass.append(measure) if 26 < max(cell): octavation = Octavation(measure[:]) octavation.start = 1 notated_polar_value = cur_polar_value if cell_number_in_prominence is not None: if field_id == second_field_id_in_prominence: notated_polar_value = next_polar_value polar_clef = pitchtools.suggest_clef([Pitch(notated_polar_value)]) if polar_clef == cell_clef: chord = Chord(measure[0]) notehead = NoteHead(None, notated_polar_value) chord.append(notehead) else: note = Note(rest_measure[0]) note.pitch = notated_polar_value notehead = note.notehead notehead.style = 'harmonic' notehead.color = 'blue' first_leaf = bass[-1].leaves[0] if cell_number_in_prominence is not None: first_markup = r'\small \line { %s / %s-%s-%s }' % ( cell_index_in_score, section_number, first_prominent_triple + 1, cell_number_in_prominence) else: first_markup = r'\small \line { %s / %s-%s }' % ( cell_index_in_score, section_number, cell_number_in_section) first_leaf.markup.down.append(first_markup) second_markup = r'\small \line { %s-%s \with-color #blue (%s) }' % ( field_id, cell_number_in_field, notated_polar_value) first_leaf.markup.down.append(second_markup) ## make output to write to disk output_cell = ( cell_index_in_score, field_id, cell_number_in_field, cell, section_number, cell_number_in_section, cell_number_in_prominence, notated_polar_value) output_cells.append(output_cell) cell_number_in_section += 1 cell_index_in_score += 1 lower_bass_markup_blocks(bass) front, back = Fraction(1, 16), Fraction(1, 32) layout.insert_measure_padding(score, front, back) section_lengths = [len(section) for section in sections] label_sections_in_treble_in_blue(treble, section_lengths) treble.text.X_offset = 'center' treble.text.self_alignment_X = 'center' bass.text.staff_padding = 4 layout.line_break_every_prolated(treble, Fraction(54, 16)) layout.line_break_every_prolated(bass, Fraction(54, 16)) staves = StaffAlignmentOffsets(0, -10) systems = SystemYOffsets(45, 5) positioning = FixedStaffPositioning(systems, staves) layout.apply_fixed_staff_positioning(treble, positioning) score.rest.transparent = True score.formatter.number.measures = 'comment' return score, output_cells