Ejemplo n.º 1
0
    def __call__(self):
        """Return ``self.ready_staff``."""
        abjad_instrument = self.abjad_instrument
        staves = self.append_staves(self)
        self.append_voices(self, staves)
        staff_count = self.staff_count

        if staff_count == 1:
            abjad.annotate(staves[0], "default_instrument", abjad_instrument)
            self.ready_staff = staves[0]
        else:
            if abjad_instrument == abjad.Piano():
                staffgroup = abjad.StaffGroup(
                    lilypond_type="PianoStaff",
                    name="Piano_StaffGroup",
                    tag=self.tag,
                    simultaneous=True,
                )
                for staff in staves:
                    staffgroup.append(staff)

            else:
                staffgroup = abjad.StaffGroup(name=self.name, tag=self.tag)
                for staff in staves:
                    staffgroup.append(staff)

            abjad.annotate(staffgroup, "default_instrument", abjad_instrument)

            self.ready_staff = staffgroup

        return self.ready_staff
Ejemplo n.º 2
0
def test_LilyPondParser__contexts__PianoStaff_01():

    maker = abjad.NoteMaker()
    target = abjad.StaffGroup([
        abjad.Staff(maker([0, 2, 4, 5, 7], (1, 8))),
        abjad.Staff(maker([0, 2, 4, 5, 7], (1, 8)))
    ])
    target.lilypond_type = 'PianoStaff'

    assert format(target) == abjad.String.normalize(r"""
        \new PianoStaff
        <<
            \new Staff
            {
                c'8
                d'8
                e'8
                f'8
                g'8
            }
            \new Staff
            {
                c'8
                d'8
                e'8
                f'8
                g'8
            }
        >>
        """)

    parser = abjad.parser.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
    def __call__(self):
        """
        Calls score template.

        Returns score.
        """
        import abjad
        staves = []
        tag = 'GroupedStavesScoreTemplate'
        for index in range(self.staff_count):
            number = index + 1
            voice = abjad.Voice(
                [],
                name='Voice_{}'.format(number),
                tag=tag,
            )
            staff = abjad.Staff(
                [voice],
                name='Staff_{}'.format(number),
                tag=tag,
            )
            staves.append(staff)
            self.voice_abbreviations['v{}'.format(number)] = voice.name
        staff_group = abjad.StaffGroup(
            staves,
            name='Grouped_Staves_Staff_Group',
            tag=tag,
        )
        score = abjad.Score(
            [staff_group],
            name='Grouped_Staves_Score',
            tag=tag,
        )
        return score
Ejemplo n.º 4
0
def test_lilypondproxytools_LilyPondGrobNameManager___setattr___44():
    r'''Override LilyPond SystemStartBar grob.
    '''

    score = abjad.Score(
        [abjad.StaffGroup([abjad.Staff("c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8")])])
    abjad.override(score).system_start_bar.collapse_height = 0
    abjad.override(score).system_start_bar.color = 'red'

    assert format(score) == abjad.String.normalize(r'''
        \new Score
        \with
        {
            \override SystemStartBar.collapse-height = #0
            \override SystemStartBar.color = #red
        }
        <<
            \new StaffGroup
            <<
                \new Staff
                {
                    c'8
                    c'8
                    c'8
                    c'8
                    c'8
                    c'8
                    c'8
                    c'8
                }
            >>
        >>
        ''')
def test_scoretools_Inspection_get_effective_staff_03():
    r'''Staff changes work on the last note of a staff.
    '''

    staves = 2 * abjad.Staff("c'8 d'8 e'8 f'8")
    staff_group = abjad.StaffGroup(staves)
    staff_group.lilypond_type = 'PianoStaff'
    staff_group.is_simultaneous = True
    staff_group[0].name = 'RH'
    staff_group[1].name = 'LH'
    staff_change = abjad.StaffChange(staff_group[1])
    abjad.attach(staff_change, staff_group[0][-1])

    assert format(staff_group) == abjad.String.normalize(r'''
        \new PianoStaff
        <<
            \context Staff = "RH"
            {
                c'8
                d'8
                e'8
                \change Staff = LH
                f'8
            }
            \context Staff = "LH"
            {
                c'8
                d'8
                e'8
                f'8
            }
        >>
        ''')

    assert abjad.inspect(staff_group).is_well_formed()
