def make_harmonic_walk_sections():

    harmonic_walk = manifolds.etc.pitch.harmonic_walk
    harmonic_walk = sequencetools.flatten_sequence(harmonic_walk)
    lengths = manifolds.etc.pitch.harmonic_walk_lengths
    sections = sequencetools.partition_by_lengths(harmonic_walk, lengths)
    sections = [tuple(x) for x in sections]

    return sections
def make_territoires_parts():

    ratio = [1] * 9
    lengths = mathtools.partition_integer_by_ratio(164, ratio)
    parts = sequencetools.partition_by_lengths(fully_labelled_cells, lengths)

    parts = sequencetools.rotate(parts, -3)
    territoires_parts = parts[:2] + parts[3:8]

    originals = range(1, 9 + 1)

    ## territoires part numbers are [(4, 5), 6, (7, 8, 9, 1, 2), 3]
    territoires_part_numbers = [4, 5, 7, 8, 9, 1, 2]
    original_territoires_part_numbers = zip(originals, territoires_part_numbers)

    parts = sequencetools.rotate(parts, -3)
    manifolds_parts = parts[:4] + parts[5:]

    ## manifolds part numbers are [(7, 8, 9, 1), 2, (3, 4, 5, 6)]
    manifolds_part_numbers = [7, 8, 9, 1, 3, 4, 5, 6]
    original_manifolds_part_numbers = zip(originals, manifolds_part_numbers)

    return territoires_parts, original_territoires_part_numbers, \
        manifolds_parts, original_manifolds_part_numbers
def label_sections_in_treble_in_blue(treble, section_lengths):

    treble_sections = sequencetools.partition_by_lengths(
        treble[:], section_lengths, cyclic = True)

    for section_index, treble_section in enumerate(treble_sections):
        section_number = section_index + 1
        if 1 < len(treble_section):
            treble_leaves = list(iterate.naive(treble_section, _Leaf))
            bracket = Bracket(treble_leaves[1:])
            bracket.staff_padding = 8
            bracket.color = 'blue'
            bracket.dash_period = 2
            bracket.dash_fraction = 0.25
            section_markup = '\halign #0 \with-color #blue \circle { %s } " "'
            section_markup %= section_number
            bracket.bound_details__left__text = Markup(section_markup)
            bracket.bound_details__left__stencil_align_dir_y = 'center'
        else:
            first_note = treble_section[0][1]
            section_markup = '\with-color #blue \circle { %s } " "'
            section_markup %= section_number
            first_note.markup.up.append(section_markup)
            first_note.text.staff_padding = 8
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
示例#5
0
def P(l):
    return sequencetools.partition_by_lengths(l, [12], cyclic=False, overhang=False)
示例#6
0
# -*- coding: utf-8 -*-
from abjad.tools import sequencetools
from baca import tools


sixteenths = [[1, 1, 5], [1, 2, 4, 5]]
sixteenths = tools.helianthate(sixteenths, 1, 1)
sixteenths *= 3
# TODO: Unsure whether overhang should be True or False below
sixteenths = sequencetools.partition_by_lengths(
    sixteenths, 
    [2, 3], 
    cyclic=True, 
    overhang=True,
    )
sixteenths = [sum(part) for part in sixteenths]

pairs = [(n / 2, 8) if n % 2 == 0 else (n, 16) for n in sixteenths]
#durations = [duration.Duration(*p) for p in pairs]
durations = [Fraction(*p) for p in pairs]
directives = [r'\time %s/%s' % (p[0], p[1]) for p in pairs]

outer = [[2, 4, 4, 4], [2, 3, 4, 6], [2, 6, 6]] # valid
outer = tools.helianthate(outer, 1, 1)
#tools.segment(outer, sixteenths * 3, cycle = 'sheet')
#outer = tools.segment(outer, sixteenths * 5, cycle = 'sheet')
outer = sequencetools.repeat_list_to_weight(outer, sum(sixteenths * 5), remainder = 'more')
outer = sequencetools.partition_sequence_once_by_weights_at_least_without_overhang(outer, sixteenths * 5)

