Example #1
0
 def test_equals_identifies_equal_objects_with_pcs_only(self):
     ts = ToneSystem(9)
     mode1 = ModalGroup(ts, pcs=ts.get_pitch_class_set([1,2,4]))
     mode2 = ModalGroup(ts, pcs=ts.get_pitch_class_set([1,3,4]))
     self.assertEqual(mode1, mode2)
     mode2 = ModalGroup(ts, pcs=ts.get_pitch_class_set([1,2,5]))
     self.assertNotEqual(mode1, mode2)
Example #2
0
 def test_can_append_modal_group_to_empty_stream(self): 
     ts = ToneSystem(12, rand=NotReallyRand())
     t = NoteStream(ts, [], group_length=3)
     grp = ts.get_pitch_class_set([2,3,4,-1])
     t = t.append(Link([grp]))
     result = ts.get_pitch_class_set(t.notes)
     self.assertEqual(ts.get_pitch_class_set([2,3,4,-1]), result)
Example #3
0
 def test_will_generate_notes_from_pcs(self):
     ts = ToneSystem(13, rand=NotReallyRand())
     expected = [1,2,4]
     expected_pcs = ts.get_pitch_class_set(expected)
     mode1 = ModalGroup(ts, pcs=expected_pcs)
     notes = mode1.generate_notes([6])
     self.assertEqual(expected_pcs, ts.get_pitch_class_set(notes))
     self.assertEquals(6, notes[0])
Example #4
0
 def test_can_append_modal_group(self): 
     ts = ToneSystem(12, rand=NotReallyRand())
     t = NoteStream(ts, [1,2,3,4], group_length=4)
     grp = ts.get_pitch_class_set([2,3,4,-1])
     t = t.append(Link([grp]))
     print "Notes: ", t.notes
     result = ts.get_pitch_class_set(t.notes)
     self.assertEqual(ts.get_pitch_class_set([1,2,3,4,-1]), result)
Example #5
0
 def test_large_pcs_benchmark(self):
     ts = ToneSystem(42, rand=NotReallyRand())
     expected = [1,4,7,9,12,5,6,20,3,2,8,11]
     expected_pcs = ts.get_pitch_class_set(expected)
     mode1 = ModalGroup(ts, pcs=expected_pcs)
     notes = mode1.generate_notes([5,24])
     self.assertEqual(12, len(notes))
     self.assertEqual(expected_pcs, ts.get_pitch_class_set(notes))
     self.assertEquals(5, notes[0])
     self.assertEquals(24, notes[1])
Example #6
0
    def test_will_not_allow_pcs_and_notes_to_be_specified(self):
        ts = ToneSystem(23)
        ok = False
        try:
            mode = ModalGroup(ts, pcs=ts.get_pitch_class_set([1,2,4]), \
                                  notes=[1,2,4])
        except:
            ok = True

        self.assertTrue(ok, 'should have thrown in the constructor')
Example #7
0
 def test_large_pcs_benchmark_with_only_2_notes_to_complete(self):
     ts = ToneSystem(42, rand=NotReallyRand())
     expected = [1,4,7,9,12,5,6,20,3,2,8,11]
     expected_pcs = ts.get_pitch_class_set(expected)
     mode1 = ModalGroup(ts, pcs=expected_pcs)
     notes = mode1.generate_notes([5,24,6,7,8,9,10,11,12,13])
     #TODO: should the pcs class has an add note method that returns
     #a new object? That would help with large groups
     self.assertEqual(12, len(notes))
     self.assertEqual(expected_pcs, ts.get_pitch_class_set(notes))
     self.assertEquals(5, notes[0])
     self.assertEquals(24, notes[1])
Example #8
0
    def test_can_find_out_number_of_notes_from_number_of_intervals(self):
        #The actual tone system doesn't really matter, it's just 
        #easier to generate a pcs using a tone system than by hand
        ts = ToneSystem(9)
        
        #First one by hand, then automate
        pcs = ts.get_pitch_class_set([1,12,3,4,5])
        result = ModalGroup.get_note_count_from_pcs(pcs)
        self.assertEqual(5, result)

        for i in range(1,40):
            p = range(i, 41)
            expected = len(p)
            pcs = ts.get_pitch_class_set(p)
            result = ModalGroup.get_note_count_from_pcs(pcs)
            self.assertEqual(expected, result)