Ejemplo n.º 6
0
def make_desordre_score(pitches):
    """
    Makes Désordre score.
    """

    assert len(pitches) == 2
    staff_group = abjad.StaffGroup()
    staff_group.lilypond_type = 'PianoStaff'

    # build the music
    for hand in pitches:
        staff = make_desordre_staff(hand)
        staff_group.append(staff)

    # set clef and key signature to left hand staff
    leaf = abjad.inspect(staff_group[1]).leaf(0)
    clef = abjad.Clef('bass')
    abjad.attach(clef, leaf)
    key_signature = abjad.KeySignature('b', 'major')
    abjad.attach(key_signature, leaf)

    # wrap the piano staff in a score
    score = abjad.Score([staff_group])

    return score
Ejemplo n.º 7
0
    def __call__(self):
        """
        Calls score template.

        Returns score.
        """
        import abjad

        staves = []
        site = "abjad.GroupedStavesScoreTemplate.__call__()"
        tag = Tag(site)
        for index in range(self.staff_count):
            number = index + 1
            voice = abjad.Voice([], name="Voice_{}".format(number), tag=tag)
            staff = abjad.Staff([voice],
                                name="Staff_{}".format(number),
                                tag=tag)
            staves.append(staff)
            self.voice_abbreviations["v{}".format(number)] = voice.name
        staff_group = abjad.StaffGroup(staves,
                                       name="Grouped_Staves_Staff_Group",
                                       tag=tag)
        score = abjad.Score([staff_group],
                            name="Grouped_Staves_Score",
                            tag=tag)
        return score
Ejemplo n.º 8
0
 def _make_instrument_staff_group(
     self,
     clef_name=None,
     count=None,
     instrument=None,
 ):
     import abjad
     name = instrument.name.title()
     instrument_staff_group = abjad.StaffGroup(
         lilypond_type='{}StaffGroup'.format(name),
         name='{} Staff Group'.format(name),
     )
     tag_names = []
     if count == 1:
         performer_staff_group, tag_name = \
             self._make_performer_staff_group(
                 clef_name=clef_name,
                 instrument=instrument,
                 number=None,
                 )
         instrument_staff_group.append(performer_staff_group)
         tag_names.append(tag_name)
     else:
         for i in range(1, count + 1):
             performer_staff_group, tag_name = \
                 self._make_performer_staff_group(
                     clef_name=clef_name,
                     instrument=instrument,
                     number=i,
                     )
             instrument_staff_group.append(performer_staff_group)
             tag_names.append(tag_name)
     return instrument_staff_group, tag_names
Ejemplo n.º 9
0
def test_LilyPondGrobNameManager___setattr___36():
    """
    Override LilyPond SystemStartBar grob.
    """

    score = abjad.Score(
        [abjad.StaffGroup([abjad.Staff("c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8")])])
    abjad.override(score).system_start_bar.collapse_height = 0
    abjad.override(score).system_start_bar.color = "red"

    assert format(score) == abjad.String.normalize(r"""
        \new Score
        \with
        {
            \override SystemStartBar.collapse-height = #0
            \override SystemStartBar.color = #red
        }
        <<
            \new StaffGroup
            <<
                \new Staff
                {
                    c'8
                    c'8
                    c'8
                    c'8
                    c'8
                    c'8
                    c'8
                    c'8
                }
            >>
        >>
        """)
Ejemplo n.º 10
0
def _make_piano_staff(stem, *contexts):
    if not isinstance(stem, str):
        raise Exception(f"stem must be string: {stem!r}.")
    contexts = tuple(_ for _ in contexts if _ is not None)
    if contexts:
        return abjad.StaffGroup(contexts, name=f"{stem}_Piano_Staff")
    else:
        return None
