Add decimal number (bitmask), from Goyette (2012)
This commit is contained in:
parent
929813c587
commit
6c42477d7a
2 changed files with 19 additions and 0 deletions
|
|
@ -82,6 +82,16 @@ class SetClass(list):
|
||||||
"""Returns the brightness of the set class, defined as the sum of the pitch class values."""
|
"""Returns the brightness of the set class, defined as the sum of the pitch class values."""
|
||||||
return sum(self.pitch_classes)
|
return sum(self.pitch_classes)
|
||||||
|
|
||||||
|
@cache_property
|
||||||
|
def decimal(self) -> int:
|
||||||
|
"""
|
||||||
|
Returns the decimal value of the pitch classes expressed as a binary bit mask, i.e. the sum
|
||||||
|
of 2ⁱ where i is each pitch class value. For example, {0,1,4,6} has a binary value of
|
||||||
|
000001010011, which is the decimal value 83.
|
||||||
|
— Goyette (2012) p. 25, citing Brinkman (1986).
|
||||||
|
"""
|
||||||
|
return sum([2**i for i in self.pitch_classes])
|
||||||
|
|
||||||
@cache_property
|
@cache_property
|
||||||
def adjacency_intervals(self) -> list(int):
|
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."""
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,11 @@ def test_brightness():
|
||||||
assert f520.brightness == 20
|
assert f520.brightness == 20
|
||||||
|
|
||||||
|
|
||||||
|
def test_decimal():
|
||||||
|
"Set classes have a unique decimal number (sum of 2 raised to each normalised pitch class value)"
|
||||||
|
assert f520.decimal == 355
|
||||||
|
|
||||||
|
|
||||||
def test_pitch_classes():
|
def test_pitch_classes():
|
||||||
"Set classes have pitch classes"
|
"Set classes have pitch classes"
|
||||||
assert len(f520) == 5
|
assert len(f520) == 5
|
||||||
|
|
@ -153,6 +158,10 @@ def test_complement_brightness():
|
||||||
assert f520.complement.brightness == 32
|
assert f520.complement.brightness == 32
|
||||||
|
|
||||||
|
|
||||||
|
def test_complement_decimal():
|
||||||
|
assert f520.complement.decimal == 935
|
||||||
|
|
||||||
|
|
||||||
def test_complement_pitch_classes():
|
def test_complement_pitch_classes():
|
||||||
assert len(f520.complement) == 7
|
assert len(f520.complement) == 7
|
||||||
assert len(f520.complement.pitch_classes) == 7
|
assert len(f520.complement.pitch_classes) == 7
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue