Skip to content

File pypisoundmicro.py#

File List > build > lib.linux-armv7l-cpython-311 > pypisoundmicro > swig > pypisoundmicro.py

Go to the documentation of this file

# This file was automatically generated by SWIG (https://www.swig.org).
# Version 4.1.0
#
# Do not make changes to this file unless you know what you are doing - modify
# the SWIG interface file instead.

from sys import version_info as _swig_python_version_info
# Import the low-level C/C++ module
if __package__ or "." in __name__:
    from . import _pypisoundmicro
else:
    import _pypisoundmicro

try:
    import builtins as __builtin__
except ImportError:
    import __builtin__

def _swig_repr(self):
    try:
        strthis = "proxy of " + self.this.__repr__()
    except __builtin__.Exception:
        strthis = ""
    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)


def _swig_setattr_nondynamic_instance_variable(set):
    def set_instance_attr(self, name, value):
        if name == "this":
            set(self, name, value)
        elif name == "thisown":
            self.this.own(value)
        elif hasattr(self, name) and isinstance(getattr(type(self), name), property):
            set(self, name, value)
        else:
            raise AttributeError("You cannot add instance attributes to %s" % self)
    return set_instance_attr


def _swig_setattr_nondynamic_class_variable(set):
    def set_class_attr(cls, name, value):
        if hasattr(cls, name) and not isinstance(getattr(cls, name), property):
            set(cls, name, value)
        else:
            raise AttributeError("You cannot add class attributes to %s" % cls)
    return set_class_attr


def _swig_add_metaclass(metaclass):
    """Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass"""
    def wrapper(cls):
        return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())
    return wrapper


class _SwigNonDynamicMeta(type):
    """Meta class to enforce nondynamic attributes (no new attributes) for a class"""
    __setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)


UPISND_MAX_ELEMENT_NAME_LENGTH = _pypisoundmicro.UPISND_MAX_ELEMENT_NAME_LENGTH
r""" Maximum Element name length, the size includes the '``' character."""
UPISND_ELEMENT_TYPE_INVALID = _pypisoundmicro.UPISND_ELEMENT_TYPE_INVALID

UPISND_ELEMENT_TYPE_NONE = _pypisoundmicro.UPISND_ELEMENT_TYPE_NONE

UPISND_ELEMENT_TYPE_ENCODER = _pypisoundmicro.UPISND_ELEMENT_TYPE_ENCODER

UPISND_ELEMENT_TYPE_ANALOG_INPUT = _pypisoundmicro.UPISND_ELEMENT_TYPE_ANALOG_INPUT

UPISND_ELEMENT_TYPE_GPIO = _pypisoundmicro.UPISND_ELEMENT_TYPE_GPIO

UPISND_ELEMENT_TYPE_ACTIVITY = _pypisoundmicro.UPISND_ELEMENT_TYPE_ACTIVITY

UPISND_ELEMENT_TYPE_COUNT = _pypisoundmicro.UPISND_ELEMENT_TYPE_COUNT

UPISND_ACTIVITY_INVALID = _pypisoundmicro.UPISND_ACTIVITY_INVALID

UPISND_ACTIVITY_MIDI_INPUT = _pypisoundmicro.UPISND_ACTIVITY_MIDI_INPUT

UPISND_ACTIVITY_MIDI_OUTPUT = _pypisoundmicro.UPISND_ACTIVITY_MIDI_OUTPUT

UPISND_ACTIVITY_COUNT = _pypisoundmicro.UPISND_ACTIVITY_COUNT

UPISND_PIN_PULL_INVALID = _pypisoundmicro.UPISND_PIN_PULL_INVALID
r""" Invalid value."""
UPISND_PIN_PULL_NONE = _pypisoundmicro.UPISND_PIN_PULL_NONE

UPISND_PIN_PULL_UP = _pypisoundmicro.UPISND_PIN_PULL_UP

UPISND_PIN_PULL_DOWN = _pypisoundmicro.UPISND_PIN_PULL_DOWN

UPISND_PIN_PULL_COUNT = _pypisoundmicro.UPISND_PIN_PULL_COUNT

UPISND_PIN_DIR_INVALID = _pypisoundmicro.UPISND_PIN_DIR_INVALID

UPISND_PIN_DIR_INPUT = _pypisoundmicro.UPISND_PIN_DIR_INPUT

UPISND_PIN_DIR_OUTPUT = _pypisoundmicro.UPISND_PIN_DIR_OUTPUT

UPISND_PIN_DIR_COUNT = _pypisoundmicro.UPISND_PIN_DIR_COUNT

UPISND_PIN_A27 = _pypisoundmicro.UPISND_PIN_A27

UPISND_PIN_A28 = _pypisoundmicro.UPISND_PIN_A28

UPISND_PIN_A29 = _pypisoundmicro.UPISND_PIN_A29

UPISND_PIN_A30 = _pypisoundmicro.UPISND_PIN_A30

UPISND_PIN_A31 = _pypisoundmicro.UPISND_PIN_A31

UPISND_PIN_A32 = _pypisoundmicro.UPISND_PIN_A32

UPISND_PIN_B03 = _pypisoundmicro.UPISND_PIN_B03

UPISND_PIN_B04 = _pypisoundmicro.UPISND_PIN_B04

UPISND_PIN_B05 = _pypisoundmicro.UPISND_PIN_B05

UPISND_PIN_B06 = _pypisoundmicro.UPISND_PIN_B06

