scamp_extensions.pitch.scale.PitchInterval
- class scamp_extensions.pitch.scale.PitchInterval(cents: float, ratio: Fraction)[source]
Bases:
SavesToJSON
Represents an interval between two pitches. This combines a cents displacement and a frequency ratio, allowing it to represent both just and equal-tempered intervals, or even a combination of both. PitchIntervals can be added, negated, and subtracted.
- Parameters:
cents – cents displacement
ratio – frequency ratio, either instead of or in addition to the cents displacement
Methods
parse
(representation)Parses several different possible types of data into a PitchInterval object.
to_cents
()Resolves this interval to its size in cents.
Resolves this interval to its size in half steps.
Returns a string representation of this interval for use in exporting to scala files.
Inherited Methods
Returns a copy of this object by serializing to and from JSON.
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 parse(representation)[source]
Parses several different possible types of data into a PitchInterval object.
- Parameters:
representation – One of the following: - a float (representing cents) - an int or a Fraction object (representing a ratio) - a tuple of (cents, ratio) - a string, which will be evaluated as a (cents, ratio) tuple if it has a comma, and will be evaluated as a Fraction if it has a slash. e.g. “3” is a ratio, “37.” is cents, “4/3” is a ratio, and “200., 5/4” is a cents displacement followed by a ratio.
- Returns:
a PitchInterval
- to_scala_string()[source]
Returns a string representation of this interval for use in exporting to scala files. Scala intervals can be either in cents or frequency ratio, however, unlike
PitchInterval
, they cannot combine the two. Thus, if this PitchInterval combines the two, it will be converted to a flat cents value.
- 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