Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
0
 def _rewrite_meter_(
     selections,
     meters,
     reference_meters=None,
     rewrite_tuplets=False,
     use_messiaen_style_ties=False,
 ):
     from abjad.tools import metertools
     from abjad.tools import scoretools
     from abjad.tools.topleveltools import mutate
     meters = [metertools.Meter(_) for _ in meters]
     durations = [durationtools.Duration(_) for _ in meters]
     reference_meters = reference_meters or ()
     selections = DurationSpellingSpecifier._split_at_measure_boundaries(
         selections,
         meters,
         use_messiaen_style_ties=use_messiaen_style_ties,
     )
     measures = scoretools.make_spacer_skip_measures(durations)
     staff = scoretools.Staff(measures)
     mutate(staff).replace_measure_contents(selections)
     for measure, meter in zip(staff, meters):
         for reference_meter in reference_meters:
             if str(reference_meter) == str(meter):
                 meter = reference_meter
                 break
         mutate(measure[:]).rewrite_meter(
             meter,
             rewrite_tuplets=rewrite_tuplets,
             use_messiaen_style_ties=use_messiaen_style_ties,
         )
     selections = []
     for measure in staff:
         selections.append(measure[:])
     return selections
Esempio n. 7
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
Esempio n. 8
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
Esempio n. 9
0
    def make_score_with_indicators_02(self):
        r'''Make 200-note staff with dynamic on every 4th note.

        ::

            2.12 (r9704) initialization:      4,632,761 function calls
            2.12 (r9710) initialization:        327,280 function calls
            2.12 (r9726) initialization:        325,371 function calls

            2.12 (r9704) LilyPond format:       220,277 function calls
            2.12 (r9710) LilyPond format:        84,530 function calls
            2.12 (r9726) LilyPond format:        90,056 function calls

        '''
        from abjad.tools import indicatortools
        from abjad.tools import scoretools
        from abjad.tools import sequencetools
        from abjad.tools import topleveltools
        staff = scoretools.Staff(200 * scoretools.Note("c'16"))
        for part in sequencetools.partition_sequence_by_counts(
                staff[:],
            [4],
                cyclic=True,
        ):
            dynamic = indicatortools.Dynamic('f')
            topleveltools.attach(dynamic, part[0])
        return staff
Esempio n. 10
0
    def make_score_with_indicators_01(self):
        r'''Make 200-note voice with dynamic on every 20th note:

        ::

            2.12 (r9704) initialization:        630,433 function calls
            2.12 (r9710) initialization:        235,120 function calls
            2.12 r(9726) initialization:        235,126 function calls

            2.12 (r9704) LilyPond format:       136,637 function calls
            2.12 (r9710) LilyPond format:        82,730 function calls
            2.12 (r9726) LilyPond format:        88,382 function calls

        '''
        from abjad.tools import indicatortools
        from abjad.tools import scoretools
        from abjad.tools import sequencetools
        from abjad.tools import topleveltools
        staff = scoretools.Staff(200 * scoretools.Note("c'16"))
        for part in sequencetools.partition_sequence_by_counts(
                staff[:],
            [20],
                cyclic=True,
        ):
            dynamic = indicatortools.Dynamic('f')
            topleveltools.attach(dynamic, part[0])
        return staff
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
Esempio n. 12
0
def make_desordre_staff(pitches):
    r'''Makes Désordre staff.
    '''

    staff = scoretools.Staff()
    for sequence in pitches:
        measure = abjad.demos.desordre.make_desordre_measure(sequence)
        staff.append(measure)
    return staff
Esempio n. 13
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
Esempio n. 14
0
def make_rhythmic_sketch_staff(music):
    r'''Make rhythmic staff with transparent time_signature and transparent bar
    lines.
    '''
    from abjad.tools import scoretools

    staff = scoretools.Staff(music)
    staff.context_name = 'RhythmicStaff'
    override(staff).time_signature.transparent = True
    override(staff).bar_line.transparent = True

    return staff
