コード例 #1
0
def test_quantizationtools_QGrid_pickle_01():
    q_grid = quantizationtools.QGrid(
        root_node=quantizationtools.QGridContainer(
            preprolated_duration=1,
            children=[
                quantizationtools.QGridLeaf(
                    preprolated_duration=1,
                    q_event_proxies=[
                        quantizationtools.QEventProxy(
                            quantizationtools.SilentQEvent(100),
                            0.5,
                            ),
                        ],
                    ),
                ],
            ),
        next_downbeat=quantizationtools.QGridLeaf(
            preprolated_duration=1,
            q_event_proxies=[
                quantizationtools.QEventProxy(
                    quantizationtools.TerminalQEvent(200),
                    0.9,
                    ),
                ],
            ),
        )
    pickled = pickle.loads(pickle.dumps(q_grid))

    assert format(pickled) == format(q_grid)
    assert pickled is not q_grid
    assert pickled != q_grid, \
        systemtools.TestManager.diff(pickled, q_grid, 'Diff:')
def test_quantizationtools_QGridContainer___eq___02():

    a = quantizationtools.QGridContainer(
        preprolated_duration=1,
        children=[quantizationtools.QGridLeaf(preprolated_duration=1)])
    b = quantizationtools.QGridContainer(
        preprolated_duration=1,
        children=[quantizationtools.QGridLeaf(preprolated_duration=1)])

    assert format(a) == format(b)
    assert a != b
コード例 #3
0
def test_quantizationtools_QGrid___eq___02():
    a = quantizationtools.QGrid(
        root_node=quantizationtools.QGridContainer(
            preprolated_duration=1,
            children=[
                quantizationtools.QGridLeaf(
                    preprolated_duration=1,
                    q_event_proxies=[
                        quantizationtools.QEventProxy(
                            quantizationtools.SilentQEvent(100),
                            0.5,
                        ),
                    ],
                ),
            ],
        ),
        next_downbeat=quantizationtools.QGridLeaf(
            preprolated_duration=1,
            q_event_proxies=[
                quantizationtools.QEventProxy(
                    quantizationtools.TerminalQEvent(200),
                    0.9,
                ),
            ],
        ),
    )
    b = quantizationtools.QGrid(
        root_node=quantizationtools.QGridContainer(
            preprolated_duration=1,
            children=[
                quantizationtools.QGridLeaf(
                    preprolated_duration=1,
                    q_event_proxies=[
                        quantizationtools.QEventProxy(
                            quantizationtools.SilentQEvent(100),
                            0.5,
                        ),
                    ],
                ),
            ],
        ),
        next_downbeat=quantizationtools.QGridLeaf(
            preprolated_duration=1,
            q_event_proxies=[
                quantizationtools.QEventProxy(
                    quantizationtools.TerminalQEvent(200),
                    0.9,
                ),
            ],
        ),
    )
    assert format(a) == format(b)
    assert a != b
コード例 #4
0
def test_quantizationtools_QGrid___eq___03():
    a = quantizationtools.QGrid()
    b = quantizationtools.QGrid(root_node=quantizationtools.QGridContainer(
        preprolated_duration=1,
        children=[
            quantizationtools.QGridLeaf(
                preprolated_duration=1,
                q_event_proxies=[
                    quantizationtools.QEventProxy(
                        quantizationtools.SilentQEvent(100), 0.5)
                ],
            ),
        ],
    ), )
    c = quantizationtools.QGrid(next_downbeat=quantizationtools.QGridLeaf(
        preprolated_duration=1,
        q_event_proxies=[
            quantizationtools.QEventProxy(
                quantizationtools.TerminalQEvent(200), 0.9),
        ],
    ), )
    d = quantizationtools.QGrid(
        root_node=quantizationtools.QGridContainer(
            preprolated_duration=1,
            children=[
                quantizationtools.QGridLeaf(
                    preprolated_duration=1,
                    q_event_proxies=[
                        quantizationtools.QEventProxy(
                            quantizationtools.SilentQEvent(100), 0.5),
                    ],
                ),
            ],
        ),
        next_downbeat=quantizationtools.QGridLeaf(
            preprolated_duration=1,
            q_event_proxies=[
                quantizationtools.QEventProxy(
                    quantizationtools.TerminalQEvent(200),
                    0.9,
                ),
            ],
        ),
    ),

    assert a != b
    assert a != c
    assert a != d
    assert b != c
    assert b != d
    assert c != d
コード例 #5
0
ファイル: QGrid.py プロジェクト: mscuthbert/abjad
 def __init__(self, root_node=None, next_downbeat=None):
     from abjad.tools import quantizationtools
     if root_node is None:
         root_node = quantizationtools.QGridLeaf(preprolated_duration=1)
     assert isinstance(
         root_node,
         (quantizationtools.QGridLeaf, quantizationtools.QGridContainer))
     if next_downbeat is None:
         next_downbeat = quantizationtools.QGridLeaf(preprolated_duration=1)
     assert isinstance(next_downbeat, quantizationtools.QGridLeaf)
     self._root_node = root_node
     self._next_downbeat = next_downbeat
     self._next_downbeat._offset = durationtools.Offset(1)
     self._next_downbeat._offsets_are_current = True
コード例 #6
0
def test_quantizationtools_QGridLeaf___copy___02():
    leaf = quantizationtools.QGridLeaf(2, [
        quantizationtools.QEventProxy(quantizationtools.SilentQEvent(1000), 0.5)
        ])
    copied = copy.copy(leaf)
    assert format(leaf) == format(copied)
    assert leaf != copied
    assert leaf is not copied
