Exemplo n.º 1
0
    def __illustrate__(self):
        r'''Illustrates pitch range.

        ::

            >>> show(pitch_range) # doctest: +SKIP

        Returns LilyPond file.
        '''
        from abjad.tools import durationtools
        from abjad.tools import lilypondfiletools
        from abjad.tools import indicatortools
        from abjad.tools import markuptools
        from abjad.tools import pitchtools
        from abjad.tools import scoretools
        from abjad.tools import spannertools
        from abjad.tools.topleveltools import attach
        from abjad.tools.topleveltools import iterate
        from abjad.tools.topleveltools import override
        start_pitch_clef = pitchtools.suggest_clef_for_named_pitches(
            self.start_pitch)
        stop_pitch_clef = pitchtools.suggest_clef_for_named_pitches(
            self.stop_pitch)
        start_note = scoretools.Note(self.start_pitch, 1)
        stop_note = scoretools.Note(self.stop_pitch, 1)
        glissando = spannertools.Glissando()
        if start_pitch_clef == stop_pitch_clef:
            if start_pitch_clef == indicatortools.Clef('bass'):
                bass_staff = scoretools.Staff()
                attach(indicatortools.Clef('bass'), bass_staff)
                bass_staff.extend([start_note, stop_note])
                attach(glissando, bass_staff.select_leaves())
                score = scoretools.Score([bass_staff])
            else:
                treble_staff = scoretools.Staff()
                attach(indicatortools.Clef('treble'), treble_staff)
                treble_staff.extend([start_note, stop_note])
                attach(glissando, treble_staff.select_leaves())
                score = scoretools.Score([treble_staff])
        else:
            result = scoretools.make_empty_piano_score()
            score, treble_staff, bass_staff = result
            bass_staff.extend([start_note, stop_note])
            treble_staff.extend(scoretools.Skip(1) * 2)
            attach(glissando, bass_staff.select_leaves())
            attach(indicatortools.StaffChange(treble_staff), bass_staff[1])
        for leaf in iterate(score).by_class(scoretools.Leaf):
            attach(durationtools.Multiplier(1, 4), leaf)
        override(score).bar_line.stencil = False
        override(score).span_bar.stencil = False
        override(score).glissando.thickness = 2
        override(score).time_signature.stencil = False
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(score)
        lilypond_file.header_block.tagline = markuptools.Markup('""')
        return lilypond_file
Exemplo n.º 2
0
 def _make_markup_score_block(selection):
     from abjad.tools import lilypondfiletools
     from abjad.tools import schemetools
     from abjad.tools import scoretools
     selection = copy.deepcopy(selection)
     staff = scoretools.Staff(selection)
     staff.context_name = 'RhythmicStaff'
     staff.remove_commands.append('Time_signature_engraver')
     staff.remove_commands.append('Staff_symbol_engraver')
     override(staff).stem.direction = Up
     #override(staff).stem.length = 4
     override(staff).stem.length = 5
     override(staff).tuplet_bracket.bracket_visibility = True
     override(staff).tuplet_bracket.direction = Up
     override(staff).tuplet_bracket.padding = 1.25
     override(staff).tuplet_bracket.shorten_pair = (-1, -1.5)
     scheme = schemetools.Scheme('tuplet-number::calc-fraction-text')
     override(staff).tuplet_number.text = scheme
     set_(staff).tuplet_full_length = True
     layout_block = lilypondfiletools.Block(name='layout')
     layout_block.indent = 0
     layout_block.ragged_right = True
     score = scoretools.Score([staff])
     override(score).spacing_spanner.spacing_increment = 0.5
     set_(score).proportional_notation_duration = False
     return score, layout_block
Exemplo n.º 3
0
 def _make_score(
     self,
     rhythm_maker,
     division_list,
     score_number_markup,
 ):
     lists = rhythm_maker(division_list)
     music = sequencetools.flatten_sequence(lists)
     measures = scoretools.make_spacer_skip_measures(division_list)
     time_signature_context = scoretools.Context(
         measures,
         context_name='TimeSignatureContext',
         name='TimeSignatureContext',
     )
     measures = scoretools.make_spacer_skip_measures(division_list)
     staff = scoretools.Staff(measures)
     set_(staff).instrument_name = score_number_markup
     staff.context_name = 'RhythmicStaff'
     staff.name = 'Note-entry staff'
     measures = mutate(staff).replace_measure_contents(music)
     score = scoretools.Score()
     score.append(time_signature_context)
     score.append(staff)
     self._add_final_bar_line(score)
     self._check_score(score)
     return score
