Пример #1
0
 def test_set_OctaveClass(self):
     f = FundamentalTone(hz=440, pitchClass=9, octaveClass=5)
     self.assertEqual(5, f.OctaveClass)
     self.assertEqual(69, f.NoteNumber)
     f.OctaveClass = 4
     self.assertEqual(4, f.OctaveClass)
     self.assertEqual(57, f.NoteNumber)
Пример #2
0
 def test_set_PitchClass(self):
     f = FundamentalTone(hz=440, pitchClass=9, octaveClass=5)
     self.assertEqual(9, f.PitchClass)
     self.assertEqual(69, f.NoteNumber)
     f.PitchClass = 0
     self.assertEqual(0, f.PitchClass)
     self.assertEqual(60, f.NoteNumber)
Пример #3
0
 def test_set_NoteNumber(self):
     f = FundamentalTone(hz=440, pitchClass=9, octaveClass=5)
     self.assertEqual(9, f.PitchClass)
     self.assertEqual(5, f.OctaveClass)
     self.assertEqual(69, f.NoteNumber)
     f.NoteNumber = 56
     self.assertEqual(8, f.PitchClass)
     self.assertEqual(4, f.OctaveClass)
     self.assertEqual(56, f.NoteNumber)
Пример #4
0
 def test_Get(self):
     f = FundamentalTone(hz=440, pitchClass=9, octaveClass=5)
     p = PythagoreanTuning(f)
     for pitch in range(PitchClass.Max + 1):
         hz = p.GetFrequency(pitch, 5)
         print(hz)
         if 9 == pitch: self.assertEqual(440, math.floor(hz))
 def __init__(self, fundamentalTone=None):
     if None is fundamentalTone:
         self.__fundamentalTone = FundamentalTone()
     else:
         self.__fundamentalTone = weakref.proxy(fundamentalTone)
     self.__Frequencies = []
     self.__calcFrequencies()
Пример #6
0
 def test_init_set(self):
     f = FundamentalTone(hz=432, pitchClass=9, octaveClass=5)
     #        s = Scale(0, ScaleIntervals.Minor)
     s = Scale('C', ScaleIntervals.Minor)
     j = JustIntonation(f, s)
     self.assertTrue(isinstance(j.FundamentalTone, FundamentalTone))
     self.assertEqual(432, j.FundamentalTone.Hz)
     self.assertEqual(9, j.FundamentalTone.PitchClass)
     self.assertEqual(5, j.FundamentalTone.OctaveClass)
     self.assertTrue(isinstance(j.Scale, Scale))
     self.assertTrue(j.Scale.Key.PitchClass == 0)
     #        self.assertTrue(j.Scale.Key == 0)
     self.assertTrue(j.Scale.Intervals == ScaleIntervals.Minor)
     del f
     with self.assertRaises(ReferenceError) as ex:
         print(j.FundamentalTone)
     self.assertIn('weakly-referenced object no longer exists',
                   str(ex.exception))
     del s
     with self.assertRaises(ReferenceError) as ex:
         print(
             j.Scale
         )  #AssertionError: ReferenceError not raised    循環参照のせいだと思う。(Scale, ScaleKey)
     self.assertIn('weakly-referenced object no longer exists',
                   str(ex.exception))
Пример #7
0
 def test_Get_AllOctave_432(self):
     f = FundamentalTone(hz=432, pitchClass=9, octaveClass=5)
     p = PythagoreanTuning(f)
     for octave in range(10 + 1):
         hz = p.GetFrequency(9, octave)
         self.assertEqual(math.floor(432 * pow(2, octave - 5)),
                          math.floor(hz))
 def test_Get_A4(self):
     print('基音=A4(440Hz) 調=A4')
     f = FundamentalTone(hz=440, pitchClass=9, octaveClass=5)
     s = Scale(9, ScaleIntervals.Major)
     j = JustIntonation(f, s)
     for p in range(PitchClass.Max + 1):
         print(j.GetFrequency(p, 5))
 def test_Get_C4(self):
     print('基音=A4(440Hz) 調=C4')
     f = FundamentalTone(hz=440, pitchClass=9, octaveClass=5)
     s = Scale(0, ScaleIntervals.Major)
     j = JustIntonation(f, s)
     for p in range(PitchClass.Max + 1):
         print(j.GetFrequency(p, 5))
         #正解の基準がない。出た数値が正解ということにする。
     print('純正律の周波数において、正解の基準が見つけられなかった。出た数値が正解ということにする。')
