mirror of
https://github.com/kennethreitz/pytheory.git
synced 2026-06-05 06:46:14 +00:00
fix bug #7
This commit is contained in:
+1
-1
@@ -18,7 +18,7 @@ class System:
|
||||
@property
|
||||
def tones(self):
|
||||
from . import Tone
|
||||
return tuple([Tone.from_string(tone) for tone in self.tone_names])
|
||||
return tuple([Tone.from_tuple(tone) for tone in self.tone_names])
|
||||
|
||||
|
||||
@property
|
||||
|
||||
+21
-4
@@ -3,7 +3,10 @@ from ._statics import REFERENCE_A, TEMPERAMENTS
|
||||
class Tone:
|
||||
# __slots__ = ("name", "octave", "system")
|
||||
|
||||
def __init__(self, *, name, octave=None, system='western'):
|
||||
def __init__(self, *, name, alt_names=None, octave=None, system='western'):
|
||||
if alt_names is None:
|
||||
alt_names = []
|
||||
|
||||
self.name = name
|
||||
self.octave = octave
|
||||
|
||||
@@ -26,7 +29,8 @@ class Tone:
|
||||
return self._system
|
||||
|
||||
if self.system_name:
|
||||
return SYSTEMS[self.system_name]
|
||||
self._system = SYSTEMS[self.system_name]
|
||||
return self.system
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
@@ -35,6 +39,9 @@ class Tone:
|
||||
else:
|
||||
return self.name
|
||||
|
||||
def names(self):
|
||||
return [self.name] + self.alt_names
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Tone {self.full_name}>"
|
||||
|
||||
@@ -46,24 +53,34 @@ class Tone:
|
||||
|
||||
# Comparing against other Tones.
|
||||
try:
|
||||
if (self.name == other.name) and (self.octave == other.octave):
|
||||
if (self.name in other.names) and (self.octave == other.octave):
|
||||
return True
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def from_string(klass, s, system=None):
|
||||
tone = "".join([c for c in filter(str.isalpha, s)])
|
||||
try:
|
||||
octave = int("".join([c for c in filter(str.isdigit, s)]))
|
||||
except ValueError:
|
||||
octave = None
|
||||
|
||||
tone = s.replace(str(octave), '') if octave else s
|
||||
|
||||
if system:
|
||||
return klass(name=tone, octave=octave, system=system)
|
||||
else:
|
||||
return klass(name=tone, octave=octave)
|
||||
|
||||
@classmethod
|
||||
def from_tuple(klass, t):
|
||||
if len(t) == 1:
|
||||
return klass.from_string(s=t[0])
|
||||
else:
|
||||
tone = klass.from_string(s=t[0])
|
||||
tone.alt_names = t[1:]
|
||||
return tone
|
||||
|
||||
@classmethod
|
||||
def from_index(klass, i, *, octave, system):
|
||||
tone = system.tones[i].name
|
||||
|
||||
Reference in New Issue
Block a user