Exemplo n.º 4
0
    def __illustrate__(self, **kwargs):
        r'''Illustrates segment.

        Returns LilyPond file.
        '''
        from abjad.tools import durationtools
        from abjad.tools import indicatortools
        from abjad.tools import lilypondfiletools
        from abjad.tools import markuptools
        from abjad.tools import scoretools
        from abjad.tools import schemetools
        from abjad.tools.topleveltools import attach
        from abjad.tools.topleveltools import override
        from abjad.tools.topleveltools import select
        from abjad.tools.topleveltools import set_
        notes = []
        for item in self:
            note = scoretools.Note(item, durationtools.Duration(1, 8))
            notes.append(note)
        voice = scoretools.Voice(notes)
        staff = scoretools.Staff([voice])
        score = scoretools.Score([staff])
        score.add_final_bar_line()
        override(score).bar_line.transparent = True
        override(score).bar_number.stencil = False
        override(score).beam.stencil = False
        override(score).flag.stencil = False
        override(score).stem.stencil = False
        override(score).time_signature.stencil = False
        string = 'override Score.BarLine.transparent = ##f'
        command = indicatortools.LilyPondCommand(string, format_slot='after')
        last_leaf = select().by_leaf()(score)[-1][-1]
        attach(command, last_leaf)
        moment = schemetools.SchemeMoment((1, 12))
        set_(score).proportional_notation_duration = moment
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(
            global_staff_size=12,
            music=score,
        )
        if 'title' in kwargs:
            title = kwargs.get('title')
            if not isinstance(title, markuptools.Markup):
                title = markuptools.Markup(title)
            lilypond_file.header_block.title = title
        if 'subtitle' in kwargs:
            markup = markuptools.Markup(kwargs.get('subtitle'))
            lilypond_file.header_block.subtitle = markup
        command = indicatortools.LilyPondCommand('accidentalStyle forget')
        lilypond_file.layout_block.items.append(command)
        lilypond_file.layout_block.indent = 0
        string = 'markup-system-spacing.padding = 8'
        command = indicatortools.LilyPondCommand(string, prefix='')
        lilypond_file.paper_block.items.append(command)
        string = 'system-system-spacing.padding = 10'
        command = indicatortools.LilyPondCommand(string, prefix='')
        lilypond_file.paper_block.items.append(command)
        string = 'top-markup-spacing.padding = 4'
        command = indicatortools.LilyPondCommand(string, prefix='')
        lilypond_file.paper_block.items.append(command)
        return lilypond_file
Exemplo n.º 5
0
    def __call__(self):
        staves = []
        for index in range(self.staff_count):
            number = index + 1
            voice = scoretools.Voice(name='Voice {}'.format(number))
            staff = scoretools.Staff([voice], name='Staff {}'.format(number))
            clef = indicatortools.Clef('bass')
            attach(clef, staff)
            cello = instrumenttools.Cello(
                instrument_name='Cello {}'.format(number),
                short_instrument_name='Vc. {}'.format(number),
            )
            attach(cello, staff)
            override(staff).stem.stemlet_length = 2
            override(staff).beam.damping = '+inf.0'
            staves.append(staff)

        windungen_staff_group = scoretools.StaffGroup(
            staves,
            name='Windungen Staff Group',
        )

        windungen_score = scoretools.Score(
            [windungen_staff_group],
            name='Windungen Score',
        )

        return windungen_score
Exemplo n.º 6
0
    def __illustrate__(self):
        r'''Attempts to illustrate selection.

        Evaluates the storage format of the selection (to sever any references
        to the source score from which the selection was taken). Then tries to
        wrap the result in a staff; in the case that notes of only C4 are found
        then sets the staff context name to ``'RhythmicStaff'``. If this works
        then the staff is wrapped in a LilyPond file and the file is returned.
        If this doesn't work then the method raises an exception.

        The idea is that the illustration should work for simple selections of
        that represent an essentially contiguous snippet of a single voice of
        music.

        Returns LilyPond file.
        '''
        from abjad.tools import lilypondfiletools
        from abjad.tools import markuptools
        from abjad.tools import pitchtools
        from abjad.tools import scoretools
        from abjad.tools.topleveltools import mutate
        music = mutate(self).copy()
        staff = scoretools.Staff(music)
        found_different_pitch = False
        for pitch in pitchtools.list_named_pitches_in_expr(staff):
            if pitch != pitchtools.NamedPitch("c'"):
                found_different_pitch = True
                break
        if not found_different_pitch:
            staff.context_name = 'RhythmicStaff'
        score = scoretools.Score([staff])
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(score)
        lilypond_file.header_block.tagline = markuptools.Markup('""')
        return lilypond_file
Exemplo n.º 7
0
    def __call__(self):
        r'''Calls string quartet score template.

        Returns score.
        '''

        # make first violin voice and staff
        first_violin_voice = scoretools.Voice(name='First Violin Voice')
        first_violin_staff = scoretools.Staff([first_violin_voice],
                                              name='First Violin Staff')
        clef = indicatortools.Clef('treble')
        attach(clef, first_violin_staff)
        violin = instrumenttools.Violin()
        attach(violin, first_violin_staff)

        # make second violin voice and staff
        second_violin_voice = scoretools.Voice(name='Second Violin Voice')
        second_violin_staff = scoretools.Staff([second_violin_voice],
                                               name='Second Violin Staff')
        clef = indicatortools.Clef('treble')
        attach(clef, second_violin_staff)
        violin = instrumenttools.Violin()
        attach(violin, second_violin_staff)

        # make viola voice and 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)
        viola = instrumenttools.Viola()
        attach(viola, viola_staff)

        # make cello voice and 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)
        cello = instrumenttools.Cello()
        attach(cello, cello_staff)

        # make string quartet staff group
        string_quartet_staff_group = scoretools.StaffGroup(
            [
                first_violin_staff,
                second_violin_staff,
                viola_staff,
                cello_staff,
            ],
            name='String Quartet Staff Group',
        )

        # make string quartet score
        string_quartet_score = scoretools.Score(
            [string_quartet_staff_group],
            name='String Quartet Score',
        )

        # return string quartet score
        return string_quartet_score
