Enable handling uppercased notes

This commit is contained in:
Bartłomiej Pluta
2019-06-28 22:35:25 +02:00
parent c629612ff4
commit a025c19be9
3 changed files with 239 additions and 7 deletions

36
Note.py Normal file
View File

@@ -0,0 +1,36 @@
from enum import Enum
class NotePitch(Enum):
C = 1
CIS = 2
D = 3
DIS = 4
E = 5
F = 6
FIS = 7
G = 8
GIS = 9
A = 10
AIS = 11
H = 12
@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()]
class Note:
def __init__(self, note, octave, duration):
if type(note) == str:
self.note = NotePitch.toPitch(note)
else:
self.note = note
self.octave = octave
self.duration = duration
def __str__(self):
return f"{self.note}[{self.octave}, {self.duration}]"