Esempio n. 15
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
Esempio n. 16
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
Esempio n. 17
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
Esempio n. 18
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
Esempio n. 19
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
Esempio n. 20
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
Esempio n. 21
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
Esempio n. 22
0
    def make_score_with_indicators_03(self):
        r'''Make 200-note staff with dynamic on every note.

        ::

            2.12 (r9704) initialization:     53,450,195 function calls (!!)
            2.12 (r9710) initialization:      2,124,500 function calls
            2.12 (r9724) initialization:      2,122,591 function calls

            2.12 (r9704) LilyPond format:       533,927 function calls
            2.12 (r9710) LilyPond format:        91,280 function calls
            2.12 (r9724) LilyPond format:        96,806 function calls

        '''
        from abjad.tools import indicatortools
        from abjad.tools import scoretools
        from abjad.tools import topleveltools
        staff = scoretools.Staff(200 * scoretools.Note("c'16"))
        for note in staff.select_leaves():
            dynamic = indicatortools.Dynamic('f')
            topleveltools.attach(dynamic, note)
        return staff
Esempio n. 23
0
    def __illustrate__(self):
        r'''Illustrates clef inventory.

        ::

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

        Returns LilyPond file.
        '''
        from abjad.tools import lilypondfiletools
        from abjad.tools import scoretools
        staff = scoretools.Staff()
        for clef in self:
            rest = scoretools.Rest((1, 8))
            clef = copy.copy(clef)
            attach(clef, rest)
            staff.append(rest)
        override(staff).clef.full_size_change = True
        override(staff).rest.transparent = True
        override(staff).time_signature.stencil = False
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(staff)
        lilypond_file.header_block.tagline = False
        return lilypond_file
Esempio n. 24
0
    def __illustrate__(self):
        r'''Illustrates pitch.

        Returns LilyPond file.
        '''
        from abjad.tools import durationtools
        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 attach
        from abjad.tools.topleveltools import override
        pitch = pitchtools.NamedPitch(self)
        note = scoretools.Note(pitch, 1)
        attach(durationtools.Multiplier(1, 4), note)
        clef = pitchtools.suggest_clef_for_named_pitches([pitch])
        staff = scoretools.Staff()
        attach(clef, staff)
        staff.append(note)
        override(staff).time_signature.stencil = False
        lilypond_file = lilypondfiletools.make_basic_lilypond_file(staff)
        lilypond_file.header_block.tagline = markuptools.Markup('""')
        return lilypond_file
Esempio n. 25
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
Esempio n. 26
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
Esempio n. 27
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
Esempio n. 28
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
Esempio n. 29
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
Esempio n. 30
0
 def _make_performer_staff_group(
     self,
     clef_name=None,
     instrument=None,
     number=None,
 ):
     if number is not None:
         name = '{} {}'.format(
             instrument.instrument_name.title(),
             number,
         )
     else:
         name = instrument.instrument_name.title()
     pitch_range = instrument.pitch_range
     staff_group = scoretools.StaffGroup(
         context_name='StringPerformerStaffGroup',
         name='{} Staff Group'.format(name),
     )
     tag_name = name.replace(' ', '')
     tag_string = "tag #'{}".format(tag_name)
     tag_command = indicatortools.LilyPondCommand(
         tag_string,
         'before',
     )
     attach(tag_command, staff_group)
     if self.split_hands:
         lh_voice = scoretools.Voice(
             context_name='FingeringVoice',
             name='{} Fingering Voice'.format(name),
         )
         abbreviation = lh_voice.name.lower().replace(' ', '_')
         self.voice_name_abbreviations[abbreviation] = lh_voice.name
         lh_staff = scoretools.Staff(
             [lh_voice],
             context_name='FingeringStaff',
             name='{} Fingering Staff'.format(name),
         )
         lh_staff.is_simultaneous = True
         attach(pitch_range, lh_staff)
         attach(indicatortools.Clef(clef_name), lh_staff)
         rh_voice = scoretools.Voice(
             context_name='BowingVoice',
             name='{} Bowing Voice'.format(name),
         )
         abbreviation = rh_voice.name.lower().replace(' ', '_')
         self.voice_name_abbreviations[abbreviation] = rh_voice.name
         rh_staff = scoretools.Staff(
             [rh_voice],
             context_name='BowingStaff',
             name='{} Bowing Staff'.format(name),
         )
         rh_staff.is_simultaneous = True
         staff_group.extend([rh_staff, lh_staff])
     else:
         lh_voice = scoretools.Voice(
             context_name='FingeringVoice',
             name='{} Voice'.format(name),
         )
         lh_staff = scoretools.Staff(
             [lh_voice],
             context_name='FingeringStaff',
             name='{} Staff'.format(name),
         )
         lh_staff.is_simultaneous = True
         attach(pitch_range, lh_staff)
         attach(indicatortools.Clef(clef_name), lh_staff)
         staff_group.append(lh_staff)
     return staff_group, tag_name