Ejemplo n.º 11
0
    def __call__(self):
        """
        Calls two-staff piano score template.

        Returns score.
        """
        import abjad
        tag = 'TwoStaffPianoScoreTemplate'
        # GLOBAL CONTEXT
        global_context = self._make_global_context()

        # RH STAFF
        rh_voice = abjad.Voice(
            name='RH_Voice',
            tag=tag,
        )
        rh_staff = abjad.Staff(
            [rh_voice],
            name='RH_Staff',
            tag=tag,
        )

        # LH STAFF
        lh_voice = abjad.Voice(
            name='LH_Voice',
            tag=tag,
        )
        lh_staff = abjad.Staff(
            [lh_voice],
            name='LH_Staff',
            tag=tag,
        )
        abjad.annotate(
            lh_staff,
            'default_clef',
            abjad.Clef('bass'),
        )

        # PIANO STAFF
        staff_group = abjad.StaffGroup(
            [rh_staff, lh_staff],
            lilypond_type='PianoStaff',
            name='Piano_Staff',
            tag=tag,
        )
        abjad.annotate(
            staff_group,
            'default_instrument',
            abjad.Piano(),
        )

        # SCORE
        score = abjad.Score(
            [global_context, staff_group],
            name='Two_Staff_Piano_Score',
            tag=tag,
        )
        return score
Ejemplo n.º 12
0
def test_scoretools_Inspection_get_vertical_moment_at_01():

    score = abjad.Score([])
    tuplet = abjad.Tuplet((4, 3), "d''8 c''8 b'8")
    score.append(abjad.Staff([tuplet]))
    staff_group = abjad.StaffGroup([])
    staff_group.lilypond_type = 'PianoStaff'
    staff_group.append(abjad.Staff("a'4 g'4"))
    staff_group.append(abjad.Staff("f'8 e'8 d'8 c'8"))
    clef = abjad.Clef('bass')
    abjad.attach(clef, staff_group[1][0])
    score.append(staff_group)

    assert format(score) == abjad.String.normalize(r'''
        \new Score
        <<
            \new Staff
            {
                \tweak text #tuplet-number::calc-fraction-text
                \times 4/3 {
                    d''8
                    c''8
                    b'8
                }
            }
            \new PianoStaff
            <<
                \new Staff
                {
                    a'4
                    g'4
                }
                \new Staff
                {
                    \clef "bass"
                    f'8
                    e'8
                    d'8
                    c'8
                }
            >>
        >>
        ''')

    moment = abjad.inspect(staff_group).get_vertical_moment_at((0, 8))
    assert moment.leaves == (staff_group[0][0], staff_group[1][0])

    moment = abjad.inspect(staff_group).get_vertical_moment_at((1, 8))
    assert moment.leaves == (staff_group[0][0], staff_group[1][1])

    moment = abjad.inspect(staff_group).get_vertical_moment_at((2, 8))
    assert moment.leaves == (staff_group[0][1], staff_group[1][2])

    moment = abjad.inspect(staff_group).get_vertical_moment_at((3, 8))
    assert moment.leaves == (staff_group[0][1], staff_group[1][3])

    moment = abjad.inspect(staff_group).get_vertical_moment_at((99, 8))
    assert moment.leaves == ()
Ejemplo n.º 13
0
    def __call__(self):
        '''Calls score template.

        Returns LilyPond file.
        '''
        # make bell voice and staff
        bell_voice = abjad.Voice(name='Bell Voice')
        bell_staff = abjad.Staff([bell_voice], name='Bell Staff')

        # make first violin voice and staff
        first_violin_voice = abjad.Voice(name='First Violin Voice')
        first_violin_staff = abjad.Staff(
            [first_violin_voice],
            name='First Violin Staff',
        )

        # make second violin voice and staff
        second_violin_voice = abjad.Voice(name='Second Violin Voice')
        second_violin_staff = abjad.Staff(
            [second_violin_voice],
            name='Second Violin Staff',
        )

        # make viola voice and staff
        viola_voice = abjad.Voice(name='Viola Voice')
        viola_staff = abjad.Staff([viola_voice], name='Viola Staff')

        # make cello voice and staff
        cello_voice = abjad.Voice(name='Cello Voice')
        cello_staff = abjad.Staff([cello_voice], name='Cello Staff')

        # make bass voice and staff
        bass_voice = abjad.Voice(name='Bass Voice')
        bass_staff = abjad.Staff([bass_voice], name='Bass Staff')

        # make strings staff group
        strings_staff_group = abjad.StaffGroup(
            [
                first_violin_staff,
                second_violin_staff,
                viola_staff,
                cello_staff,
                bass_staff,
            ],
            name='Strings Staff Group',
        )

        # make score
        score = abjad.Score([
            bell_staff,
            strings_staff_group,
        ],
                            name='Pärt Cantus Score')

        # return Pärt Cantus score
        return score
Ejemplo n.º 14
0
def see_pitches(pitches):
    G_staff = abjad.Staff()
    F_staff = abjad.Staff()
    staff_group = abjad.StaffGroup([G_staff, F_staff])
    pitch_range = abjad.pitch.PitchRange("[C4, +inf]")
    for pitch in pitches:
        test = pitch in pitch_range
        if test is True:
            note = abjad.Note.from_pitch_and_duration(pitch, (1, 1))
            G_staff.append(note)
            F_staff.append(abjad.Skip((1, 1)))
        if test is False:
            note = abjad.Note.from_pitch_and_duration(pitch, (1, 1))
            G_staff.append(abjad.Skip((1, 1)))
            F_staff.append(note)

    for i, note in enumerate(F_staff):
        abjad.attach(abjad.Markup(i), note)

    clef3 = abjad.Clef("treble^8")
    clef3_range = abjad.pitch.PitchRange("[G6, +inf]")
    clef2 = abjad.Clef("treble")
    clef2_range = abjad.pitch.PitchRange("[E4, E5]")
    clef1 = abjad.Clef("bass")
    clef1_range = abjad.pitch.PitchRange("[A1, G3]")
    clef0 = abjad.Clef("bass_8")
    clef0_range = abjad.pitch.PitchRange("[-inf, C1]")

    selection = abjad.select(G_staff).leaves()
    for i, leaf in enumerate(selection):
        if isinstance(leaf, abjad.Note):
            test3 = leaf in clef3_range
            test2 = leaf in clef2_range
            if test3 is True:
                abjad.attach(clef3, G_staff[i])
            elif test2 is True:
                abjad.attach(clef2, G_staff[i])

    selection2 = abjad.select(F_staff).leaves()
    for i, leaf in enumerate(selection2):
        if isinstance(leaf, abjad.Note):
            test3 = leaf in clef3_range
            test2 = leaf in clef2_range
            test1 = leaf in clef1_range
            test0 = leaf in clef0_range
            if test2 is True:
                abjad.attach(clef2, F_staff[i])
            elif test1 is True:
                abjad.attach(clef1, F_staff[i])
            elif test0 is True:
                abjad.attach(clef0, F_staff[i])

    abjad.show(staff_group)

    return staff_group
def test_scoretools_Inspection_get_effective_staff_04():
    r'''Redudant staff changes are allowed.
    '''

    staves = 2 * abjad.Staff("c'8 d'8 e'8 f'8")
    staff_group = abjad.StaffGroup(staves)
    staff_group.lilypond_type = 'PianoStaff'
    staff_group.is_simultaneous = True
    staff_group[0].name = 'RH'
    staff_group[1].name = 'LH'
    staff_change = abjad.StaffChange(staff_group[1])
    abjad.attach(staff_change, staff_group[0][0])
    staff_change = abjad.StaffChange(staff_group[1])
    abjad.attach(staff_change, staff_group[0][1])

    assert format(staff_group) == abjad.String.normalize(r'''
        \new PianoStaff
        <<
            \context Staff = "RH"
            {
                \change Staff = LH
                c'8
                \change Staff = LH
                d'8
                e'8
                f'8
            }
            \context Staff = "LH"
            {
                c'8
                d'8
                e'8
                f'8
            }
        >>
        ''')

    assert abjad.inspect(staff_group).is_well_formed()
    assert abjad.inspect(
        staff_group[0][0]).get_effective_staff() is staff_group[1]
    assert abjad.inspect(
        staff_group[0][1]).get_effective_staff() is staff_group[1]
    assert abjad.inspect(
        staff_group[0][2]).get_effective_staff() is staff_group[1]
    assert abjad.inspect(
        staff_group[0][3]).get_effective_staff() is staff_group[1]
    assert abjad.inspect(
        staff_group[1][0]).get_effective_staff() is staff_group[1]
    assert abjad.inspect(
        staff_group[1][1]).get_effective_staff() is staff_group[1]
    assert abjad.inspect(
        staff_group[1][2]).get_effective_staff() is staff_group[1]
    assert abjad.inspect(
        staff_group[1][3]).get_effective_staff() is staff_group[1]
