def make_vertical_pitch_fields_score():

    duration = Fraction(1, 16)

    pitch_fields = manifolds.etc.pitch.pitch_fields
    pitch_fields = [Chord(x, duration) for x in pitch_fields]

    score = Score([])
    score.append(PianoStaff([]))

    score[0].extend([Staff([]), Staff([])])
    treble_staff = score[0][0]
    bass_staff = score[0][1]

    treble_staff.clef.forced = Clef('treble')
    treble_staff.accidental.style = 'forget'
    treble_staff.meter.forced = Meter(2 * len(pitch_fields), duration._d)

    bass_staff.clef.forced = Clef('bass')
    bass_staff.accidental.style = 'forget'
    bass_staff.meter.forced = Meter(2 * len(pitch_fields), duration._d)

    for pitch_field in pitch_fields:
        t, b = chordtools.split(pitch_field)
        treble_staff.extend([t, Skip(duration)])
        bass_staff.extend([b, Skip(duration)])

    treble_staff.breaks.line = True
    score.rest.transparent = True
    score.meter.transparent = True

    return score
def make_mixed_segmented_fields_score():

    score = Score([])

    staff = Staff([])
    staff.accidental.style = 'forget'

    score.append(staff)

    duration = Fraction(1, 16)
    for field in manifolds.etc.pitch.mixed_segmented_fields:
        for segment in field:
            measure = AnonymousMeasure([])
            measure.denominator = 16
            tuplet = FixedDurationTuplet((3, 8), [])
            measure.append(tuplet)
            if min(segment) <= -1:
                measure.clef.forced = Clef('bass')
            else:
                measure.clef.forced = Clef('treble')
            notes = [Note(x, duration) for x in segment]
            tuplet.extend(notes)
            if 31 < max(segment):
                spanner = Octavation(tuplet)
                spanner.start = 1
            measure.insert(0, Rest((1, 16)))
            measure.append(Rest((1, 16)))
            staff.append(measure)
            measure.formatter.number.self = 'comment'
        measure.barline.kind = '||'
        measure.breaks.line = True

    measure.barline.kind = '|.'
    score.rest.transparent = True
    score.meter.break_visibility = Function('end-of-line-invisible')
    score.clef.break_visibility = Function('end-of-line-invisible')
    pitchtools.make_sharp(score)

    score.tupletnumber.stencil = False
    score.tupletbracket.stencil = False

    #indicator = FixedSystemsIndicator(
    #    (0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200), 1)
    #layout.apply_fixed_systems_indicator(staff, indicator)

    staves = StaffAlignmentOffsets(0)
    systems = SystemYOffsets(20, 10, 1)
    positioning = FixedStaffPositioning(systems, staves)
    layout.apply_fixed_staff_positioning(staff, positioning)

    return score
def make_set_theoretic_chords_score():

    score = Score([])
    duration = Fraction(1, 16)

    aggregate_chords = manifolds.etc.pitch.aggregates
    aggregate_chords = [Chord(x, duration) for x in aggregate_chords]
    aggregate_piano_staff = make_piano_staff(aggregate_chords)
    score.append(aggregate_piano_staff)

    union_chords = manifolds.etc.pitch.union_chords
    union_chords = [Chord(x, duration) for x in union_chords]
    union_piano_staff = make_piano_staff(union_chords)
    score.append(union_piano_staff)

    intersection_chords = manifolds.etc.pitch.intersection_chords
    intersection_chords = [Chord(x, duration) for x in intersection_chords]
    intersection_piano_staff = make_piano_staff(intersection_chords)
    score.append(intersection_piano_staff)

    aggregate_piano_staff[0].breaks.line = True
    score.rest.transparent = True
    score.meter.transparent = True

    return score