UPISND_PIN_B07 = _pypisoundmicro.UPISND_PIN_B07

UPISND_PIN_B08 = _pypisoundmicro.UPISND_PIN_B08

UPISND_PIN_B09 = _pypisoundmicro.UPISND_PIN_B09

UPISND_PIN_B10 = _pypisoundmicro.UPISND_PIN_B10

UPISND_PIN_B11 = _pypisoundmicro.UPISND_PIN_B11

UPISND_PIN_B12 = _pypisoundmicro.UPISND_PIN_B12

UPISND_PIN_B13 = _pypisoundmicro.UPISND_PIN_B13

UPISND_PIN_B14 = _pypisoundmicro.UPISND_PIN_B14

UPISND_PIN_B15 = _pypisoundmicro.UPISND_PIN_B15

UPISND_PIN_B16 = _pypisoundmicro.UPISND_PIN_B16

UPISND_PIN_B17 = _pypisoundmicro.UPISND_PIN_B17

UPISND_PIN_B18 = _pypisoundmicro.UPISND_PIN_B18

UPISND_PIN_B23 = _pypisoundmicro.UPISND_PIN_B23

UPISND_PIN_B24 = _pypisoundmicro.UPISND_PIN_B24

UPISND_PIN_B25 = _pypisoundmicro.UPISND_PIN_B25

UPISND_PIN_B26 = _pypisoundmicro.UPISND_PIN_B26

UPISND_PIN_B27 = _pypisoundmicro.UPISND_PIN_B27

UPISND_PIN_B28 = _pypisoundmicro.UPISND_PIN_B28

UPISND_PIN_B29 = _pypisoundmicro.UPISND_PIN_B29

UPISND_PIN_B30 = _pypisoundmicro.UPISND_PIN_B30

UPISND_PIN_B31 = _pypisoundmicro.UPISND_PIN_B31

UPISND_PIN_B32 = _pypisoundmicro.UPISND_PIN_B32

UPISND_PIN_B33 = _pypisoundmicro.UPISND_PIN_B33

UPISND_PIN_B34 = _pypisoundmicro.UPISND_PIN_B34

UPISND_PIN_B37 = _pypisoundmicro.UPISND_PIN_B37

UPISND_PIN_B38 = _pypisoundmicro.UPISND_PIN_B38

UPISND_PIN_B39 = _pypisoundmicro.UPISND_PIN_B39

UPISND_PIN_COUNT = _pypisoundmicro.UPISND_PIN_COUNT

UPISND_PIN_INVALID = _pypisoundmicro.UPISND_PIN_INVALID
r""" Value for indicating an invalid pin."""
UPISND_VALUE_MODE_INVALID = _pypisoundmicro.UPISND_VALUE_MODE_INVALID

UPISND_VALUE_MODE_CLAMP = _pypisoundmicro.UPISND_VALUE_MODE_CLAMP
r""" The value is clamped to input_min and input_max range."""
UPISND_VALUE_MODE_WRAP = _pypisoundmicro.UPISND_VALUE_MODE_WRAP
r""" The value is wrapped over to the other boundary of the input range."""
UPISND_VALUE_MODE_COUNT = _pypisoundmicro.UPISND_VALUE_MODE_COUNT

class upisnd_range_t(object):
    r""" Number range for input_min, input_max and value_low, value_high."""

    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr
    low = property(_pypisoundmicro.upisnd_range_t_low_get, _pypisoundmicro.upisnd_range_t_low_set, doc=r"""low : int""")
    high = property(_pypisoundmicro.upisnd_range_t_high_get, _pypisoundmicro.upisnd_range_t_high_set, doc=r"""high : int""")

    def __init__(self):
        r"""__init__(upisnd_range_t self) -> upisnd_range_t"""
        _pypisoundmicro.upisnd_range_t_swiginit(self, _pypisoundmicro.new_upisnd_range_t())
    __swig_destroy__ = _pypisoundmicro.delete_upisnd_range_t

# Register upisnd_range_t in _pypisoundmicro:
_pypisoundmicro.upisnd_range_t_swigregister(upisnd_range_t)
class upisnd_encoder_opts_t(object):
    r""" Encoder specific options."""

    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr
    input_range = property(_pypisoundmicro.upisnd_encoder_opts_t_input_range_get, _pypisoundmicro.upisnd_encoder_opts_t_input_range_set, doc=r"""input_range : upisnd_range_t""")
    value_range = property(_pypisoundmicro.upisnd_encoder_opts_t_value_range_get, _pypisoundmicro.upisnd_encoder_opts_t_value_range_set, doc=r"""value_range : upisnd_range_t""")
    value_mode = property(_pypisoundmicro.upisnd_encoder_opts_t_value_mode_get, _pypisoundmicro.upisnd_encoder_opts_t_value_mode_set, doc=r"""value_mode : upisnd_value_mode_e""")

    def __init__(self):
        r"""__init__(upisnd_encoder_opts_t self) -> upisnd_encoder_opts_t"""
        _pypisoundmicro.upisnd_encoder_opts_t_swiginit(self, _pypisoundmicro.new_upisnd_encoder_opts_t())
    __swig_destroy__ = _pypisoundmicro.delete_upisnd_encoder_opts_t