keys, shared, breath, rotation, distance = sequencetools.partition_by_lengths(
    outer, len(sixteenths), cyclic = False, overhang = False)
def make_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([])
    staff = Staff([])
    staff.accidental.style = 'forget'
    score.append(staff)

    duration = Fraction(1, 16)
    for cell_number, cell in enumerate(cells):
        measure = AnonymousMeasure([])
        notes = [Note(pitch, duration) for pitch in cell]
        measure.extend(notes)
        pitches = [note.pitch for note in notes]
        clef = pitchtools.suggest_clef(pitches)
        measure.clef.forced = clef

        if 26 < max(cell):
            octavation = Octavation(measure[:])
            octavation.start = 1

        measure.formatter.number.self = 'comment'
        staff.append(measure)

        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 = measure.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(measure, front, back)

    lengths = manifolds.etc.pitch.harmonic_walk_lengths
    parts = sequencetools.partition_by_lengths(staff[:], lengths, cyclic = True)
    spacing_voice = Voice([])

    for part_number, part in enumerate(parts):
        if 1 < len(part):
            bracket = Bracket(part)
            bracket.staff_padding = None

        skip = Skip((1, 16))
        spacing_voice.append(skip)

        skip = Skip((1, 1))
        skip.duration.multiplier = durationtools.sum_prolated(part) - Fraction(1, 16)
        spacing_voice.append(skip)

        label = r'\with-color #blue \circle { %s }' % (part_number + 1)
        skip.markup.down.append(label)

    spacing_voice.text.staff_padding = 4

    Voice(staff[:])
    staff.parallel = True
    staff.append(spacing_voice)

    lines = Fraction(58, 16)
    systems = SystemYOffsets(33, 7, 1)
    positioning = FixedStaffPositioning(systems)
    layout.line_break_every_prolated(staff, lines)
    layout.apply_fixed_staff_positioning(staff, positioning)

    score.rest.transparent = True

    return score
def make_sequence_with_prominences():

    harmonic_walk_lengths = manifolds.etc.pitch.harmonic_walk_lengths
    harmonic_walk_lengths *= 2

    field_center_cell_triples = manifolds.etc.pitch.field_center_cell_triples

    assert sum(harmonic_walk_lengths) == len(field_center_cell_triples)

    partitioned_triples = sequencetools.partition_by_lengths(
        field_center_cell_triples, harmonic_walk_lengths)

    prominent_sections = manifolds.etc.pitch.prominent_sections

    assert len(prominent_sections) == len(partitioned_triples) == 46

    prominent_section_numbers = manifolds.etc.pitch.prominent_section_numbers

    pairwise_parts = sequencetools.pairwise(partitioned_triples, mode = 'wrap')

    from manifolds.etc.pitch._helpers import field_number_to_field

    prominent_counts = manifolds.etc.pitch.prominent_counts

    modified_parts = []

    for part_index, pair in enumerate(pairwise_parts):

        first_part, second_part = pair
        part_number = part_index + 1

        if part_number in prominent_section_numbers:

            start_triple = first_part[-1]
            stop_triple = second_part[0]

            start_field, start_direction, start_pitch = _unpack(start_triple)
            stop_field, stop_direction, stop_pitch = _unpack(stop_triple)

            count = prominent_counts[part_index]

            if 0 < count:

                prominence = make_prominence_between(
                    start_field, start_direction, start_pitch,
                    stop_field, stop_direction, stop_pitch,
                    count)

                print len(prominence)

                modified_first_part = list(first_part[:-1]) + prominence

            else:
                modified_first_part = list(first_part)

        else:
            modified_first_part = list(first_part)

        modified_parts.append(modified_first_part)

    assert len(modified_parts) == 46

    return modified_parts