Exemplo n.º 8
0
    def make_score(self):
        r'''Make MIDI playback score from scale:

        ::

            >>> scale = tonalanalysistools.Scale('E', 'major')
            >>> score = scale.make_score()

        ..  doctest::

            >>> print(format(score))
            \new Score \with {
                tempoWholesPerMinute = #(ly:make-moment 30 1)
            } <<
                \new Staff {
                    \key e \major
                    e'8
                    fs'8
                    gs'8
                    a'8
                    b'8
                    cs''8
                    ds''8
                    e''8
                    ds''8
                    cs''8
                    b'8
                    a'8
                    gs'8
                    fs'8
                    e'4
                }
            >>

        ::

            >>> show(score) # doctest: +SKIP

        Returns score.
        '''
        ascending_notes = self.make_notes(8, durationtools.Duration(1, 8))
        descending_notes = copy.deepcopy(ascending_notes[:-1])
        descending_notes = list(descending_notes)
        descending_notes.reverse()
        descending_notes = selectiontools.Selection(descending_notes)
        notes = ascending_notes + descending_notes
        notes[-1].written_duration = durationtools.Duration(1, 4)
        staff = scoretools.Staff(notes)
        key_signature = copy.copy(self.key_signature)
        attach(key_signature, staff)
        score = scoretools.Score([staff])
        set_(score).tempo_wholes_per_minute = schemetools.SchemeMoment(30)
        return score
Exemplo n.º 9
0
def make_lilypond_file(music, divisions, implicit_scaling=False):
    r'''Makes LilyPond file.

    ..  container::

        ::

            >>> maker = rhythmmakertools.EvenRunRhythmMaker(1)
            >>> divisions = [(3, 4), (4, 8), (1, 4)]
            >>> music = maker(divisions)
            >>> lilypond_file = rhythmmakertools.make_lilypond_file(
            ...     music,
            ...     divisions,
            ...     )
            >>> show(lilypond_file) # doctest: +SKIP

    Used in rhythm-maker docs.

    Returns LilyPond file.
    '''

    assert isinstance(music, list), repr(music)
    prototype = (selectiontools.Selection, scoretools.Tuplet)
    assert all(isinstance(x, prototype) for x in music), repr(music)
    assert isinstance(divisions, (tuple, list)), repr(divisions)

    score = scoretools.Score()
    lilypond_file = \
        lilypondfiletools.make_floating_time_signature_lilypond_file(score)

    context = scoretools.Context(context_name='TimeSignatureContext')
    measures = scoretools.make_spacer_skip_measures(
        divisions,
        implicit_scaling=implicit_scaling,
    )
    context.extend(measures)
    score.append(context)

    measures = scoretools.make_spacer_skip_measures(
        divisions,
        implicit_scaling=implicit_scaling,
    )
    staff = scoretools.Staff(measures)
    staff.context_name = 'RhythmicStaff'
    music = sequencetools.flatten_sequence(music)

    measures = mutate(staff).replace_measure_contents(music)
    score.append(staff)

    return lilypond_file
Exemplo n.º 10
0
    def __illustrate__(self):
        r'''Illustrates tempo inventory.

        ::

            >>> show(inventory) # doctest: +SKIP

        Returns LilyPond file.
        '''
        from abjad.tools import durationtools
        from abjad.tools import lilypondfiletools
        from abjad.tools import indicatortools
        from abjad.tools import markuptools
        from abjad.tools import pitchtools
        from abjad.tools import scoretools
        from abjad.tools import spannertools
        from abjad.tools.topleveltools import attach
        from abjad.tools.topleveltools import iterate
        from abjad.tools.topleveltools import override
        from abjad.tools.topleveltools import new
        staff = scoretools.Staff()
        score = scoretools.Score([staff])
        time_signature = indicatortools.TimeSignature((2, 4))
        attach(time_signature, staff)
        # the zero note avoids a lilypond spacing problem:
        # score-initial tempo indications slip to the left
        zero_note = scoretools.Note("c'2")
        staff.append(zero_note)
        command = indicatortools.LilyPondCommand('break')
        attach(command, zero_note)
        for tempo in self.items:
            note = scoretools.Note("c'2")
            attach(tempo, note)
            staff.append(note)
            command = indicatortools.LilyPondCommand('break')
            attach(command, note)
        override(score).bar_line.transparent = True
        override(score).bar_number.stencil = False
        override(score).clef.stencil = False
        override(score).note_head.no_ledgers = True
        override(score).note_head.transparent = True
        override(score).staff_symbol.transparent = True
        override(score).stem.transparent = True
        override(score).time_signature.stencil = False
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(score)
        lilypond_file.layout_block.indent = 0
        lilypond_file.layout_block.ragged_right = True
        lilypond_file.items.remove(lilypond_file['paper'])
        lilypond_file.header_block.tagline = markuptools.Markup('""')
        return lilypond_file