# Register upisnd_encoder_opts_t in _pypisoundmicro:
_pypisoundmicro.upisnd_encoder_opts_t_swigregister(upisnd_encoder_opts_t)
class upisnd_analog_input_opts_t(object):
    r""" Analog Input specific options."""

    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr
    input_range = property(_pypisoundmicro.upisnd_analog_input_opts_t_input_range_get, _pypisoundmicro.upisnd_analog_input_opts_t_input_range_set, doc=r"""input_range : upisnd_range_t""")
    value_range = property(_pypisoundmicro.upisnd_analog_input_opts_t_value_range_get, _pypisoundmicro.upisnd_analog_input_opts_t_value_range_set, doc=r"""value_range : upisnd_range_t""")

    def __init__(self):
        r"""__init__(upisnd_analog_input_opts_t self) -> upisnd_analog_input_opts_t"""
        _pypisoundmicro.upisnd_analog_input_opts_t_swiginit(self, _pypisoundmicro.new_upisnd_analog_input_opts_t())
    __swig_destroy__ = _pypisoundmicro.delete_upisnd_analog_input_opts_t

# Register upisnd_analog_input_opts_t in _pypisoundmicro:
_pypisoundmicro.upisnd_analog_input_opts_t_swigregister(upisnd_analog_input_opts_t)

def upisnd_init():
    r"""
     libpisoundmicro initialization function. Must be called once before using any other API.

    It is reference counted, so you may call it multiple times, you must call ::upisnd_uninit
    a matching number of times.

    Not thread-safe.

    :rtype: int
    :return: 0 on success, -1 on error, inspect `errno` for details.
    """
    return _pypisoundmicro.upisnd_init()

def upisnd_uninit():
    r"""
     libpisoundmicro uninitialization function.

    Takes care of releasing any remaining Elements.

    Not thread-safe.

    Must be called upon process cleanup, including when handling signals,
    the same number of times as ::upisnd_init was called.
    """
    return _pypisoundmicro.upisnd_uninit()

def upisnd_is_pin_valid(pin):
    r""" Checks validity of the provided pin number."""
    return _pypisoundmicro.upisnd_is_pin_valid(pin)

def upisnd_pin_to_str(pin):
    r""" Converts the provided pin to its string representation."""
    return _pypisoundmicro.upisnd_pin_to_str(pin)

def upisnd_str_to_pin(str):
    r"""
     Parses the provided string and returns the corresponding pin number.

    :rtype: upisnd_pin_t
    :return: The pin number, or #UPISND_PIN_INVALID if the string is not a valid pin number.
    """
    return _pypisoundmicro.upisnd_str_to_pin(str)

def upisnd_pin_pull_to_str(pull):
    r""" Converts the provided pin pull to its string representation."""
    return _pypisoundmicro.upisnd_pin_pull_to_str(pull)

def upisnd_str_to_pin_pull(str):
    r""" Parses the provided string and returns the corresponding pin pull."""
    return _pypisoundmicro.upisnd_str_to_pin_pull(str)

def upisnd_activity_to_str(activity):
    r""" Converts the provided activity type to its string representation."""
    return _pypisoundmicro.upisnd_activity_to_str(activity)

def upisnd_str_to_activity(str):
    r""" Parses the provided string and returns the corresponding activity type."""
    return _pypisoundmicro.upisnd_str_to_activity(str)

def upisnd_element_type_to_str(type):
    r""" Converts the provided element type to its string representation."""
    return _pypisoundmicro.upisnd_element_type_to_str(type)

def upisnd_str_to_element_type(str):
    r""" Parses the provided string and returns the corresponding element type."""
    return _pypisoundmicro.upisnd_str_to_element_type(str)

def upisnd_pin_direction_to_str(dir):
    r""" Converts the provided pin direction to its string representation."""
    return _pypisoundmicro.upisnd_pin_direction_to_str(dir)

def upisnd_str_to_pin_direction(str):
    r""" Parses the provided string and returns the corresponding pin direction."""
    return _pypisoundmicro.upisnd_str_to_pin_direction(str)

def upisnd_value_mode_to_str(mode):
    r""" Converts the provided value mode to its string representation."""
    return _pypisoundmicro.upisnd_value_mode_to_str(mode)

def upisnd_str_to_value_mode(str):
    r""" Parses the provided string and returns the corresponding value mode."""
    return _pypisoundmicro.upisnd_str_to_value_mode(str)

def upisnd_setup_for_encoder(setup, pin_a, pull_a, pin_b, pull_b):
    r""" Initialize upisnd_setup_t with options for Encoder."""
    return _pypisoundmicro.upisnd_setup_for_encoder(setup, pin_a, pull_a, pin_b, pull_b)

def upisnd_setup_for_analog_input(setup, pin):
    r""" Initialize upisnd_setup_t with options for Analog Input."""
    return _pypisoundmicro.upisnd_setup_for_analog_input(setup, pin)

def upisnd_setup_for_gpio_input(setup, pin, pull):
    r""" Initialize upisnd_setup_t with options for GPIO Input."""
    return _pypisoundmicro.upisnd_setup_for_gpio_input(setup, pin, pull)

def upisnd_setup_for_gpio_output(setup, pin, high):
    r""" Initialize upisnd_setup_t with options for GPIO Output."""
    return _pypisoundmicro.upisnd_setup_for_gpio_output(setup, pin, high)

def upisnd_setup_for_activity(setup, pin, activity):
    r""" Initialize upisnd_setup_t with options for Activity Element."""
    return _pypisoundmicro.upisnd_setup_for_activity(setup, pin, activity)

def upisnd_setup_get_element_type(setup):
    r""" Extracts the Element type from the setup container."""
    return _pypisoundmicro.upisnd_setup_get_element_type(setup)

