コード例 #1
0
 def test_octave_arp_oscillate(self):
     arpeggio = []
     octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4], oscillate=True)
     for i in range(36):
         arpeggio.append(octaveArp())
     self.assertEquals(arpeggio, [
         1, 2, 3, 4, 13, 14, 15, 16, 25, 26, 27, 28, 37, 38, 39, 40, 25, 26,
         27, 28, 13, 14, 15, 16, 1, 2, 3, 4, 13, 14, 15, 16, 25, 26, 27, 28
     ])
コード例 #2
0
 def test_octave_arp_descending(self):
     arpeggio = []
     octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4], direction=-1)
     for i in range(20):
         arpeggio.append(octaveArp())
     self.assertEquals(arpeggio, [
         37, 38, 39, 40, 25, 26, 27, 28, 13, 14, 15, 16, 1, 2, 3, 4, 37, 38,
         39, 40
     ])
コード例 #3
0
 def test_numeric_sorting(self):
     """
     Test that numeric values are sorted correctly and
     non-numeric values retain their position in the arpeggio.
     """
     arpeggio = []
     ascarp = AscArp([1, 3, N, 2])
     for i in range(8):
         arpeggio.append(ascarp())
     self.assertEquals(arpeggio, [1, 2, None, 3, 1, 2, None, 3])
コード例 #4
0
    def test_octave_arp_ascending(self):
        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4])
        for i in range(20):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio, [
            1, 2, 3, 4, 13, 14, 15, 16, 25, 26, 27, 28, 37, 38, 39, 40, 1, 2,
            3, 4
        ])

        arpeggio = []
        octaveArp = OctaveArp(DescArp(), [1, 2, 3, 4])
        for i in range(20):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio, [
            4, 3, 2, 1, 16, 15, 14, 13, 28, 27, 26, 25, 40, 39, 38, 37, 4, 3,
            2, 1
        ])

        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4], 1)
        for i in range(12):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio, [1, 2, 3, 4, 13, 14, 15, 16, 1, 2, 3, 4])
コード例 #5
0
 def test_adder(self):
     arpeggio = []
     octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4])
     adder = Adder(octaveArp)
     for i in range(16):
         arpeggio.append(adder())
     self.assertEquals(
         arpeggio,
         [1, 2, 3, 4, 13, 14, 15, 16, 25, 26, 27, 28, 37, 38, 39, 40])
     adder.amount = 2
     arpeggio = []
     for i in range(16):
         arpeggio.append(adder())
     self.assertEquals(arpeggio, [
         v + 2 for v in
         [1, 2, 3, 4, 13, 14, 15, 16, 25, 26, 27, 28, 37, 38, 39, 40]
     ])
コード例 #6
0
ファイル: test_arp.py プロジェクト: csv/beatlounge
 def setUp(self):
     self.arpeggio = arpeggio = [0, 2, 1, 3]
     self.ascArp = AscArp(arpeggio)
     self.descArp = DescArp(arpeggio)
     self.ordArp = OrderedArp(arpeggio)
     self.randArp = RandomArp(arpeggio)
コード例 #7
0
ファイル: test_arp.py プロジェクト: csv/beatlounge
class ArpTests(TestCase):

    def setUp(self):
        self.arpeggio = arpeggio = [0, 2, 1, 3]
        self.ascArp = AscArp(arpeggio)
        self.descArp = DescArp(arpeggio)
        self.ordArp = OrderedArp(arpeggio)
        self.randArp = RandomArp(arpeggio)

    def test_ascArp(self):
        arpeggio = []
        for i in range(8):
            arpeggio.append(self.ascArp())
        self.assertEquals(arpeggio, [0, 1, 2, 3, 0, 1, 2, 3])

    def test_descArp(self):
        arpeggio = []
        for i in range(8):
            arpeggio.append(self.descArp())
        self.assertEquals(arpeggio, [3, 2, 1, 0, 3, 2, 1, 0])

    def test_orderedArp(self):
        arpeggio = []
        for i in range(8):
            arpeggio.append(self.ordArp())
        self.assertEquals(arpeggio, [0, 2, 1, 3, 0, 2, 1, 3])

    def test_randomArp(self):
        r = cycle([1, 2, 0, 0, 2, 0, 1, 0])

        class myrandom:
            @classmethod
            def randint(cls, *blah):
                return r.next()

        self.patch(arp, 'random', myrandom)

        arpeggio = []
        for i in range(8):
            arpeggio.append(self.randArp())
        self.assertEquals(arpeggio, [2, 3, 0, 1, 0, 2, 1, 3])

    def test_numeric_sorting(self):
        """
        Test that numeric values are sorted correctly and
        non-numeric values retain their position in the arpeggio.
        """
        arpeggio = []
        ascarp = AscArp([1, 3, N, 2])
        for i in range(8):
            arpeggio.append(ascarp())
        self.assertEquals(arpeggio, [1, 2, None, 3, 1, 2, None, 3])

    def test_resetting(self):
        """
        Test various behaviors of resetting values on an arp midstream.
        """

        arpeggio = []
        for i in range(2):
            arpeggio.append(self.ascArp())
        self.ascArp.reset([5, 6, 7, 8])
        for i in range(2):
            arpeggio.append(self.ascArp())
        self.assertEquals(arpeggio, [0, 1, 7, 8])

        arpeggio = []
        self.ascArp.reset([0, 1, 2, 3])
        for i in range(3):
            arpeggio.append(self.ascArp())
        self.ascArp.reset([5, 6])
        arpeggio.append(self.ascArp())
        self.assertEquals(arpeggio, [0, 1, 2, 6])

        arpeggio = []
        self.ascArp.reset([0, 1, 2, 3])
        for i in range(3):
            arpeggio.append(self.ascArp())
        self.ascArp.reset([4, 5, 6, 7, 8, 9, 10, 11])
        arpeggio.append(self.ascArp())
        self.assertEquals(arpeggio, [0, 1, 2, 10])

        arpeggio = []
        for i in range(2):
            arpeggio.append(self.descArp())
        self.descArp.reset([5, 6, 7, 8])
        for i in range(2):
            arpeggio.append(self.descArp())
        self.assertEquals(arpeggio, [3, 2, 6, 5])

        arpeggio = []
        self.descArp.reset([0, 1, 2, 3])
        for i in range(3):
            arpeggio.append(self.descArp())
        self.descArp.reset([5, 6])
        arpeggio.append(self.descArp())
        self.assertEquals(arpeggio, [3, 2, 1, 5])

        arpeggio = []
        self.descArp.reset([0, 1, 2, 3])
        for i in range(3):
            arpeggio.append(self.descArp())
        self.descArp.reset([4, 5, 6, 7, 8, 9, 10, 11])
        arpeggio.append(self.descArp())
        self.assertEquals(arpeggio, [3, 2, 1, 5])

    def test_octave_arp_ascending(self):
        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4])
        for i in range(20):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio,
            [1, 2, 3, 4,
             13, 14, 15, 16,
             25, 26, 27, 28,
             37, 38, 39, 40,
             1, 2, 3, 4])

        arpeggio = []
        octaveArp = OctaveArp(DescArp(), [1, 2, 3, 4])
        for i in range(20):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio,
            [4, 3, 2, 1,
             16, 15, 14, 13,
             28, 27, 26, 25,
             40, 39, 38, 37,
             4, 3, 2, 1])

        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4], 1)
        for i in range(12):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio,
            [1, 2, 3, 4, 13, 14, 15, 16, 1, 2, 3, 4])

    def test_octave_arp_descending(self):
        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4], direction=-1)
        for i in range(20):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio,
            [37, 38, 39, 40,
             25, 26, 27, 28,
             13, 14, 15, 16,
             1, 2, 3, 4,
             37, 38, 39, 40])

    def test_octave_arp_with_0_octaves(self):
        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4], 0)
        for i in range(8):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio,
            [1, 2, 3, 4, 1, 2, 3, 4])

    def test_octave_arp_oscillate(self):
        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4], oscillate=True)
        for i in range(36):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio,
            [1, 2, 3, 4,
             13, 14, 15, 16,
             25, 26, 27, 28,
             37, 38, 39, 40,
             25, 26, 27, 28,
             13, 14, 15, 16,
             1, 2, 3, 4,
             13, 14, 15, 16,
             25, 26, 27, 28])

    def test_adder(self):
        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4])
        adder = Adder(octaveArp)
        for i in range(16):
            arpeggio.append(adder())
        self.assertEquals(arpeggio,
            [1, 2, 3, 4,
             13, 14, 15, 16,
             25, 26, 27, 28,
             37, 38, 39, 40])
        adder.amount = 2
        arpeggio = []
        for i in range(16):
            arpeggio.append(adder())
        self.assertEquals(arpeggio,
            [v + 2 for v in
             [1, 2, 3, 4,
              13, 14, 15, 16,
              25, 26, 27, 28,
              37, 38, 39, 40]])

    def test_empty_arps(self):
        for klass in (AscArp, DescArp, OrderedArp):
            a = klass([])
            for i in range(4):
                a()

    def test_paradiddle_patterns(self):
        notes = [1, 2]
        single = SingleParadiddle(notes)
        pattern = [single() for i in range(16)]
        self.assertEquals(pattern,
            [1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2])

        double = DoubleParadiddle(notes)
        pattern = [double() for i in range(24)]
        self.assertEqual(pattern,
            [1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2] * 2)

        triple = TripleParadiddle(notes)
        pattern = [triple() for i in range(32)]
        self.assertEqual(pattern,
            [1, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2, 2] * 2)

        pdd = ParadiddleDiddle(notes)
        pattern = [pdd() for i in range(24)]
        self.assertEqual(pattern,
            [1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 2,
             2, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 1])

    def test_arp_map(self):
        random.seed(0)
        arpmap = ArpMap(lambda x: x * 2, OrderedArp([1, 2, 3]))
        results = [arpmap() for i in range(6)]
        self.assertEqual(results, [2, 4, 6, 2, 4, 6])
        arpmap = ArpMap(lambda x: x * 2, RandomArp([1, 2, lambda: 3]))
        results = [arpmap() for i in range(6)]
        self.assertEqual(results, [6, 4, 2, 6, 2, 6])

    def test_pattern_arp(self):
        pattern = [0, 1, 2, 0, 0, 3, 2]
        notes = [1, 2, 3, 4]
        arp = PatternArp(notes, pattern)
        played = [arp() for i in range(14)]
        self.assertEqual(played, [1, 2, 3, 1, 1, 4, 3] * 2)
        arp.resetPattern([0, 0, 1, 1])
        played = [arp() for i in range(4)]
        self.assertEqual(played, [1, 1, 2, 2])
        arp.resetPattern(cycle([0, 1, 2, 3]).next)
        played = [arp() for i in range(8)]
        self.assertEqual(played, [1, 2, 3, 4, 1, 2, 3, 4])

    def test_chord_pattern_arp(self):
        pattern = [0, 1, 2, [1, 2, 3], 3, 2, 1]
        notes = [1, 2, 3, 4]
        arp = ChordPatternArp(notes, pattern)
        played = [arp() for i in range(14)]
        self.assertEqual(played,
                         [(1,), (2,), (3,), [2, 3, 4], (4,), (3,), (2,)] * 2)
