예제 #1
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
예제 #2
0
 def instantiate_score(self):
     score = self.score_specification.score_template()
     context = scoretools.Context(
         name='TimeSignatureContext',
         context_name='TimeSignatureContext',
     )
     score.insert(0, context)
     return score
예제 #3
0
 def _add_time_signature_context(self, score):
     time_signatures = self.time_signatures
     if not time_signatures:
         return
     time_signature_context = scoretools.Context(
         context_name='TimeSignatureContext',
         name='Time Signature Context',
     )
     measures = scoretools.make_spacer_skip_measures(time_signatures)
     time_signature_context.extend(measures)
     score.insert(0, time_signature_context)
예제 #4
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
예제 #5
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
예제 #6
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