Ejemplo n.º 1
0
def add_new_spacing_section(meter_voice, start_measure_number, new_moment,
    revert_measure_number = None):

    normal_spacing_duration = abjad.schemetools.SchemeMoment(1, 96)
    if revert_measure_number is None:
        revert_measure_number = start_measure_number + 1

    #measure = measuretools.get_one_indexed_measure_number_in_expr(
    #    meter_voice, start_measure_number)
    measures = list(abjad.iterate(meter_voice).by_class(abjad.Measure))

    start_measure_index = start_measure_number - 1
    measure = measures[start_measure_index]
    command = abjad.LilyPondCommand('newSpacingSection', 'before')
    abjad.attach(command, measure)
    moment = abjad.schemetools.SchemeMoment(new_moment)
    #measure.set.score.proportional_notation_duration = moment
    abjad.set_(measure).score.proportional_notation_duration = moment

    #measure = measuretools.get_one_indexed_measure_number_in_expr(
    #    meter_voice, revert_measure_number)
    revert_measure_index = revert_measure_number - 1
    measure = measures[revert_measure_index]

    command = abjad.LilyPondCommand('newSpacingSection', 'before')
    abjad.attach(command, measure)
    abjad.set_(measure).score.proportional_notation_duration = \
        normal_spacing_duration
Ejemplo n.º 2
0
    def __call__(self):

        # Violin
        violin_staff = Staff(
            [Voice(name='Violin Voice')],
            name='Violin Staff',
            context_name='ViolinStaff',
        )
        violin_tag = LilyPondCommand(r"tag #'violin", format_slot='before')
        attach(violin_tag, violin_staff)
        attach(Clef('treble'), violin_staff)
        attach(instrumenttools.Violin(), violin_staff)
        set_(violin_staff).midi_instrument = schemetools.Scheme(
            'violin', force_quotes=True)

        # Viola
        viola_staff = Staff(
            [Voice(name='Viola Voice')],
            name='Viola Staff',
            context_name='ViolaStaff',
        )
        viola_tag = LilyPondCommand(r"tag #'viola", format_slot='before')
        attach(viola_tag, viola_staff)
        attach(Clef('alto'), viola_staff)
        attach(instrumenttools.Viola(), viola_staff)
        set_(viola_staff).midi_instrument = schemetools.Scheme(
            'viola', force_quotes=True)

        # Cello
        cello_staff = Staff(
            [Voice(name='Cello Voice')],
            name='Cello Staff',
            context_name='CelloStaff',
        )
        cello_tag = LilyPondCommand(r"tag #'cello", format_slot='before')
        attach(cello_tag, cello_staff)
        attach(Clef('bass'), cello_staff)
        attach(instrumenttools.Cello(), cello_staff)
        set_(cello_staff).midi_instrument = schemetools.Scheme(
            'cello', force_quotes=True)

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

        return score
Ejemplo n.º 3
0
    def __call__(self, segment_maker):
        r'''Calls spacing specifier.

        Returns none.
        '''
        score = segment_maker._score
        skip_context = score['Time Signature Context Skips']
        leaves = abjad.iterate(score).by_leaf()
        minimum_leaf_durations_by_measure = \
            self._get_minimum_leaf_durations_by_measure(skip_context, leaves)
        fermata_start_offsets = getattr(
            segment_maker,
            '_fermata_start_offsets',
            [],
            )
        skips = abjad.iterate(skip_context).by_leaf(abjad.scoretools.Skip)
        for measure_index, skip in enumerate(skips):
            measure_timespan = abjad.inspect_(skip).get_timespan()
            if (self.fermata_measure_width is not None and
                measure_timespan.start_offset in fermata_start_offsets):
                duration = self.fermata_measure_width
            else:
                duration = minimum_leaf_durations_by_measure[measure_index]
                if self.minimum_width is not None:
                    if self.minimum_width < duration:
                        duration = self.minimum_width
                if self.multiplier is not None:
                    duration = duration / self.multiplier
            command = abjad.indicatortools.LilyPondCommand('newSpacingSection')
            abjad.attach(command, skip)
            moment = abjad.schemetools.SchemeMoment(duration)
            abjad.set_(skip).score.proportional_notation_duration = moment
