예제 #1
0
    def __init__(self, grid, x, y, *, is_passive=False):
        super().__init__(
            grid,
            x,
            y,
            "midi",
            "Send MIDI note",
            glyph=":",
            is_passive=True,
        )

        self.ports.update(
            {
                "channel": InputPort(self.x + 1, self.y),
                "octave": InputPort(
                    self.x + 2, self.y, clamp=lambda x: min(max(0, x), 8)
                ),
                "note": InputPort(self.x + 3, self.y),
                "velocity": InputPort(
                    self.x + 4, self.y, default="f", clamp=lambda x: min(max(0, x), 16)
                ),
                "length": InputPort(
                    self.x + 5, self.y, clamp=lambda x: min(max(0, x), 32)
                ),
            }
        )
예제 #2
0
    def __init__(self, grid, x, y, *, is_passive=False):
        super().__init__(
            grid, x, y, "add", "Output sum of inputs", glyph="a", is_passive=is_passive
        )

        self.ports.update(
            {
                "a": InputPort(x - 1, y),
                "b": InputPort(x + 1, y),
                OUTPUT_PORT_NAME: OutputPort(x, y + 1, is_sensitive=True),
            }
        )
예제 #3
0
 def __init__(self, grid, x, y, *, is_passive=False):
     super().__init__(
         grid,
         x,
         y,
         "generator",
         "Write operands with offset",
         glyph="g",
         is_passive=is_passive,
     )
     self.ports.update(
         {
             "x": InputPort(x - 3, y),
             "y": InputPort(x - 2, y),
             "len": InputPort(x - 1, y, clamp=lambda x: max(x, 1)),
         }
     )
예제 #4
0
 def __init__(self, grid, x, y, *, is_passive=False):
     super().__init__(
         grid,
         x,
         y,
         "track",
         "Reads eastward operand",
         glyph="t",
         is_passive=is_passive,
     )
     self.ports.update(
         {
             "key": InputPort(x - 2, y),
             "len": InputPort(x - 1, y, clamp=lambda x: max(1, x)),
             OUTPUT_PORT_NAME: OutputPort(x, y + 1),
         }
     )
예제 #5
0
 def __init__(self, grid, x, y, *, is_passive=False):
     super().__init__(
         grid,
         x,
         y,
         "increment",
         "Increment operator southward",
         glyph="i",
         is_passive=is_passive,
     )
     self.ports.update(
         {
             "step": InputPort(x - 1, y, default="1"),
             "mod": InputPort(x + 1, y),
             OUTPUT_PORT_NAME: OutputPort(x, y + 1, is_sensitive=True),
         }
     )
예제 #6
0
    def __init__(self, grid, x, y, *, is_passive=False):
        super().__init__(
            grid,
            x,
            y,
            "random",
            "Outputs random value",
            glyph="r",
            is_passive=is_passive,
        )

        self.ports.update(
            {
                "min": InputPort(x - 1, y),
                "max": InputPort(x + 1, y),
                OUTPUT_PORT_NAME: OutputPort(x, y + 1, is_sensitive=True),
            }
        )
예제 #7
0
    def operation(self, frame, force=False):
        key = self._grid.listen_as_value(self.ports["key"])
        length = self._grid.listen_as_value(self.ports["len"])

        for offset in range(length):
            self._grid.lock(self.x + offset + 1, self.y)

        port = InputPort(self.x + 1 + key % length, self.y)
        return self._grid.listen(port)
예제 #8
0
    def __init__(self, grid, x, y, *, is_passive=False):
        super().__init__(
            grid,
            x,
            y,
            "if",
            "Bang if inputs are equal",
            glyph="f",
            is_passive=is_passive,
        )

        self.ports.update(
            {
                "a": InputPort(x - 1, y),
                "b": InputPort(x + 1, y),
                OUTPUT_PORT_NAME: OutputPort(x, y + 1, is_bang=True),
            }
        )
예제 #9
0
    def __init__(self, grid, x, y, *, is_passive=False):
        super().__init__(
            grid,
            x,
            y,
            "delay",
            "Bangs on module of frame",
            glyph="d",
            is_passive=is_passive,
        )

        self.ports.update(
            {
                "rate": InputPort(x - 1, y, clamp=lambda x: max(1, x)),
                "mod": InputPort(x + 1, y, default="8"),
                OUTPUT_PORT_NAME: OutputPort(x, y + 1, is_bang=True),
            }
        )
