musicscore.time

class musicscore.time.Time(*signatures, show=True, **kwargs)[source]

Bases: XMLWrapper

XMLClass

alias of XMLTime

get_beats_quarter_durations() List[QuarterDuration][source]
Returns:

List of quarter durations according to actual_signatures

to_string(*args, **kwargs) str

XMLWrapper method

Calls to_string method of self.xml_object

Returns:

musicxml snippet

property actual_signatures: List[int]

Set and gets actual signatures. If parent_measure exists its beats inside voices will be updated.

Returns:

A list of int representing actual time signatures. If not set manually, it is calculated internally. For example a 4/4 time signature gets automatically [1, 4, 1, 4, 1, 4, 1, 4] as actual_signatures if not set otherwise.

property parent_measure: Measure | None

Set and get parent Measure.

property show: bool

If time signature is shown or not.

Type:

bool

Returns:

bool

property signatures: List[int]

Set and gets signatures. If parent_measure exists, beats inside its voices will be updated. If it is set to None a 4/4 signature will be used.

Returns:

A list of int representing time signature.

property xml_object: XMLElement

XMLWrapper method

This musicscore class has an equivalent MusicXML class which can be reached via this property.

If an attribute is not found directly in the main class, it wll be passed on to __get_attribute__ or __set__attribute__ methods of self.xml_object. It can also use the short cut attributes of XMLElement to get or set the first child.

Returns:

wrapped MusicXML element of type XMLClass

musicscore.time.flatten_times(times) List[Time][source]
Parameters:

times – an expandable list of times or tuples representing times. For example [x * Time(3, 8)] return x time intances of Time(3, 8)

Returns:

List[Time]

>>> ts = [2 * Time(3, 8), (3, 4), 3 * [(1, 8)], Time(1, 8, 3, 4), Time(3, 4)]
>>> [t.signatures for t in flatten_times(ts)]
[(3, 8), (3, 8), (3, 4), (1, 8), (1, 8), (1, 8), (1, 8, 3, 4), (3, 4)]
musicscore.time.CONVERSION_DICTIONARY = {'2/8': [2, 8], '4/8': [2, 8, 2, 8], '5/8': [3, 8, 2, 8], '7/8': [4, 8, 3, 8]}

If Time.actual_signatures is not set manually first this dictionary is used to create actual signature.