Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
>>> sequencetools.all_are_integer_equivalent_exprs([1, '2', 3.0, Fraction(4, 1)])
True
Otherwise false:
::
>>> sequencetools.all_are_integer_equivalent_exprs([1, '2', 3.5, 4])
False
Returns boolean.
'''
try:
return all(mathtools.is_integer_equivalent_expr(x) for x in expr)
except TypeError:
return False
def _make_score_number_markup(
configuration_number,
score_number,
):
assert mathtools.is_nonnegative_integer(configuration_number)
assert mathtools.is_nonnegative_integer(score_number)
number_string = '{}-{}'.format(
configuration_number,
score_number,
)
command = markuptools.MarkupCommand('fontsize', 2, number_string)
command = markuptools.MarkupCommand('italic', command)
command = markuptools.MarkupCommand('box', command)
pair = schemetools.SchemePair('box-padding', 0.75)
command = markuptools.MarkupCommand('override', pair, command)
width = 9
command = markuptools.MarkupCommand('hcenter-in', width, command)
markup = markuptools.Markup(command)
return markup
def evaluate(self):
r'''Evaluate measure select expression.
Returns none when nonevaluable.
Returns start-positioned division payload expression when evaluable.
'''
from experimental.tools import musicexpressiontools
anchor_timespan = self._evaluate_anchor_timespan()
time_relation = self._get_time_relation(anchor_timespan)
time_signatures = self.root_specification.time_signatures[:]
time_signatures = \
[mathtools.NonreducedFraction(x) for x in time_signatures]
start_offset = self.root_specification.timespan.start_offset
expression = \
musicexpressiontools.StartPositionedDivisionPayloadExpression(
payload=time_signatures,
start_offset=start_offset,
)
callback_cache = self.score_specification.interpreter.callback_cache
expression = expression.get_elements_that_satisfy_time_relation(
time_relation, callback_cache)
expression = self._apply_callbacks(expression)
#expression._voice_name = self.voice_name
return expression
... group
[NonreducedFraction(1, 4), NonreducedFraction(1, 8)]
[NonreducedFraction(1, 3), NonreducedFraction(1, 6)]
[NonreducedFraction(1, 4)]
Return list of duration lists.
'''
from abjad.tools import durationtools
durations = [mathtools.NonreducedFraction(duration) for duration in durations]
assert 0 < len(durations)
group = [durations[0]]
result = [group]
for d in durations[1:]:
d_f = set(mathtools.factors(d.denominator))
d_f.discard(2)
gd_f = set(mathtools.factors(group[0].denominator))
gd_f.discard(2)
if d_f == gd_f:
group.append(d)
else:
group = [d]
result.append(group)
return result
def direction_number(self):
return mathtools.sign(self.interval_number)
right_lengths = self._none_to_new_list(right_lengths)
secondary_divisions = self._none_to_new_list(secondary_divisions)
talea_helper = self._none_to_trivial_helper(talea_helper)
prolation_addenda_helper = self._none_to_trivial_helper(
prolation_addenda_helper)
lefts_helper = self._none_to_trivial_helper(lefts_helper)
middles_helper = self._none_to_trivial_helper(middles_helper)
rights_helper = self._none_to_trivial_helper(rights_helper)
left_lengths_helper = self._none_to_trivial_helper(
left_lengths_helper)
right_lengths_helper = self._none_to_trivial_helper(
right_lengths_helper)
secondary_divisions_helper = self._none_to_trivial_helper(
secondary_divisions_helper)
assert sequencetools.all_are_integer_equivalent_numbers(talea)
assert mathtools.is_positive_integer_equivalent_number(
talea_denominator)
assert sequencetools.all_are_nonnegative_integer_equivalent_numbers(
prolation_addenda)
assert all(x in (-1, 0, 1) for x in lefts)
assert all(x in (-1, 0, 1) for x in middles)
assert all(x in (-1, 0, 1) for x in rights)
assert sequencetools.all_are_nonnegative_integer_equivalent_numbers(
left_lengths)
assert sequencetools.all_are_nonnegative_integer_equivalent_numbers(
right_lengths)
assert sequencetools.all_are_nonnegative_integer_equivalent_numbers(
secondary_divisions)
assert isinstance(talea_helper,
(types.FunctionType, types.MethodType))
assert isinstance(prolation_addenda_helper,
(types.FunctionType, types.MethodType))
def __init__(
self,
layer=None,
start_offset=mathtools.NegativeInfinity(),
stop_offset=mathtools.Infinity(),
voice_name=None,
):
timespantools.Timespan.__init__(
self,
start_offset=start_offset,
stop_offset=stop_offset,
)
if layer is not None:
layer = int(layer)
self._layer = layer
self._voice_name = voice_name
def __init__(self, ratio=None):
ratio = ratio or mathtools.Ratio((1,))
ratio = mathtools.Ratio(ratio)
self._ratio = ratio
>>> print format(result)
musicexpressiontools.IterablePayloadExpression(
payload=(
mathtools.NonreducedFraction(4, 16),
mathtools.NonreducedFraction(2, 16),
mathtools.NonreducedFraction(4, 16),
mathtools.NonreducedFraction(2, 16),
mathtools.NonreducedFraction(1, 16),
),
)
Returns newly constructed payload expression.
'''
if not sequencetools.all_are_numbers(self.payload):
payload = [mathtools.NonreducedFraction(x) for x in self.payload]
else:
payload = self.payload
payload = sequencetools.repeat_sequence_to_weight_exactly(
payload, duration)
result = self.__makenew__(payload=payload)
return result
NonreducedFraction(12, 20)
::
>>> fraction = mathtools.NonreducedFraction(5, 6)
>>> fraction.multiply_with_cross_cancelation((6, 5))
NonreducedFraction(1, 1)
Returns nonreduced fraction.
'''
from abjad.tools import durationtools
from abjad.tools import mathtools
multiplier = durationtools.Multiplier(multiplier)
self_numerator_factors = mathtools.factors(self.numerator)
multiplier_denominator_factors = mathtools.factors(
multiplier.denominator)
for factor in multiplier_denominator_factors[:]:
if factor in self_numerator_factors:
self_numerator_factors.remove(factor)
multiplier_denominator_factors.remove(factor)
self_denominator_factors = mathtools.factors(self.denominator)
multiplier_numerator_factors = mathtools.factors(multiplier.numerator)
for factor in multiplier_numerator_factors[:]:
if factor in self_denominator_factors:
self_denominator_factors.remove(factor)
multiplier_numerator_factors.remove(factor)
result_numerator_factors = self_numerator_factors + \
multiplier_numerator_factors