Enable handling unknown notes
This commit is contained in:
16
Note.py
16
Note.py
@@ -1,4 +1,5 @@
|
||||
from enum import Enum
|
||||
from parser import ParseError
|
||||
|
||||
class NotePitch(Enum):
|
||||
C = 1
|
||||
@@ -16,12 +17,15 @@ class NotePitch(Enum):
|
||||
|
||||
@staticmethod
|
||||
def toPitch(string):
|
||||
map = { 'c': NotePitch.C, 'c#': NotePitch.CIS, 'db': NotePitch.CIS, 'd': NotePitch.D,
|
||||
'd#': NotePitch.DIS, 'eb': NotePitch.DIS, 'e': NotePitch.E, 'fb': NotePitch.E, 'e#': NotePitch.F,
|
||||
'f': NotePitch.F, 'f#': NotePitch.FIS, 'gb': NotePitch.FIS, 'g': NotePitch.G, 'g#': NotePitch.GIS,
|
||||
'ab': NotePitch.GIS, 'a': NotePitch.A, 'a#': NotePitch.AIS, 'b': NotePitch.AIS, 'h': NotePitch.H
|
||||
}
|
||||
return map[string.lower()]
|
||||
try:
|
||||
map = { 'c': NotePitch.C, 'c#': NotePitch.CIS, 'db': NotePitch.CIS, 'd': NotePitch.D,
|
||||
'd#': NotePitch.DIS, 'eb': NotePitch.DIS, 'e': NotePitch.E, 'fb': NotePitch.E, 'e#': NotePitch.F,
|
||||
'f': NotePitch.F, 'f#': NotePitch.FIS, 'gb': NotePitch.FIS, 'g': NotePitch.G, 'g#': NotePitch.GIS,
|
||||
'ab': NotePitch.GIS, 'a': NotePitch.A, 'a#': NotePitch.AIS, 'b': NotePitch.AIS, 'h': NotePitch.H
|
||||
}
|
||||
return map[string.lower()]
|
||||
except KeyError as e:
|
||||
raise ParseError(f"Note '{string}' does not exist")
|
||||
|
||||
class Note:
|
||||
def __init__(self, note, octave, duration):
|
||||
|
||||
Reference in New Issue
Block a user