def upisnd_setup_get_pin_id(setup):
    r""" Extracts the main pin from the setup container."""
    return _pypisoundmicro.upisnd_setup_get_pin_id(setup)

def upisnd_setup_get_gpio_pull(setup):
    r""" Extracts the GPIO pull from the setup container, applies to GPIO Input and the first pin of Encoder."""
    return _pypisoundmicro.upisnd_setup_get_gpio_pull(setup)

def upisnd_setup_get_gpio_dir(setup):
    r""" Extracts the GPIO direction from the setup container, applies only to GPIO Input or Output."""
    return _pypisoundmicro.upisnd_setup_get_gpio_dir(setup)

def upisnd_setup_get_gpio_output(setup):
    r""" Extracts the GPIO output level from the setup container, applies only to GPIO Output."""
    return _pypisoundmicro.upisnd_setup_get_gpio_output(setup)

def upisnd_setup_get_encoder_pin_b_id(setup):
    r""" Extracts the Encoder's second pin from the setup container, applies only to Encoders."""
    return _pypisoundmicro.upisnd_setup_get_encoder_pin_b_id(setup)

def upisnd_setup_get_encoder_pin_b_pull(setup):
    r""" Extracts the Encoder's second pin pull from the setup container, applies only to Encoders."""
    return _pypisoundmicro.upisnd_setup_get_encoder_pin_b_pull(setup)

def upisnd_setup_get_activity_type(setup):
    r""" Extracts the Activity type from the setup container, applies only to Activity Elements."""
    return _pypisoundmicro.upisnd_setup_get_activity_type(setup)

def upisnd_setup_set_element_type(setup, value):
    r"""
     Sets the Element type in the setup container.

    Always set the Element Type before setting any other property of setup, as
    the type is double-checked to know if the set operation is valid for this type.

    :rtype: int
    :return: 0 on success, `-errno` on error.
    """
    return _pypisoundmicro.upisnd_setup_set_element_type(setup, value)

def upisnd_setup_set_pin_id(setup, value):
    r"""
     Sets the main pin id in the setup container.

    :rtype: int
    :return: 0 on success, `-errno` on error.
    """
    return _pypisoundmicro.upisnd_setup_set_pin_id(setup, value)

def upisnd_setup_set_gpio_dir(setup, value):
    r"""
     Sets the GPIO direction in the setup container, applies only to GPIO Elements.

    Always set the GPIO dir before setting the pull and output, as the direction is double-checked
    to know whether pull (only input) or output level (only output) properties are valid.

    :rtype: int
    :return: 0 on success, `-errno` on error.
    """
    return _pypisoundmicro.upisnd_setup_set_gpio_dir(setup, value)

def upisnd_setup_set_gpio_pull(setup, value):
    r"""
     Sets the GPIO pull in the setup container, applies only to GPIO Input.

    Make sure to first set the GPIO dir to #UPISND_PIN_DIR_INPUT.

    :rtype: int
    :return: 0 on success, `-errno` on error.
    """
    return _pypisoundmicro.upisnd_setup_set_gpio_pull(setup, value)

def upisnd_setup_set_gpio_output(setup, value):
    r"""
     Sets the GPIO output level in the setup container, applies only to GPIO Output.

    Make sure to first set the GPIO dir to #UPISND_PIN_DIR_OUTPUT.

    :rtype: int
    :return: 0 on success, `-errno` on error.
    """
    return _pypisoundmicro.upisnd_setup_set_gpio_output(setup, value)

def upisnd_setup_set_encoder_pin_b_id(setup, value):
    r"""
     Sets the Encoder's second pin id in the setup container, applies only to Encoders.

    :rtype: int
    :return: 0 on success, `-errno on error.
    """
    return _pypisoundmicro.upisnd_setup_set_encoder_pin_b_id(setup, value)

def upisnd_setup_set_encoder_pin_b_pull(setup, value):
    r"""
     Sets the Encoder's second pin pull in the setup container, applies only to Encoders.

    :rtype: int
    :return: 0 on success, `-errno` on error.
    """
    return _pypisoundmicro.upisnd_setup_set_encoder_pin_b_pull(setup, value)

def upisnd_setup_set_activity_type(setup, value):
    r"""
     Sets the Activity type in the setup container, applies only to Activity Elements.

    :rtype: int
    :return: 0 on success, `-errno` on error.
    """
    return _pypisoundmicro.upisnd_setup_set_activity_type(setup, value)

def upisnd_validate_element_name(name):
    r"""
     Verifies that the provided element name is valid.

    :rtype: int
    :return: The length of *name* on success, `-errno` on error.
    """
    return _pypisoundmicro.upisnd_validate_element_name(name)

def upisnd_generate_random_element_name(dst, n, prefix):
    r"""
     A helper for generating a random element name with the provided prefix.

    :type dst: string
    :param dst: The buffer to write the generated name to.
    :type n: int
    :param n: The size of the buffer, at most #UPISND_MAX_ELEMENT_NAME_LENGTH.
    :type prefix: string
    :param prefix: The prefix to use for the generated name, can be NULL if not needed. The prefix can be up to `UPISND_MAX_ELEMENT_NAME_LENGTH - 23` long.

    It is not strictly necessary to use this function, you may use any fixed valid name for your Element.

    :rtype: int
    :return: The return value is directly forwarded from the `snprintf` call. A negative value indicates an error,
        a value >= *n* means the *dst* buffer was not long enough, and a value < *n* indicates success. Check out
        `snprintf` documentation for more details.
    """
    return _pypisoundmicro.upisnd_generate_random_element_name(dst, n, prefix)