Ejemplo n.º 16
0
    def __call__(self):
        """
        Calls score template.

        Returns score.
        """
        import abjad
        staves = []
        tag = 'GroupedRhythmicStavesScoreTemplate'
        if isinstance(self.staff_count, int):
            for index in range(self.staff_count):
                number = index + 1
                name = 'Voice_{}'.format(number)
                voice = abjad.Voice([], name=name, tag=tag)
                name = 'Staff_{}'.format(number)
                staff = abjad.Staff([voice], name=name, tag=tag)
                staff.lilypond_type = 'RhythmicStaff'
                abjad.annotate(staff, 'default_clef', abjad.Clef('percussion'))
                staves.append(staff)
                key = 'v{}'.format(number)
                self.voice_abbreviations[key] = voice.name
        elif isinstance(self.staff_count, list):
            for staff_index, voice_count in enumerate(self.staff_count):
                staff_number = staff_index + 1
                name = 'Staff_{}'.format(staff_number)
                staff = abjad.Staff(name=name, tag=tag)
                staff.lilypond_type = 'RhythmicStaff'
                assert 1 <= voice_count
                for voice_index in range(voice_count):
                    voice_number = voice_index + 1
                    if voice_count == 1:
                        voice_identifier = str(staff_number)
                    else:
                        voice_identifier = '{}_{}'.format(
                            staff_number, voice_number)
                        staff.is_simultaneous = True
                    name = 'Voice_{}'.format(voice_identifier)
                    voice = abjad.Voice([], name=name, tag=tag)
                    staff.append(voice)
                    key = 'v{}'.format(voice_identifier)
                    self.voice_abbreviations[key] = voice.name
                staves.append(staff)
        grouped_rhythmic_staves_staff_group = abjad.StaffGroup(
            staves,
            name='Grouped_Rhythmic_Staves_Staff_Group',
            tag=tag,
        )
        grouped_rhythmic_staves_score = abjad.Score(
            [grouped_rhythmic_staves_staff_group],
            name='Grouped_Rhythmic_Staves_Score',
            tag=tag,
        )
        return grouped_rhythmic_staves_score
Ejemplo n.º 17
0
    def __call__(self):
        """
        Calls score template.

        Returns score.
        """
        import abjad

        staves = []
        site = "abjad.GroupedRhythmicStavesScoreTemplate.__call__()"
        tag = Tag(site)
        if isinstance(self.staff_count, int):
            for index in range(self.staff_count):
                number = index + 1
                name = "Voice_{}".format(number)
                voice = abjad.Voice([], name=name, tag=tag)
                name = "Staff_{}".format(number)
                staff = abjad.Staff([voice], name=name, tag=tag)
                staff.lilypond_type = "RhythmicStaff"
                abjad.annotate(staff, "default_clef", abjad.Clef("percussion"))
                staves.append(staff)
                key = "v{}".format(number)
                self.voice_abbreviations[key] = voice.name
        elif isinstance(self.staff_count, list):
            for staff_index, voice_count in enumerate(self.staff_count):
                staff_number = staff_index + 1
                name = "Staff_{}".format(staff_number)
                staff = abjad.Staff(name=name, tag=tag)
                staff.lilypond_type = "RhythmicStaff"
                assert 1 <= voice_count
                for voice_index in range(voice_count):
                    voice_number = voice_index + 1
                    if voice_count == 1:
                        voice_identifier = str(staff_number)
                    else:
                        voice_identifier = "{}_{}".format(staff_number, voice_number)
                        staff.simultaneous = True
                    name = "Voice_{}".format(voice_identifier)
                    voice = abjad.Voice([], name=name, tag=tag)
                    staff.append(voice)
                    key = "v{}".format(voice_identifier)
                    self.voice_abbreviations[key] = voice.name
                staves.append(staff)
        grouped_rhythmic_staves_staff_group = abjad.StaffGroup(
            staves, name="Grouped_Rhythmic_Staves_Staff_Group", tag=tag
        )
        grouped_rhythmic_staves_score = abjad.Score(
            [grouped_rhythmic_staves_staff_group],
            name="Grouped_Rhythmic_Staves_Score",
            tag=tag,
        )
        return grouped_rhythmic_staves_score
