mutwo.timeline_interfaces¶
Place events with absolute start and end times on a time line.
Mutwo events usually follow an approach of relative placement in time. This means each event has a duration, and if there is a sequence of events the second event will start after the first event finishes. So the start and end time of any event dependent on all events which happens before the given event. This package implements the possibility to model events with independent start and end times in mutwo.
Object |
Documentation |
|---|---|
Place any event at specific start and end times. |
|
Timeline to place events on. |
|
A conflict represents two overlapping |
|
Abstract base class for overlapping solving classes. |
|
Always picks the left |
|
Alterate between the left and the right |
|
Pick |
- class EventPlacement(event, start_or_start_range, end_or_end_range)[source]¶
Bases:
MutwoObjectPlace any event at specific start and end times.
- Parameters:
event (core_events.Concurrence[core_events.Chronon | core_events.Consecution | core_events.Concurrence]) – The event to be placed on a
TimeLine. This needs to be filled with events with a tag property. Each child event represents a specific object (e.g. instrument or player) The tag is necessary to concatenate two events on a TimeLine which belong to the same object (e.g. same instrument or same player).start_or_start_range (UnspecificTimeOrTimeRange) – Sets when the event starts. This can be a single
mutwo.core_parameters.abc.Durationor aranges.Rangeof two durations. In the second case the placement is flexible within the given area.end_or_end_range (UnspecificTimeOrTimeRange) – Sets when the event ends. This can be a single
mutwo.core_parameters.abc.Durationor aranges.Rangeof two durations. In the second case the placement is flexible within the given area.
Warning:
An
EventPlacementitself is not an event and can’t be treated like an event.Public Data Attributes:
tag_tuplestart_or_start_rangeend_or_end_rangedurationmean_startmean_endmin_startmax_startmin_endmax_endtime_rangePublic Methods:
is_overlapping(other)move_by(duration)copy()Return a deep copy of mutwo object.
Inherited from
MutwoObjectcopy()Return a deep copy of mutwo object.
- is_overlapping(other)[source]¶
- Parameters:
other (EventPlacement) –
- Return type:
bool
- property end_or_end_range: mutwo.core_parameters.abc.Duration | ranges.Range.Range¶
- property start_or_start_range: mutwo.core_parameters.abc.Duration | ranges.Range.Range¶
- property tag_tuple: tuple[str, ...]¶
- property time_range: Range¶
- class TimeLine(event_placement_sequence=[], duration=None)[source]¶
Bases:
MutwoObjectTimeline to place events on.
- Parameters:
duration (Optional[UnspecificTime]) – If this is set to None the
durationproperty of the TimeLine is dynamically calculated (by the end times of all registeredEventPlacement. If the duration is not None, then the duration is statically set to this time. If the user tries to register anEventPlacementwith end > duration this would raise an error. Default toNone.event_placement_sequence (Sequence[EventPlacement]) –
Warning:
An
TimeLineitself is not an event and can’t be treated like an event.Public Data Attributes:
durationevent_placement_tupletag_setPublic Methods:
register(event_placement)Register a new
EventPlacementon givenTimeLine.unregister(event_placement)Unregister an
EventPlacementwhich is part ofTimeLine.sort()Sort all
EventPlacementby start time (and if equal by end time).get_event_placement(tag, index, *[, sort])Find specific
EventPlacementresolve_conflicts([...])Resolve overlapping
EventPlacementinTimeLine.Inherited from
MutwoObjectcopy()Return a deep copy of mutwo object.
- get_event_placement(tag, index, *, sort=True)[source]¶
Find specific
EventPlacement- Parameters:
tag (str) – The tag which the
EventPlacementshould include.index (int) – The index of the
EventPlacementsort (bool) – Can be set to
Falsewhen sequentially calling get_event_placement without changing theTimeLine. When sort = False, but theTimeLine(or anyEventPlacementinside the timeTimeLine) has changed unexpected results may happen. If you want to be sure not to break anything, just leave it asTrue. Default toTrue.
- Return type:
- register(event_placement)[source]¶
Register a new
EventPlacementon givenTimeLine.- Parameters:
event_placement (EventPlacement) – The
EventPlacementwhich should be placed on theTimeLine.
- resolve_conflicts(conflict_resolution_strategy_sequence=[<mutwo.timeline_interfaces.timelines.AlwaysLeftStrategy object>], is_conflict=<function TimeLine.<lambda>>, *, sort=True)[source]¶
Resolve overlapping
EventPlacementinTimeLine.- Parameters:
conflict_resolution_strategy_sequence (Sequence[ConflictResolutionStrategy]) – Provide the
ConflictResolutionStrategyyou want to use here. If multiple are added, the algorithm initially tries the first one and if this doesn’t work it continues with the next strategy. Default to[AlwaysLeftStrategy()].is_conflict (Callable[[EventPlacement, EventPlacement], bool]) – Function which takes two
EventPlacementand which returns either True if the placements are conflicting and return False if not. This function doesn’t need to check if two placements are overlapping, this is done seperately and independently. A conflict is created only in caseis_conflictreturnsTrueand the placements are overlapping. By default this function simply checks if the event placements share any common tag. The logic behind this is the assumption that tag equals instruments and that an instrument can’t play two different event placements at the same time.sort (bool) – Can be set to
Falsewhen sequentially calling resolve_conflicts without changing theTimeLine. When sort = False, but theTimeLine(or anyEventPlacementinside the timeTimeLine) has changed unexpected results may happen. If you want to be sure not to break anything, just leave it asTrue. Default toTrue.
- Raises:
UnresolvedConflict – If none of the provided
ConflictResolutionStrategycould solve the conflict.
- sort()[source]¶
Sort all
EventPlacementby start time (and if equal by end time).- Return type:
- unregister(event_placement)[source]¶
Unregister an
EventPlacementwhich is part ofTimeLine.- Parameters:
event_placement (EventPlacement) – The
EventPlacementwhich should be removed from theTimeLine.- Raises:
EventPlacementNotFoundError – If
EventPlacementisn’t insideTimeLine.
- property event_placement_tuple: tuple[mutwo.timeline_interfaces.timelines.EventPlacement, ...]¶
- property tag_set: set[str]¶
- class Conflict(left, right)[source]¶
Bases:
MutwoObjectA conflict represents two overlapping
EventPlacement- Parameters:
left (EventPlacement) – The earlier
EventPlacement.right (EventPlacement) – The later
EventPlacement.
Two overlapping
EventPlacementare mostly only a problem if their instruments are the same. Nevertheless the precise definition of aConflictdepends on the callable passed to the ‘is_conflict’ parameter of theTimeLine.resolve_conflicts()method.Public Data Attributes:
leftrightPublic Methods:
Inherited from
MutwoObjectcopy()Return a deep copy of mutwo object.
- left: EventPlacement¶
- right: EventPlacement¶
- class ConflictResolutionStrategy[source]¶
Bases:
ABCAbstract base class for overlapping solving classes.
You only need to the define the resolve_conflict method.
Public Methods:
resolve_conflict(timeline, conflict)Resolve conflict between two overlapping
EventPlacement.
- abstract resolve_conflict(timeline, conflict)[source]¶
Resolve conflict between two overlapping
EventPlacement.- Parameters:
timeline (TimeLine) – The timeline which hosts the conflict. Can be used in order to remove one or both of the conflicting event placements.
conflict (Conflict) – A
Conflictobject which hosts the two overlappingEventPlacement.
- Return type:
bool
This method should return
Trueif the class managed to resolve the conflict. If it returns any negative boolean value (e.g.Nonemutwoassumes that the conflict couldn’t be resolved).The concrete strategy how the conflict is resolved is up to the resolution strategy class: either the conflicting event placements are removed, or the timeline is adjusted in other ways (e.g. stretched) so that the event placements aren’t overlapping anymore.
- class AlwaysLeftStrategy[source]¶
Bases:
ConflictResolutionStrategyAlways picks the left
EventPlacement.Public Methods:
resolve_conflict(timeline, conflict)Resolve conflict between two overlapping
EventPlacement.Inherited from
ConflictResolutionStrategyresolve_conflict(timeline, conflict)Resolve conflict between two overlapping
EventPlacement.
- resolve_conflict(timeline, conflict)[source]¶
Resolve conflict between two overlapping
EventPlacement.- Parameters:
timeline (TimeLine) – The timeline which hosts the conflict. Can be used in order to remove one or both of the conflicting event placements.
conflict (Conflict) – A
Conflictobject which hosts the two overlappingEventPlacement.
- Return type:
bool
This method should return
Trueif the class managed to resolve the conflict. If it returns any negative boolean value (e.g.Nonemutwoassumes that the conflict couldn’t be resolved).The concrete strategy how the conflict is resolved is up to the resolution strategy class: either the conflicting event placements are removed, or the timeline is adjusted in other ways (e.g. stretched) so that the event placements aren’t overlapping anymore.
- class AlternatingStrategy[source]¶
Bases:
ConflictResolutionStrategyAlterate between the left and the right
EventPlacement.Public Methods:
resolve_conflict(timeline, conflict)Resolve conflict between two overlapping
EventPlacement.Inherited from
ConflictResolutionStrategyresolve_conflict(timeline, conflict)Resolve conflict between two overlapping
EventPlacement.
- resolve_conflict(timeline, conflict)[source]¶
Resolve conflict between two overlapping
EventPlacement.- Parameters:
timeline (TimeLine) – The timeline which hosts the conflict. Can be used in order to remove one or both of the conflicting event placements.
conflict (Conflict) – A
Conflictobject which hosts the two overlappingEventPlacement.
- Return type:
bool
This method should return
Trueif the class managed to resolve the conflict. If it returns any negative boolean value (e.g.Nonemutwoassumes that the conflict couldn’t be resolved).The concrete strategy how the conflict is resolved is up to the resolution strategy class: either the conflicting event placements are removed, or the timeline is adjusted in other ways (e.g. stretched) so that the event placements aren’t overlapping anymore.
- class TagCountStrategy(prefer_more=True)[source]¶
Bases:
ConflictResolutionStrategyPick
EventPlacementaccording to tag count.- Parameters:
prefer_more (bool) – If set to
Truethe strategy drops theEventPlacementwith fewer tags. If set toFalseit drops theEventPlacementwith more tags. Default toTrue.
If two
EventPlacementhave an equal amount of tags, this strategy won’t be able to solve the conflict.Public Methods:
resolve_conflict(timeline, conflict)Resolve conflict between two overlapping
EventPlacement.Inherited from
ConflictResolutionStrategyresolve_conflict(timeline, conflict)Resolve conflict between two overlapping
EventPlacement.
- resolve_conflict(timeline, conflict)[source]¶
Resolve conflict between two overlapping
EventPlacement.- Parameters:
timeline (TimeLine) – The timeline which hosts the conflict. Can be used in order to remove one or both of the conflicting event placements.
conflict (Conflict) – A
Conflictobject which hosts the two overlappingEventPlacement.
- Return type:
bool
This method should return
Trueif the class managed to resolve the conflict. If it returns any negative boolean value (e.g.Nonemutwoassumes that the conflict couldn’t be resolved).The concrete strategy how the conflict is resolved is up to the resolution strategy class: either the conflicting event placements are removed, or the timeline is adjusted in other ways (e.g. stretched) so that the event placements aren’t overlapping anymore.