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_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 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): 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
def Name(self, v): self.__pitchClass = PitchClass.Get(Key.Get(v))[0] self.__name = v self.__scale._Scale__calcPitchClasses(self)
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))