示例#1
0
 def setUpClass(cls):
     cls.tonic_quarter = Relative_Note(Relative_Pitch(0, Degrees.TONIC, 0),
                                       1)
     cls.subdominant_quarter = Relative_Note(
         Relative_Pitch(0, Degrees.SUBDOMINANT, 0), 1)
     cls.subdominant_dotted_quarter = Relative_Note(
         Relative_Pitch(0, Degrees.SUBDOMINANT, 0), 1.5)
示例#2
0
 def test_hash(self):
     this_class = Test_Relative_Pitch
     self.assertEqual(hash(this_class.low_leading_enharmonic),
                      hash(this_class.low_leading_enharmonic), 'identity')
     self.assertEqual(hash(this_class.middle_subdominant_sharp),
                      hash(Relative_Pitch(0, Degrees.SUBDOMINANT, 1)))
     self.assertEqual(hash(this_class.higher_mediant),
                      hash(Relative_Pitch(2, Degrees.MEDIANT, 0)))
示例#3
0
 def test_hash(self):
     this_class = Test_Relative_Note
     self.assertEqual(hash(this_class.tonic_quarter),
                      hash(this_class.tonic_quarter), 'identity')
     self.assertEqual(
         hash(this_class.tonic_quarter),
         hash(Absolute_Note(Relative_Pitch(0, Degrees.TONIC, 0), 1)))
     self.assertEqual(
         hash(this_class.subdominant_dotted_quarter),
         hash(Relative_Note(Relative_Pitch(0, Degrees.SUBDOMINANT, 0),
                            1.5)))
示例#4
0
 def test_eq(self):
     this_class = Test_Relative_Note
     self.assertEqual(this_class.tonic_quarter, this_class.tonic_quarter,
                      'identity')
     self.assertEqual(this_class.tonic_quarter,
                      Relative_Note(Relative_Pitch(0, Degrees.TONIC, 0), 1),
                      'same note')
     self.assertFalse(
         this_class.tonic_quarter == Relative_Note_Alt(
             Relative_Pitch(0, Degrees.TONIC, 0), 1), 'different classes')
     self.assertNotEqual(this_class.tonic_quarter,
                         this_class.subdominant_quarter,
                         'different pitches')
     self.assertNotEqual(this_class.subdominant_dotted_quarter,
                         this_class.subdominant_quarter,
                         'different durations')
示例#5
0
 def setUpClass(cls):
     cls.low_leading_tone = Relative_Pitch(-2, Degrees.LEADING_TONE, 0)
     cls.low_leading_enharmonic = Relative_Pitch(-1, Degrees.TONIC, -1)
     cls.middle_tonic = Relative_Pitch(0, Degrees.TONIC, 0)
     cls.middle_subdominant = Relative_Pitch(0, Degrees.SUBDOMINANT, 0)
     cls.middle_subdominant_sharp = Relative_Pitch(0, Degrees.SUBDOMINANT,
                                                   1)
     cls.high_mediant = Relative_Pitch(1, Degrees.MEDIANT, 0)
     cls.higher_mediant = Relative_Pitch(2, Degrees.MEDIANT, 0)
示例#6
0
    def make_piece(length, key):
        # length is in number of notes; key is an interval up from C
        current_triad = Degrees.TONIC
        current_length = 1
        target_length = length
        part_names = ['soprano', 'alto', 'tenor', 'bass']
        parts = {}
        for part, instrument in zip(part_names, ('violin', 'violin', 'viola', 'cello')):
            parts[part] = Part(key, part, Instrument(instrument))
        current_pitches = (Relative_Pitch(2, Degrees.TONIC, 0), Relative_Pitch(1, Degrees.MEDIANT, 0), Relative_Pitch(0, Degrees.DOMINANT, 0), (Relative_Pitch(-1, Degrees.TONIC, 0)))
        for part_name, pitch in zip(part_names, current_pitches):
            parts[part_name].extend(Relative_Note(pitch, 1))

        piece = (Piece((parts['soprano'], parts['alto'], parts['tenor'], parts['bass'])))

        while current_length < target_length:
            next_triad = random.choice(list(next_triad_major(current_triad)))
            piece.extend(next_triad, (0,))
            current_triad = next_triad
            current_length += 1
        
        return piece
示例#7
0
 def test_eq_true(self):
     self.assertEqual(Test_Relative_Pitch.middle_tonic,
                      Relative_Pitch(0, Degrees.TONIC, 0), 'same pitch')