Exemplo n.º 11
0
    def __call__(self):
        '''Calls score template.

        ::

            >>> score = template()

        ::

            >>> print(format(score))
            \context Score = "Grouped Staves Score" <<
                \context StaffGroup = "Grouped Staves Staff Group" <<
                    \context Staff = "Staff 1" {
                        \context Voice = "Voice 1" {
                        }
                    }
                    \context Staff = "Staff 2" {
                        \context Voice = "Voice 2" {
                        }
                    }
                    \context Staff = "Staff 3" {
                        \context Voice = "Voice 3" {
                        }
                    }
                    \context Staff = "Staff 4" {
                        \context Voice = "Voice 4" {
                        }
                    }
                >>
            >>

        Returns score.
        '''
        staves = []
        for index in range(self.staff_count):
            number = index + 1
            voice = scoretools.Voice(name='Voice {}'.format(number))
            staff = scoretools.Staff([voice], name='Staff {}'.format(number))
            staves.append(staff)
            self.context_name_abbreviations['v{}'.format(number)] = voice.name
        grouped_rhythmic_staves_staff_group = scoretools.StaffGroup(
            staves,
            name='Grouped Staves Staff Group',
        )
        grouped_rhythmic_staves_score = scoretools.Score(
            [grouped_rhythmic_staves_staff_group],
            name='Grouped Staves Score',
        )
        return grouped_rhythmic_staves_score
Exemplo n.º 12
0
def make_score(tuplet_duration, row_count, column_count):
    r'''Makes score.
    '''

    score = scoretools.Score()
    rows_of_nested_tuplets = \
        abjad.demos.ferneyhough.make_rows_of_nested_tuplets(
        tuplet_duration, row_count, column_count)
    for row_of_nested_tuplets in rows_of_nested_tuplets:
        staff = scoretools.Staff(row_of_nested_tuplets)
        staff.context_name = 'RhythmicStaff'
        time_signature = indicatortools.TimeSignature((1, 4))
        attach(time_signature, staff)
        score.append(staff)
    return score
Exemplo n.º 13
0
def make_empty_piano_score():
    r'''Make empty piano score:

    ::

        >>> score, treble, bass = scoretools.make_empty_piano_score()

    ..  doctest::

        >>> print(format(score))
        \new Score <<
            \new PianoStaff <<
                \context Staff = "treble" {
                    \clef "treble"
                }
                \context Staff = "bass" {
                    \clef "bass"
                }
            >>
        >>

    Returns score, treble staff, bass staff.
    '''
    from abjad.tools import indicatortools
    from abjad.tools import scoretools

    # make treble staff
    treble_staff = scoretools.Staff([])
    treble_staff.name = 'treble'
    clef = indicatortools.Clef('treble')
    attach(clef, treble_staff)

    # make bass staff
    bass_staff = scoretools.Staff([])
    bass_staff.name = 'bass'
    clef = indicatortools.Clef('bass')
    attach(clef, bass_staff)

    # make piano staff and score
    staff_group = scoretools.StaffGroup([treble_staff, bass_staff])
    staff_group.context_name = 'PianoStaff'
    score = scoretools.Score([])
    score.append(staff_group)

    # return score, treble staff, bass staff
    return score, treble_staff, bass_staff
Exemplo n.º 14
0
    def __illustrate__(self, format_specification=''):
        r'''Formats time signature inventory.

        ::

            >>> show(inventory) # doctest: +SKIP

        Returns LilyPond file.
        '''
        from abjad.tools import lilypondfiletools
        from abjad.tools import scoretools
        measures = scoretools.make_spacer_skip_measures(self)
        staff = scoretools.Staff(measures)
        staff.context_name = 'RhythmicStaff'
        score = scoretools.Score([staff])
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(score)
        return lilypond_file
Exemplo n.º 15
0
    def __illustrate__(self, **kwargs):
        r'''Illustrates pitch-class tree.

        Returns LilyPond file.
        '''
        from abjad import abjad_configuration
        from abjad.tools import indicatortools
        from abjad.tools import lilypondfiletools
        from abjad.tools import markuptools
        from abjad.tools import scoretools
        from abjad.tools.topleveltools import override
        voice = scoretools.Voice()
        staff = scoretools.Staff([voice])
        score = scoretools.Score([staff])
        stylesheet = os.path.join(
            abjad_configuration.abjad_directory,
            'stylesheets',
            'rhythm-letter-16.ily',
            )
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(
            music=score,
            includes=[stylesheet],
            )
        voice.consists_commands.append('Horizontal_bracket_engraver')
        leaf_list_stack = []
        self._bracket_inner_nodes(leaf_list_stack, self, voice)
        score.add_final_bar_line()
        override(score).bar_line.stencil = False
        override(score).flag.stencil = False
        override(score).stem.stencil = False
        override(score).text_script.staff_padding = 3
        override(score).time_signature.stencil = False
        if 'title' in kwargs:
            markup = markuptools.Markup(kwargs.get('title'))
            lilypond_file.header_block.title = markup
        if 'subtitle' in kwargs:
            markup = markuptools.Markup(kwargs.get('subtitle'))
            lilypond_file.header_block.subtitle = markup
        command = indicatortools.LilyPondCommand('accidentalStyle forget')
        lilypond_file.layout_block.items.append(command)
        return lilypond_file
Exemplo n.º 16
0
    def __call__(self):
        r'''Calls two-staff piano score template.

        Returns score.
        '''

        # make RH voice and staff
        rh_voice = scoretools.Voice(name='RH Voice')
        rh_staff = scoretools.Staff(
            [rh_voice],
            name='RH Staff',
            )
        clef = indicatortools.Clef('treble')
        attach(clef, rh_staff)

        # make LH voice and staff
        lh_voice = scoretools.Voice(name='LH Voice')
        lh_staff = scoretools.Staff(
            [lh_voice],
            name='LH Staff',
            )
        clef = indicatortools.Clef('bass')
        attach(clef, lh_staff)

        # make piano staff
        staff_group = scoretools.StaffGroup(
            [rh_staff, lh_staff],
            context_name='PianoStaff',
            name='Piano Staff',
            )
        piano = instrumenttools.Piano()
        attach(piano, staff_group)

        # make two-staf piano score
        two_staff_piano_score = scoretools.Score(
            [staff_group],
            name='Two-Staff Piano Score',
            )

        # return two-staff piano score
        return two_staff_piano_score
