def test_Get_Hi(self):
     print('test_Get_Low')
     e = EqualTemperament()
     expecteds = [261,277,293,311,329,349,369,391,415,440,466,493]
     for p in range(PitchClass.Max+1):
         print(e.GetFrequency(p, 5+1))
         self.assertIn(math.floor(e.GetFrequency(p, 5+1)), [math.floor(expecteds[p]*2), math.floor(expecteds[p]*2)+1])
コード例 #2
0
 def test_Get_OutOfRange_Pitch_Max(self):
     e = EqualTemperament()
     with self.assertRaises(ValueError) as ex:
         e.GetFrequency(12, 5)
     self.assertIn(
         f'引数pitchClassは{PitchClass.Min}〜{PitchClass.Max}までの整数値にしてください。',
         str(ex.exception))
 def test_Get_MinOctave(self):
     print('test_Get_MinOctave')
     e = EqualTemperament()
     expecteds = [261,277,293,311,329,349,369,391,415,440,466,493]
     for p in range(PitchClass.Max+1):
         print(e.GetFrequency(p, 0))
         self.assertEqual(math.floor(expecteds[p]/math.pow(2,5)), math.floor(e.GetFrequency(p, 0)))
 def test_Get_MaxOctave(self):
     print('test_Get_MaxOctave')
     e = EqualTemperament()
     expecteds = [8372,8869,9397,9956,10548,11175,11839,12543]
     for p in range(PitchClass.Max+1):
         if p + (10 * (PitchClass.Max+1)) < 128:
             print(e.GetFrequency(p, 10))
             self.assertEqual(expecteds[p], math.floor(e.GetFrequency(p, 10)))
コード例 #5
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))
コード例 #6
0
        )
        for scale_name in [
                'Major', 'Minor', 'Diminished', 'HarmonicMinor',
                'MelodicMinor', 'MajorPentaTonic', 'MinorPentaTonic',
                'BlueNote'
        ]:
            print('----------', scale_name, '----------')
            scale.Intervals = getattr(ScaleIntervals, scale_name)
            for scaleKeyId in range(temperament.Denominator):
                scale.Key = scaleKeyId
                for tone in scale.Tones:
                    print('{:2}'.format(GetToneName(tone[0])), end=' ')
                print()
                PlayAndMaker.Run(temperament, scale, scale_name)

    run(EqualTemperament())
    run(PythagoreanTuning())

    #純正律
    def PlayAndMakeJustIntonation(temperaments):
        if not isinstance(temperaments, JustIntonation):
            raise Exception(f'このメソッドの引数temperamentsはJustIntonation型のみ対応です。')
        wm = Wave.BaseWaveMaker.BaseWaveMaker()
        sampler = Wave.Sampler.Sampler()
        wf = Wave.WaveFile.WaveFile()
        wf.BasePath = pathlib.PurePath(
            f'../res/440/JustIntonation/scales/{temperaments.Scale}')
        wav = []
        for f0 in temperaments.Frequencies:
            wav.append(sampler.Sampling(wm.Sin(a=1, fs=8000, f0=f0, sec=0.5)))
        wf.Write(b''.join(wav),
コード例 #7
0
 def test_Get_Invalid_Type_OctaveClass(self):
     e = EqualTemperament()
     with self.assertRaises(TypeError) as ex:
         e.GetFrequency(9, 'octave')
     self.assertIn('引数octaveはint型にしてください。', str(ex.exception))
コード例 #8
0
 def test_Get_Invalid_Type_PitchClass(self):
     e = EqualTemperament()
     with self.assertRaises(TypeError) as ex:
         e.GetFrequency('pitch', 5)
     self.assertIn('引数pitchClassはint型にしてください。', str(ex.exception))
コード例 #9
0
 def test_init_Default(self):
     e = EqualTemperament()
     self.assertTrue(isinstance(e.FundamentalTone, FundamentalTone))
     self.assertEqual(440, e.FundamentalTone.Hz)
     self.assertEqual(9, e.FundamentalTone.PitchClass)
     self.assertEqual(5, e.FundamentalTone.OctaveClass)
コード例 #10
0
 def test_Get_OutOfRange_Octave_Max(self):
     e = EqualTemperament()
     with self.assertRaises(ValueError) as ex:
         e.GetFrequency(9, 11)
     self.assertIn('引数octaveは0〜10の値にしてください。', str(ex.exception))
コード例 #11
0
        #        p.Open()

        #スケールの構成音生成
        wf.BasePath = pathlib.PurePath(f'../res/440/EqualTemperament/scales/')
        wav = []
        for f0 in scaleTones:
            wav.append(sampler.Sampling(wm.Sin(a=1, fs=8000, f0=f0, sec=0.5)))
        wf.Write(b''.join(wav),
                 filename=GetToneName(scaleKeyId).replace('#', '+') + 'Major')
        wav.clear()


#        p.Close()

if __name__ == '__main__':
    et = EqualTemperament()
    et.Denominator = 12
    et.SetBaseKey(keyId=9, pitch=4, hz=440)
    scale = Scale(et)  # scale.Temperament = et
    print(
        f'BaseKey: {GetToneName(et.BaseKeyId)}{et.BaseKeyPitch} {et.BaseFrequency}Hz'
    )
    print(f'{et.Denominator}平均律')
    """
    for scaleKeyId in range(et.Denominator):
        tones = scale.Get(scaleKeyId, ScaleIntervals.Major)
        for tone in tones: print('{:2}'.format(GetToneName(tone[0])), end=' ')
        print()
        PlayAndMaker.Run(scaleKeyId, [tone[2] for tone in tones])
    """
    """
 def test_Get_OutOfRange_Octave_Max(self):
     e = EqualTemperament()
     with self.assertRaises(ValueError) as ex:
         e.GetFrequency(9, 11)
     self.assertIn('ノート番号が0〜127の範囲外になりました。', str(ex.exception))
 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)