def __init__(self, operator_string="<", length=None): Inequality.__init__(self, operator_string=operator_string) if length is None: length = mathtools.Infinity() assert 0 <= length infinities = (mathtools.Infinity(), mathtools.NegativeInfinity()) if length not in infinities: length = int(length) self._length = length
def __init__( self, start_offset=mathtools.NegativeInfinity(), stop_offset=mathtools.Infinity(), divisions=None, forbid_fusing=None, forbid_splitting=None, layer=None, minimum_duration=None, music=None, music_specifier=None, original_start_offset=None, original_stop_offset=None, voice_name=None, ): abjad.Timespan.__init__( self, start_offset=start_offset, stop_offset=stop_offset, ) if divisions is not None: divisions = tuple(abjad.Duration(_) for _ in divisions) assert sum(divisions) == self.duration self._divisions = divisions if forbid_fusing is not None: forbid_fusing = bool(forbid_fusing) self._forbid_fusing = forbid_fusing if forbid_splitting is not None: forbid_splitting = bool(forbid_splitting) self._forbid_splitting = forbid_splitting if layer is not None: layer = int(layer) self._layer = layer if minimum_duration is not None: minimum_duration = abjad.Duration(minimum_duration) self._minimum_duration = minimum_duration #if music is not None: # assert inspect(music).get_duration() == self.duration self._music = music #if music_specifier is not None: # assert isinstance(music_specifier, tsmakers.MusicSpecifier), \ # music_specifier self._music_specifier = music_specifier if original_start_offset is not None: original_start_offset = abjad.Offset(original_start_offset) else: original_start_offset = self.start_offset self._original_start_offset = original_start_offset if original_stop_offset is not None: original_stop_offset = abjad.Offset(original_stop_offset) else: original_stop_offset = self.stop_offset self._original_stop_offset = original_stop_offset self._voice_name = voice_name
def _to_measure_number(self, component, measure_number_start_offsets): inspector = inspect(component) component_start_offset = inspector.timespan().start_offset measure_number_start_offsets = measure_number_start_offsets[:] measure_number_start_offsets.append(mathtools.Infinity()) pairs = Sequence(measure_number_start_offsets) pairs = pairs.nwise() for measure_index, pair in enumerate(pairs): if pair[0] <= component_start_offset < pair[-1]: measure_number = measure_index + 1 return measure_number message = "can not find measure number: {!r}, {!r}." message = message.format(component, measure_number_start_offsets) raise ValueError(message)
def __init__( self, start_offset=mathtools.NegativeInfinity(), stop_offset=mathtools.Infinity(), layer=None, voice_name=None, ): abjad.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 _to_measure_number(self, component, measure_start_offsets): component_start_offset = inspect(component).timespan().start_offset displacement = component_start_offset.displacement if displacement is not None: component_start_offset = Offset( component_start_offset, displacement=None ) # score-initial grace music only: if displacement < 0 and component_start_offset == 0: measure_number = 0 return measure_number measure_start_offsets = measure_start_offsets[:] measure_start_offsets.append(mathtools.Infinity()) pairs = Sequence(measure_start_offsets) pairs = pairs.nwise() for measure_index, pair in enumerate(pairs): if pair[0] <= component_start_offset < pair[-1]: measure_number = measure_index + 1 return measure_number message = f"can not find measure number for {repr(component)}:\n" message += f" {repr(measure_start_offsets)}" raise ValueError(message)
""" Utility classes and functions. """ from abjad import mathtools # noqa Infinity = mathtools.Infinity() NegativeInfinity = mathtools.NegativeInfinity() del mathtools from .CyclicTuple import CyclicTuple from .Duration import Duration from .Enumerator import Enumerator from .Inequality import Inequality from .DurationInequality import DurationInequality from .Expression import Expression from .LengthInequality import LengthInequality from .Multiplier import Multiplier from .Offset import Offset from .Pattern import Pattern from .TypedCollection import TypedCollection from .TypedTuple import TypedTuple from .OrderedDict import OrderedDict from .PatternTuple import PatternTuple from .PitchInequality import PitchInequality from .Sequence import Sequence from .SortedCollection import SortedCollection from .String import String from .TypedCounter import TypedCounter from .TypedFrozenset import TypedFrozenset from .TypedList import TypedList