17. Working with score templates and LilyPond concatentation

>>> template = templatetools.TwoStaffPianoScoreTemplate()
>>> score = template()
>>> print(format(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 = scoretools.Voice(name='Violin Voice')
        violin_staff = scoretools.Staff([violin_voice], name='Violin Staff')
        clef = indicatortools.Clef('treble')
        attach(clef, violin_staff)
        instrument = instrumenttools.Violin()
        attach(instrument, violin_staff)

        viola_voice = scoretools.Voice(name='Viola Voice')
        viola_staff = scoretools.Staff([viola_voice], name='Viola Staff')
        clef = indicatortools.Clef('alto')
        attach(clef, viola_staff)
        instrument = instrumenttools.Viola()
        attach(instrument, viola_staff)

        cello_voice = scoretools.Voice(name='Cello Voice')
        cello_staff = scoretools.Staff([cello_voice], name='Cello Staff')
        clef = indicatortools.Clef('bass')
        attach(clef, cello_staff)
        instrument = instrumenttools.Cello()
        attach(instrument, cello_staff)

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

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

        return score
>>> template = StringTrioScoreTemplate()
>>> score = template()
>>> print(format(score))
\context Score = "String Trio Score" <<
    \context StaffGroup = "String Trio Staff Group" <<
        \context Staff = "Violin Staff" {
            \clef "treble"
            \set Staff.instrumentName = \markup { Violin }
            \set Staff.shortInstrumentName = \markup { Vn. }
            \context Voice = "Violin Voice" {
            }
        }
        \context Staff = "Viola Staff" {
            \clef "alto"
            \set Staff.instrumentName = \markup { Viola }
            \set Staff.shortInstrumentName = \markup { Va. }
            \context Voice = "Viola Voice" {
            }
        }
        \context Staff = "Cello Staff" {
            \clef "bass"
            \set Staff.instrumentName = \markup { Cello }
            \set Staff.shortInstrumentName = \markup { Vc. }
            \context Voice = "Cello Voice" {
            }
        }
    >>
>>
>>> score['Violin Voice'].extend("c'2 d'2 e'2 f'2")
>>> score['Viola Voice'].extend("c'2 d'2 e'2 f'2")
>>> score['Cello Voice'].extend("c'2 d'2 e'2 f'2")
>>> show(score)

17.2. Context concatenation

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

\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" {
                    \clef "treble"
                    \set Staff.instrumentName = \markup { Violin }
                    \set Staff.shortInstrumentName = \markup { Vn. }
                    \context Voice = "Violin Voice" {
                        c'8
                        d'8
                        e'8
                        f'8
                    }
                }
                \context Staff = "Viola Staff" {
                    \clef "alto"
                    \set Staff.instrumentName = \markup { Viola }
                    \set Staff.shortInstrumentName = \markup { Va. }
                    \context Voice = "Viola Voice" {
                        c8
                        d8
                        e8
                        f8
                    }
                }
                \context Staff = "Cello Staff" {
                    \clef "bass"
                    \set Staff.instrumentName = \markup { Cello }
                    \set Staff.shortInstrumentName = \markup { Vc. }
                    \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" {
                    \clef "treble"
                    \set Staff.instrumentName = \markup { Violin }
                    \set Staff.shortInstrumentName = \markup { Vn. }
                    \context Voice = "Violin Voice" {
                        g'8
                        a'8
                        b'8
                        c''8
                    }
                }
                \context Staff = "Viola Staff" {
                    \clef "alto"
                    \set Staff.instrumentName = \markup { Viola }
                    \set Staff.shortInstrumentName = \markup { Va. }
                    \context Voice = "Viola Voice" {
                        g8
                        a8
                        b8
                        c'8
                    }
                }
                \context Staff = "Cello Staff" {
                    \clef "bass"
                    \set Staff.instrumentName = \markup { Cello }
                    \set Staff.shortInstrumentName = \markup { Vc. }
                    \context Voice = "Cello Voice" {
                        g,8
                        a,8
                        b,8
                        c8
                    }
                }
            >>
        >>
    }
}