def upisnd_unsetup(name):
    r"""
     Force-unsetup an Element by name. This is normally not necessary.

    Unrefing the element will automatically unsetup it once last reference is released.
    This function is only useful if recovering from crash, avoid if possible.

    :rtype: int
    :return: 0 on success, -1 on error, inspect `errno` for details.
    """
    return _pypisoundmicro.upisnd_unsetup(name)

def upisnd_element_get(name):
    r"""
     Get a reference to an Element by name that was set up during the current runtime session.

    If the Element exists in `/sys/pisound-micro/elements/`, but it was not created
    by the current program, it won't get returned. In this case, you can try setting up
    an Element with the exact same setup options, if they match, you'll get a reference,
    otherwise, use ::upisnd_unsetup to remove the Element first, and set it up fresh.

    :rtype: upisnd_elements_list_node_t
    :return: A valid Element reference on success, NULL on error.
    """
    return _pypisoundmicro.upisnd_element_get(name)

def upisnd_element_add_ref(ref):
    r"""
     Increment the reference count of the Element.

    :rtype: upisnd_elements_list_node_t
    :return: The same reference that was passed in.
    """
    return _pypisoundmicro.upisnd_element_add_ref(ref)

def upisnd_element_unref(ref):
    r"""
     Decrement the reference count of the Element.

    :type ref: upisnd_elements_list_node_t
    :param ref: The pointer to reference to unref, will be automatically NULL-ed out.

    If the reference count reaches 0, the Element will be unsetup and released.
    """
    return _pypisoundmicro.upisnd_element_unref(ref)

def upisnd_element_get_name(el):
    r"""
     Get the name of the Element.

    The result is valid, as long as the element reference is valid.

    :rtype: string
    :return: The name of the Element, or NULL if the reference is invalid.
    """
    return _pypisoundmicro.upisnd_element_get_name(el)

def upisnd_element_get_type(el):
    r"""
     Get the type of the Element.

    :rtype: int
    :return: The type of the Element. If #UPISND_ELEMENT_TYPE_INVALID, check the `errno`.
    """
    return _pypisoundmicro.upisnd_element_get_type(el)

def upisnd_element_get_pin(el):
    r"""
     Get the pin number of the Element.

    :rtype: upisnd_pin_t
    :return: The pin number of the Element. If #UPISND_PIN_INVALID, check the `errno`.
    """
    return _pypisoundmicro.upisnd_element_get_pin(el)

def upisnd_element_open_value_fd(el, flags):
    r"""
     Opens the Element's value file descriptor.

    :type el: upisnd_elements_list_node_t
    :param el: The Element reference.
    :type flags: int
    :param flags: The flags to pass to the `open` system call.

    You must set the access flags, such as O_RDONLY, O_WRONLY or O_RDWR,
    defined in the system's `fcntl.h` header. We recommend setting O_CLOEXEC as well.
    (combine the flags using logic OR `|`).

    Use ::upisnd_value_read and ::upisnd_value_write to read and write the value.

    You may also `poll` for changes (use `POLLPRI`). Look into the documentation for
    `poll`, `ppoll` and `select` system APIs for more details.

    Once you're done with the fd, close it using the `close` system call.

    :rtype: int
    :return: The file descriptor on success, -1 on error, inspect `errno` for details.
    """
    return _pypisoundmicro.upisnd_element_open_value_fd(el, flags)

def upisnd_value_read(fd):
    r"""
     Reads the Element's value.

    :type fd: int
    :param fd: The file descriptor of the Element's value file.

    :rtype: int
    :return: The value read from the Element's value file. On successful read, `errno` will be 0.
    """
    return _pypisoundmicro.upisnd_value_read(fd)

def upisnd_value_write(fd, value):
    r"""
     Writes the Element's value.

    :type fd: int
    :param fd: The file descriptor of the Element's value file.
    :type value: int
    :param value: The value to write to the Element's value file.

    :rtype: int
    :return: Number of characters written on success, -1 on error, inspect `errno` for details.
    """
    return _pypisoundmicro.upisnd_value_write(fd, value)

def upisnd_setup(name, setup):
    r"""
     Set up an Element with the provided name and setup options container.

    :type name: string
    :param name: The name of the Element to set up.
    :type setup: int
    :param setup: The setup options container for the Element.

    In case an Element already exists with the same name, and the requested configuration is the same,
    the existing Element will get returned and its refcount will get incremented. Otherwise, NULL
    will be returned, and `errno` set appropriately.

    :rtype: upisnd_elements_list_node_t
    :return: A valid Element reference on success, NULL on error, inspect `errno` for details.
    """
    return _pypisoundmicro.upisnd_setup(name, setup)

def upisnd_setup_encoder(name, pin_a, pull_a, pin_b, pull_b):
    r""" Set up an Encoder Element with the provided name and setup options."""
    return _pypisoundmicro.upisnd_setup_encoder(name, pin_a, pull_a, pin_b, pull_b)

def upisnd_setup_analog_input(name, pin):
    r""" Set up an Analog Input Element with the provided name and setup options."""
    return _pypisoundmicro.upisnd_setup_analog_input(name, pin)

def upisnd_setup_gpio_input(name, pin, pull):
    r""" Set up a GPIO Input Element with the provided name and setup options."""
    return _pypisoundmicro.upisnd_setup_gpio_input(name, pin, pull)