Exemplo n.º 17
0
def make_desordre_score(pitches):
    '''Makes Désordre score.
    '''

    assert len(pitches) == 2
    staff_group = scoretools.StaffGroup()
    staff_group.context_name = 'PianoStaff'

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

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

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

    return score
Exemplo n.º 18
0
    def __call__(self):
        r'''Calls score template.

        ..  container:: example

            **Example 1.** Call first template:

            ::

                >>> score_1 = template_1()

            ::

                >>> print(format(score_1))
                \context Score = "Grouped Rhythmic Staves Score" <<
                    \context StaffGroup = "Grouped Rhythmic Staves Staff Group" <<
                        \context RhythmicStaff = "Staff 1" {
                            \context Voice = "Voice 1" {
                            }
                        }
                        \context RhythmicStaff = "Staff 2" {
                            \context Voice = "Voice 2" {
                            }
                        }
                        \context RhythmicStaff = "Staff 3" {
                            \context Voice = "Voice 3" {
                            }
                        }
                        \context RhythmicStaff = "Staff 4" {
                            \context Voice = "Voice 4" {
                            }
                        }
                    >>
                >>

        ..  container:: example

            **Example 2.** Call second template:

            ::

                >>> score_2 = template_2()

            ::

                >>> print(format(score_2))
                \context Score = "Grouped Rhythmic Staves Score" <<
                    \context StaffGroup = "Grouped Rhythmic Staves Staff Group" <<
                        \context RhythmicStaff = "Staff 1" <<
                            \context Voice = "Voice 1-1" {
                            }
                            \context Voice = "Voice 1-2" {
                            }
                        >>
                        \context RhythmicStaff = "Staff 2" {
                            \context Voice = "Voice 2" {
                            }
                        }
                        \context RhythmicStaff = "Staff 3" <<
                            \context Voice = "Voice 3-1" {
                            }
                            \context Voice = "Voice 3-2" {
                            }
                        >>
                    >>
                >>

        Returns score.
        '''
        staves = []
        if isinstance(self.staff_count, int):
            for index in range(self.staff_count):
                number = index + 1
                name = 'Voice {}'.format(number)
                voice = scoretools.Voice(name=name)
                name = 'Staff {}'.format(number)
                staff = scoretools.Staff([voice], name=name)
                staff.context_name = 'RhythmicStaff'
                staves.append(staff)
                key = 'v{}'.format(number)
                self.context_name_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 = scoretools.Staff(name=name)
                staff.context_name = '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 = scoretools.Voice(name=name)
                    staff.append(voice)
                    key = 'v{}'.format(voice_identifier)
                    self.context_name_abbreviations[key] = voice.name
                staves.append(staff)
        if self.with_clefs:
            for staff in staves:
                attach(indicatortools.Clef('percussion'), staff)
        grouped_rhythmic_staves_staff_group = scoretools.StaffGroup(
            staves,
            name='Grouped Rhythmic Staves Staff Group',
        )
        grouped_rhythmic_staves_score = scoretools.Score(
            [grouped_rhythmic_staves_staff_group],
            name='Grouped Rhythmic Staves Score',
        )
        return grouped_rhythmic_staves_score
Exemplo n.º 19
0
    def __call__(self):
        '''Calls score template.

        Returns LilyPond file.
        '''

        # make bell voice and staff
        bell_voice = scoretools.Voice(name='Bell Voice')
        bell_staff = scoretools.Staff([bell_voice], name='Bell Staff')
        clef = indicatortools.Clef('treble')
        attach(clef, bell_staff)
        bells = instrumenttools.Instrument(
            instrument_name='Campana in La',
            short_instrument_name='Camp.',
            pitch_range='[C4, C6]',
        )
        attach(bells, bell_staff)
        tempo = indicatortools.Tempo((1, 4), (112, 120))
        attach(tempo, bell_staff)
        time_signature = indicatortools.TimeSignature((6, 4))
        attach(time_signature, bell_staff)

        # make first violin voice and staff
        first_violin_voice = scoretools.Voice(name='First Violin Voice')
        first_violin_staff = scoretools.Staff(
            [first_violin_voice],
            name='First Violin Staff',
        )
        clef = indicatortools.Clef('treble')
        attach(clef, first_violin_staff)
        violin = instrumenttools.Violin(
            instrument_name_markup=markuptools.Markup('Violin I'),
            short_instrument_name_markup=markuptools.Markup('Vl. I'),
        )
        attach(violin, first_violin_staff)

        # make second violin voice and staff
        second_violin_voice = scoretools.Voice(name='Second Violin Voice')
        second_violin_staff = scoretools.Staff(
            [second_violin_voice],
            name='Second Violin Staff',
        )
        clef = indicatortools.Clef('treble')
        attach(clef, second_violin_staff)
        violin = instrumenttools.Violin(
            instrument_name_markup=markuptools.Markup('Violin II'),
            short_instrument_name_markup=markuptools.Markup('Vl. II'),
        )
        attach(violin, second_violin_staff)

        # make viola voice and 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)
        viola = instrumenttools.Viola()
        attach(viola, viola_staff)

        # make cello voice and 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)
        cello = instrumenttools.Cello()
        attach(cello, cello_staff)

        # make bass voice and staff
        bass_voice = scoretools.Voice(name='Bass Voice')
        bass_staff = scoretools.Staff([bass_voice], name='Bass Staff')
        clef = indicatortools.Clef('bass')
        attach(clef, bass_staff)
        contrabass = instrumenttools.Contrabass(
            short_instrument_name_markup=markuptools.Markup('Cb.'), )
        attach(contrabass, bass_staff)

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

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

        # return Pärt Cantus score
        return score
