17. Working with score templates and LilyPond concatentation

>>> import abjad
>>> template = abjad.templatetools.TwoStaffPianoScoreTemplate()
>>> score = template()
>>> f(score)
\context Score = "Two-Staff Piano Score" <<
    \context PianoStaff = "Piano Staff" <<
        \set PianoStaff.instrumentName = \markup { Piano }
        \set PianoStaff.shortInstrumentName = \markup { Pf. }
        \context Staff = "RH Staff" {
            \clef "treble"
            \context Voice = "RH Voice" {
            }
        }
        \context Staff = "LH Staff" {
            \clef "bass"
            \context Voice = "LH Voice" {
            }
        }
    >>
>>

17.1. Creating a basic score template

class StringTrioScoreTemplate(abctools.AbjadObject):

    def __call__(self):

        violin_voice = abjad.Voice(name='Violin Voice')
        violin_staff = abjad.Staff([violin_voice], name='Violin Staff')
        skip = abjad.Skip(1)
        violin_voice.append(skip)
        clef = abjad.Clef('treble')
        attach(clef, skip)
        instrument = abjad.instrumenttools.Violin()
        abjad.attach(instrument, skip)

        viola_voice = abjad.Voice(name='Viola Voice')
        viola_staff = abjad.Staff([viola_voice], name='Viola Staff')
        skip = abjad.Skip(1)
        viola_voice.append(skip)
        clef = abjad.Clef('alto')
        attach(clef, skip)
        instrument = abjad.instrumenttools.Viola()
        abjad.attach(instrument, skip)

        cello_voice = abjad.Voice(name='Cello Voice')
        cello_staff = abjad.Staff([cello_voice], name='Cello Staff')
        skip = abjad.Skip(1)
        cello_voice.append(skip)
        clef = abjad.Clef('bass')
        abjad.attach(clef, skip)
        instrument = abjad.instrumenttools.Cello()
        abjad.attach(instrument, skip)

        staff_group = abjad.StaffGroup(
            [violin_staff, viola_staff, cello_staff],
            name='String Trio Staff Group',
            )

        score = abjad.Score(
            [staff_group],
            name='String Trio Score',
            )

        return score
>>> template = StringTrioScoreTemplate()
>>> score = template()
>>> f(score)
\context Score = "String Trio Score" <<
    \context StaffGroup = "String Trio Staff Group" <<
        \context Staff = "Violin Staff" {
            \context Voice = "Violin Voice" {
                \set Staff.instrumentName = \markup { Violin }
                \set Staff.shortInstrumentName = \markup { Vn. }
                \clef "treble"
                s1
            }
        }
        \context Staff = "Viola Staff" {
            \context Voice = "Viola Voice" {
                \set Staff.instrumentName = \markup { Viola }
                \set Staff.shortInstrumentName = \markup { Va. }
                \clef "alto"
                s1
            }
        }
        \context Staff = "Cello Staff" {
            \context Voice = "Cello Voice" {
                \set Staff.instrumentName = \markup { Cello }
                \set Staff.shortInstrumentName = \markup { Vc. }
                \clef "bass"
                s1
            }
        }
    >>
>>
>>> show(score)

17.2. Context concatenation

>>> score_one = template()
>>> score_two = template()
>>> score_one['Violin Voice'][:] = "c'8 d'8 e'8 f'8"
>>> score_one['Viola Voice'][:] = "c8 d8 e8 f8"
>>> score_one['Cello Voice'][:] = "c,8 d,8 e,8 f,8"
>>> show(score_one)
>>> score_two['Violin Voice'][:] = "g'8 a'8 b'8 c''8"
>>> score_two['Viola Voice'][:] = "g8 a8 b8 c'8"
>>> score_two['Cello Voice'][:] = "g,8 a,8 b,8 c8"
>>> show(score_two)
>>> lilypond_file = abjad.LilyPondFile.new()
>>> both_scores = [score_one, score_two]
>>> lilypond_file.score_block.items.append(both_scores)
>>> show(lilypond_file)
>>> print(format(lilypond_file))
% 2017-08-02 22:03

\version "2.19.44"
\language "english"

\header {}

\layout {}

\paper {}

\score {
    {
        \context Score = "String Trio Score" <<
            \context StaffGroup = "String Trio Staff Group" <<
                \context Staff = "Violin Staff" {
                    \context Voice = "Violin Voice" {
                        c'8
                        d'8
                        e'8
                        f'8
                    }
                }
                \context Staff = "Viola Staff" {
                    \context Voice = "Viola Voice" {
                        c8
                        d8
                        e8
                        f8
                    }
                }
                \context Staff = "Cello Staff" {
                    \context Voice = "Cello Voice" {
                        c,8
                        d,8
                        e,8
                        f,8
                    }
                }
            >>
        >>
        \context Score = "String Trio Score" <<
            \context StaffGroup = "String Trio Staff Group" <<
                \context Staff = "Violin Staff" {
                    \context Voice = "Violin Voice" {
                        g'8
                        a'8
                        b'8
                        c''8
                    }
                }
                \context Staff = "Viola Staff" {
                    \context Voice = "Viola Voice" {
                        g8
                        a8
                        b8
                        c'8
                    }
                }
                \context Staff = "Cello Staff" {
                    \context Voice = "Cello Voice" {
                        g,8
                        a,8
                        b,8
                        c8
                    }
                }
            >>
        >>
    }
}