Ejemplo n.º 1
0
def test_audio_node_disconnect(audio_graph):
    node1 = InternalAudioNode()
    node2 = InternalAudioNode()

    n = node1.connect(node2).disconnect(node2)

    assert (node1, node2, 0, 0) not in audio_graph.connections
    assert n is node1
Ejemplo n.º 2
0
def test_audio_node_chain(audio_graph):
    node1 = InternalAudioNode()
    node2 = InternalAudioNode()
    node3 = InternalAudioNode()

    n = node1.chain(node2, node3)

    assert (node1, node2, 0, 0) in audio_graph.connections
    assert (node2, node3, 0, 0) in audio_graph.connections
    assert n is node1
Ejemplo n.º 3
0
def test_pyaudionode(audio_graph):
    in_node_in = InternalAudioNode()
    in_node_out = InternalAudioNode()
    in_node = PyAudioNode(in_node_in, in_node_out)
    out_node = InternalAudioNode()
    node = PyAudioNode(in_node, out_node, name="test")

    assert node.disposed is False
    assert node.number_of_inputs == 1
    assert node.number_of_outputs == 1
    assert node.channel_count == 2
    assert node.channel_count_mode == "max"
    assert node.channel_interpretation == "speakers"
    assert repr(node) == "PyAudioNode(name='test')"

    assert node.input is in_node
    assert node.output is out_node

    assert isinstance(node.widget, PyInternalAudioNode)
    assert node.widget.input is in_node_in
    assert node.widget.output is out_node

    node2 = InternalAudioNode()
    n = node.connect(node2)
    assert (node.widget, node2, 0, 0) in audio_graph.connections
    assert n is node

    node3 = InternalAudioNode()
    node3.connect(node)
    assert (node3, node.widget, 0, 0) in audio_graph.connections

    n = node.disconnect(node2)
    assert (node.widget, node2, 0, 0) not in audio_graph.connections
    assert n is node

    node4 = InternalAudioNode()
    node5 = InternalAudioNode()
    n = node.fan(node4, node5)
    assert (node.widget, node4, 0, 0) in audio_graph.connections
    assert (node.widget, node5, 0, 0) in audio_graph.connections
    assert n is node

    node6 = InternalAudioNode()
    node7 = InternalAudioNode()
    n = node.chain(node6, node7)
    assert (node.widget, node6, 0, 0) in audio_graph.connections
    assert (node6, node7, 0, 0) in audio_graph.connections
    assert n is node

    n = node.to_destination()
    assert (node.widget, destination, 0, 0) in audio_graph.connections
    assert n is node

    n = node.dispose()
    assert node.disposed is True
    assert n is node
Ejemplo n.º 4
0
def test_audio_node_to_destination(audio_graph):
    node = InternalAudioNode()

    n = node.to_destination()

    assert (node, destination, 0, 0) in audio_graph.connections
    assert n is node
Ejemplo n.º 5
0
def test_audio_node_dispose(audio_graph):
    in_node = InternalAudioNode()
    out_node = InternalAudioNode()
    node1 = AudioNode(_input=in_node, _output=out_node)
    node2 = InternalAudioNode()

    node1.connect(node2)

    assert node1.disposed is False
    assert (node1, node2, 0, 0) in audio_graph.connections

    node1.dispose()

    assert node1.disposed is True
    assert in_node.disposed is True
    assert out_node.disposed is True
    assert (node1, node2, 0, 0) not in audio_graph.connections
Ejemplo n.º 6
0
def test_audio_graph_errors(audio_graph):
    src = InternalAudioNode()
    dest = InternalAudioNode()
    param = Param()

    with pytest.raises(ValueError, match=".*not connected to.*"):
        audio_graph.disconnect(src, dest)

    with pytest.raises(ValueError, match="src_node must be.*"):
        audio_graph.connect(param, dest)

    with pytest.raises(ValueError, match=".*dest_node must be.*"):
        audio_graph.connect(src, "not a node")

    src = InternalAudioNode()
    dest = InternalAudioNode(_n_inputs=0)
    with pytest.raises(ValueError, match="Cannot connect to audio source.*"):
        audio_graph.connect(src, dest)

    src = InternalAudioNode(_n_outputs=0)
    dest = InternalAudioNode()
    with pytest.raises(ValueError, match="Cannot connect from audio sink.*"):
        audio_graph.connect(src, dest)
Ejemplo n.º 7
0
def test_internal_audio_node():
    node = InternalAudioNode(type="test")

    assert node.number_of_inputs == 1
    assert node.number_of_outputs == 1
    assert repr(node) == "InternalAudioNode(type='test')"
Ejemplo n.º 8
0
import pytest

from ipytone.base import NativeAudioNode, NativeAudioParam
from ipytone.core import InternalAudioNode, Param


@pytest.mark.parametrize(
    "src,dest,param",
    [
        (InternalAudioNode(), InternalAudioNode(), Param()),
        (NativeAudioNode(), NativeAudioNode(), NativeAudioParam()),
    ],
)
def test_audio_graph(audio_graph, src, dest, param):
    with audio_graph.hold_state():
        audio_graph.connect(src, dest)
        assert (src, dest, 0, 0) not in audio_graph.connections
    assert (src, dest, 0, 0) in audio_graph.connections

    audio_graph.connect(src, param, 0, 1)
    assert (src, param, 0, 1) in audio_graph.connections

    assert audio_graph.nodes == list({src, dest, param})
    assert audio_graph.connections == [(src, dest, 0, 0), (src, param, 0, 1)]

    with audio_graph.hold_state():
        audio_graph.disconnect(src, dest)
        assert (src, dest, 0, 0) in audio_graph.connections
    assert (src, dest, 0, 0) not in audio_graph.connections