Пример #10
0
 def test_init_set(self):
     f = FundamentalTone(hz=432, pitchClass=9, octaveClass=5)
     e = EqualTemperament(f)
     self.assertTrue(isinstance(e.FundamentalTone, FundamentalTone))
     self.assertEqual(432, e.FundamentalTone.Hz)
     self.assertEqual(9, e.FundamentalTone.PitchClass)
     self.assertEqual(5, e.FundamentalTone.OctaveClass)
     del f
     with self.assertRaises(ReferenceError) as ex:
         print(e.FundamentalTone)
     self.assertIn('weakly-referenced object no longer exists',
                   str(ex.exception))
Пример #11
0
    def __init__(self, fundamentalTone=None, scale=None):
        if None is fundamentalTone: self.__fundamentalTone = FundamentalTone()
        else:
            if not isinstance(fundamentalTone, FundamentalTone): raise TypeError('引数fundamentalToneはFundamentalTone型にしてください。: type(fundamentalTone)={type(fundamentalTone)}')
            self.__fundamentalTone = weakref.proxy(fundamentalTone)
        if None is scale: self.__scale = Scale()
        else:
            if not isinstance(scale, Scale): raise TypeError('引数scaleはScale型にしてください。: type(scale)={type(scale)')
            self.__scale = weakref.proxy(scale)
        self.__Frequencies = []
        self.__ScaleFrequencies = []
#        self.__calcFrequencies()
#        self.__calcScaleFrequencies()
        self.__calcFrequencies(self.__Frequencies, self.FundamentalTone.Hz)
        self.__flatOctave(self.__Frequencies, self.FundamentalTone.PitchClass)
        self.__calcFrequencies(self.__ScaleFrequencies, self.__Frequencies[self.Scale.Key])
 def test_init_set(self):
     f = FundamentalTone(hz=261, pitchClass=0, octaveClass=5)
     e = EqualTemperament(f)
     self.assertEqual(261, e.FundamentalTone.Hz)
     self.assertEqual(0, e.FundamentalTone.PitchClass)
     self.assertEqual(5, e.FundamentalTone.OctaveClass)
Пример #13
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 __init__(self, fundamentalTone=None):
     self.__fundamentalTone = fundamentalTone
     if None is fundamentalTone:
         self.__fundamentalTone = FundamentalTone()
     else:
         self.__fundamentalTone = weakref.proxy(fundamentalTone)
Пример #15
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)
Пример #16
0
 def test_init_OutOfRange_Hz(self):
     with self.assertRaises(ValueError) as e:
         f = FundamentalTone(hz=-1, pitchClass=0, octaveClass=5)
     self.assertIn('Hzは0以上の数値にしてください。', str(e.exception))        
Пример #17
0
 def test_set_OctaveClass_Invalid_Type(self):
     with self.assertRaises(TypeError) as e:
         f = FundamentalTone(hz=440, pitchClass=9, octaveClass='o')
     self.assertIn('引数pitchClass, relativeOctaveはint型にしてください。', str(e.exception))
Пример #18
0
 def test_set_NoteNumber_Invalid_Type(self):
     with self.assertRaises(TypeError) as e:
         f = FundamentalTone(hz=440, pitchClass=9, octaveClass=5)
         f.NoteNumber = 'n'
     self.assertIn('引数halfToneNumはint型にしてください。', str(e.exception))
Пример #19
0
 def test_set_Hz_Invalid_Type(self):
     with self.assertRaises(TypeError) as e:
         f = FundamentalTone(hz='hz', pitchClass=9, octaveClass=5)
     self.assertIn('Hzは数値型(int, float)にしてください。', str(e.exception))
Пример #20
0
 def test_init_PitchClass(self):
     f = FundamentalTone(hz=0, pitchClass=12, octaveClass=5)
     self.assertEqual(0, f.PitchClass)
     self.assertEqual(5, f.OctaveClass)
Пример #21
0
 def __init__(self, fundamentalTone=None):
     self.__fundamentalTone = fundamentalTone
     if None is fundamentalTone:
         self.__fundamentalTone = FundamentalTone()
Пример #22
0
 def test_init_OutOfRange_OctaveClass(self):
     with self.assertRaises(ValueError) as e:
         f = FundamentalTone(hz=440, pitchClass=0, octaveClass=-1)
     self.assertIn('ノート番号が0〜127の範囲外になりました。', str(e.exception))
Пример #23
0
 def test_set_Hz(self):
     f = FundamentalTone(hz=440, pitchClass=9, octaveClass=5)
     self.assertEqual(440, f.Hz)
     f.Hz = 555
     self.assertEqual(555, f.Hz)