Ejemplo n.º 4
0
def make_color_score():

    duration = Fraction(1, 16)

    pitch_fields = manifolds.etc.pitch.pitch_fields
    pitch_fields = [Chord(x, duration) for x in pitch_fields]

    score = Score([])
    score.append(PianoStaff([]))
    piano_staff = score[0]

    piano_staff.extend([Staff([]), Staff([])])
    treble = piano_staff[0]
    bass = piano_staff[1]

    treble.clef.forced = Clef('treble')
    treble.accidental.style = 'forget'

    bass.clef.forced = Clef('bass')
    bass.accidental.style = 'forget'

    for pitch_field in pitch_fields:
        treble_measure = DynamicMeasure()
        bass_measure = DynamicMeasure()
        treble_measure.denominator = 16
        bass_measure.denominator = 16
        for note in chordtools.arpeggiate(pitch_field):
            t, b = chordtools.split(note)
            treble_measure.append(t)
            bass_measure.append(b)
        treble_measure.breaks.line = True
        bass_measure.breaks.line = True
        treble.append(treble_measure)
        bass.append(bass_measure)

    score.rest.transparent = True
    score.meter.break_visibility = Function('end-of-line-invisible')
    score.meter.transparent = True
    pitchtools.make_sharp(score)
    label.leaf_pcs(score, color = True)
    score.text.staff_padding = 4

    return score
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_labeled_mixed_fields_score():

    score = Score([])
    segmentation_series = manifolds.etc.pitch.segmentation_series
    fields = manifolds.etc.pitch.mixed_segmented_fields
    duration = Fraction(1, 16)

    measures_per_line = 6

    ## for eight *pairs of* fields
    for i in range(len(fields) / 2):

        ## for the first or second member of each pair
        for member in ('first', 'second'):

            ## find a sequence between 0 and 15, inclusive
            if member == 'first':
                field_sequence = i
            else:
                field_sequence = i + 8

            ## find a field number between 1 and 8, inclusive
            field_number = (field_sequence + 6) % 8 + 1

            ## find direction of segmentation
            if segmentation_series[field_sequence] == -1:
                direction = 'L'
            elif segmentation_series[field_sequence] == 1:
                direction = 'R'
            else:
                raise ValueError

            ## find name for first system
            name = Markup(
                r'\hcenter-in #12 \box \pad-markup #1 \bold { %s%s }' % (
                direction, field_number))

            ## find name for second system
            if direction == 'L':
                second_system_direction = 'R'
            else:
                second_system_direction = 'L'
            short_name = Markup(
                r'\hcenter-in #12 \box \pad-markup #1 \bold { %s%s }' % (
                second_system_direction, field_number))

            ## if first field in pair
            if member == 'first':

                ## set up a staff
                staff = Staff([])
                staff.accidental.style = 'forget'
                staff.instrument.name = name
                staff.instrument.short_name = short_name
                score.append(staff)

            ## get field to lay out, from 0 to 15, inclusive
            field = fields[field_sequence]

            ## lay out field as a single line of music
            for segment_number, segment in enumerate(field):
                measure = AnonymousMeasure([])
                measure.denominator = 16

#            if segment_number == 0:
#               if member == 'second':
#                  print name
#                  directive = r'\set Staff.shortInstrumentName = %s'
#                  directive %= name.format
#                  measure.directives.before.append(directive)

                tuplet = FixedDurationTuplet((3, 8), [])
                measure.append(tuplet)
                if min(segment) <= -1:
                    measure.clef.forced = Clef('bass')
                else:
                    measure.clef.forced = Clef('treble')
                notes = [Note(x, duration) for x in segment]
                tuplet.extend(notes)
                if 31 < max(segment) < 36:
                    spanner = Octavation(tuplet)
                    spanner.start = 1
                elif 36 <= max(segment):
                    spanner = Octavation(tuplet)
                    spanner.start = 2
                measure.insert(0, Rest((1, 16)))
                measure.append(Rest((1, 16)))
                staff.append(measure)

