How to use the abjad.tools.durationtools function in abjad

To help you get started, we’ve selected a few abjad examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Abjad / abjad / experimental / tools / makertools / FuseByCountsDivisionCallback.py View on Github external
def _coerce_divisions(self, divisions):
        divisions_ = []
        for division in divisions:
            if hasattr(division, 'time_signature'):
                argument = division.time_signature.pair
            elif hasattr(division, 'duration'):
                argument = division.duration
            else:
                argument = division
            division_ = durationtools.Division(argument)
            divisions_.append(division_)
        return divisions_
github josiah-wolf-oberholtzer / consort / makers / PitchClassPitchMaker.py View on Github external
def _duration_and_ratio_to_offsets(
        self,
        duration=None,
        ratio=None,
        ):
        ratio_sum = sum(ratio)
        duration_parts = []
        for ratio_part in ratio:
            multiplier = durationtools.Multiplier(ratio_part, ratio_sum)
            duration_part = duration * multiplier
            duration_parts.append(duration_part)
        offsets = mathtools.cumulative_sums(duration_parts)
        offsets = offsets[:-1]
        return offsets
github Abjad / abjad / trunk / abjad / tools / tuplettools / _make_tuplet_from_duration_with_proportions_and_encourage_dots.py View on Github external
# TODO: only this call differs from _duration_into_arbitrary_fixed_duration_tuplet_undotted;
    #         so combined the two functions. #
    # find basic written duration of note in tuplet
    basic_written_duration = durationtools.rational_to_equal_or_greater_assignable_rational(
        basic_prolated_duration)

    # find written duration of each note in tuplet
    written_durations = [x * basic_written_duration for x in divisions]

    # make tuplet leaves
    try:
        notes = [notetools.Note(0, x) if 0 < x else resttools.Rest(abs(x)) for x in written_durations]
    except AssignabilityError:
        denominator = duration._denominator
        note_durations = [durationtools.Duration(x, denominator) for x in divisions]
        pitches = [None if note_duration < 0 else 0 for note_duration in note_durations]
        leaf_durations = [abs(note_duration) for note_duration in note_durations]
        notes = leaftools.make_leaves(pitches, leaf_durations, big_endian=big_endian)

    # make tuplet
    tuplet = tuplettools.FixedDurationTuplet(duration, notes)

    # fix tuplet contents if necessary
    tuplettools.fix_contents_of_tuplets_in_expr(tuplet)

    # switch prolation if necessary
    if not tuplet.multiplier == 1:
        if prolation == 'diminution':
            if not tuplet.is_diminution:
                tuplettools.change_augmented_tuplets_in_expr_to_diminished(tuplet)
        else:
github Abjad / abjad / trunk / abjad / tools / quantizationtools / QTargetBeat.py View on Github external
def __init__(self, 
        beatspan=None, 
        offset_in_ms=None, 
        search_tree=None, 
        tempo=None,
        ):
        from abjad.tools import quantizationtools

        beatspan = durationtools.Duration(beatspan)
        offset_in_ms = durationtools.Offset(offset_in_ms)

        if search_tree is None:
            search_tree = quantizationtools.UnweightedSearchTree()
        assert isinstance(search_tree, quantizationtools.SearchTree)
        tempo = marktools.TempoMark(tempo)
        assert not tempo.is_imprecise

        q_events = []
        q_grids = []

        self._beatspan = beatspan
        self._distances = {}
        self._offset_in_ms = offset_in_ms
        self._q_events = q_events
        self._q_grid = None
        self._q_grids = q_grids
github Abjad / abjad / trunk / abjad / tools / marktools / TempoMark.py View on Github external
def __init__(self, *args, **kwargs):
        from abjad.tools import scoretools
        target_context = kwargs.get('target_context', scoretools.Score)
        ContextMark.__init__(self, target_context=target_context)
        if len(args) == 1 and isinstance(args[0], type(self)):
            tempo_indication = args[0]
            duration = durationtools.Duration(tempo_indication.duration)
            textual_indication = tempo_indication.textual_indication
            units_per_minute = tempo_indication.units_per_minute
        elif len(args) == 1 and isinstance(args[0], str):
            duration = None
            textual_indication = args[0]
            units_per_minute = None
            assert isinstance(textual_indication, (str, type(None)))
        elif len(args) == 1 and isinstance(args[0], tuple) and \
            len(args[0]) == 2:
            textual_indication = None
            duration, units_per_minute = args[0]
        elif len(args) == 1 and isinstance(args[0], tuple) and \
            len(args[0]) == 3:
            textual_indication, duration, units_per_minute = args[0]
        elif len(args) in [2, 3]:
            if len(args) == 3:
github Abjad / abjad / experimental / tools / expressiontools / StartPositionedPayloadExpression / StartPositionedPayloadExpression.py View on Github external
def _get_duration_of_list(self, expr):
        duration = durationtools.Duration(0)
        for element in expr:
            duration += self._get_duration_of_expr(element)
        return duration
github Abjad / abjad / trunk / abjad / tools / spannertools / MetricGridSpanner / _MetricGridSpannerFormatInterface.py View on Github external
else:
                meter, temp_hide = matching_meter
            #if meter and not getattr(meter, '_temp_hide', False):
            if meter and not temp_hide:
                result.append(meter.format)
            #m = spanner._slicing_meters(leaf)
            m = spanner._slicing_meters(leaf)
            #m = [meter for meter in m if not getattr(meter, '_temp_hide', False)]
            m = [triple for triple in m if not triple[-1]]
            if m:
                # set spanner._slicing_metersFound as temporary flag so that
                # spanner._after does not have to recompute _slicing_meters()
                spanner._slicing_metersFound = True
                result.append('<<')
                for meter, moffset, temp_hide in m:
                    s = Skip(durationtools.Duration(1))
                    #s.duration_multiplier = meter._offset - leaf._offset.start
                    s.duration_multiplier = moffset - leaf._offset.start
                    numerator, denominator = meter.numerator, meter.denominator
                    mark = contexttools.TimeSignatureMark((numerator, denominator))(s)
                    mark._is_cosmetic_mark = True
                    container = Container([s])
                    result.append(container.format)
        return result
github Abjad / abjad / trunk / abjad / tools / timespantools / TimespanInventory.py View on Github external
Duration(20, 1)

        Zero when empty:

        ::

            >>> timespan_inventory_3.duration
            Duration(0, 1)

        Returns duration.
        '''
        if self.stop_offset is not Infinity and \
            self.start_offset is not NegativeInfinity:
            return self.stop_offset - self.start_offset
        else:
            return durationtools.Duration(0)
github Abjad / abjad / abjad / tools / handlertools / DynamicHandler.py View on Github external
def __init__(self, minimum_duration=None):
        Handler.__init__(self)
        if minimum_duration is not None:
            minimum_duration = durationtools.Duration(minimum_duration)
        self._minimum_duration = minimum_duration
github Abjad / abjad / abjad / tools / scoretools / move_full_measure_tuplet_prolation_to_measure_time_signature.py View on Github external
}

    Returns none.
    '''
    from abjad.tools import indicatortools
    from abjad.tools import scoretools

    for measure in iterate(argument).by_class(scoretools.Measure):
        if len(measure) == 1:
            if isinstance(measure[0], scoretools.Tuplet):
                tuplet = measure[0]
                tuplet_multiplier = tuplet.multiplier
                tuplet_denominator = tuplet_multiplier.denominator
                reduced_denominator = mathtools.remove_powers_of_two(tuplet_denominator)
                time_signature = measure.time_signature
                time_signature_rational = durationtools.Duration(
                    time_signature.numerator, time_signature.denominator)
                numerator = time_signature_rational.numerator * reduced_denominator
                denominator = time_signature_rational.denominator * reduced_denominator
                time_signature = indicatortools.TimeSignature((numerator, denominator))
                detach(indicatortools.TimeSignature, measure)
                attach(time_signature, measure)
                if time_signature.has_non_power_of_two_denominator:
                    measure.implicit_scaling = True
                time_signature_multiplier = \
                    measure.time_signature.implied_prolation
                written_adjustment = tuplet_multiplier.__div__(time_signature_multiplier)
                tuplet._extract()
                measure._scale_contents(written_adjustment)