コード例 #8
0
 def setUp(self):
     self.arpeggio = arpeggio = [0, 2, 1, 3]
     self.ascArp = AscArp(arpeggio)
     self.descArp = DescArp(arpeggio)
     self.ordArp = OrderedArp(arpeggio)
     self.randArp = RandomArp(arpeggio)
コード例 #9
0
 def test_octave_arp_with_0_octaves(self):
     arpeggio = []
     octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4], 0)
     for i in range(8):
         arpeggio.append(octaveArp())
     self.assertEquals(arpeggio, [1, 2, 3, 4, 1, 2, 3, 4])
コード例 #10
0
class ArpTests(TestCase):
    def setUp(self):
        self.arpeggio = arpeggio = [0, 2, 1, 3]
        self.ascArp = AscArp(arpeggio)
        self.descArp = DescArp(arpeggio)
        self.ordArp = OrderedArp(arpeggio)
        self.randArp = RandomArp(arpeggio)

    def test_ascArp(self):
        arpeggio = []
        for i in range(8):
            arpeggio.append(self.ascArp())
        self.assertEquals(arpeggio, [0, 1, 2, 3, 0, 1, 2, 3])

    def test_descArp(self):
        arpeggio = []
        for i in range(8):
            arpeggio.append(self.descArp())
        self.assertEquals(arpeggio, [3, 2, 1, 0, 3, 2, 1, 0])

    def test_orderedArp(self):
        arpeggio = []
        for i in range(8):
            arpeggio.append(self.ordArp())
        self.assertEquals(arpeggio, [0, 2, 1, 3, 0, 2, 1, 3])

    def test_randomArp(self):
        r = cycle([1, 2, 0, 0, 2, 0, 1, 0])

        class myrandom:
            @classmethod
            def randint(cls, *blah):
                return r.next()

        self.patch(arp, 'random', myrandom)

        arpeggio = []
        for i in range(8):
            arpeggio.append(self.randArp())
        self.assertEquals(arpeggio, [2, 3, 0, 1, 0, 2, 1, 3])

    def test_numeric_sorting(self):
        """
        Test that numeric values are sorted correctly and
        non-numeric values retain their position in the arpeggio.
        """
        arpeggio = []
        ascarp = AscArp([1, 3, N, 2])
        for i in range(8):
            arpeggio.append(ascarp())
        self.assertEquals(arpeggio, [1, 2, None, 3, 1, 2, None, 3])

    def test_resetting(self):
        """
        Test various behaviors of resetting values on an arp midstream.
        """

        arpeggio = []
        for i in range(2):
            arpeggio.append(self.ascArp())
        self.ascArp.reset([5, 6, 7, 8])
        for i in range(2):
            arpeggio.append(self.ascArp())
        self.assertEquals(arpeggio, [0, 1, 7, 8])

        arpeggio = []
        self.ascArp.reset([0, 1, 2, 3])
        for i in range(3):
            arpeggio.append(self.ascArp())
        self.ascArp.reset([5, 6])
        arpeggio.append(self.ascArp())
        self.assertEquals(arpeggio, [0, 1, 2, 6])

        arpeggio = []
        self.ascArp.reset([0, 1, 2, 3])
        for i in range(3):
            arpeggio.append(self.ascArp())
        self.ascArp.reset([4, 5, 6, 7, 8, 9, 10, 11])
        arpeggio.append(self.ascArp())
        self.assertEquals(arpeggio, [0, 1, 2, 10])

        arpeggio = []
        for i in range(2):
            arpeggio.append(self.descArp())
        self.descArp.reset([5, 6, 7, 8])
        for i in range(2):
            arpeggio.append(self.descArp())
        self.assertEquals(arpeggio, [3, 2, 6, 5])

        arpeggio = []
        self.descArp.reset([0, 1, 2, 3])
        for i in range(3):
            arpeggio.append(self.descArp())
        self.descArp.reset([5, 6])
        arpeggio.append(self.descArp())
        self.assertEquals(arpeggio, [3, 2, 1, 5])

        arpeggio = []
        self.descArp.reset([0, 1, 2, 3])
        for i in range(3):
            arpeggio.append(self.descArp())
        self.descArp.reset([4, 5, 6, 7, 8, 9, 10, 11])
        arpeggio.append(self.descArp())
        self.assertEquals(arpeggio, [3, 2, 1, 5])

    def test_octave_arp_ascending(self):
        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4])
        for i in range(20):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio, [
            1, 2, 3, 4, 13, 14, 15, 16, 25, 26, 27, 28, 37, 38, 39, 40, 1, 2,
            3, 4
        ])

        arpeggio = []
        octaveArp = OctaveArp(DescArp(), [1, 2, 3, 4])
        for i in range(20):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio, [
            4, 3, 2, 1, 16, 15, 14, 13, 28, 27, 26, 25, 40, 39, 38, 37, 4, 3,
            2, 1
        ])

        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4], 1)
        for i in range(12):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio, [1, 2, 3, 4, 13, 14, 15, 16, 1, 2, 3, 4])

    def test_octave_arp_descending(self):
        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4], direction=-1)
        for i in range(20):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio, [
            37, 38, 39, 40, 25, 26, 27, 28, 13, 14, 15, 16, 1, 2, 3, 4, 37, 38,
            39, 40
        ])

    def test_octave_arp_with_0_octaves(self):
        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4], 0)
        for i in range(8):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio, [1, 2, 3, 4, 1, 2, 3, 4])

    def test_octave_arp_oscillate(self):
        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4], oscillate=True)
        for i in range(36):
            arpeggio.append(octaveArp())
        self.assertEquals(arpeggio, [
            1, 2, 3, 4, 13, 14, 15, 16, 25, 26, 27, 28, 37, 38, 39, 40, 25, 26,
            27, 28, 13, 14, 15, 16, 1, 2, 3, 4, 13, 14, 15, 16, 25, 26, 27, 28
        ])

    def test_adder(self):
        arpeggio = []
        octaveArp = OctaveArp(AscArp(), [1, 2, 3, 4])
        adder = Adder(octaveArp)
        for i in range(16):
            arpeggio.append(adder())
        self.assertEquals(
            arpeggio,
            [1, 2, 3, 4, 13, 14, 15, 16, 25, 26, 27, 28, 37, 38, 39, 40])
        adder.amount = 2
        arpeggio = []
        for i in range(16):
            arpeggio.append(adder())
        self.assertEquals(arpeggio, [
            v + 2 for v in
            [1, 2, 3, 4, 13, 14, 15, 16, 25, 26, 27, 28, 37, 38, 39, 40]
        ])

    def test_empty_arps(self):
        for klass in (AscArp, DescArp, OrderedArp):
            a = klass([])
            for i in range(4):
                a()

    def test_paradiddle_patterns(self):
        notes = [1, 2]
        single = SingleParadiddle(notes)
        pattern = [single() for i in range(16)]
        self.assertEquals(pattern,
                          [1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2])

        double = DoubleParadiddle(notes)
        pattern = [double() for i in range(24)]
        self.assertEqual(pattern, [1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2] * 2)

        triple = TripleParadiddle(notes)
        pattern = [triple() for i in range(32)]
        self.assertEqual(pattern,
                         [1, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2, 2] * 2)

        pdd = ParadiddleDiddle(notes)
        pattern = [pdd() for i in range(24)]
        self.assertEqual(pattern, [
            1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 2, 2, 1, 2, 2, 1, 1, 2, 1, 2, 2,
            1, 1
        ])

    def test_arp_map(self):
        random.seed(0)
        arpmap = ArpMap(lambda x: x * 2, OrderedArp([1, 2, 3]))
        results = [arpmap() for i in range(6)]
        self.assertEqual(results, [2, 4, 6, 2, 4, 6])
        arpmap = ArpMap(lambda x: x * 2, RandomArp([1, 2, lambda: 3]))
        results = [arpmap() for i in range(6)]
        self.assertEqual(results, [6, 4, 2, 6, 2, 6])

    def test_pattern_arp(self):
        pattern = [0, 1, 2, 0, 0, 3, 2]
        notes = [1, 2, 3, 4]
        arp = PatternArp(notes, pattern)
        played = [arp() for i in range(14)]
        self.assertEqual(played, [1, 2, 3, 1, 1, 4, 3] * 2)
        arp.resetPattern([0, 0, 1, 1])
        played = [arp() for i in range(4)]
        self.assertEqual(played, [1, 1, 2, 2])
        arp.resetPattern(cycle([0, 1, 2, 3]).next)
        played = [arp() for i in range(8)]
        self.assertEqual(played, [1, 2, 3, 4, 1, 2, 3, 4])

    def test_chord_pattern_arp(self):
        pattern = [0, 1, 2, [1, 2, 3], 3, 2, 1]
        notes = [1, 2, 3, 4]
        arp = ChordPatternArp(notes, pattern)
        played = [arp() for i in range(14)]
        self.assertEqual(played, [(1, ), (2, ), (3, ), [2, 3, 4], (4, ), (3, ),
                                  (2, )] * 2)