def test_Get_Bad_Combination(self): with self.assertRaises(ValueError) as e: Key.Get('c#') self.assertIn('keyは次のうちのいずれかにしてください。', str(e.exception)) with self.assertRaises(ValueError) as e: Key.Get('CC') self.assertIn('引数accidentalに使える文字は次のものだけです。', str(e.exception))
def test_Get_ZERO(self): lowerLimit = 0 self.assertEqual(0, NoteName.Get('C0', lowerLimit)) self.assertEqual(69, NoteName.Get('A5', lowerLimit)) self.assertEqual(127, NoteName.Get('G10', lowerLimit)) for k in Key.Keys.keys(): for o in range(lowerLimit, lowerLimit+10, 1): with self.subTest(key=k, octave=o): octave = o + abs(lowerLimit) if lowerLimit < 0 else o - abs(lowerLimit) expected = PitchClass.Get(Key.Get(k))[0] + (octave * (PitchClass.Max+1)) self.assertEqual(expected, NoteName.Get(k + str(o), lowerLimit)) expected = PitchClass.Get(Key.Get(k)+1)[0] + (octave * (PitchClass.Max+1)) self.assertEqual(expected, NoteName.Get(k + '#' + str(o), lowerLimit)) expected = PitchClass.Get(Key.Get(k)-1)[0] + (octave * (PitchClass.Max+1)) self.assertEqual(expected, NoteName.Get(k + 'b' + str(o), lowerLimit))
def Get(cls, name: str, lowerLimit=-1): if not (name and isinstance(name, str)): raise TypeError(f'引数nameはstr型にしてください。: type(name)={type(name)}') k, o = cls.__Split(name) pitch_class = PitchClass.Get(Key.Get(k))[0] # B#の場合、Cになる。相対オクターブは無視される octave_class = cls.__GetOctave(o, lowerLimit) return NoteNumber.Get(pitch_class, octave_class)
def test_Get_Accidental(self): for k, kp in Key.Keys.items(): for acc_count in range(1, 4): for a, ap in Accidental.Accidentals.items(): key = k + a * acc_count pitch = kp + (ap * acc_count) with self.subTest(key=key): self.assertEqual(pitch, Key.Get(key))
def test_Get_Accidental(self): keys = {'C':0, 'D':2, 'E':4, 'F':5, 'G':7, 'A':9, 'B':11} for k, kp in keys.items(): for acc_count in range(1, 4): for a, ap in Accidental.Accidentals.items(): key = k + a*acc_count pitch = kp + (ap*acc_count) with self.subTest(key=key): self.assertEqual(pitch, Key.Get(key))
def __calcNames(self): self.__names.clear() # self.__names.append(self.Key.Name) baseInterval = self.Key.PitchClass baseNames = self.__getBaseNames() # print('baseNames',baseNames) # baseNames = self.__getBaseNames(self.Key.PitchClass) for i, p in enumerate(self.PitchClasses): # print(self.__names) baseInterval += p[0] if p[0] in Key.PitchClasses: #構成音が幹音なら self.__names.append(Key.Keys[Key.PitchClasses.index(p[0])]) else: if p[0] == Key.Get(baseNames[i] + '#'): self.__names.append(baseNames[i] + '#') elif p[0] == Key.Get(baseNames[i] + 'b'): self.__names.append(baseNames[i] + 'b') else: raise RuntimeError('音名を決められませんでした。アルゴリズムに問題があります。') """
def test_GetName_fr(self): names = Key.KeyNames['fr'] for i,key in enumerate(Key.Keys): self.assertEqual(names[i], Key.GetName(key, 'fr')) self.assertEqual(names[i]+' dièse', Key.GetName(key+'#', 'fr')) self.assertEqual(names[i]+' bémol', Key.GetName(key+'b', 'fr')) self.assertEqual(names[i]+' double dièse', Key.GetName(key+'##', 'fr')) self.assertEqual(names[i]+' double bémol', Key.GetName(key+'bb', 'fr')) self.assertEqual(names[i]+' dièse*3', Key.GetName(key+'###', 'fr')) self.assertEqual(names[i]+' bémol*3', Key.GetName(key+'bbb', 'fr'))
def test_GetName_es(self): names = Key.KeyNames['es'] for i,key in enumerate(Key.Keys): self.assertEqual(names[i], Key.GetName(key, 'es')) self.assertEqual(names[i]+' sostenido', Key.GetName(key+'#', 'es')) self.assertEqual(names[i]+' bemol', Key.GetName(key+'b', 'es')) self.assertEqual(names[i]+' sostenido doble', Key.GetName(key+'##', 'es')) self.assertEqual(names[i]+' bemol doble', Key.GetName(key+'bb', 'es')) self.assertEqual(names[i]+' sostenido*3', Key.GetName(key+'###', 'es')) self.assertEqual(names[i]+' bemol*3', Key.GetName(key+'bbb', 'es'))
def test_GetName_de(self): names = Key.KeyNames['de'] for i,key in enumerate(Key.Keys): self.assertEqual(names[i], Key.GetName(key, 'de')) self.assertEqual(names[i]+' is', Key.GetName(key+'#', 'de')) self.assertEqual(names[i]+' es', Key.GetName(key+'b', 'de')) self.assertEqual(names[i]+' isis', Key.GetName(key+'##', 'de')) self.assertEqual(names[i]+' eses', Key.GetName(key+'bb', 'de')) self.assertEqual(names[i]+' is*3', Key.GetName(key+'###', 'de')) self.assertEqual(names[i]+' es*3', Key.GetName(key+'bbb', 'de'))
def test_GetName_en(self): names = Key.KeyNames['en'] for i,key in enumerate(Key.Keys): self.assertEqual(names[i], Key.GetName(key, 'en')) self.assertEqual(names[i]+' sharp', Key.GetName(key+'#', 'en')) self.assertEqual(names[i]+' flat', Key.GetName(key+'b', 'en')) self.assertEqual(names[i]+' double sharp', Key.GetName(key+'##', 'en')) self.assertEqual(names[i]+' double flat', Key.GetName(key+'bb', 'en')) self.assertEqual(names[i]+' sharp*3', Key.GetName(key+'###', 'en')) self.assertEqual(names[i]+' flat*3', Key.GetName(key+'bbb', 'en'))
def test_GetName_en(self): names = Key.KeyNames['ja'] for i,key in enumerate(Key.Keys): self.assertEqual(names[i], Key.GetName(key, 'ja')) self.assertEqual('嬰'+names[i], Key.GetName(key+'#', 'ja')) self.assertEqual('変'+names[i], Key.GetName(key+'b', 'ja')) self.assertEqual('重嬰'+names[i], Key.GetName(key+'##', 'ja')) self.assertEqual('重変'+names[i], Key.GetName(key+'bb', 'ja')) self.assertEqual('嬰*3'+names[i], Key.GetName(key+'###', 'ja')) self.assertEqual('変*3'+names[i], Key.GetName(key+'bbb', 'ja'))
def test_GetName_it(self): names = Key.KeyNames['it'] for i,key in enumerate(Key.Keys): self.assertEqual(names[i], Key.GetName(key, 'it')) self.assertEqual(names[i]+' diesis', Key.GetName(key+'#', 'it')) self.assertEqual(names[i]+' bemolle', Key.GetName(key+'b', 'it')) self.assertEqual(names[i]+' doppio diesis', Key.GetName(key+'##', 'it')) self.assertEqual(names[i]+' doppio bemolle', Key.GetName(key+'bb', 'it')) self.assertEqual(names[i]+' diesis*3', Key.GetName(key+'###', 'it')) self.assertEqual(names[i]+' bemolle*3', Key.GetName(key+'bbb', 'it'))
def test_GetName_zh(self): names = Key.KeyNames['zh'] for i,key in enumerate(Key.Keys): self.assertEqual(names[i], Key.GetName(key, 'zh')) self.assertEqual('升'+names[i], Key.GetName(key+'#', 'zh')) self.assertEqual('降'+names[i], Key.GetName(key+'b', 'zh')) self.assertEqual('重升'+names[i], Key.GetName(key+'##', 'zh')) self.assertEqual('重降'+names[i], Key.GetName(key+'bb', 'zh')) self.assertEqual('升*3'+names[i], Key.GetName(key+'###', 'zh')) self.assertEqual('降*3'+names[i], Key.GetName(key+'bbb', 'zh'))
def test_Get_SPN(self): self.assertEqual(0, NoteName.Get('C-1')) self.assertEqual(69, NoteName.Get('A4')) self.assertEqual(127, NoteName.Get('G9')) lowerLimit = -1 for k in Key.Keys: for o in range(lowerLimit, lowerLimit + 10, 1): with self.subTest(key=k, octave=o): octave = o + abs( lowerLimit) if lowerLimit < 0 else o - abs(lowerLimit) expected = PitchClass.Get( Key.Get(k))[0] + (octave * (PitchClass.Max + 1)) self.assertEqual(expected, NoteName.Get(k + str(o))) expected = PitchClass.Get(Key.Get(k) + 1)[0] + (octave * (PitchClass.Max + 1)) self.assertEqual(expected, NoteName.Get(k + '#' + str(o))) expected = PitchClass.Get(Key.Get(k) - 1)[0] + (octave * (PitchClass.Max + 1)) self.assertEqual(expected, NoteName.Get(k + 'b' + str(o)))
def Name(self, v): self.__pitchClass = PitchClass.Get(Key.Get(v))[0] self.__name = v self.__scale._Scale__calcPitchClasses(self)
def test_Get_Invalid(self): with self.assertRaises(ValueError) as e: Key.Get('無効値') self.assertIn('keyは次のうちのいずれかにしてください。', str(e.exception))
def test_Get_int(self): with self.assertRaises(TypeError) as e: Key.Get(100) self.assertIn('引数nameはstr型にしてください。', str(e.exception))
def test_Get(self): keys = {'C':0, 'D':2, 'E':4, 'F':5, 'G':7, 'A':9, 'B':11} for key, pitch_class in keys.items(): with self.subTest(key=key): self.assertEqual(pitch_class, Key.Get(key))
def test_Get(self): for key, pitch_class in Key.Keys.items(): with self.subTest(key=key): self.assertEqual(pitch_class, Key.Get(key))
def Name(self, v): self.__pitchClass = PitchClass.Get(Key.Get(v))[0] self.__name = v