def upisnd_setup_gpio_output(name, pin, high):
    r""" Set up a GPIO Output Element with the provided name and setup options."""
    return _pypisoundmicro.upisnd_setup_gpio_output(name, pin, high)

def upisnd_setup_activity(name, pin, activity):
    r""" Set up an Activity Element with the provided name and setup options."""
    return _pypisoundmicro.upisnd_setup_activity(name, pin, activity)

def upisnd_element_gpio_get_direction(el):
    r""" Get the GPIO Element's direction."""
    return _pypisoundmicro.upisnd_element_gpio_get_direction(el)

def upisnd_element_gpio_get_pull(el):
    r""" Get the GPIO or Encoder Element's input pull."""
    return _pypisoundmicro.upisnd_element_gpio_get_pull(el)

def upisnd_element_activity_get_type(el):
    r""" Get the Activity Element's activity type."""
    return _pypisoundmicro.upisnd_element_activity_get_type(el)

def upisnd_element_encoder_init_default_opts(opts):
    r""" Initialize the values of Encoder's options struct to the defaults."""
    return _pypisoundmicro.upisnd_element_encoder_init_default_opts(opts)

def upisnd_element_encoder_get_opts(el, opts):
    r""" Retrieve the Encoder's options."""
    return _pypisoundmicro.upisnd_element_encoder_get_opts(el, opts)

def upisnd_element_encoder_set_opts(el, opts):
    r""" Set the Encoder's options."""
    return _pypisoundmicro.upisnd_element_encoder_set_opts(el, opts)

def upisnd_element_encoder_get_pin_b(el):
    r"""  Get the Encoder's second pin."""
    return _pypisoundmicro.upisnd_element_encoder_get_pin_b(el)

def upisnd_element_encoder_get_pin_b_pull(el):
    r"""  Get the Encoder's second pin pull. Use ::upisnd_element_gpio_get_pull to get pull of first pin."""
    return _pypisoundmicro.upisnd_element_encoder_get_pin_b_pull(el)

def upisnd_element_analog_input_init_default_opts(opts):
    r""" Initialize the values of Analog Input's options struct to the defaults."""
    return _pypisoundmicro.upisnd_element_analog_input_init_default_opts(opts)

def upisnd_element_analog_input_get_opts(el, opts):
    r""" Retrieve the Analog Input's options."""
    return _pypisoundmicro.upisnd_element_analog_input_get_opts(el, opts)

def upisnd_element_analog_input_set_opts(el, opts):
    r""" Set the Analog Input's options."""
    return _pypisoundmicro.upisnd_element_analog_input_set_opts(el, opts)
class LibInitializer(object):
    r"""
     Simply calls ::upisnd_init and ::upisnd_uninit in its constructor and destructor, for convenience.

    You may have a global `upisnd::LibInitializer` variable, or place it inside your main function,
    prior to calling any other libpisoundmicro functions or instantiating other classes.

    To know if the initialization succeeded, you can check the result of `getResult()` method, it keeps
    the value returned by ::upisnd_init.

    See also: upisnd_init
    See also: upisnd_uninit

    """

    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr

    def __init__(self):
        r"""__init__(LibInitializer self) -> LibInitializer"""
        _pypisoundmicro.LibInitializer_swiginit(self, _pypisoundmicro.new_LibInitializer())

    def getResult(self):
        r"""getResult(LibInitializer self) -> int"""
        return _pypisoundmicro.LibInitializer_getResult(self)
    __swig_destroy__ = _pypisoundmicro.delete_LibInitializer

# Register LibInitializer in _pypisoundmicro:
_pypisoundmicro.LibInitializer_swigregister(LibInitializer)
class ValueFd(object):
    r"""
     A wrapper around a file descriptor that can be used to read/write the Element's value.

    Takes care of managing the lifetime of the fd.

    You may retrieve the fd value using get() or take ownership of it using take(). If you take
    the ownership, the ValueFd object will immediately forget about the fd, and you'll be responsible
    to `close` it yourself.
    """

    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr
    __swig_destroy__ = _pypisoundmicro.delete_ValueFd

    def __init__(self, *args):
        r"""
        *Overload 1:*
        Creates a ValueFd from an existing fd, takes ownership of it, so it will close it in the destructor.

        |

        *Overload 2:*
        Copy constructor, duplicates the fd using F_DUPFD_CLOEXEC fcntl call.

        |

        *Overload 3:*
        Move constructor, moves take ownership of the fd.
        """
        _pypisoundmicro.ValueFd_swiginit(self, _pypisoundmicro.new_ValueFd(*args))

    def isValid(self):
        r""" Returns true if the object holds a valid fd."""
        return _pypisoundmicro.ValueFd_isValid(self)

    def take(self):
        r""" Returns the fd value, and won't close it in the destructor, transferring ownership."""
        return _pypisoundmicro.ValueFd_take(self)

    def get(self):
        r""" Returns the fd value for your use, but keeps ownership, and will close it upon destruction."""
        return _pypisoundmicro.ValueFd_get(self)

    def close(self):
        r""" Closes the fd and forgets about it."""
        return _pypisoundmicro.ValueFd_close(self)

    def write(self, value):
        r""" Outputs a decimal number to the fd."""
        return _pypisoundmicro.ValueFd_write(self, value)

    def read(self):
        r"""
        Reads a decimal number from the fd and returns it as integer.
        :type err: int, optional
        :param err: If not NULL, will be set to the `errno` value if the read failed, 0 otherwise.
        """
        return _pypisoundmicro.ValueFd_read(self)

