# 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
# Gum sound editor (https://github.com/stackp/Gum)
# Copyright 2009 (C) Pierre Duquesne <stackp@online.fr>
# Licensed under the Revised BSD License.


class AlsaBackend(object):
    def __init__(self, rate=44100):
        self._pcm = alsaaudio.PCM(type=alsaaudio.PCM_PLAYBACK,
                            mode=alsaaudio.PCM_NORMAL)
        self._pcm.setchannels(2)
        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)

# 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

# Gum sound editor (https://github.com/stackp/Gum)
# Copyright 2009 (C) Pierre Duquesne <stackp@online.fr>
# Licensed under the Revised BSD License.


class AlsaBackend(object):
    def __init__(self, rate=44100):
        self._pcm = alsaaudio.PCM(type=alsaaudio.PCM_PLAYBACK,
                            mode=alsaaudio.PCM_NORMAL)
        self._pcm.setchannels(2)
        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))