Exemplo n.º 20
0
    def to_score(self):
        r'''Makes score from pitch arrays in inventory.

        ::

            >>> array_1 = pitchtools.PitchArray([
            ...   [1, (2, 1), ([-2, -1.5], 2)],
            ...   [(7, 2), (6, 1), 1]])

        ::

            >>> array_2 = pitchtools.PitchArray([
            ...   [1, 1, 1],
            ...   [1, 1, 1]])

        ::

            >>> arrays = [array_1, array_2]
            >>> inventory = pitchtools.PitchArrayInventory(arrays)

        ::

            >>> score = inventory.to_score()

        ..  doctest::

            >>> print(format(score))
            \new Score <<
                \new StaffGroup <<
                    \new Staff {
                        {
                            \time 4/8
                            r8
                            d'8
                            <bf bqf>4
                        }
                        {
                            \time 3/8
                            r8
                            r8
                            r8
                        }
                    }
                    \new Staff {
                        {
                            \time 4/8
                            g'4
                            fs'8
                            r8
                        }
                        {
                            \time 3/8
                            r8
                            r8
                            r8
                        }
                    }
                >>
            >>

        ::

            >>> show(score) # doctest: +SKIP

        Create one staff per pitch-array row.

        Returns score.
        '''
        from abjad.tools import scoretools
        score = scoretools.Score([])
        staff_group = scoretools.StaffGroup([])
        score.append(staff_group)
        number_staves = self[0].depth
        staves = scoretools.Staff([]) * number_staves
        staff_group.extend(staves)
        for pitch_array in self:
            measures = pitch_array.to_measures()
            for staff, measure in zip(staves, measures):
                staff.append(measure)
        return score
Exemplo n.º 21
0
    def __illustrate__(self):
        r'''Illustrates pitch range inventory.

        ::

            >>> show(inventory) # doctest: +SKIP

        Returns LilyPond file.
        '''
        from abjad.tools import durationtools
        from abjad.tools import lilypondfiletools
        from abjad.tools import indicatortools
        from abjad.tools import markuptools
        from abjad.tools import pitchtools
        from abjad.tools import scoretools
        from abjad.tools import spannertools
        from abjad.tools.topleveltools import attach
        from abjad.tools.topleveltools import iterate
        from abjad.tools.topleveltools import override
        start_note_clefs = []
        stop_note_clefs = []
        for pitch_range in self.items:
            start_note_clef = indicatortools.Clef.from_selection(
                pitch_range.start_pitch)
            start_note_clefs.append(start_note_clef)
            stop_note_clef = indicatortools.Clef.from_selection(
                pitch_range.stop_pitch)
            stop_note_clefs.append(stop_note_clef)
        if start_note_clefs == stop_note_clefs:
            clef = start_note_clefs[0]
            staff = scoretools.Staff()
            attach(clef, staff)
            score = scoretools.Score([staff])
            for pitch_range in self.items:
                start_note = scoretools.Note(pitch_range.start_pitch, 1)
                stop_note = scoretools.Note(pitch_range.stop_pitch, 1)
                notes = [start_note, stop_note]
                glissando = spannertools.Glissando()
                staff.extend(notes)
                attach(glissando, notes)
        else:
            result = scoretools.make_empty_piano_score()
            score, treble_staff, bass_staff = result
            for pitch_range in self.items:
                start_note = scoretools.Note(pitch_range.start_pitch, 1)
                start_note_clef = indicatortools.Clef.from_selection(
                    pitch_range.start_pitch)
                stop_note = scoretools.Note(pitch_range.stop_pitch, 1)
                stop_note_clef = indicatortools.Clef.from_selection(
                    pitch_range.stop_pitch)
                notes = [start_note, stop_note]
                glissando = spannertools.Glissando()
                skips = 2 * scoretools.Skip(1)
                treble_clef = indicatortools.Clef('treble')
                bass_clef = indicatortools.Clef('bass')
                if start_note_clef == stop_note_clef == treble_clef:
                    treble_staff.extend(notes)
                    bass_staff.extend(skips)
                elif start_note_clef == stop_note_clef == bass_clef:
                    bass_staff.extend(notes)
                    treble_staff.extend(skips)
                else:
                    assert start_note_clef == bass_clef
                    assert stop_note_clef == treble_clef
                    bass_staff.extend(notes)
                    treble_staff.extend(skips)
                    staff_change = indicatortools.StaffChange(treble_staff)
                    attach(staff_change, stop_note)
                attach(glissando, notes)
        for leaf in iterate(score).by_class(scoretools.Leaf):
            multiplier = durationtools.Multiplier(1, 4)
            attach(multiplier, leaf)
        override(score).bar_line.stencil = False
        override(score).span_bar.stencil = False
        override(score).glissando.thickness = 2
        override(score).time_signature.stencil = False
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(score)
        lilypond_file.items.remove(lilypond_file['layout'])
        lilypond_file.items.remove(lilypond_file['paper'])
        lilypond_file.header_block.tagline = markuptools.Markup('""')
        return lilypond_file
