Пример #1
0
    def __call__(self, logical_ties, timespan=None, offset=0):
        r'''Calls note and chord hairpin handler on `logical_ties` 
        with `offset`.

        Returns none.
        '''
        groups = self._group_contiguous_logical_ties(logical_ties)
        for group in groups:
            notes = []
            for logical_tie in group:
                for note in logical_tie:
                    notes.append(note)
            if len(notes) <= 1:
                continue
            total_notes = len(notes)
            notes_to_span = []
            for i, note in enumerate(notes):
                if self._index_matches_patterns(i, total_notes):
                    notes_to_span.append(note)
            if not notes_to_span:
                continue
            descriptor = ' '.join([_ for _ in self.hairpin_token if _])
            hairpin = spannertools.Hairpin(
                descriptor=descriptor,
                include_rests=False,
            )
            attach(hairpin, notes_to_span)
    def __call__(self, logical_ties, timespan=None, offset=0):
        r'''Calls note and chord hairpin handler on `logical_ties`
        with `offset`.

        Returns none.
        '''
        if (self.span == 'contiguous notes and chords'
                or isinstance(self.span, (tuple, list))):
            groups = self._group_contiguous_logical_ties(logical_ties)
        elif self.span == 'nontrivial ties':
            groups = [[_] for _ in logical_ties]
        else:
            raise ValueError(self.span)
        if isinstance(self.span, (tuple, list)):
            new_groups = []
            for group in groups:
                leaves = iterate(group).by_class(scoretools.Leaf)
                leaves = list(leaves)
                shards = sequencetools.partition_sequence_by_counts(
                    leaves,
                    counts=self.span,
                    cyclic=True,
                )
                new_groups.extend(shards)
            groups = new_groups
            groups = [[_] for _ in groups]
        for group_index, group in enumerate(groups):
            notes = []
            for logical_tie in group:
                for note in logical_tie:
                    notes.append(note)
            if len(notes) == 0:
                continue
            total_notes = len(notes)
            notes_to_span = []
            for note_index, note in enumerate(notes):
                if self._index_matches_patterns(note_index, total_notes):
                    notes_to_span.append(note)
            if not notes_to_span:
                continue
            if (len(notes_to_span) == 1
                    and not self.attach_start_dynamic_to_lone_notes):
                continue
            if (len(notes_to_span) == 1
                    and self.attach_start_dynamic_to_lone_notes):
                hairpin_token = self.hairpin_token[group_index]
                start_dynamic = hairpin_token[0]
                dynamic = indicatortools.Dynamic(start_dynamic)
                attach(dynamic, notes[0])
                continue
            hairpin_token = self.hairpin_token[group_index]
            descriptor = ' '.join([_ for _ in hairpin_token if _])
            hairpin = spannertools.Hairpin(
                descriptor=descriptor,
                include_rests=False,
            )
            attach(hairpin, notes_to_span)
Пример #3
0
    def __call__(self, logical_ties, timespan=None, offset=0):
        r'''Calls handler on `logical_ties` with `offset`.

        Returns none.
        '''
        hairpin_tokens = datastructuretools.CyclicTuple(self.hairpin_tokens)
        logical_tie_groups = self._group_contiguous_logical_ties(logical_ties)
        for logical_tie_group in logical_tie_groups:
            pairs = sequencetools.iterate_sequence_nwise(
                logical_tie_group,
                n=2,
                )
            for i, pair in enumerate(pairs):
                hairpin_token = hairpin_tokens[i]
                descriptor = ' '.join([_ for _ in hairpin_token if _])
                hairpin = spannertools.Hairpin(
                    descriptor=descriptor,
                    include_rests=False,
                    )
                first_logical_tie, second_logical_tie = pair
                notes = []
                notes.extend(first_logical_tie)
                notes.append(second_logical_tie.head)
                attach(hairpin, notes)
