# Path: gum/lib/event.py
# class Signal(object):
# 
#     def __init__(self):
#         self.__slots = WeakValueDictionary()
# 
#         # For keeping references to _FuncHost objects.
#         self.__funchosts = {}
# 
#     def __call__(self, *args, **kargs):
#         for key in self.__slots:
#             func, _ = key
#             func(self.__slots[key], *args, **kargs)
# 
#     def connect(self, slot):
#         if inspect.ismethod(slot):
#             key = (slot.im_func, id(slot.im_self))
#             self.__slots[key] = slot.im_self
#         else:
#             host = _FuncHost(slot)
#             self.connect(host.meth)
#             # We stick a copy in here just to keep the instance alive.
#             self.__funchosts[slot] = host
# 
#     def disconnect(self, slot):
#         if inspect.ismethod(slot):
#             key = (slot.im_func, id(slot.im_self))
#             if key in self.__slots:
#                 self.__slots.pop(key)
#         else:
#             if slot in self.__funchosts:
#                 self.disconnect(self.__funchosts[slot].meth)
#                 self.__funchosts.pop(slot)
# 
#     def clear(self):
#         self.__slots.clear()
#         self.__funchosts.clear()


import alsaaudio
import threading
import numpy
    import pysndfile
    import gum
from  gum.lib.event import Signal
    from gum.lib.mock import Mock
    from math import sin
    from time import sleep
    from time import sleep
        self._pcm.setformat(alsaaudio.PCM_FORMAT_FLOAT_LE)
        self.set_samplerate(rate)
        # alsaaudio.PCM.setperiodsize() attempts to change the
        # periodsize and returns the actual period size.
        self.periodsize = self._pcm.setperiodsize(1024)

    def set_samplerate(self, rate):
        self._pcm.setrate(rate)

    def write(self, buf):
        if buf.ndim == 1:
            # converting mono to stereo
            buf = numpy.array([buf, buf]).transpose()
        if 0 < len(buf) < self.periodsize:
            # zero padding to flush the ALSA buffer
            padlen = self.periodsize - len(buf)
            padding = numpy.zeros((padlen, buf.ndim))
            buf = numpy.concatenate((buf, padding))
        bytes = buf.astype(numpy.float32).tostring()
        self._pcm.write(bytes)
        

class Player(object):
    """Play sound using alsa.

    """
    def __init__(self, sound):
        self._playing = False
        self._lock = threading.Lock()
        self.start_playing = Signal()

# Path: gum/lib/event.py
# class Signal(object):
# 
#     def __init__(self):
#         self.__slots = WeakValueDictionary()
# 
#         # For keeping references to _FuncHost objects.
#         self.__funchosts = {}
# 
#     def __call__(self, *args, **kargs):
#         for key in self.__slots:
#             func, _ = key
#             func(self.__slots[key], *args, **kargs)
# 
#     def connect(self, slot):
#         if inspect.ismethod(slot):
#             key = (slot.im_func, id(slot.im_self))
#             self.__slots[key] = slot.im_self
#         else:
#             host = _FuncHost(slot)
#             self.connect(host.meth)
#             # We stick a copy in here just to keep the instance alive.
#             self.__funchosts[slot] = host
# 
#     def disconnect(self, slot):
#         if inspect.ismethod(slot):
#             key = (slot.im_func, id(slot.im_self))
#             if key in self.__slots:
#                 self.__slots.pop(key)
#         else:
#             if slot in self.__funchosts:
#                 self.disconnect(self.__funchosts[slot].meth)
#                 self.__funchosts.pop(slot)
# 
#     def clear(self):
#         self.__slots.clear()
#         self.__funchosts.clear()


# Path: gum/controllers/player.py
import alsaaudio
import threading
import numpy
    import pysndfile
    import gum
from  gum.lib.event import Signal
    from gum.lib.mock import Mock
    from math import sin
    from time import sleep
    from time import sleep

        self._pcm.setformat(alsaaudio.PCM_FORMAT_FLOAT_LE)
        self.set_samplerate(rate)
        # alsaaudio.PCM.setperiodsize() attempts to change the
        # periodsize and returns the actual period size.
        self.periodsize = self._pcm.setperiodsize(1024)

    def set_samplerate(self, rate):
        self._pcm.setrate(rate)

    def write(self, buf):
        if buf.ndim == 1:
            # converting mono to stereo
            buf = numpy.array([buf, buf]).transpose()
        if 0 < len(buf) < self.periodsize:
            # zero padding to flush the ALSA buffer
            padlen = self.periodsize - len(buf)
            padding = numpy.zeros((padlen, buf.ndim))
            buf = numpy.concatenate((buf, padding))
        bytes = buf.astype(numpy.float32).tostring()
        self._pcm.write(bytes)
        

class Player(object):
    """Play sound using alsa.

    """
    def __init__(self, sound):
        self._playing = False
        self._lock = threading.Lock()
        self.start_playing = Signal()

        self.stop_playing = Signal()