Exemplo n.º 22
0
def make_lilypond_file(
    selections,
    divisions,
    implicit_scaling=None,
    pitched_staff=None,
    time_signatures=None,
):
    r'''Makes LilyPond file.

    ..  container::

        **Example 1.**

        ::

            >>> maker = rhythmmakertools.EvenRunRhythmMaker(exponent=1)
            >>> divisions = [(3, 4), (4, 8), (1, 4)]
            >>> selections = maker(divisions)
            >>> lilypond_file = rhythmmakertools.make_lilypond_file(
            ...     selections,
            ...     divisions,
            ...     )
            >>> show(lilypond_file) # doctest: +SKIP

    Used in rhythm-maker docs.

    Returns LilyPond file.
    '''
    assert isinstance(selections, list), repr(selections)
    prototype = selectiontools.Selection
    assert all(isinstance(_, prototype) for _ in selections), repr(selections)
    assert isinstance(divisions, (tuple, list)), repr(divisions)
    time_signatures = time_signatures or divisions
    score = scoretools.Score()
    lilypond_file = \
        lilypondfiletools.make_floating_time_signature_lilypond_file(score)
    context = scoretools.Context(context_name='TimeSignatureContext')
    measures = scoretools.make_spacer_skip_measures(
        time_signatures,
        implicit_scaling=implicit_scaling,
    )
    context.extend(measures)
    score.append(context)
    measures = scoretools.make_spacer_skip_measures(
        time_signatures,
        implicit_scaling=implicit_scaling,
    )
    if pitched_staff:
        staff = scoretools.Staff(measures)
    else:
        staff = scoretools.Staff(measures, context_name='RhythmicStaff')
    selections = sequencetools.flatten_sequence(selections)
    selections_ = copy.deepcopy(selections)
    try:
        measures = mutate(staff).replace_measure_contents(selections)
    except StopIteration:
        if pitched_staff:
            staff = scoretools.Staff(selections_)
        else:
            staff = scoretools.Staff(selections_, context_name='RhythmicStaff')
    score.append(staff)
    return lilypond_file
