scamp.quantization.TimeSignature

class scamp.quantization.TimeSignature(numerator: Union[int, Sequence[int]], denominator: int, beat_lengths: Sequence[float] = None)[source]

Bases: expenvelope.json_serializer.SavesToJSON

Class representing the time signature of a measure

Parameters
  • numerator – time signature numerator. Can be a list/tuple of ints, in the case of an additive time signature

  • denominator – time signature denominator

  • beat_lengths – (optional) This is a hint as to how the time signature is divided up into beats. By default, it is None, meaning that a sensible default will be constructed. Should add up to the length of the time signature.

Variables
  • numerator – time signature numerator. Can be a list/tuple of ints, in the case of an additive time signature

  • denominator – time signature denominator

  • beat_lengths – Representation of how the time signature is divided up into beats. (Affects the quantization process.)

Methods

as_string()

Returns a string representation of the time signature, e.g.

as_tuple()

Returns a tuple representation of the time signature, e.g.

from_measure_length(measure_length)

Constructs a TimeSignature of the appropriate measure length.

from_string(time_signature_string)

Constructs a TimeSignature from its string representation

measure_length()

Get the length of the measure in quarter notes

to_abjad()

Returns the abjad version of this time signature

Inherited Methods

duplicate()

Returns a copy of this object by serializing to and from JSON.

json_dumps()

Dump this object as a JSON string.

json_loads(s)

Load this object from a JSON string.

load_from_json(file_path)

Load this object from a JSON file with the given path.

save_to_json(file_path)

Save this object to a JSON file using the given path.

classmethod from_measure_length(measure_length: float)scamp.quantization.TimeSignature[source]

Constructs a TimeSignature of the appropriate measure length. (Defaults to the simple rather than compound)

Parameters

measure_length – length of the measure in quarter notes

Returns

the TimeSignature so constructed

classmethod from_string(time_signature_string: str)[source]

Constructs a TimeSignature from its string representation

Parameters

time_signature_string – e.g. “7/8”, or “3+5+2/8” in the case of a compound time signature

Returns

the TimeSignature so constructed

as_string() → str[source]

Returns a string representation of the time signature, e.g. “5/4” or “3+2+1/8”

as_tuple() → Tuple[source]

Returns a tuple representation of the time signature, e.g. (5, 4) or ((3, 2, 1), 8)

measure_length() → float[source]

Get the length of the measure in quarter notes

to_abjad() → abjad.indicators.TimeSignature.TimeSignature[source]

Returns the abjad version of this time signature

duplicate() → T

Returns a copy of this object by serializing to and from JSON.

json_dumps() → str

Dump this object as a JSON string. This uses a custom encoder that recognizes and appropriately converts any attributes that are object inheriting from SavesToJSON.

classmethod json_loads(s: str) → T

Load this object from a JSON string. This uses a custom decoder that looks for a “_type” key in any object/dictionary being parsed and converts it to the class specified (assuming it a subclass of SavesToJSON).

Parameters

s – a string representing this object in JSON format

classmethod load_from_json(file_path: str) → T

Load this object from a JSON file with the given path. This uses a custom decoder that looks for a “_type” key in any object/dictionary being parsed and converts it to the class specified (assuming it a subclass of SavesToJSON).

Parameters

file_path – path for loading the file

save_to_json(file_path: str) → None

Save this object to a JSON file using the given path. This uses a custom encoder that recognizes and appropriately converts any attributes that are object inheriting from SavesToJSON.

Parameters

file_path – path for saving the file