# Register ValueFd in _pypisoundmicro:
_pypisoundmicro.ValueFd_swigregister(ValueFd)
class ElementName(object):
    r""" A helper class for formatting Element names."""

    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr

    def __str__(self):
        r""" Implicit conversion to const char *."""
        return _pypisoundmicro.ElementName___str__(self)

    @staticmethod
    def regular(name):
        r""" Returns an ElementName initialized from the provided string."""
        return _pypisoundmicro.ElementName_regular(name)

    @staticmethod
    def randomized(prefix=None):
        r"""
        Returns a randomized ElementName. You may optionally specify a prefix to be prepended to the name.
        See also: ::upisnd_generate_random_element_name
        """
        return _pypisoundmicro.ElementName_randomized(prefix)

    def __init__(self, *args):
        r"""
        __init__(ElementName self, char const * str) -> ElementName
        __init__(ElementName self, ElementName rhs) -> ElementName
        """
        _pypisoundmicro.ElementName_swiginit(self, _pypisoundmicro.new_ElementName(*args))
    __swig_destroy__ = _pypisoundmicro.delete_ElementName

# Register ElementName in _pypisoundmicro:
_pypisoundmicro.ElementName_swigregister(ElementName)
class Element(object):
    r"""
     An Element class for shared functionality of all Pisound Micro Elements.

    It takes care of adding and releaseing references to the underlying C API element,
    it follows the usual C++ class semantics.

    It also provides a safe templated as() method for casting to the appropriate class.

    You may use the Element::setup method to create a new element from a #upisnd_setup_t setup
    option container.

    """

    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr

    def __init__(self, *args):
        r"""
        __init__(Element self) -> Element
        __init__(Element self, upisnd_element_ref_t el) -> Element
        __init__(Element self, Element rhs) -> Element
        __init__(Element self, Element rhs) -> Element
        """
        _pypisoundmicro.Element_swiginit(self, _pypisoundmicro.new_Element(*args))
    __swig_destroy__ = _pypisoundmicro.delete_Element

    @staticmethod
    def get(name):
        r"""
         Gets an Element following ::upisnd_element_get semantics.

        :type name: :py:class:`ElementName`
        :param name: The name of the element to get. Can be provided as a string constant or `const char *`.
        """
        return _pypisoundmicro.Element_get(name)

    @staticmethod
    def setup(name, setup):
        r"""
         Sets up a new Element from a #upisnd_setup_t setup option container.

        :type name: :py:class:`ElementName`
        :param name: The name of the element to get. Can be provided as a string constant or `const char *`.
        :type setup: int
        :param setup: The setup option container. See ::upisnd_setup_set_element_type and the rest of the
            upisnd_setup_* APIs in api.h.
        """
        return _pypisoundmicro.Element_setup(name, setup)

    def isValid(self):
        r""" Checks if the element is valid."""
        return _pypisoundmicro.Element_isValid(self)

    def release(self):
        r""" Unreferences the underlying C #upisnd_element_ref_t handle and resets the object."""
        return _pypisoundmicro.Element_release(self)

    def getName(self):
        r""" Gets the name of the element."""
        return _pypisoundmicro.Element_getName(self)

    def getType(self):
        r""" Gets the type of the element."""
        return _pypisoundmicro.Element_getType(self)

    def getPin(self):
        r""" Gets the pin of the element."""
        return _pypisoundmicro.Element_getPin(self)

    def openValueFd(self, flags):
        r"""
         Opens the Element's `value` attribute as a file descriptor.

        :type flags: int
        :param flags: The flags to pass to ::open.

        See also: upisnd_element_open_value_fd
        """
        return _pypisoundmicro.Element_openValueFd(self, flags)

    def as_analog_input(self):
        r"""as_analog_input(Element self) -> AnalogInput"""
        return _pypisoundmicro.Element_as_analog_input(self)

    def as_encoder(self):
        r"""as_encoder(Element self) -> Encoder"""
        return _pypisoundmicro.Element_as_encoder(self)

    def as_gpio(self):
        r"""as_gpio(Element self) -> Gpio"""
        return _pypisoundmicro.Element_as_gpio(self)

    def as_activity(self):
        r"""as_activity(Element self) -> Activity"""
        return _pypisoundmicro.Element_as_activity(self)

# Register Element in _pypisoundmicro:
_pypisoundmicro.Element_swigregister(Element)
class Encoder(Element):
    r""" The Encoder element class."""

    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr

    @staticmethod
    def setup(name, pin_a, pull_a, pin_b, pull_b):
        r"""
        Set up an encoder element.
        See also: ::upisnd_setup_encoder
        """
        return _pypisoundmicro.Encoder_setup(name, pin_a, pull_a, pin_b, pull_b)

    def get(self):
        r"""
        This is for quick access to the value, otherwise, it's recommended to keep the

        ValueFd returned by Element::openValueFd, to avoid file open and close overhead.
        Inspect the `errno` to check for errors.
        """
        return _pypisoundmicro.Encoder_get(self)

    def getOpts(self, opts):
        r""" Retrieves the Encoder options. See also: ::upisnd_element_encoder_get_opts"""
        return _pypisoundmicro.Encoder_getOpts(self, opts)

    def setOpts(self, opts):
        r""" Sets the Encoder options. See also: ::upisnd_element_encoder_set_opts"""
        return _pypisoundmicro.Encoder_setOpts(self, opts)

    def getPinB(self):
        r""" Retrieves the 2nd pin of the Encoder. See also: ::upisnd_element_encoder_get_pin_b"""
        return _pypisoundmicro.Encoder_getPinB(self)

    def getPinPull(self):
        r""" Retrieves the pull-up/pull-down configuration of the 1st pin of the Encoder. See also: ::upisnd_element_gpio_get_pull"""
        return _pypisoundmicro.Encoder_getPinPull(self)

    def getPinBPull(self):
        r""" Retrieves the pull-up/pull-down configuration of the 2nd pin of the Encoder. See also: ::upisnd_element_encoder_get_pin_b_pull"""
        return _pypisoundmicro.Encoder_getPinBPull(self)

    def __init__(self):
        r"""__init__(Encoder self) -> Encoder"""
        _pypisoundmicro.Encoder_swiginit(self, _pypisoundmicro.new_Encoder())
    __swig_destroy__ = _pypisoundmicro.delete_Encoder