Ejemplo n.º 4
0
 def _make_score(self):
     template = recursif.tools.ScoreTemplate()
     score = template()
     first_measure_number = self.measure_numbers[0]
     abjad.set_(score).current_bar_number = first_measure_number
     for staff in abjad.iterate(score).by_class(abjad.Staff):
         time_signature = abjad.TimeSignature(self.measure_duration)
         abjad.attach(time_signature, staff)
     self._score = score
Ejemplo n.º 5
0
    def __illustrate__(
        self, 
        rhythm=None, 
        proportional_notation_duration=abjad.Duration(1, 16),
        subtitle=None,
        title=None, 
        ):
        r'''Illustrates rhythm-maker.

        Returns LilyPond file.
        '''
        if rhythm is None:
            rhythm = self()
        tuplets, time_signatures = [], []
        for selection, time_signature in rhythm:
            tuplets.extend(selection)
            time_signatures.append(time_signature)
        lilypond_file = abjad.rhythmmakertools.make_lilypond_file(
            tuplets,
            time_signatures,
            )
        first_leaves = []
        for tuplet in tuplets:
            first_leaf = tuplet[0]
            first_leaves.append(first_leaf)
        for i, first_leaf in enumerate(first_leaves):
            markup = abjad.Markup(str(i)).small()
            abjad.attach(markup, first_leaf)
        score = lilypond_file.score_block.items[0]
        score.add_final_bar_line()
        self._tweak_length_1_tuplets(score)
        abjad.override(score).text_script.staff_padding = 4
        abjad.override(score).time_signature.style = 'numbered'
        abjad.override(score).tuplet_bracket.staff_padding = 3.5
        pair = proportional_notation_duration.pair
        moment = abjad.schemetools.SchemeMoment(pair)
        abjad.set_(score).proportional_notation_duration = moment
        assert abjad.inspect_(score).is_well_formed()
        lilypond_file.layout_block.indent = 0
        if subtitle is not None:
            subtitle = abjad.Markup(subtitle)
            lilypond_file.header_block.subtitle = subtitle
        lilypond_file.header_block.tagline = abjad.Markup.null()
        if title is not None:
            title = abjad.Markup(title)
            lilypond_file.header_block.title = abjad.Markup(title)
        vector = layouttools.make_spacing_vector(0, 20, 0, 0)
        lilypond_file.paper_block.markup_system_spacing = vector
        return lilypond_file
Ejemplo n.º 6
0
    def __illustrate__(self, start_pitch=None, title=None, subtitle=None):
        r'''Illustrates color-maker output.

        Returns LilyPond file.
        '''
        notes = self(start_pitch=start_pitch)
        self._attach_clefs(notes)
        note_voice = Voice(notes)
        durations = [inspect_(_).get_duration() for _ in notes]
        skips = scoretools.make_skips(abjad.Duration(1), durations)
        label_voice = abjad.Voice(skips)
        abjad.labe(label_voice).with_indices(direction=Down)
        abjad.override(label_voice).text_script.staff_padding = 4
        staff = abjad.Staff([note_voice, label_voice], is_simultaneous=True)
        score = abjad.Score([staff])
        abjad.attach(abjad.TimeSignature((1, 4)), staff)
        abjad.override(score).bar_line.stencil = False
        abjad.override(score).bar_number.transparent = True
        abjad.override(score).spacing_spanner.strict_grace_spacing = True
        abjad.override(score).spacing_spanner.strict_note_spacing = True
        abjad.override(score).stem.transparent = True
        abjad.override(score).text_script.staff_padding = 1
        abjad.override(score).time_signature.stencil = False
        moment = abjad.schemetools.SchemeMoment((1, 9))
        abjad.set_(score).proportional_notation_duration = moment
        lilypond_file = abjad.lilypondfiletools.make_basic_lilypond_file(score)
        lilypond_file.global_staff_size = 12
        if subtitle is not None:
            subtitle = abjad.Markup(subtitle)
            lilypond_file.header_block.subtitle = subtitle
        lilypond_file.header_block.tagline = abjad.Markup.null()
        if title is not None:
            title = abjad.Markup(title)
            lilypond_file.header_block.title = title
        lilypond_file.layout_block.indent = 0
        lilypond_file.paper_block.left_margin = 20
        vector = abjad.layouttools.make_spacing_vector(0, 20, 0, 0)
        lilypond_file.paper_block.markup_system_spacing = vector
        vector = abjad.layouttools.make_spacing_vector(0, 0, 12, 0)
        lilypond_file.paper_block.system_system_spacing = vector
        vector = abjad.layouttools.make_spacing_vector(0, 4, 0, 0)
        lilypond_file.paper_block.top_markup_spacing = vector
        return lilypond_file