Пример #4
0
    def __call__(self, logical_ties):
        r'''Calls hairpin handler on `logical_ties`.

        Passes silently when `logical_ties` is empty.

        Returns none.
        '''
        if not logical_ties:
            return
        if not isinstance(logical_ties[0], selectiontools.LogicalTie):
            assert isinstance(logical_ties[0], scoretools.Leaf)
            logical_ties = [selectiontools.LogicalTie(_) for _ in logical_ties]
        if (self.span == 'contiguous notes and chords'
            or isinstance(self.span, (tuple, list))):
            groups = self._group_contiguous_logical_ties(logical_ties)
        elif self.span == 'nontrivial ties':
            groups = [[_] for _ in logical_ties]
        else:
            raise ValueError(self.span)
        if isinstance(self.span, (tuple, list)):
            if not self.enchain_hairpins:
                groups = self._partition_groups(groups)
            else:
                groups = self._partition_enchained_groups(groups)
        hairpin_tokens = self.hairpin_tokens
        for group_index, group in enumerate(groups):
            notes = []
            for logical_tie in group:
                for note in logical_tie:
                    notes.append(note)
            if len(notes) == 0:
                continue
            total_notes = len(notes)
            notes_to_span = []
            for note_index, note in enumerate(notes):
                if self._index_matches_patterns(note_index, total_notes):
                    notes_to_span.append(note)
            if not notes_to_span:
                continue
            if self.include_following_rests:
                last_note = notes_to_span[-1]
                next_leaf = inspect_(last_note).get_leaf(1)
                prototype = (scoretools.Rest, scoretools.MultimeasureRest)
                if isinstance(next_leaf, prototype):
                    notes_to_span.append(next_leaf)
            if len(notes_to_span) == 1 and self.omit_lone_note_dynamic:
                continue
            if len(notes_to_span) == 1 and not self.omit_lone_note_dynamic:
                hairpin_token = hairpin_tokens[group_index]
                start_dynamic = hairpin_token[0]
                if start_dynamic == 'niente':
                    message = 'can not attach niente dynamics to components.'
                    raise Exception(message)
                dynamic = indicatortools.Dynamic(start_dynamic)
                attach(dynamic, notes[0])
                continue
            hairpin_token = hairpin_tokens[group_index]
            if hairpin_token is None:
                continue
            if isinstance(hairpin_token, tuple):
                descriptor = ' '.join([_ for _ in hairpin_token if _])
                include_rests = bool(self.include_following_rests)
                hairpin = spannertools.Hairpin(
                    descriptor=descriptor,
                    include_rests=include_rests,
                    )
                attach(hairpin, notes_to_span)
            # hook to allow callable custom classes like SwellSpecifier
            else:
                hairpin_token(notes_to_span)
            if self.flare:
                first_note = notes_to_span[0]
                prototype = scoretools.Note
                assert isinstance(first_note, prototype), repr(first_note)
                stencil = schemetools.Scheme('flared-hairpin')
                override(first_note).hairpin.stencil = stencil
Пример #5
0
         selector=selectortools.Selector().by_logical_tie(
             pitched=True).by_duration('==', (1, 16), preprolated=True)[0],
     ),
     shimmer=consort.AttachmentExpression(
         attachments=[
             [
                 indicatortools.Articulation('accent'),
                 indicatortools.Dynamic('fp'),
             ],
         ],
         selector=selectortools.Selector().by_logical_tie(
             pitched=True).by_duration(
                 '>', (1, 16),
                 preprolated=True).by_leaf().by_length('==', 1)[0]),
     swell=consort.AttachmentExpression(
         attachments=spannertools.Hairpin('niente < f'),
         selector=selectortools.Selector().by_logical_tie(
             pitched=True).by_duration(
                 '>', (1, 16),
                 preprolated=True).by_leaf().by_length('>', 1)),
     text_spanner=consort.AttachmentExpression(
         attachments=abbreviations.make_text_spanner('snare'),
         selector=selectortools.select_pitched_runs(),
     ),
     tremolo=consort.AttachmentExpression(
         attachments=spannertools.StemTremoloSpanner(),
         selector=selectortools.Selector().by_logical_tie(
             pitched=True).by_duration('>', (1, 16), preprolated=True)),
 ),
 color='yellow',
 labels=[],