def __init__(self, dynamic_name, target_context=None): from abjad.tools.stafftools.Staff import Staff target_context = target_context or Staff ContextMark.__init__(self, target_context=target_context) if isinstance(dynamic_name, type(self)): dynamic_name = dynamic_name.dynamic_name self._dynamic_name = dynamic_name
def __init__(self, staff=None, target_context=None): from abjad.tools import stafftools target_context = target_context or stafftools.Staff ContextMark.__init__(self, target_context=target_context) if not isinstance(staff, (stafftools.Staff, type(None))): message = 'staff change mark input value {!r}' message += ' must be staff instance.' message.format(staff) raise TypeError(message) self._staff = staff
def __init__(self, *args, **kwargs): from abjad.tools import stafftools target_context = kwargs.get('target_context', stafftools.Staff) ContextMark.__init__(self, target_context=target_context) if self._target_context == stafftools.Staff: self._has_default_target_context = True else: self._has_default_target_context = False partial, suppress = None, None # initialize numerator and denominator from *args if len(args) == 1 and isinstance(args[0], type(self)): time_signature = args[0] numerator = time_signature.numerator denominator = time_signature.denominator partial = time_signature.partial suppress = time_signature.suppress elif len(args) == 1 and isinstance(args[0], durationtools.Duration): numerator, denominator = args[0].numerator, args[0].denominator elif len(args) == 1 and isinstance(args[0], tuple): numerator, denominator = args[0][0], args[0][1] elif len(args) == 1 and hasattr(args[0], 'numerator') and \ hasattr(args[0], 'denominator'): numerator, denominator = args[0].numerator, args[0].denominator else: message = 'invalid time_signature initialization: {!r}.' message = message.format(args) raise TypeError(message) self._numerator = numerator self._denominator = denominator # initialize partial from **kwargs partial = partial or kwargs.get('partial', None) if not isinstance(partial, (type(None), durationtools.Duration)): raise TypeError self._partial = partial if partial is not None: self._partial_repr_string = ', partial=%r' % self._partial else: self._partial_repr_string = '' # initialize suppress from kwargs suppress = suppress or kwargs.get('suppress', None) if not isinstance(suppress, (bool, type(None))): raise TypeError self.suppress = suppress # initialize derived attributes self._multiplier = self.implied_prolation self._has_non_power_of_two_denominator = \ not mathtools.is_nonnegative_integer_power_of_two( self.denominator)
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: textual_indication, duration, units_per_minute = args else: textual_indication = None duration, units_per_minute = args else: message = 'can not initialize tempo indication.' raise ValueError(message) assert isinstance(textual_indication, (str, type(None))) if duration: try: duration = durationtools.Duration(duration) except TypeError: duration = durationtools.Duration(*duration) assert isinstance(units_per_minute, (int, long, float, durationtools.Duration, list, tuple, type(None))) if isinstance(units_per_minute, (list, tuple)): assert len(units_per_minute) == 2 assert all( isinstance(x, (int, long, float, durationtools.Duration)) for x in units_per_minute) units_per_minute = tuple(sorted(units_per_minute)) self._duration = duration self._textual_indication = textual_indication self._units_per_minute = units_per_minute
def __call__(self, *args): from abjad.tools import spannertools if len(args) == 1: spanner_classes = ( spannertools.DynamicTextSpanner, spannertools.HairpinSpanner, ) parentage = args[0]._get_parentage() dynamic_spanners = parentage._get_spanners(spanner_classes) for dynamic_spanner in dynamic_spanners: if not dynamic_spanner._is_exterior_leaf(args[0]): message = 'can not attach dynamic mark' message += ' to interior component of dynamic spanner.' raise WellFormednessError(message) return ContextMark.__call__(self, *args)
def detach(self): r'''Detaches time signature mark. :: >>> time_signature = contexttools.TimeSignatureMark((3, 8)) >>> staff = Staff() :: >>> attach(time_signature, staff) TimeSignatureMark((3, 8))(Staff{}) :: >>> time_signature.detach() TimeSignatureMark((3, 8)) Returns time signature mark. ''' return ContextMark.detach(self)
def _bind_start_component(self, start_component): ContextMark._bind_start_component(self, start_component) self._start_component._update_later(offsets_in_seconds=True)
def _bind_correct_effective_context(self, correct_effective_context): ContextMark._bind_correct_effective_context( self, correct_effective_context) correct_effective_context._update_later(offsets_in_seconds=True)