def test_Get_OutOfRange_Minus(self):
     with self.assertRaises(ValueError) as e:
         NoteNumber.Get(0, -1)
     self.assertIn(f'ノート番号が{NoteNumber.Min}〜{NoteNumber.Max}の範囲外になりました。',
                   str(e.exception))
     with self.assertRaises(ValueError) as e:
         NoteNumber.Get(-1, 0)
     self.assertIn(
         f'引数pitchClassは{PitchClass.Min}〜{PitchClass.Max}までの整数値にしてください。',
         str(e.exception))
     with self.assertRaises(ValueError) as e:
         NoteNumber.Get(-1, -1)
     self.assertIn(
         f'引数pitchClassは{PitchClass.Min}〜{PitchClass.Max}までの整数値にしてください。',
         str(e.exception))
Beispiel #2
0
 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_Validate_OutOfRange_128(self):
     with self.assertRaises(ValueError) as e:
         NoteNumber.Validate(128)
     self.assertIn(
         f'引数noteNumberは{NoteNumber.Min}〜{NoteNumber.Max}までの整数値にしてください。',
         str(e.exception))
 def test_Validate_Invalid_Type(self):
     with self.assertRaises(TypeError) as e:
         NoteNumber.Validate('無効な型')
     self.assertIn('引数noteNumberはint型にしてください。', str(e.exception))
 def test_Validate(self):
     for pitchClass in range(NoteNumber.Min, NoteNumber.Max + 1):
         NoteNumber.Validate(pitchClass)
 def test_Get_Invalid_Type(self):
     with self.assertRaises(TypeError) as e:
         NoteNumber.Get('pitch', 'octave')
     self.assertIn('引数pitchClass, relativeOctaveはint型にしてください。',
                   str(e.exception))
 def test_Get(self):
     for halfToneNumber in range(NoteNumber.Min, NoteNumber.Max + 1):
         with self.subTest(halfToneNumber=halfToneNumber):
             self.assertEqual(
                 halfToneNumber,
                 NoteNumber.Get(*PitchClass.Get(halfToneNumber)))
 def GetFrequency(self, pitchClass, octaveClass):
     PitchClass.Validate(pitchClass)
     OctaveClass.Validate(octaveClass, _min=0)
     return self.FundamentalTone.Hz * math.pow(2, (NoteNumber.Get(
         pitchClass, octaveClass) - self.FundamentalTone.NoteNumber) /
                                               (PitchClass.Max + 1))
Beispiel #9
0
 def test_Default(self):
     f = FundamentalTone()
     self.assertEqual(440, f.Hz)
     self.assertEqual(9, f.PitchClass)
     self.assertEqual(5, f.OctaveClass)
     self.assertEqual(NoteNumber.Get(9,5), f.NoteNumber)
Beispiel #10
0
 def test_init(self):
     f = FundamentalTone(hz=261, pitchClass=0, octaveClass=5)
     self.assertEqual(261, f.Hz)
     self.assertEqual(0, f.PitchClass)
     self.assertEqual(5, f.OctaveClass)
     self.assertEqual(NoteNumber.Get(0,5), f.NoteNumber)
 def OctaveClass(self, v):
     o = OctaveClass.Get(v, _min=0)
     self.__octaveClass = o
     self.__noteNumber = NoteNumber.Get(self.PitchClass, o)
 def PitchClass(self, v):
     p = PitchClass.Get(v)[0]
     self.__pitchClass = p
     self.__noteNumber = NoteNumber.Get(p, self.OctaveClass)