Ejemplo n.º 18
0
def test_Container_is_simultaneous_01():
    """
    Is true when container encloses contents in LilyPond << >> brackets,
    otherwise False.
    """

    assert not abjad.Container().simultaneous
    assert not abjad.Tuplet().simultaneous
    assert abjad.Score().simultaneous
    assert not abjad.Container().simultaneous
    assert not abjad.Staff().simultaneous
    assert abjad.StaffGroup().simultaneous
    assert not abjad.Voice().simultaneous
def test_lilypondparsertools_LilyPondParser__contexts__StaffGroup_01():

    target = abjad.StaffGroup([])

    assert format(target) == abjad.String.normalize(r'''
        \new StaffGroup
        <<
        >>
        ''')

    parser = abjad.lilypondparsertools.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
Ejemplo n.º 20
0
def test_LilyPondParser__contexts__StaffGroup_01():

    target = abjad.StaffGroup([])

    assert format(target) == abjad.String.normalize(r"""
        \new StaffGroup
        <<
        >>
        """)

    parser = abjad.parser.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
Ejemplo n.º 21
0
def test_scoretools_Container_is_simultaneous_01():
    r'''Is true when container encloses contents in LilyPond << >> brackets,
    otherwise False.
    '''

    assert not abjad.Container().is_simultaneous
    assert not abjad.Tuplet().is_simultaneous
    assert not abjad.Measure().is_simultaneous
    assert abjad.Score().is_simultaneous
    assert not abjad.Container().is_simultaneous
    assert not abjad.Staff().is_simultaneous
    assert abjad.StaffGroup().is_simultaneous
    assert not abjad.Voice().is_simultaneous
Ejemplo n.º 22
0
    def convert(
        self,
        tagged_simultaneous_event: ot2_basic.TaggedSimultaneousEvent[
            basic.SimultaneousEvent[basic.SequentialEvent[music.NoteLike]]],
    ) -> abjad.Score:
        staff_group = abjad.StaffGroup([])

        duration = tagged_simultaneous_event.duration

        for instrument_id in sorted(
                tagged_simultaneous_event.tag_to_event_index.keys(),
                key=lambda tag: tagged_simultaneous_event.tag_to_event_index[
                    tag],
        ):
            converter = self._instrument_id_to_sequential_event_to_abjad_voice_converter[
                instrument_id]
            simultaneous_event = tagged_simultaneous_event[instrument_id]

            staff = abjad.Staff([], simultaneous=True)
            # staff.remove_commands.append("Time_signature_engraver")
            for sequential_event in simultaneous_event:
                difference = duration - sequential_event.duration
                if difference:
                    sequential_event.append(music.NoteLike([], difference))

                if instrument_id == instruments.ID_PERCUSSIVE:
                    sequential_event = self._prepare_percussion_sequential_event(
                        sequential_event)

                abjad_voice = converter.convert(sequential_event)

                if instrument_id not in (
                        instruments.ID_PERCUSSIVE,
                        instruments.ID_NOISE,
                ):
                    self._prepare_duration_line_voice(abjad_voice)

                if instrument_id == instruments.ID_PERCUSSIVE:
                    self._prepare_percussion_voice(abjad_voice)
                elif instrument_id == instruments.ID_DRONE:
                    self._prepare_drone_voice(abjad_voice)
                elif instrument_id == instruments.ID_NOISE:
                    self._prepare_percussion_voice(abjad_voice)

                self._prepare_voice(abjad_voice, instrument_id)
                staff.append(abjad_voice)

            staff_group.append(staff)

        abjad_score = abjad.Score([staff_group])
        return abjad_score