예제 #10
0
    def __init__(self, grid, x, y, *, is_passive=False):
        super().__init__(
            grid,
            x,
            y,
            "clock",
            "Outputs modulo of frame",
            glyph="c",
            is_passive=is_passive,
        )

        self.ports.update(
            {
                "rate": InputPort(x - 1, y, clamp=lambda x: max(1, x)),
                "mod": InputPort(x + 1, y, default="8"),
                OUTPUT_PORT_NAME: OutputPort(x, y + 1, is_sensitive=True),
            }
        )
예제 #11
0
    def __init__(self, grid, x, y, *, is_passive=False):
        super().__init__(
            grid,
            x,
            y,
            "substract",
            "Output difference of inputs",
            glyph="b",
            is_passive=is_passive,
        )

        self.ports.update(
            {
                "a": InputPort(x - 1, y),
                "b": InputPort(x + 1, y),
                OUTPUT_PORT_NAME: OutputPort(x, y + 1, is_sensitive=True),
            }
        )
예제 #12
0
 def _should_upper_case(self):
     output_port = self._output_port
     if output_port is None or not output_port.is_sensitive:
         return False
     else:
         right_port = InputPort(self.x + 1, self.y)
         value = self._grid.listen(right_port)
         if value.lower() == value.upper() or value.upper() != value:
             return False
         else:
             return True
예제 #13
0
    def operation(self, frame, force=False):
        length = self._grid.listen_as_value(self.ports["len"])
        x = self._grid.listen_as_value(self.ports["x"])
        y = self._grid.listen_as_value(self.ports["y"]) + 1

        for offset in range(length):
            input_port = InputPort(self.x + offset + 1, self.y)
            output_port = OutputPort(self.x + x + offset, self.y + y)
            self.ports.update(
                {
                    f"input{offset}": input_port,
                    f"output{offset}": output_port,
                }
            )
            res = self._grid.listen(input_port)
            self._output(res, output_port)
예제 #14
0
    def __init__(self, grid, x, y, *, is_passive=False):
        super().__init__(
            grid,
            x,
            y,
            "y",
            "Outputs westward operator",
            glyph="y",
            is_passive=is_passive,
        )

        self.ports.update(
            {
                "val": InputPort(x - 1, y),
                OUTPUT_PORT_NAME: OutputPort(x + 1, y),
            }
        )
예제 #15
0
    def __init__(self, grid, x, y, *, is_passive=False):
        super().__init__(
            grid,
            x,
            y,
            "j",
            "Outputs northward operator",
            glyph="f",
            is_passive=is_passive,
        )

        self.ports.update(
            {
                "val": InputPort(x, y - 1),
                OUTPUT_PORT_NAME: OutputPort(x, y + 1),
            }
        )
예제 #16
0
    def test_listen_as_value_default(self):
        # Given
        grid = O(".A.\n*.c")

        # When
        port = InputPort(0, 0)
        value = grid.listen_as_value(port)

        # Then
        assert value == 0

        # When
        port = InputPort(0, 1)
        value = grid.listen_as_value(port)

        # Then
        assert value == 0

        # When
        # we listen to a dot port with a default value
        port = InputPort(0, 0, default="3")
        value = grid.listen_as_value(port)

        # Then
        # we get the default value
        assert value == 3

        # When
        # we listen to a bang port with a default value
        port = InputPort(0, 1, default="4")
        value = grid.listen_as_value(port)

        # Then
        # we get the default value
        assert value == 4

        # When
        port = InputPort(1, 0, default="+")
        value = grid.listen_as_value(port)

        # Then
        assert value == 10

        # When
        port = InputPort(3, 3, default="+")
        value = grid.listen_as_value(port)

        # Then
        assert value == 0
예제 #17
0
    def test_listen_default(self):
        # Given
        grid = O(".A.\n*.c")

        # When
        port = InputPort(0, 0)
        value = grid.listen(port)

        # Then
        assert value == DOT_GLYPH

        # When
        port = InputPort(0, 1)
        value = grid.listen(port)

        # Then
        assert value == BANG_GLYPH

        # When
        # we listen to a dot port with a default value
        port = InputPort(0, 0, default="+")
        value = grid.listen(port)

        # Then
        # we get the default value
        assert value == "+"

        # When
        # we listen to a bang port with a default value
        port = InputPort(0, 1, default="+")
        value = grid.listen(port)

        # Then
        # we get the default value
        assert value == "+"

        # When
        port = InputPort(1, 0, default="+")
        value = grid.listen(port)

        # Then
        assert value == "A"

        # When
        port = InputPort(3, 3, default="+")
        value = grid.listen(port)

        # Then
        assert value is None