# 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/lib/history.py
# class Action(object):
# class History(object):
#     def __init__(self, do, undo):
#     def do(self):
#     def undo(self):
#     def __init__(self):
#     def _push(self, action):
#     def undo(self):
#     def redo(self):
#     def add(self, do, undo):
#     def revision(self):
#     def is_empty(self):
#     def testAction():
#     def testHistory():    
# 
# Path: gum/lib/edit.py
# def resample(frames, ratio):
# def mix_channels(frames, gain_lists):
# def mix_channels_auto(frames, n):


from gum.lib.event import Signal
from gum.lib import history, edit
from copy import copy
    from copy import copy
    from math import sin
    from gum.lib import mock
import pysndfile
import os.path
import numpy
    import gum
    import os
            filename = os.path.expanduser(filename)
            f = pysndfile.PySndfile(filename)
            nframes = f.frames()
            self.frames = f.read_frames(nframes)
            self.samplerate = f.samplerate()
            self._format = f.format()
            self._saved_revision = self.history.revision()

    def numchan(self):
        return self.frames.ndim

    def save(self):
        self.save_as(self.filename)

    def save_as(self, filename):
        if filename is None:
            raise Exception("No filename")
        f = pysndfile.PySndfile(filename,
                                mode='w',
                                format=self._format,
                                channels=self.numchan(),
                                samplerate=self.samplerate)
        f.write_frames(self.frames)
        self.filename = filename
        self._saved_revision = self.history.revision()

    def cut(self, start, end):
        clip = copy(self.frames[start:end])
        do = (self._do_cut, (start, end))
        undo = (self._do_paste, (start, start, clip))

# 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/lib/history.py
# class Action(object):
# class History(object):
#     def __init__(self, do, undo):
#     def do(self):
#     def undo(self):
#     def __init__(self):
#     def _push(self, action):
#     def undo(self):
#     def redo(self):
#     def add(self, do, undo):
#     def revision(self):
#     def is_empty(self):
#     def testAction():
#     def testHistory():    
# 
# Path: gum/lib/edit.py
# def resample(frames, ratio):
# def mix_channels(frames, gain_lists):
# def mix_channels_auto(frames, n):


# Path: gum/models/sound.py
from gum.lib.event import Signal
from gum.lib import history, edit
from copy import copy
    from copy import copy
    from math import sin
    from gum.lib import mock
import pysndfile
import os.path
import numpy
    import gum
    import os

            filename = os.path.expanduser(filename)
            f = pysndfile.PySndfile(filename)
            nframes = f.frames()
            self.frames = f.read_frames(nframes)
            self.samplerate = f.samplerate()
            self._format = f.format()
            self._saved_revision = self.history.revision()

    def numchan(self):
        return self.frames.ndim

    def save(self):
        self.save_as(self.filename)

    def save_as(self, filename):
        if filename is None:
            raise Exception("No filename")
        f = pysndfile.PySndfile(filename,
                                mode='w',
                                format=self._format,
                                channels=self.numchan(),
                                samplerate=self.samplerate)
        f.write_frames(self.frames)
        self.filename = filename
        self._saved_revision = self.history.revision()

    def cut(self, start, end):
        clip = copy(self.frames[start:end])
        do = (self._do_cut, (start, end))
        undo = (self._do_paste, (start, start, clip))

        self.history.add(do, undo)