コード例 #7
0
def test_quantizationtools_QGridLeaf___eq___02():
    a = quantizationtools.QGridLeaf(1, [])
    b = quantizationtools.QGridLeaf(1, [
        quantizationtools.QEventProxy(quantizationtools.SilentQEvent(1000),
                                      0.5)
    ])
    c = quantizationtools.QGridLeaf(2, [])
    d = quantizationtools.QGridLeaf(2, [
        quantizationtools.QEventProxy(quantizationtools.SilentQEvent(1000),
                                      0.5)
    ])
    assert a != b
    assert a != c
    assert a != d
    assert b != c
    assert b != d
    assert c != d
def test_quantizationtools_QGridContainer___copy___01():

    tree = quantizationtools.QGridContainer(
        preprolated_duration=1,
        children=[
            quantizationtools.QGridLeaf(preprolated_duration=1),
            quantizationtools.QGridContainer(
                preprolated_duration=2,
                children=[
                    quantizationtools.QGridLeaf(preprolated_duration=3),
                    quantizationtools.QGridContainer(
                        preprolated_duration=4,
                        children=[
                            quantizationtools.QGridLeaf(
                                preprolated_duration=1),
                            quantizationtools.QGridLeaf(
                                preprolated_duration=1),
                            quantizationtools.QGridLeaf(preprolated_duration=1)
                        ])
                ]),
            quantizationtools.QGridLeaf(preprolated_duration=2)
        ])

    copied = copy.copy(tree)

    assert format(tree) == format(copied)
    assert tree is not copied
    assert tree[0] is not copied[0]
    assert tree[1] is not copied[1]
    assert tree[2] is not copied[2]
def test_quantizationtools_QGridContainer___eq___03():

    a = quantizationtools.QGridContainer(preprolated_duration=1, children=[])
    b = quantizationtools.QGridContainer(preprolated_duration=2, children=[])
    c = quantizationtools.QGridContainer(
        preprolated_duration=1,
        children=[quantizationtools.QGridLeaf(preprolated_duration=1)])
    d = quantizationtools.QGridContainer(
        preprolated_duration=2,
        children=[quantizationtools.QGridLeaf(preprolated_duration=1)])
    e = quantizationtools.QGridContainer(
        preprolated_duration=2, children=[quantizationtools.QGridLeaf(2)])

    assert a != b
    assert a != c
    assert a != d
    assert a != e
    assert b != c
    assert b != d
    assert b != e
    assert c != d
    assert c != e
    assert d != e
コード例 #10
0
def test_quantizationtools_QGrid_subdivide_leaf_01():

    q_grid = quantizationtools.QGrid()

    a = quantizationtools.QEventProxy(quantizationtools.PitchedQEvent(0, [0]), 0)
    b = quantizationtools.QEventProxy(quantizationtools.PitchedQEvent((9, 20), [1]), (9, 20))
    c = quantizationtools.QEventProxy(quantizationtools.PitchedQEvent((1, 2), [2]), (1, 2))
    d = quantizationtools.QEventProxy(quantizationtools.PitchedQEvent((11, 20), [3]), (11, 20))
    e = quantizationtools.QEventProxy(quantizationtools.PitchedQEvent(1, [4]), 1)

    q_grid.leaves[0].q_event_proxies.extend([a, b, c, d])
    q_grid.leaves[1].q_event_proxies.append(e)

    result = q_grid.subdivide_leaf(q_grid.leaves[0], (2, 3))

    assert result == [a, b, c, d]
    root_node = quantizationtools.QGridContainer(
        children=[
            quantizationtools.QGridLeaf(preprolated_duration=2, q_event_proxies=[]),
            quantizationtools.QGridLeaf(preprolated_duration=3, q_event_proxies=[]),
            ],
        preprolated_duration=1
        )
    assert format(q_grid.root_node) == format(root_node)
コード例 #11
0
ファイル: QGrid.py プロジェクト: mscuthbert/abjad
    def subdivide_leaf(self, leaf, subdivisions):
        r'''Replace the ``QGridLeaf`` ``leaf`` contained in a ``QGrid``
        by a ``QGridContainer`` containing ``QGridLeaves`` with durations
        equal to the ratio described in ``subdivisions``

        Returns the ``QEventProxies`` attached to ``leaf``.
        '''
        from abjad.tools import quantizationtools
        container = quantizationtools.QGridContainer(
            preprolated_duration=leaf.preprolated_duration,
            children=[
                quantizationtools.QGridLeaf(preprolated_duration=subdivision)
                for subdivision in subdivisions
            ])
        if leaf.parent is not None:
            index = leaf.parent.index(leaf)
            leaf.parent[index] = container
        # otherwise, our root node if just a QGridLeaf
        else:
            self._root_node = container
        return leaf.q_event_proxies
コード例 #12
0
def test_quantizationtools_QGridLeaf___copy___01():
    leaf = quantizationtools.QGridLeaf(1)
    copied = copy.copy(leaf)
    assert format(leaf) == format(copied)
    assert leaf != copied
    assert leaf is not copied
コード例 #13
0
def test_quantizationtools_QGridLeaf___eq___01():
    a = quantizationtools.QGridLeaf(1, [])
    b = quantizationtools.QGridLeaf(1, [])
    assert format(a) == format(b)
    assert a != b