示例#1
0
 def add_part(self, part=None):
     if not part:
         part = TreePart(id=self.id)
     else:
         if part.id != self.id:
             raise ValueError('Part must have the same id as TreeScorePart')
     part.parent_score_part = self
     if self.number_of_staves is not None:
         part.staves = self.number_of_staves
     self._parts.append(part)
     return part
示例#2
0
    def test_split_chord(self):
        b = TreeBeat()
        p = TreePart('one')
        chord = TreeChord((60, 62), quarter_duration=1)
        m = TreeMeasure()
        m.add_child(p)
        p.add_chord(chord)
        b.add_chord(chord)
        split = chord.split([1, 0.5, 3])

        result = [Fraction(2, 9), Fraction(1, 9), Fraction(2, 3)]
        self.assertEqual([chord.quarter_duration for chord in split], result)
示例#3
0
    def test_duration(self):
        m = TreeMeasure(time=(3, 4))
        self.assertEqual(m.quarter_duration, 3)

        p = TreePart(id='one')
        m.add_child(p)

        tree_part_voice = p.get_staff(1).get_voice(1)
        tree_part_voice.set_beats([
            TreeBeat(duration=2),
            TreeBeat(duration=0.5),
            TreeBeat(duration=0.5)
        ])
        result = [0, 2, 2.5]
        self.assertEqual([beat.offset for beat in tree_part_voice.beats],
                         result)
示例#4
0
 def test_beats(self):
     m = TreeMeasure(time=(3, 8, 2, 4))
     p = TreePart(id='one')
     m.add_child(p)
     tree_part_voice = p.get_staff(1).get_voice(1)
     tree_part_voice.set_beats()
     result = [0.5, 0.5, 0.5, 1.0, 1.0]
     self.assertEqual([beat.duration for beat in tree_part_voice.beats], result)
     result = [0, 0.5, 1.0, 1.5, 2.5]
     self.assertEqual([beat.offset for beat in tree_part_voice.beats], result)
     # result = [4, 4, 4, 8, 8]
     # self.assertEqual([beat.max_division for beat in tree_part_voice.beats], result)
     # tree_part_voice.beats[3].max_division = 5
     # result = [4, 4, 4, 5, 8]
     # self.assertEqual([beat.max_division for beat in tree_part_voice.beats], result)
     with self.assertRaises(ValueError):
         tree_part_voice.set_beats([TreeBeat(duration=0.5), TreeBeat(duration=0.5), TreeBeat(duration=0.5)])
     tree_part_voice.set_beats([TreeBeat(duration=1), TreeBeat(duration=0.5), TreeBeat(duration=2)])
     result = [0, 1, 1.5]
     self.assertEqual([beat.offset for beat in tree_part_voice.beats], result)
示例#5
0
    def test_split_beats_2(self):
        m = TreeMeasure(time=(3, 4))
        p = TreePart(id='one')
        p.max_division = 8
        p.forbidden_divisions = []
        m.add_child(p)
        # p.set_beats()

        p.add_chord(TreeChord(60, quarter_duration=1.4))
        p.add_chord(TreeChord(60, quarter_duration=1.6))
        # p._add_chords_to_beats()
        # p._split_chords_beatwise()
        p.finish()
        result = [Fraction(1, 1), Fraction(2, 5), Fraction(3, 5), Fraction(1, 1)]
        self.assertEqual([chord.quarter_duration for chord in p.chords], result)
示例#6
0
class Test(TestCase):
    def setUp(self) -> None:
        self.part = TreePart(id='test_part')

    def test_1(self):
        self.assertIsNone(self.part.staves)

    def test_2(self):
        self.part.add_tree_part_staff(TreePartStaff(2))
        expected = 2
        actual = list(self.part.tree_part_staves)[0]
        self.assertEqual(expected, actual)

    def test_3(self):
        self.part.set_tree_part_staff(staff_number=3)
        expected = 3
        actual = list(self.part.tree_part_staves)[0]
        self.assertEqual(expected, actual)

    def test_4(self):
        tps = self.part.set_tree_part_staff(2)
        tps.add_tree_part_voice(TreePartVoice(2))
        expected = 2
        actual = list(self.part.tree_part_staves[2].tree_part_voices)[0]
        self.assertEqual(expected, actual)

    def test_5(self):
        tree_part_staff = self.part.set_tree_part_staff(1)
        tree_part_staff.add_tree_part_voice(TreePartVoice(2))
        with self.assertRaises(AttributeError):
            tree_part_staff.add_tree_part_voice(TreePartVoice(2))

    def test_6(self):
        tps = self.part.set_tree_part_staff(1)
        tpv_1 = tps.set_tree_part_voice(1)
        tpv_2 = tps.set_tree_part_voice(2)
        expected = [tpv_1, tpv_2]
        actual = self.part.tree_part_voices
        self.assertEqual(expected, actual)
示例#7
0
 def setUp(self) -> None:
     self.part = TreePart(id='test_part')
示例#8
0
    def test_quantize(self):
        m = TreeMeasure(time=(4, 4))
        p = TreePart(id='one')
        p.max_division = 8
        p.forbidden_divisions = []
        m.add_child(p)
        p.add_chord(TreeChord(60, quarter_duration=1))
        p.add_chord(TreeChord(60, quarter_duration=1.2))
        p.add_chord(TreeChord(60, quarter_duration=0.3))
        p.add_chord(TreeChord(60, quarter_duration=0.2))
        p.add_chord(TreeChord(60, quarter_duration=1.3))
        p.finish()

        result = [Fraction(1, 1), Fraction(1, 1), Fraction(1, 6), Fraction(1, 3), Fraction(1, 6), Fraction(1, 3),
                  Fraction(1, 1)]
        self.assertEqual([chord.quarter_duration for chord in p.chords], result)
示例#9
0
 def setUp(self):
     m = TreeMeasure(time=(4, 4))
     self.part = TreePart(id='one')
     self.part.max_division = 8
     self.part.forbidden_divisions = []
     m.add_child(self.part)