def Get(cls, pitchClass:int, relativeOctave:int): if not(isinstance(pitchClass, int) and isinstance(relativeOctave, int)): raise TypeError(f'引数pitchClass, relativeOctaveはint型にしてください。: type(pitchClass)={type(pitchClass)}, type(relativeOctave)={type(relativeOctave)}') PitchClass.Validate(pitchClass) noteNumber = pitchClass + (relativeOctave * (PitchClass.Max+1)) # print('noteNumber:', noteNumber, 'pitchClass:', pitchClass, 'relativeOctave:', relativeOctave) if noteNumber < cls.Min or cls.Max < noteNumber: raise ValueError(f'ノート番号が{cls.Min}〜{cls.Max}の範囲外になりました。pitchClass, relativeOctave, 共に0以上の整数値にして範囲内になるようにしてください。: noteNumber={noteNumber}, pitchClass={pitchClass}, relativeOctave={relativeOctave}') return noteNumber
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))
def GetFrequency(self, pitchClass, octaveClass): PitchClass.Validate(pitchClass) OctaveClass.Validate(octaveClass, _min=0) return self.__ScaleFrequencies[pitchClass] * math.pow(2, octaveClass - self.FundamentalTone.OctaveClass)
def test_Validate_OutOfRange_128(self): with self.assertRaises(ValueError) as e: PitchClass.Validate(12) self.assertIn(f'引数pitchClassは{PitchClass.Min}〜{PitchClass.Max}までの整数値にしてください。', str(e.exception))
def test_Validate_Invalid_Type(self): with self.assertRaises(TypeError) as e: PitchClass.Validate('無効な型') self.assertIn('引数pitchClassはint型にしてください。', str(e.exception))
def test_Validate(self): for pitchClass in range(PitchClass.Min, PitchClass.Max+1): PitchClass.Validate(pitchClass)