Beispiel #1
0
def test_Container_insert_04():
    """
    Insert works with really big positive values.
    """

    staff = abjad.Staff([abjad.Note(n, (1, 8)) for n in range(4)])
    abjad.beam(staff[:])
    staff.insert(1000, abjad.Rest((1, 4)))

    assert abjad.inspect(staff).wellformed()
    assert format(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            c'8
            [
            cs'8
            d'8
            ef'8
            ]
            r4
        }
        """)
def test_Staff___getitem___01():

    staff = abjad.Staff([
        abjad.Note("c'4"),
        abjad.Rest((1, 4)),
        abjad.Chord([2, 3, 4], (1, 4)),
        abjad.Skip((1, 4)),
        abjad.Tuplet((4, 5), "c'16 c'16 c'16 c'16"),
    ])

    assert len(staff) == 5
    assert abjad.wf.wellformed(staff)
    assert isinstance(staff[0], abjad.Note)
    assert isinstance(staff[1], abjad.Rest)
    assert isinstance(staff[2], abjad.Chord)
    assert isinstance(staff[3], abjad.Skip)
    assert isinstance(staff[4], abjad.Tuplet)
    assert isinstance(staff[-5], abjad.Note)
    assert isinstance(staff[-4], abjad.Rest)
    assert isinstance(staff[-3], abjad.Chord)
    assert isinstance(staff[-2], abjad.Skip)
    assert isinstance(staff[-1], abjad.Tuplet)
Beispiel #3
0
def test_Container_insert_01():
    """
    Insert component into container at index i.
    """

    voice = abjad.Voice("c'8 d'8 e'8 f'8")
    abjad.beam(voice[:])
    voice.insert(0, abjad.Rest((1, 8)))

    assert abjad.inspect(voice).wellformed()
    assert format(voice) == abjad.String.normalize(r"""
        \new Voice
        {
            r8
            c'8
            [
            d'8
            e'8
            f'8
            ]
        }
        """)
Beispiel #4
0
def test_Container___setitem___18():
    r"""
    Extremely small coequal indices indicate first slice in staff.
    """

    voice = abjad.Voice("c'8 [ d'8 e'8 f'8 ]")
    voice[-1000:-1000] = [abjad.Rest('r8')]

    assert format(voice) == abjad.String.normalize(
        r"""
        \new Voice
        {
            r8
            c'8
            [
            d'8
            e'8
            f'8
            ]
        }
        """
        ), print(format(voice))

    assert format(voice) == abjad.String.normalize(
        r"""
        \new Voice
        {
            r8
            c'8
            [
            d'8
            e'8
            f'8
            ]
        }
        """
        ), print(format(voice))

    assert abjad.inspect(voice).wellformed()
def test_scoretools_Container_insert_09():
    r'''Insert component into container at index i.
    Fracture spanners to the left of index i.
    Fracture spanners to the right of index i.
    Returns Python list of fractured spanners.
    '''

    "Insert works just before a spanner."

    staff = abjad.Staff([abjad.Note(n, (1, 8)) for n in range(4)])
    beam = abjad.Beam()
    abjad.attach(beam, staff[:])
    staff.insert(0, abjad.Rest('r4'), fracture_spanners=True)

    r'''
    \new Staff {
        r4
        c'8 [
        cs'8
        d'8
        ef'8 ]
    }
    '''

    assert abjad.inspect(staff).is_well_formed()
    assert format(staff) == abjad.String.normalize(
        r'''
        \new Staff
        {
            r4
            c'8
            [
            cs'8
            d'8
            ef'8
            ]
        }
        '''
        )
def test_Container_insert_06():
    """
    Insert works with really big negative values.
    """

    voice = abjad.Voice("c'8 d'8 e'8 f'8")
    abjad.beam(voice[:])
    voice.insert(-1000, abjad.Rest((1, 8)))

    assert abjad.inspect(voice).wellformed()
    assert format(voice) == abjad.String.normalize(r"""
        \new Voice
        {
            r8
            c'8
            [
            d'8
            e'8
            f'8
            ]
        }
        """)
def test_Staff___getitem___08():

    staff = abjad.Staff([
        abjad.Note("c'4"),
        abjad.Rest((1, 4)),
        abjad.Chord([2, 3, 4], (1, 4)),
        abjad.Skip((1, 4)),
        abjad.Tuplet((4, 5), 4 * abjad.Note(0, (1, 16))),
        ])

    assert len(staff) == 5
    assert abjad.inspect(staff).wellformed()
    selection = staff[:]
    assert len(selection) == 5
    assert isinstance(selection, abjad.Selection)
    assert isinstance(selection[0], abjad.Note)
    assert isinstance(selection[1], abjad.Rest)
    assert isinstance(selection[2], abjad.Chord)
    assert isinstance(selection[3], abjad.Skip)
    assert isinstance(selection[4], abjad.Tuplet)
    for x in selection:
        assert x._parent == staff
    assert abjad.inspect(staff).wellformed()
Beispiel #8
0
def test_Rest___init___12():
    """
    Initialize multiple rests from spanned notes.
    """

    voice = abjad.Voice("c'8 ( d'8 e'8 f'8 )")
    for note in voice:
        rest = abjad.Rest(note)
        abjad.mutate.replace(note, rest)

    assert abjad.lilypond(voice) == abjad.String.normalize(r"""
        \new Voice
        {
            r8
            (
            r8
            r8
            r8
            )
        }
        """)

    assert abjad.wf.wellformed(voice)
Beispiel #9
0
def test_Container___setitem___19():
    r"""Extremely large coequal indices indicate last slice in staff.
    """

    voice = abjad.Voice("c'8 [ d'8 e'8 f'8 ]")
    voice[1000:1000] = [abjad.Rest("r8")]

    assert format(voice) == abjad.String.normalize(
        r"""
        \new Voice
        {
            c'8
            [
            d'8
            e'8
            f'8
            ]
            r8
        }
        """
    ), print(format(voice))

    assert abjad.inspect(voice).wellformed()
Beispiel #10
0
    def __handle_insert_command(self, command: InsertCommand) -> List[Command]:
        """Attempt to parse whatever the InsertCommand contains. Return either [] if
        successful or a command that sets the status line text to what happened."""
        text = command.text

        if len(text) == 0:
            return

        try:
            # objects to add
            objects = []

            for item in text.split(";"):
                item = item.strip()

                if item[0] == "r":
                    obj = abjad.Rest(item)
                elif item[0] == "<":
                    obj = abjad.Chord(item)
                else:
                    obj = abjad.Note(item)

                objects.append(obj)

            for obj in objects:
                self.score.insert(self.position, obj)
                self.position += 1

            self.changed_since_saving = True
            self.previous_repeatable_command = command

        except Exception as e:
            return [
                SetStatusLineTextCommand("The string could not be parsed.",
                                         Position.CENTER)
            ]
Beispiel #11
0
def test_scoretools_Rest___init___12():
    r'''Initialize multiple rests from spanned notes.
    '''

    voice = abjad.Voice("c'8 [ d'8 e'8 f'8 ]")
    for note in voice:
        rest = abjad.Rest(note)
        abjad.mutate(note).replace(rest)

    assert format(voice) == abjad.String.normalize(
        r'''
        \new Voice
        {
            r8
            [
            r8
            r8
            r8
            ]
        }
        '''
        )

    assert abjad.inspect(voice).is_well_formed()
def test_scoretools_Container_insert_03():
    r'''Insert works just after a spanner.
    '''

    staff = abjad.Staff([abjad.Note(n, (1, 8)) for n in range(4)])
    beam = abjad.Beam()
    abjad.attach(beam, staff[:])
    staff.insert(4, abjad.Rest((1, 4)))

    r'''
    \new Staff {
        c'8
        [
        cs'8
        d'8
        ef'8
        ]
        r4
    }
    '''

    assert abjad.inspect(staff).is_well_formed()
    assert format(staff) == abjad.String.normalize(
        r'''
        \new Staff
        {
            c'8
            [
            cs'8
            d'8
            ef'8
            ]
            r4
        }
        '''
        )
def test_scoretools_Container_insert_12():
    r'''Insert works with really big positive values.
    '''

    staff = abjad.Staff([abjad.Note(n, (1, 8)) for n in range(4)])
    beam = abjad.Beam()
    abjad.attach(beam, staff[:])
    staff.insert(1000, abjad.Rest('r4'), fracture_spanners=True)

    r'''
    \new Staff {
        c'8
        [
        cs'8
        d'8
        ef'8
        ]
    r4
    }
    '''

    assert abjad.inspect(staff).is_well_formed()
    assert format(staff) == abjad.String.normalize(
        r'''
        \new Staff
        {
            c'8
            [
            cs'8
            d'8
            ef'8
            ]
            r4
        }
        '''
        )
def test_scoretools_Container_insert_06():
    r'''Insert works with really big negative values.
    '''

    voice = abjad.Voice("c'8 d'8 e'8 f'8")
    beam = abjad.Beam()
    abjad.attach(beam, voice[:])
    voice.insert(-1000, abjad.Rest((1, 8)))

    r'''
    \new Voice {
        r8
        c'8
        [
        d'8
        e'8
        f'8
        ]
    }
    '''

    assert abjad.inspect(voice).is_well_formed()
    assert format(voice) == abjad.String.normalize(
        r'''
        \new Voice
        {
            r8
            c'8
            [
            d'8
            e'8
            f'8
            ]
        }
        '''
        )
Beispiel #15
0
def test_Staff___delitem___03():

    staff = abjad.Staff([
        abjad.Note("c'4"),
        abjad.Rest((1, 4)),
        abjad.Chord([2, 3, 4], (1, 4)),
        abjad.Skip((1, 4)),
        abjad.Tuplet((4, 5), 4 * abjad.Note(0, (1, 16))),
    ])

    assert len(staff) == 5
    assert isinstance(staff[0], abjad.Note)
    assert isinstance(staff[1], abjad.Rest)
    assert isinstance(staff[2], abjad.Chord)
    assert isinstance(staff[3], abjad.Skip)
    assert isinstance(staff[4], abjad.Tuplet)
    del (staff[3])
    assert len(staff) == 4
    assert isinstance(staff[0], abjad.Note)
    assert isinstance(staff[1], abjad.Rest)
    assert isinstance(staff[2], abjad.Chord)
    assert isinstance(staff[3], abjad.Tuplet)
    del (staff[-2])
    assert len(staff) == 3
    assert isinstance(staff[0], abjad.Note)
    assert isinstance(staff[1], abjad.Rest)
    assert isinstance(staff[2], abjad.Tuplet)
    del (staff[2])
    assert len(staff) == 2
    assert isinstance(staff[0], abjad.Note)
    assert isinstance(staff[1], abjad.Rest)
    del (staff[0])
    assert len(staff) == 1
    assert isinstance(staff[0], abjad.Rest)
    del (staff[-1])
    assert len(staff) == 0
Beispiel #16
0
def test_lilypondparsertools_LilyPondParser__leaves__Rest_01():

    target = abjad.Rest((1, 8))
    parser = abjad.lilypondparsertools.LilyPondParser()
    result = parser('{ %s }' % format(target))
    assert format(target) == format(result[0]) and target is not result[0]
Beispiel #17
0
# -*- encoding: utf-8 -*-
import os
import abjad
from organi.tools import SegmentMaker

# TIME SIGNATURES
time_signatures = [(4, 4)]

# ORGAN NOTATION
rest_organ = abjad.Rest("r1")
abjad.attach(abjad.Fermata("verylongfermata"), rest_organ)
rest_organ_voice_four = abjad.Rest("r1")

# CHORD ZERO ELECTRONICS
chord_zero_electronics = abjad.Chord(
    "<cqs' f' gs' c'' e'' ftqs'' gqs'' gs''" +
    " b'' cs''' ctqs''' f''' fs''' ftqs''' gs'''>1")

# laisses vibrer
laissez_vibrer = abjad.LaissezVibrer()
abjad.attach(laissez_vibrer, chord_zero_electronics)

# tempo mark
mark = abjad.MetronomeMark(None, None, "Statico")
abjad.attach(mark, chord_zero_electronics)

# fermata
abjad.attach(abjad.Fermata("verylongfermata"), chord_zero_electronics)

# remove includes to collect segments
includes = ['../../stylesheets/stylesheet.ily']
Beispiel #18
0
                c = Chord.from_string(line)

                lower_pitches = [p for p in c.pitches if p.midi_number < 60]
                lower_abjad_chord = abjad.Chord([], abjad.Duration(1, 1))
                if len(lower_pitches) > 0:
                    for i in range(0, len(lower_pitches)):
                        lower_abjad_chord.note_heads.extend(
                            [lower_pitches[i].midi_number - 60])
                        if lower_pitches[i].is_harmonic_tone == False:
                            abjad.tweak(lower_abjad_chord.note_heads[i]
                                        ).style = 'harmonic'
                    lower_staff_components.append(lower_abjad_chord)
                else:
                    lower_staff_components.append(
                        abjad.Rest(abjad.Duration(1, 1)))

                upper_pitches = [p for p in c.pitches if p.midi_number >= 60]
                upper_abjad_chord = abjad.Chord([], abjad.Duration(1, 1))
                if len(upper_pitches) > 0:
                    for i in range(0, len(upper_pitches)):
                        upper_abjad_chord.note_heads.extend(
                            [upper_pitches[i].midi_number - 60])
                        if upper_pitches[i].is_harmonic_tone == False:
                            abjad.tweak(upper_abjad_chord.note_heads[i]
                                        ).style = 'harmonic'
                    upper_staff_components.append(upper_abjad_chord)
                else:
                    upper_staff_components.append(
                        abjad.Rest(abjad.Duration(1, 1)))
    metronome_marks = []
    for skip in skips:
        metronome_mark = abjad.inspect(skip).effective(abjad.MetronomeMark)
        metronome_marks.append(metronome_mark)

    staff = abjad.Staff()
    abjad.setting(staff).midiInstrument = '#"drums"'
    score = abjad.Score([staff], simultaneous=False)
    fermata_measure_numbers = maker.fermata_measure_empty_overrides or []
    for i, time_signature in enumerate(time_signatures):
        measure_number = i + 1
        if measure_number in fermata_measure_numbers:
            metronome_mark = abjad.MetronomeMark((1, 4), 60)
            time_signature = abjad.TimeSignature((3, 4))
            notes = [abjad.Rest("r2.")]
        else:
            metronome_mark = metronome_marks[i]
            units_per_minute = round(metronome_mark.units_per_minute)
            metronome_mark = abjad.new(
                metronome_mark,
                hide=False,
                units_per_minute=units_per_minute,
            )
            time_signature = abjad.new(time_signature)
            numerator, denominator = time_signature.pair
            notes = []
            for _ in range(numerator):
                note = abjad.Note.from_pitch_and_duration(
                    -18, (1, denominator))
                notes.append(note)
Beispiel #20
0
def sscore_to_abjad_score(sscore):
    globals = _Globals()
    score = abjad.Score(context_name='Score')

    sig = abjad.TimeSignature((1, 4))

    # don't just use the score object since we're alternating lyrics blocks
    # ooh it can be tuples (Voice, _Lyrics)
    voices = []

    # create a staff of empty measures for each jig
    for i in range(0, sscore['jigs']):
        voice = abjad.Voice(name=globals.iToStaff(i))

        for beat in range(0, sscore['beats']):
            measure = abjad.Measure(sig, "r4")
            voice.extend(measure)

        # only now that the staves have content can we set their clef
        leaf = abjad.inspect(voice).get_leaf()
        abjad.attach(abjad.Clef('alto'), leaf)

        score.append(voice)

        lyrics = _Lyrics(globals.iToStaff(i))
        score.append(lyrics)
        voices.append((voice, lyrics))
    nextState = 0
    for beat in range(0, sscore['beats']):
        while sscore['states'][nextState].beat <= beat + 1:
            # thanks python for making me write this twice
            state = sscore['states'][nextState]
            snote = state.noteObj
            pitch = globals.lilypondPitch(snote)

            # generate correct amount of rest before the note begins
            # assume powers of 2 (no tuplets, sorry boiz)
            restBeats = state.beat % 1
            if restBeats != 0:
                rest16ths = int(restBeats / 0.25)
                rest = abjad.Rest(abjad.Duration(rest16ths, 16))

                noteBeats = 1 - restBeats
                note16ths = int(noteBeats / 0.25)
                anote = abjad.Note()
                anote.written_pitch = pitch
                anote.written_duration = abjad.Duration(note16ths, 16)
                measure = abjad.Measure(sig, [rest, anote])
            else:
                anote = abjad.Note()
                anote.written_pitch = pitch
                anote.written_duration = abjad.Duration(1, 4)
                measure = abjad.Measure(sig, [anote])
            # what if the measure already contained a note this beat?
            # eh that's a risk I'm willing to take

            voiceTuple = voices[state.singamajigIndex]
            voiceTuple[0][beat] = measure
            voiceTuple[1].add_lyric(snote['syllable'])

            nextState += 1
            if nextState >= len(sscore['states']):
                break

    return score
Beispiel #21
0
for fundamental, voice in zip(fundamentals, voicewise_ratios):
    handlers.append(
        evans.PitchHandler(
            [
                evans.JIPitch(fundamental, ratio)
                for ratio in voicewise_ratios[voice]
            ],
            forget=False,
        ))
    voice_length = len(voicewise_ratios[voice])

handlers.reverse()

maker = abjad.LeafMaker()
durations = [abjad.Duration((10, 4)) for _ in range(len(out_))]
leaves_1 = [abjad.Rest((3, 8))] + [maker(["c'"], durations)]
leaves_2 = [abjad.Rest(
    (3, 4))] + [maker(["c'"], durations)] + [abjad.Rest((3, 4))]
leaves_3 = [maker(["c"], durations)]

group = abjad.StaffGroup([
    abjad.Staff([abjad.Voice(leaves_1, name="violin 3")]),
    abjad.Staff([abjad.Voice(leaves_2, name="violin 4")]),
    abjad.Staff([abjad.Voice(leaves_3, name="viola 2")]),
])
abjad.attach(abjad.Clef("treble"), group[0][0][0])
abjad.attach(abjad.Clef("treble"), group[1][0][0])
abjad.attach(abjad.Clef("alto"), group[2][0][0])

# trio 2
voices = {
Beispiel #22
0
def test_scoretools_Rest___str___01():

    rest = abjad.Rest((1, 4))

    assert str(rest) == 'r4'
    def convert2score(
        self,
        reference_pitch: int = 0,
        stretch_factor: float = 1,
        n_divisions: int = 8,
        min_tone_size: fractions.Fraction = 0,
        min_rest_size: fractions.Fraction = fractions.Fraction(1, 10),
    ) -> None:

        pitches, delays = self.quantizise(
            stretch_factor=stretch_factor,
            n_divisions=n_divisions,
            min_tone_size=min_tone_size,
            min_rest_size=min_rest_size,
        )

        bar_grid = tuple(fractions.Fraction(1, 1) for i in range(15))
        grid = tuple(fractions.Fraction(1, 4) for i in range(50))

        notes = abjad.Voice([])

        absolute_delay = tools.accumulate_from_zero(delays)
        for pitch, delay, start, stop in zip(pitches, delays, absolute_delay,
                                             absolute_delay[1:]):
            seperated_by_bar = tools.accumulate_from_n(
                lily.seperate_by_grid(start, stop, bar_grid, hard_cut=True),
                start)
            sub_delays = functools.reduce(
                operator.add,
                tuple(
                    functools.reduce(
                        operator.add,
                        tuple(
                            lily.seperate_by_assignability(d)
                            for d in lily.seperate_by_grid(start, stop, grid)),
                    ) for start, stop in zip(seperated_by_bar,
                                             seperated_by_bar[1:])),
            )
            subnotes = []
            if pitch.is_empty:
                ct = None
            else:
                ct = pitch.cents / 100
                # round to 12th tone
                ct = round(ct * 6) / 6
                ct += reference_pitch

            for delay in sub_delays:
                if ct is None:
                    obj = abjad.Rest(delay)
                else:
                    obj = abjad.Note(ct, delay)

                subnotes.append(obj)

            if ct is not None and len(subnotes) > 1:
                for note in subnotes[:-1]:
                    abjad.attach(abjad.Tie(), note)

            notes.extend(subnotes)

        score = abjad.Score([notes])

        with open("{}.ly".format(self.name), "w") as f:
            f.write('\\version "2.19.83"\n')
            f.write(lily.EKMELILY_PREAMBLE)
            f.write("\n")
            f.write(format(score))

        subprocess.call(["lilypond", "{}.ly".format(self.name)])
Beispiel #24
0
 def card_16():
     notes = [abjad.Note(pitch, (1, 8)) for pitch in ("F5", "F5", "E4")]
     notes = make_triplets(notes)
     notes += [abjad.Rest((1, 8)), blank_space()]
     return notes
Beispiel #25
0
 def card_0():
     notes = [abjad.Rest('r2')]
     return notes
Beispiel #26
0
 def card_10():
     seven_e = [abjad.Note('E4', (1, 16)) for _ in range(7)]
     notes = [abjad.Tuplet((4, 7), seven_e)]
     notes.append(abjad.Rest('r4'))
     return notes
Beispiel #27
0
 def card_6():
     notes = slur_all(
         [abjad.Note(pitch, (1, 32)) for pitch in ['G4', 'A4', 'B4', 'C5']])
     notes.append(abjad.Rest('r16'))
     notes.append((blank_space()))
     return notes
Beispiel #28
0

card_funcs = [
    func()
    for func in filter(lambda x: callable(x), CardBuilder.__dict__.values())
]

i = 0

for card_base in card_funcs:
    if os.path.exists(f'../resources/card_{i}.jpg'):
        print(f"Skipping card {i}")
        i += 1
        continue
    score = abjad.Score(name="Score")
    notes = card_base + [abjad.Rest('r2') for _ in range(3)
                         ] + [abjad.Note("C5", (1, 4)) for _ in range(4)]
    container = abjad.Container(notes)
    repeat = abjad.Repeat()
    abjad.attach(repeat, container)
    staff = abjad.Staff([container])
    score.append(staff)
    note = abjad.select(score).note(0)
    time_signature = abjad.TimeSignature((12, 4))
    abjad.attach(time_signature, note)

    lilypond_file = abjad.LilyPondFile(items=[preamble, score])
    abjad.show(lilypond_file)

    all_pdfs = glob.glob(
        r"C:\Users\bkier\projects\draw(0)\abjad\output_dir\*.pdf")
Beispiel #29
0
    def make_piano_score(leaves=None, lowest_treble_pitch="B3", sketch=False):
        r"""
        Makes piano score from ``leaves``.

        ..  container:: example

            Makes empty piano score:

            >>> result = abjad.Score.make_piano_score()

            >>> abjad.f(result[0])
            \new Score
            <<
                \new PianoStaff
                <<
                    \context Staff = "Treble_Staff"
                    {
                    }
                    \context Staff = "Bass_Staff"
                    {
                    }
                >>
            >>

        ..  container:: example

            Makes piano score from leaves:

            >>> notes = [abjad.Note(x, (1, 4)) for x in [-12, 37, -10, 2, 4, 17]]
            >>> result = abjad.Score.make_piano_score(leaves=notes)
            >>> abjad.show(result[0]) # doctest: +SKIP

            ..  docs::

                >>> abjad.f(result[0])
                \new Score
                <<
                    \new PianoStaff
                    <<
                        \context Staff = "Treble_Staff"
                        {
                            \clef "treble"
                            r4
                            cs''''4
                            r4
                            d'4
                            e'4
                            f''4
                        }
                        \context Staff = "Bass_Staff"
                        {
                            \clef "bass"
                            c4
                            r4
                            d4
                            r4
                            r4
                            r4
                        }
                    >>
                >>

        ..  container:: example

            Makes piano sketch score from leaves:

            >>> maker = abjad.NoteMaker()
            >>> notes = maker(
            ...     [-12, -10, -8, -7, -5, 0, 2, 4, 5, 7],
            ...     [(1, 16)],
            ...     )
            >>> result = abjad.Score.make_piano_score(
            ...     leaves=notes,
            ...     sketch=True,
            ...     )
            >>> abjad.show(result[0]) # doctest: +SKIP

            ..  docs::

                >>> abjad.f(result[0])
                \new Score
                \with
                {
                    \override BarLine.stencil = ##f
                    \override BarNumber.transparent = ##t
                    \override SpanBar.stencil = ##f
                    \override TimeSignature.stencil = ##f
                }
                <<
                    \new PianoStaff
                    <<
                        \context Staff = "Treble_Staff"
                        {
                            \clef "treble"
                            r16
                            r16
                            r16
                            r16
                            r16
                            c'16
                            d'16
                            e'16
                            f'16
                            g'16
                        }
                        \context Staff = "Bass_Staff"
                        {
                            \clef "bass"
                            c16
                            d16
                            e16
                            f16
                            g16
                            r16
                            r16
                            r16
                            r16
                            r16
                        }
                    >>
                >>


        Returns score, treble staff, bass staff triple.
        """
        import abjad

        leaves = leaves or []
        lowest_treble_pitch = abjad.NamedPitch(lowest_treble_pitch)
        treble_staff = abjad.Staff(name="Treble_Staff")
        bass_staff = abjad.Staff(name="Bass_Staff")
        staff_group = abjad.StaffGroup(
            [treble_staff, bass_staff], lilypond_type="PianoStaff"
        )
        score = abjad.Score()
        score.append(staff_group)
        for leaf in leaves:
            treble_pitches, bass_pitches = [], []
            for pitch in abjad.inspect(leaf).pitches():
                if pitch < lowest_treble_pitch:
                    bass_pitches.append(pitch)
                else:
                    treble_pitches.append(pitch)
            written_duration = leaf.written_duration
            if not treble_pitches:
                treble_leaf = abjad.Rest(written_duration)
            elif len(treble_pitches) == 1:
                treble_leaf = abjad.Note(treble_pitches[0], written_duration)
            else:
                treble_leaf = abjad.Chord(treble_pitches, written_duration)
            treble_staff.append(treble_leaf)
            if not bass_pitches:
                bass_leaf = abjad.Rest(written_duration)
            elif len(bass_pitches) == 1:
                bass_leaf = abjad.Note(bass_pitches[0], written_duration)
            else:
                bass_leaf = abjad.Chord(bass_pitches, written_duration)
            bass_staff.append(bass_leaf)
        if 0 < len(treble_staff):
            abjad.attach(abjad.Clef("treble"), treble_staff[0])
        if 0 < len(bass_staff):
            abjad.attach(abjad.Clef("bass"), bass_staff[0])
        if sketch:
            abjad.override(score).time_signature.stencil = False
            abjad.override(score).bar_number.transparent = True
            abjad.override(score).bar_line.stencil = False
            abjad.override(score).span_bar.stencil = False
        return score, treble_staff, bass_staff
Beispiel #30
0
 def __init__(self, *arguments):
     import abjad
     if len(arguments) == 0:
         arguments = ((1, 4), )
     rest = abjad.Rest(*arguments)
     Leaf.__init__(self, rest.written_duration)