# Path: pym2149/iface.py
# class Timer: pass
# 
# 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})"


from .iface import Timer
from .nod import Block
import logging
# Copyright 2014, 2018, 2019, 2020 Andrzej Cichocki

# 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/>.


log = logging.getLogger(__name__)

class SimpleTimer(Timer):

    def __init__(self, clock):
        self.carryticks = 0
        self.clock = clock

    def blocksforperiod(self, refreshrate):
        available = self.carryticks + self.clock
        blockticks = int(round(available / refreshrate))
        self.carryticks = available - blockticks * refreshrate

# Path: pym2149/iface.py
# class Timer: pass
# 
# 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})"


# Path: pym2149/timer.py
from .iface import Timer
from .nod import Block
import logging

# Copyright 2014, 2018, 2019, 2020 Andrzej Cichocki

# 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/>.


log = logging.getLogger(__name__)

class SimpleTimer(Timer):

    def __init__(self, clock):
        self.carryticks = 0
        self.clock = clock

    def blocksforperiod(self, refreshrate):
        available = self.carryticks + self.clock
        blockticks = int(round(available / refreshrate))
        self.carryticks = available - blockticks * refreshrate

        yield Block(blockticks)