Exemplo n.º 23
0
    def __call__(self):
        r'''Calls string orchestra template.

        Returns score.
        '''

        ### TAGS ###

        tag_names = []

        ### SCORE ###

        staff_group = scoretools.StaffGroup(name='Outer Staff Group', )

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

        ### VIOLINS ###

        if self.violin_count:
            clef_name = 'treble'
            if self.use_percussion_clefs:
                clef_name = 'percussion'
            instrument = instrumenttools.Violin()
            instrument_count = self.violin_count
            instrument_staff_group, instrument_tag_names = \
                self._make_instrument_staff_group(
                    clef_name=clef_name,
                    count=instrument_count,
                    instrument=instrument,
                    )
            staff_group.append(instrument_staff_group)
            tag_names.extend(instrument_tag_names)

        ### VIOLAS ###

        if self.viola_count:
            clef_name = 'alto'
            if self.use_percussion_clefs:
                clef_name = 'percussion'
            instrument = instrumenttools.Viola()
            instrument_count = self.viola_count
            instrument_staff_group, instrument_tag_names = \
                self._make_instrument_staff_group(
                    clef_name=clef_name,
                    count=instrument_count,
                    instrument=instrument,
                    )
            staff_group.append(instrument_staff_group)
            tag_names.extend(instrument_tag_names)

        ### CELLOS ###

        if self.cello_count:
            clef_name = 'bass'
            if self.use_percussion_clefs:
                clef_name = 'percussion'
            instrument = instrumenttools.Cello()
            instrument_count = self.cello_count
            instrument_staff_group, instrument_tag_names = \
                self._make_instrument_staff_group(
                    clef_name=clef_name,
                    count=instrument_count,
                    instrument=instrument,
                    )
            staff_group.append(instrument_staff_group)
            tag_names.extend(instrument_tag_names)

        ### BASSES ###

        if self.contrabass_count:
            clef_name = 'bass_8'
            if self.use_percussion_clefs:
                clef_name = 'percussion'
            instrument = instrumenttools.Contrabass()
            instrument_count = self.contrabass_count
            instrument_staff_group, instrument_tag_names = \
                self._make_instrument_staff_group(
                    clef_name=clef_name,
                    count=instrument_count,
                    instrument=instrument,
                    )
            staff_group.append(instrument_staff_group)
            tag_names.extend(instrument_tag_names)

        ### TIME SIGNATURE CONTEXT ###

        time_signature_context = scoretools.Context(
            name='TimeSignatureContext',
            context_name='TimeSignatureContext',
        )
        instrument_tags = ' '.join(tag_names)
        tag_string = "tag #'({})".format(instrument_tags)
        tag_command = indicatortools.LilyPondCommand(tag_string, 'before')
        attach(tag_command, time_signature_context)

        score.insert(0, time_signature_context)

        return score
    def __call__(self):

        pitch_pipes = instrumenttools.Percussion(
            instrument_name='pitch pipes',
            instrument_name_markup=markuptools.Markup.right_column(
                ['Pitch', 'Pipes'],
                direction=None,
            ),
            short_instrument_name='pp.',
        )

        time_signature_context = scoretools.Context(
            context_name='TimeSignatureContext',
            name='Time Signature Context',
        )
        self._attach_tag('time', time_signature_context)

        flute_staff = self._make_staff(
            'Flute',
            'treble',
            instrument=instrumenttools.Flute(),
            tag='flute',
        )

        oboe_staff = self._make_staff(
            'Oboe',
            'treble',
            instrument=instrumenttools.Oboe(),
            tag='oboe',
        )

        clarinet_staff = self._make_staff(
            'Clarinet',
            'treble',
            instrument=instrumenttools.BassClarinet(
                instrument_name_markup=markuptools.Markup.right_column(
                    ['Bass', 'Clarinet'],
                    direction=None,
                ), ),
            tag='clarinet',
        )

        saxophone_staff = self._make_staff(
            'Saxophone',
            'treble',
            instrument=instrumenttools.BaritoneSaxophone(
                instrument_name_markup=markuptools.Markup.right_column(
                    ['Baritone', 'Saxophone'],
                    direction=None,
                ), ),
            tag='saxophone',
        )

        wind_section_staff_group = scoretools.StaffGroup(
            [
                flute_staff,
                oboe_staff,
                clarinet_staff,
                saxophone_staff,
            ],
            context_name='WindSectionStaffGroup',
            name='Wind Section Staff Group',
        )

        guitar_staff = self._make_staff(
            'Guitar',
            'treble_8',
            instrument=instrumenttools.Guitar(),
        )
        guitar_aux_staff = self._make_staff(
            'Guitar Pitch Pipe',
            'percussion',
            abbreviation='guitar_pp',
            context_name='Pitch Pipes',
            instrument=pitch_pipes,
        )
        guitar_staff_group = scoretools.StaffGroup(
            [guitar_aux_staff, guitar_staff],
            name='Guitar Staff Group',
            context_name='GuitarStaffGroup',
        )
        self._attach_tag('guitar', guitar_staff_group)

        piano_aux_staff = self._make_staff(
            'Piano Pitch Pipe',
            'percussion',
            abbreviation='piano_pp',
            context_name='Pitch Pipes',
            instrument=pitch_pipes,
        )
        piano_rh_staff = self._make_staff(
            'Piano Upper',
            'treble',
            abbreviation='piano_rh',
        )
        piano_lh_staff = self._make_staff(
            'Piano Lower',
            'bass',
            abbreviation='piano_lh',
        )
        piano_pedals = self._make_voice(
            'Piano Pedals',
            context_name='Dynamics',
        )
        piano_staff = scoretools.StaffGroup(
            [piano_rh_staff, piano_lh_staff, piano_pedals],
            context_name='PianoStaff',
            name='Piano Staff',
        )
        attach(instrumenttools.Piano(), piano_staff)
        piano_staff_group = scoretools.StaffGroup(
            [piano_aux_staff, piano_staff],
            context_name='PianoStaffGroup',
            name='Piano Staff Group',
        )
        self._attach_tag('piano', piano_staff_group)

        percussion_staff = self._make_staff(
            'Percussion',
            'percussion',
            instrument=instrumenttools.Percussion(),
        )
        percussion_aux_staff = self._make_staff(
            'Percussion Pitch Pipe',
            'percussion',
            abbreviation='percussion_pp',
            context_name='Pitch Pipes',
            instrument=pitch_pipes,
        )
        percussion_staff_group = scoretools.StaffGroup(
            [percussion_aux_staff, percussion_staff],
            name='Percussion Staff Group',
            context_name='PercussionStaffGroup',
        )
        self._attach_tag('percussion', percussion_staff_group)

        percussion_section_staff_group = scoretools.StaffGroup(
            [
                guitar_staff_group,
                piano_staff_group,
                percussion_staff_group,
            ],
            context_name='PercussionSectionStaffGroup',
            name='Percussion Section Staff Group',
        )

        violin_staff = self._make_staff(
            'Violin',
            'treble',
            instrument=instrumenttools.Violin(),
            tag='violin',
        )

        viola_staff = self._make_staff(
            'Viola',
            'alto',
            instrument=instrumenttools.Viola(),
            tag='viola',
        )

        cello_staff = self._make_staff(
            'Cello',
            'bass',
            instrument=instrumenttools.Cello(),
            tag='cello',
        )

        contrabass_aux_staff = self._make_staff(
            'Contrabass Pitch Pipe',
            'percussion',
            abbreviation='bass_pp',
            context_name='Pitch Pipes',
            instrument=pitch_pipes,
        )
        contrabass_staff = self._make_staff(
            'Contrabass',
            'bass_8',
            abbreviation='bass',
            instrument=instrumenttools.Contrabass(pitch_range='[E1, G4]', ),
        )
        contrabass_staff_group = scoretools.StaffGroup(
            [contrabass_aux_staff, contrabass_staff],
            name='Contrabass Staff Group',
            context_name='ContrabassStaffGroup',
        )
        self._attach_tag('contrabass', contrabass_staff_group)

        string_section_staff_group = scoretools.StaffGroup(
            [
                violin_staff,
                viola_staff,
                cello_staff,
                contrabass_staff_group,
            ],
            context_name='StringSectionStaffGroup',
            name='String Section Staff Group',
        )

        score = scoretools.Score(
            [
                time_signature_context,
                wind_section_staff_group,
                percussion_section_staff_group,
                string_section_staff_group,
            ],
            name='Ersilia Score',
        )

        return score