Ejemplo n.º 23
0
    def __call__(self):

        # Violin
        violin_staff = abjad.Staff(
            [abjad.Voice(name='Violin Voice')],
            name='Violin Staff',
            lilypond_type='ViolinStaff',
        )
        violin_tag = abjad.LilyPondLiteral(r"\tag #'violin",
                                           format_slot='before')
        abjad.attach(violin_tag, violin_staff)
        abjad.setting(violin_staff).midi_instrument = abjad.scheme.Scheme(
            'violin', force_quotes=True)

        # Viola
        viola_staff = abjad.Staff(
            [abjad.Voice(name='Viola Voice')],
            name='Viola Staff',
            lilypond_type='ViolaStaff',
        )
        viola_tag = abjad.LilyPondLiteral(r"\tag #'viola",
                                          format_slot='before')
        abjad.attach(viola_tag, viola_staff)
        abjad.setting(viola_staff).midi_instrument = abjad.scheme.Scheme(
            'viola', force_quotes=True)

        # Cello
        cello_staff = abjad.Staff(
            [abjad.Voice(name='Cello Voice')],
            name='Cello Staff',
            lilypond_type='CelloStaff',
        )
        cello_tag = abjad.LilyPondLiteral(r"\tag #'cello",
                                          format_slot='before')
        abjad.attach(cello_tag, cello_staff)
        abjad.setting(cello_staff).midi_instrument = abjad.scheme.Scheme(
            'cello', force_quotes=True)

        # Everything else
        staff_group = abjad.StaffGroup(
            [violin_staff, viola_staff, cello_staff],
            name='Trio Staff Group',
        )
        score = abjad.Score(
            [staff_group],
            name='Trio Score',
        )

        return score
def test_Inspection_effective_staff_02():
    """
    Staff changes work on middle notes of a staff.
    """

    staves = 2 * abjad.Staff("c'8 d'8 e'8 f'8")
    staff_group = abjad.StaffGroup(staves)
    staff_group.lilypond_type = "PianoStaff"
    staff_group.simultaneous = True
    staff_group[0].name = "RH"
    staff_group[1].name = "LH"
    staff_change = abjad.StaffChange(staff_group[1])
    abjad.attach(staff_change, staff_group[0][0])
    staff_change = abjad.StaffChange(staff_group[0])
    abjad.attach(staff_change, staff_group[0][2])

    assert format(staff_group) == abjad.String.normalize(
        r"""
        \new PianoStaff
        <<
            \context Staff = "RH"
            {
                \change Staff = LH
                c'8
                d'8
                \change Staff = RH
                e'8
                f'8
            }
            \context Staff = "LH"
            {
                c'8
                d'8
                e'8
                f'8
            }
        >>
        """
    )

    assert abjad.inspect(staff_group).wellformed()
    assert abjad.inspect(staff_group[0][0]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[0][1]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[0][2]).effective_staff() is staff_group[0]
    assert abjad.inspect(staff_group[0][3]).effective_staff() is staff_group[0]
    assert abjad.inspect(staff_group[1][0]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[1][1]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[1][2]).effective_staff() is staff_group[1]
    assert abjad.inspect(staff_group[1][3]).effective_staff() is staff_group[1]
Ejemplo n.º 25
0
def make_empty_score():
    # Violin
    violin_voice = abjad.Voice()
    violin_staff = abjad.Staff([violin_voice], name='Violin Staff')
    # Viola
    viola_voice = abjad.Voice()
    viola_staff = abjad.Staff([viola_voice], name='Viola Staff')
    # Cello
    cello_voice = abjad.Voice()
    cello_staff = abjad.Staff([cello_voice], name='Cello Staff')
    # Everything else
    staff_group = abjad.StaffGroup([violin_staff, viola_staff, cello_staff])
    score = abjad.Score([staff_group])
    # Return the score
    return score
Ejemplo n.º 26
0
 def convert_voices2staff(voices: list) -> abjad.StaffGroup:
     # voices contain 2-element tuples (for each staff one subvoice)
     voices = tuple(zip(*voices))
     """
     new_voices = [abjad.Voice([]), abjad.Voice([])]
     for idx, voxs in enumerate(voices):
         for voice in voxs:
             new_voices[idx].extend(voice[:])
     """
     s0 = Instrument.mk_staff(voices[0])
     s1 = Instrument.mk_staff(voices[1])
     # s0 = Instrument.mk_staff([new_voices[0]])
     # s1 = Instrument.mk_staff([new_voices[1]])
     staffgroup = abjad.StaffGroup([s0, s1], context_name="PianoStaff")
     return staffgroup