# Register Encoder in _pypisoundmicro:
_pypisoundmicro.Encoder_swigregister(Encoder)
class AnalogInput(Element):
    r""" Analog input element class."""

    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr

    @staticmethod
    def setup(name, pin):
        r""" Set up an analog input element."""
        return _pypisoundmicro.AnalogInput_setup(name, pin)

    def get(self):
        r"""
        This is for quick access to the value, otherwise, it's recommended to keep the

        ValueFd returned by Element::openValueFd, to avoid file open and close overhead.
        Inspect the `errno` to check for errors.
        """
        return _pypisoundmicro.AnalogInput_get(self)

    def getOpts(self, opts):
        r""" Retrieves the Analog Input options. See also: ::upisnd_element_analog_input_get_opts"""
        return _pypisoundmicro.AnalogInput_getOpts(self, opts)

    def setOpts(self, opts):
        r""" Sets the Analog Input options. See also: ::upisnd_element_analog_input_set_opts"""
        return _pypisoundmicro.AnalogInput_setOpts(self, opts)

    def __init__(self):
        r"""__init__(AnalogInput self) -> AnalogInput"""
        _pypisoundmicro.AnalogInput_swiginit(self, _pypisoundmicro.new_AnalogInput())
    __swig_destroy__ = _pypisoundmicro.delete_AnalogInput

# Register AnalogInput in _pypisoundmicro:
_pypisoundmicro.AnalogInput_swigregister(AnalogInput)
class Gpio(Element):
    r""" The GPIO element class."""

    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr

    @staticmethod
    def setupInput(name, pin, pull):
        r"""
        Set up a GPIO element as input.
        See also: upisnd_setup_gpio_input
        """
        return _pypisoundmicro.Gpio_setupInput(name, pin, pull)

    @staticmethod
    def setupOutput(name, pin, high):
        r"""
        Set up a GPIO element as output.
        See also: upisnd_setup_gpio_output
        """
        return _pypisoundmicro.Gpio_setupOutput(name, pin, high)

    def getDirection(self):
        r""" Get the direction of the GPIO element."""
        return _pypisoundmicro.Gpio_getDirection(self)

    def getPull(self):
        r"""
        Get the pull of the GPIO Input element.
        :rtype: int
        :return: Returns #UPISND_PIN_PULL_INVALID if the element is not an input.
        """
        return _pypisoundmicro.Gpio_getPull(self)

    def get(self):
        r"""
        This is for quick access to the value, otherwise, it's recommended to keep the
        ValueFd returned by Element::openValueFd, to avoid file open and close overhead.
        :rtype: int
        :return: Negative return value indicates an error.
        """
        return _pypisoundmicro.Gpio_get(self)

    def set(self, high):
        r"""
        Set the output value of the GPIO output element.
        :rtype: int
        :return: Negative return value indicates an error.
        """
        return _pypisoundmicro.Gpio_set(self, high)

    def __init__(self):
        r"""__init__(Gpio self) -> Gpio"""
        _pypisoundmicro.Gpio_swiginit(self, _pypisoundmicro.new_Gpio())
    __swig_destroy__ = _pypisoundmicro.delete_Gpio

# Register Gpio in _pypisoundmicro:
_pypisoundmicro.Gpio_swigregister(Gpio)
class Activity(Element):
    r""" Activity element class."""

    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr

    @staticmethod
    def setup(name, pin, activity):
        r"""
        Set up an activity element.
        See also: upisnd_setup_activity
        """
        return _pypisoundmicro.Activity_setup(name, pin, activity)

    def getActivity(self):
        r""" Get the activity of the element."""
        return _pypisoundmicro.Activity_getActivity(self)

    def __init__(self):
        r"""__init__(Activity self) -> Activity"""
        _pypisoundmicro.Activity_swiginit(self, _pypisoundmicro.new_Activity())
    __swig_destroy__ = _pypisoundmicro.delete_Activity

# Register Activity in _pypisoundmicro:
_pypisoundmicro.Activity_swigregister(Activity)

import atexit
from threading import Lock

_upisnd_mutex = Lock()

_upisnd_initializer = None

def _init():
    global _upisnd_initializer
    with _upisnd_mutex:
        if _upisnd_initializer is None:
            _upisnd_initializer = LibInitializer()

def _cleanup():
    global _upisnd_initializer
    with _upisnd_mutex:
        if _upisnd_initializer is not None:
            del _upisnd_initializer
            _upisnd_initializer = None

# Register the cleanup function to be called on normal interpreter shutdown.
atexit.register(_cleanup)

_init()