#            segment_letter = chr(ord('a') + segment_number)
#            segment_id = r'\circle \pad-markup #0.25 { %s }'
#            segment_id %= segment_letter
#            tuplet.leaves[0].markup.up.append(segment_id)

                segment_center = float(sum(segment)) / len(segment)
                segment_center = round(segment_center, 1)
                if int(segment_center) == segment_center:
                    markup = r'\bold { %s }' % int(segment_center)
                else:
                    markup = r'\bold { %.1f }' % segment_center
                tuplet.leaves[0].markup.down.append(markup)

            extra_measure_count = measures_per_line - (segment_number + 1)
            for j in range(extra_measure_count):
                measure = AnonymousMeasure([])
                measure.extend(construct.rests([(1, 16), (3, 8), (1, 16)]))
                measure.dots.transparent = True
                staff.append(measure)
            measure.barline.kind = '||'
            measure.breaks.line = True

    measure.barline.kind = '|.'
    score.rest.transparent = True
    score.meter.break_visibility = Function('end-of-line-invisible')
    #score.clef.break_visibility = Function('end-of-line-invisible')
    pitchtools.make_sharp(score)

    for i, measure in enumerate(iterate.naive(score, AnonymousMeasure)):
        measure.formatter.number.self = 'comment'
        if not i % 6 == 5:
            measure.breaks.whitespace = Fraction(1, 16)

    score.tupletnumber.stencil = False
    score.tupletbracket.stencil = False

    score[0][measures_per_line - 1].breaks.page = True

    alignment_offsets = [-25 * x for x in range(8)]

    score[0][0].breaks.x = 10
    score[0][0].breaks.y = 30
    score[0][0].breaks.alignment_offsets = alignment_offsets

    score[0][measures_per_line].breaks.x = 10
    score[0][measures_per_line].breaks.y = 15
    score[0][measures_per_line].breaks.alignment_offsets = alignment_offsets

    return score
def make_segmented_pitch_fields_score(bigger):

    duration = Fraction(1, 16)

    score = Score([])
    score.append(PianoStaff([]))
    piano_staff = score[0]

    piano_staff.extend([Staff([]), Staff([])])
    treble = piano_staff[0]
    bass = piano_staff[1]

    treble.clef.forced = Clef('treble')
    treble.accidental.style = 'forget'

    bass.clef.forced = Clef('bass')
    bass.accidental.style = 'forget'

    if bigger == 'left':
        segmented_pitch_fields = manifolds.etc.pitch.left_segmented_fields
    elif bigger == 'right':
        segmented_pitch_fields = manifolds.etc.pitch.right_segmented_fields
    else:
        raise ValueError

    for i, segmented_pitch_field in enumerate(segmented_pitch_fields):
        field_number = (i + 6) % 8 + 1
        segment_number = 0
        for segment in segmented_pitch_field:
            segment = Chord(segment, duration)
            treble_measure = AnonymousMeasure()
            bass_measure = AnonymousMeasure()
            treble_measure.denominator = 16
            bass_measure.denominator = 16
            for note in chordtools.arpeggiate(segment):
                t, b = chordtools.split(note)
                treble_measure.append(t)
                bass_measure.append(b)
            treble.append(treble_measure)
            bass.append(bass_measure)
            segment_letter = chr(ord('a') + segment_number)
            treble_measure.leaves[0].markup.up.append(
                r'\circle { %s-%s }' % (field_number, segment_letter))
            segment_number += 1
        treble_measure.breaks.line = True
        bass_measure.breaks.line = True

    score.rest.transparent = True
    score.meter.break_visibility = Function('end-of-line-invisible')
    pitchtools.make_sharp(score)
    label.leaf_pcs(score, color = True)
    score.text.staff_padding = 4

    #indicator = FixedSystemsIndicator((0, 40, 80, 120), 1)
    #layout.apply_fixed_systems_indicator(treble, indicator)

    staves = StaffAlignmentOffsets(0, -12)
    systems = SystemYOffsets(40, 4, 1)
    positioning = FixedStaffPositioning(systems, staves)
    layout.apply_fixed_staff_positioning(treble, positioning)

    return score
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