Ejemplo n.º 27
0
def treblebass():
    trebleclef = ab.Clef('treble')
    treblestaff = ab.Staff(listnotes(toplist))
    ab.attach(trebleclef, treblestaff[0])
    ab.attach(ksignature, treblestaff[0])
    ab.attach(tsignature, treblestaff[0])

    bassclef = ab.Clef('bass')
    bassstaff = ab.Staff(listnotes(bottomlist))
    ab.attach(bassclef, bassstaff[0])
    ab.attach(ksignature, bassstaff[0])
    ab.attach(tsignature, bassstaff[0])

    group = ab.StaffGroup([treblestaff, bassstaff])
    ab.show(group)
Ejemplo n.º 28
0
def test_get_staff_04():
    """
    Redudant staff changes are allowed.
    """

    staff_group = abjad.StaffGroup(
        [abjad.Staff("c'8 d'8 e'8 f'8"),
         abjad.Staff("c'8 d'8 e'8 f'8")])
    staff_group.lilypond_type = "PianoStaff"
    staff_group.simultaneous = True
    staff_group[0].name = "RH"
    staff_group[1].name = "LH"
    staff_change = abjad.StaffChange("LH")
    abjad.attach(staff_change, staff_group[0][0])
    staff_change = abjad.StaffChange("LH")
    abjad.attach(staff_change, staff_group[0][1])

    assert abjad.lilypond(staff_group) == abjad.String.normalize(r"""
        \new PianoStaff
        <<
            \context Staff = "RH"
            {
                \change Staff = LH
                c'8
                \change Staff = LH
                d'8
                e'8
                f'8
            }
            \context Staff = "LH"
            {
                c'8
                d'8
                e'8
                f'8
            }
        >>
        """)

    assert abjad.wf.wellformed(staff_group)
    assert abjad.get.effective_staff(staff_group[0][0]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[0][1]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[0][2]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[0][3]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[1][0]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[1][1]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[1][2]) is staff_group[1]
    assert abjad.get.effective_staff(staff_group[1][3]) is staff_group[1]
Ejemplo n.º 29
0
def _make_square_staff_group(stem, *contexts):
    if not isinstance(stem, str):
        raise Exception(f"stem must be string: {stem!r}.")
    tag = baca.site(inspect.currentframe())
    contexts = tuple(_ for _ in contexts if _ is not None)
    result = None
    if len(contexts) == 1:
        prototype = (abjad.Staff, abjad.StaffGroup)
        assert isinstance(contexts[0], prototype), repr(contexts[0])
        result = contexts[0]
    elif 1 < len(contexts):
        name = f"{stem}_Square_Staff_Group"
        staff_group = abjad.StaffGroup(contexts, name=name, tag=tag)
        abjad.setting(
            staff_group).system_start_delimiter = "#'SystemStartSquare"
        result = staff_group
    return result
Ejemplo n.º 30
0
def test_get_timespan_24():
    """
    Offsets works in nested simultaneous and sequential contexts.
    """

    voice_1 = abjad.Voice("c'8 d'8 e'8 f'8")
    voice_2 = abjad.Voice("c'8 d'8 e'8 f'8")
    voice_1b = abjad.Voice("c'8 d'8 e'8 f'8")
    voice_2b = abjad.Voice("c'8 d'8 e'8 f'8")
    voice_1.name = voice_1b.name = "voiceOne"
    staff_1 = abjad.Staff([voice_1, voice_1b])
    staff_2 = abjad.Staff([voice_2, voice_2b])
    abjad.StaffGroup([staff_1, staff_2])
    assert abjad.get.timespan(voice_1).start_offset == 0
    assert abjad.get.timespan(voice_2).start_offset == 0
    assert abjad.get.timespan(voice_1b).start_offset == abjad.Offset(4, 8)
    assert abjad.get.timespan(voice_2b).start_offset == abjad.Offset(4, 8)