Add more type hints, fix from_string for tonality
This commit is contained in:
parent
b0e0fe94ee
commit
929813c587
1 changed files with 7 additions and 7 deletions
|
|
@ -61,7 +61,7 @@ class SetClass(list):
|
||||||
return sum([hash(i) for i in self.pitch_classes])
|
return sum([hash(i) for i in self.pitch_classes])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pitch_classes(self) -> list:
|
def pitch_classes(self) -> list(int):
|
||||||
return list(self)
|
return list(self)
|
||||||
|
|
||||||
@cache_property
|
@cache_property
|
||||||
|
|
@ -83,7 +83,7 @@ class SetClass(list):
|
||||||
return sum(self.pitch_classes)
|
return sum(self.pitch_classes)
|
||||||
|
|
||||||
@cache_property
|
@cache_property
|
||||||
def adjacency_intervals(self) -> list:
|
def adjacency_intervals(self) -> list(int):
|
||||||
"""Adjacency intervals between the pitch classes, used for Leonard notation subscripts."""
|
"""Adjacency intervals between the pitch classes, used for Leonard notation subscripts."""
|
||||||
if not self.pitch_classes:
|
if not self.pitch_classes:
|
||||||
return list()
|
return list()
|
||||||
|
|
@ -138,7 +138,7 @@ class SetClass(list):
|
||||||
return min(SetClass.ordered_interval(a, b), SetClass.ordered_interval(b, a))
|
return min(SetClass.ordered_interval(a, b), SetClass.ordered_interval(b, a))
|
||||||
|
|
||||||
@cache_property
|
@cache_property
|
||||||
def versions(self) -> list:
|
def versions(self) -> list(SetClass):
|
||||||
"""
|
"""
|
||||||
Returns all possible zero-normalised versions (clock rotations) of this set class,
|
Returns all possible zero-normalised versions (clock rotations) of this set class,
|
||||||
sorted by brightness. See Rahn (1980) Set types, Tₙ
|
sorted by brightness. See Rahn (1980) Set types, Tₙ
|
||||||
|
|
@ -309,12 +309,12 @@ class SetClass(list):
|
||||||
# Class methods -----------------------------------------------------------
|
# Class methods -----------------------------------------------------------
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_string(this, string: str) -> SetClass:
|
def from_string(this, string: str, tonality: int = 12) -> SetClass:
|
||||||
"""
|
"""
|
||||||
Attempt to create a SetClass from any string containing a sequence of zero or more integers.
|
Attempt to create a SetClass from any string containing a sequence of zero or more integers.
|
||||||
A useful convenience function, e.g. SetClass.from_string('{0,3,7,9}')
|
A useful convenience function, e.g. SetClass.from_string('{0,3,7,9}')
|
||||||
"""
|
"""
|
||||||
return SetClass(*re.findall(r'\d+', string))
|
return SetClass(*re.findall(r'\d+', string), tonality=tonality)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def all_of_cardinality(cls, cardinality: int, tonality: int = 12) -> set:
|
def all_of_cardinality(cls, cardinality: int, tonality: int = 12) -> set:
|
||||||
|
|
@ -363,7 +363,7 @@ class SetClass(list):
|
||||||
"""
|
"""
|
||||||
cases = set()
|
cases = set()
|
||||||
for C in range(13): # 0 to 12
|
for C in range(13): # 0 to 12
|
||||||
for sc in SetClass.all_of_cardinality(C):
|
for sc in this.all_of_cardinality(C):
|
||||||
if sc.darkest_form.brightness < sc.rahn_normal_form.brightness:
|
if sc.darkest_form.brightness < sc.rahn_normal_form.brightness:
|
||||||
cases.add((C, sc.darkest_form, sc.rahn_normal_form))
|
cases.add((C, sc.darkest_form, sc.rahn_normal_form))
|
||||||
return cases
|
return cases
|
||||||
|
|
@ -379,7 +379,7 @@ class SetClass(list):
|
||||||
"""
|
"""
|
||||||
cases = set()
|
cases = set()
|
||||||
for C in range(13): # 0 to 12
|
for C in range(13): # 0 to 12
|
||||||
for sc in SetClass.all_of_cardinality(C):
|
for sc in this.all_of_cardinality(C):
|
||||||
if sc.darkest_form.brightness < sc.prime_form.brightness:
|
if sc.darkest_form.brightness < sc.prime_form.brightness:
|
||||||
cases.add((C, sc.darkest_form, sc.prime_form))
|
cases.add((C, sc.darkest_form, sc.prime_form))
|
||||||
return cases
|
return cases
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue