Enable handling unknown notes

This commit is contained in:
Bartłomiej Pluta
2019-06-28 22:40:46 +02:00
parent a025c19be9
commit 2f362da0bd
3 changed files with 10 additions and 241 deletions

16
Note.py
View File

@@ -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):