# Path: pym2149/buf.py
# class BufType:
# 
#     def __init__(self, _, dtype):
#         self.dtype = dtype
# 
#     def __call__(self):
#         return MasterBuf(self.dtype)
# 
# Path: pym2149/dac.py
# class Dac(BufNode):
# 
#     def __init__(self, level, log2maxpeaktopeak, ampshare):
#         buftype = BufType.float
#         super().__init__(buftype)
#         # We take off .5 so that the peak amplitude is about -3 dB:
#         maxpeaktopeak = (2 ** (log2maxpeaktopeak - .5)) / ampshare
#         # Lookup of ideal amplitudes:
#         self.leveltopeaktopeak = np.fromiter((level5toamp(v) * maxpeaktopeak for v in range(32)), buftype.dtype)
#         self.level = level
# 
#     def callimpl(self):
#         self.blockbuf.mapbuf(self.chain(self.level), self.leveltopeaktopeak)
# 
# Path: pym2149/nod.py
# class Block:
# 
#     def __init__(self, framecount):
#         # If it's a numpy type it can cause overflow in osc module, so ensure arbitrary precision:
#         self.framecount = int(framecount)
# 
#     def __repr__(self):
#         return f"{type(self).__name__}({self.framecount!r})"
# 
# class BufNode(Node):
# 
#     def __init__(self, buftype, channels = 1):
#         super().__init__()
#         self.masterbuf = buftype()
#         self.channels = channels
#         self.realcallimpl = self.callimpl
#         self.callimpl = self.makeresult
# 
#     def makeresult(self):
#         self.blockbuf = self.masterbuf.ensureandcrop(self.block.framecount * self.channels)
#         resultornone = self.realcallimpl()
#         if resultornone is not None:
#             return resultornone
#         return self.blockbuf


from .buf import BufType
from .dac import Dac
from .nod import Block, BufNode
from unittest import TestCase
# This file is part of pym2149.
#
# pym2149 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pym2149 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pym2149.  If not, see <http://www.gnu.org/licenses/>.


class Ramps(BufNode):

    buftype = BufType.signal

    def __init__(self):
        super().__init__(self.buftype)

    def callimpl(self):
        for i in range(self.block.framecount):
            self.blockbuf.fillpart(i, i + 1, self.buftype.dtype(i))

class TestDac(TestCase):

    def test_works(self):

# Path: pym2149/buf.py
# class BufType:
# 
#     def __init__(self, _, dtype):
#         self.dtype = dtype
# 
#     def __call__(self):
#         return MasterBuf(self.dtype)
# 
# Path: pym2149/dac.py
# class Dac(BufNode):
# 
#     def __init__(self, level, log2maxpeaktopeak, ampshare):
#         buftype = BufType.float
#         super().__init__(buftype)
#         # We take off .5 so that the peak amplitude is about -3 dB:
#         maxpeaktopeak = (2 ** (log2maxpeaktopeak - .5)) / ampshare
#         # Lookup of ideal amplitudes:
#         self.leveltopeaktopeak = np.fromiter((level5toamp(v) * maxpeaktopeak for v in range(32)), buftype.dtype)
#         self.level = level
# 
#     def callimpl(self):
#         self.blockbuf.mapbuf(self.chain(self.level), self.leveltopeaktopeak)
# 
# Path: pym2149/nod.py
# class Block:
# 
#     def __init__(self, framecount):
#         # If it's a numpy type it can cause overflow in osc module, so ensure arbitrary precision:
#         self.framecount = int(framecount)
# 
#     def __repr__(self):
#         return f"{type(self).__name__}({self.framecount!r})"
# 
# class BufNode(Node):
# 
#     def __init__(self, buftype, channels = 1):
#         super().__init__()
#         self.masterbuf = buftype()
#         self.channels = channels
#         self.realcallimpl = self.callimpl
#         self.callimpl = self.makeresult
# 
#     def makeresult(self):
#         self.blockbuf = self.masterbuf.ensureandcrop(self.block.framecount * self.channels)
#         resultornone = self.realcallimpl()
#         if resultornone is not None:
#             return resultornone
#         return self.blockbuf


# Path: pym2149/test_dac.py
from .buf import BufType
from .dac import Dac
from .nod import Block, BufNode
from unittest import TestCase

# This file is part of pym2149.
#
# pym2149 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pym2149 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pym2149.  If not, see <http://www.gnu.org/licenses/>.


class Ramps(BufNode):

    buftype = BufType.signal

    def __init__(self):
        super().__init__(self.buftype)

    def callimpl(self):
        for i in range(self.block.framecount):
            self.blockbuf.fillpart(i, i + 1, self.buftype.dtype(i))

class TestDac(TestCase):

    def test_works(self):

        d = Dac(Ramps(), 16, 1)