Move some functions to standard library

This commit is contained in:
Bartłomiej Pluta
2019-07-13 10:21:08 +02:00
parent a68f870037
commit 4f2058eaac
15 changed files with 63 additions and 90 deletions

View File

@@ -16,7 +16,7 @@ class NotePitch(Enum):
A = 9
AIS = 10
H = 11
def toFrequency(self):
return {
NotePitch.C: 16.35,
@@ -32,19 +32,23 @@ class NotePitch(Enum):
NotePitch.AIS: 29.17,
NotePitch.H: 30.87
}[self]
def __str__(self):
return self.name
def __repr__(self):
return self.__str__()
@staticmethod
def toPitch(string):
try:
if string.lower() in stringToPitch:
return stringToPitch[string.lower()]
except KeyError as e:
raise NoteException(f"Note '{string}' does not exist")
if string.upper() in NotePitch:
return NotePitch[string.upper()]
raise NoteException(f"Note '{string}' does not exist")
stringToPitch = {
'cb': NotePitch.H,
@@ -67,4 +71,4 @@ stringToPitch = {
'a#': NotePitch.AIS,
'b': NotePitch.AIS,
'h': NotePitch.H
}
}