Ejemplo n.º 7
0
 def make_performer_group(
     context_name=None,
     instrument=None,
     label=None,
     ):
     context_name = context_name or 'PerformerGroup'
     name = '{} Performer Group'.format(instrument.instrument_name.title())
     performer_group = scoretools.StaffGroup(
         context_name=context_name,
         name=name,
         )
     performer_group.is_simultaneous = True
     if label is not None:
         ScoreTemplateManager.attach_tag(label, performer_group)
     attach(
         instrument,
         performer_group,
         scope=context_name,
         is_annotation=True,
         )
     manager = set_(performer_group)
     manager.instrument_name = instrument.instrument_name_markup
     manager.short_instrument_name = instrument.short_instrument_name_markup
     return performer_group
Ejemplo n.º 8
0
    def __call__(self):
        r'''Calls score template.

        ..  container:: example

            **Example.** Calls score template:

            ::

                >>> template = recursif.tools.ScoreTemplate()
                >>> score = template()

            ::
            
                >>> f(score)
                \context Score = "Score" <<
                    \context StaffGroup = "Staff Group" <<
                        \context StaffOne = "Staff 1" \with {
                            instrumentName = \markup {
                                \hcenter-in
                                    #12
                                    \bold
                                        \scale
                                            #'(1.5 . 1.5)
                                            1
                                }
                            shortInstrumentName = \markup {
                                \hcenter-in
                                    #12
                                    \bold
                                        \scale
                                            #'(1.5 . 1.5)
                                            1
                                }
                        } {
                        }
                        \context StaffTwo = "Staff 2" \with {
                            instrumentName = \markup {
                                \hcenter-in
                                    #12
                                    \bold
                                        \scale
                                            #'(1.5 . 1.5)
                                            2
                                }
                            shortInstrumentName = \markup {
                                \hcenter-in
                                    #12
                                    \bold
                                        \scale
                                            #'(1.5 . 1.5)
                                            2
                                }
                        } {
                        }
                        ...
                        \context StaffSixtyFour = "Staff 64" \with {
                            instrumentName = \markup {
                                \hcenter-in
                                    #12
                                    \bold
                                        \scale
                                            #'(1.5 . 1.5)
                                            64
                                }
                            shortInstrumentName = \markup {
                                \hcenter-in
                                    #12
                                    \bold
                                        \scale
                                            #'(1.5 . 1.5)
                                            64
                                }
                        } {
                        }
                    >>
                >>

        Returns score.
        '''
        staves = []
        engine = inflect.engine()
        for staff_index in range(64):
            staff_number = staff_index + 1
            staff_number_word = engine.number_to_words(staff_number)
            staff_number_word = abjad.stringtools.to_upper_camel_case(
                staff_number_word)
            context_name = 'Staff{}'.format(staff_number_word)
            name = 'Staff {}'.format(staff_number)
            staff = abjad.scoretools.Staff(
                context_name=context_name,
                name=name,
                )
            markup = abjad.Markup(staff_number)
            markup = markup.scale((1.5, 1.5))
            markup = markup.bold()
            markup = markup.hcenter_in(12)
            abjad.set_(staff).instrument_name = markup
            abjad.set_(staff).short_instrument_name = markup
            staves.append(staff)
        staff_group = abjad.scoretools.StaffGroup(
            staves,
            name='Staff Group',
            )
        score = abjad.Score(
            [staff_group], 
            name='Score',
            )
        return score
Ejemplo n.º 9
0
    def __illustrate__(self):
        r"""Illustrates time signature groups.

        ::

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

        ..  doctest::

            >>> lilypond_file = groups.__illustrate__()
            >>> score = lilypond_file.score_block.items[0]
            >>> f(score)
            \new Score \with {
                proportionalNotationDuration = #(ly:make-moment 1 8)
            } <<
                \new Staff \with {
                    \consists Horizontal_bracket_engraver
                    \override Clef.stencil = ##f
                    \override HorizontalBracket.bracket-flare = #'(0 . 0)
                    \override HorizontalBracket.direction = #up
                    \override HorizontalBracket.extra-offset = #'(-4 . 0)
                    \override HorizontalBracket.staff-padding = #2.5
                    \override Rest.transparent = ##t
                    \override TextScript.extra-offset = #'(-4 . 0)
                    \override TextScript.staff-padding = #4.5
                } {
                    {
                        \time 3/8
                        r1 * 3/8 \startGroup
                            ^ \markup {
                                \circle
                                    \smaller
                                        0
                                }
                    }
                    {
                        \time 3/16
                        r1 * 3/16
                    }
                    {
                        \time 3/16
                        r1 * 3/16 \stopGroup
                    }
                    {
                        \time 5/8
                        r1 * 5/8 \startGroup
                            ^ \markup {
                                \circle
                                    \smaller
                                        1
                                }
                    }
                    {
                        \time 5/16
                        r1 * 5/16
                    }
                    {
                        \time 5/16
                        r1 * 5/16
                    }
                    {
                        \time 5/16
                        r1 * 5/16 \stopGroup
                    }
                }
            >>

        Returns LilyPond file.
        """
        staff = abjad.scoretools.Staff()
        staff.consists_commands.append("Horizontal_bracket_engraver")
        for group_index, group in enumerate(self.groups):
            measure_group = self._make_measure_group(group)
            spanner = abjad.spannertools.HorizontalBracketSpanner()
            leaves = list(abjad.iterate(measure_group).by_leaf())
            abjad.attach(spanner, leaves)
            staff.extend(measure_group)
            markup = abjad.markuptools.Markup(group_index, direction=Up)
            markup = markup.smaller()
            markup = markup.circle()
            abjad.attach(markup, measure_group[0])
        slide = -4
        abjad.override(staff).clef.stencil = False
        abjad.override(staff).horizontal_bracket.bracket_flare = (0, 0)
        abjad.override(staff).horizontal_bracket.direction = Up
        abjad.override(staff).horizontal_bracket.extra_offset = (slide, 0)
        abjad.override(staff).horizontal_bracket.staff_padding = 2.5
        abjad.override(staff).rest.transparent = True
        abjad.override(staff).text_script.extra_offset = (slide, 0)
        abjad.override(staff).text_script.staff_padding = 4.5
        score = abjad.scoretools.Score([staff])
        moment = abjad.schemetools.SchemeMoment((1, 8))
        abjad.set_(score).proportional_notation_duration = moment
        lilypond_file = abjad.lilypondfiletools.make_basic_lilypond_file(score)
        lilypond_file.header_block.tagline = abjad.markuptools.Markup.null()
        return lilypond_file