# Path: core/interfaces/base.py
# class BaseInterface(ABC, Module):
# 
#     def  __init__(self, hplayer, name="INTERFACE", color="blue"):
#         super().__init__(hplayer, name, color)
#         self.hplayer = hplayer
# 
#         # stopping flag
#         self.stopped = threading.Event()
#         self.stopped.set()
# 
#         # Listen thread
#         self.recvThread = threading.Thread(target=self.listen)
# 
# 
#     # Receiver THREAD (ABSTRACT)
#     @abstractmethod
#     def listen(self):
#         self.stopped.wait()
# 
#     # Start
#     def start(self):
#         self.stopped.clear()
#         self.recvThread.start()
#         return self
# 
#     # Stop
#     def quit(self):
#         self.log("stopping...")
#         self.stopped.set()
#         self.recvThread.join()
#         self.log("stopped")
# 
# 	# is Running
#     def isRunning(self, state=None):
#         if state is not None:
#             self.stopped.clear() if state else self.stopped.set()
#         return not self.stopped.is_set()


from .base import BaseInterface
from zyre import Zyre, ZyreEvent
from czmq import *
from time import sleep
from threading import Timer, Lock
from ctypes import string_at
from sys import getsizeof
from binascii import hexlify
import time, random
import json
        if 'at' in data:
            if self.peer(data['from']):
                data['at'] -= self.peer(data['from']).clockshift()
            delay =  (data['at']) / PRECISION - time.time()

            if delay <= -10000:
                self.interface.log('WARNING event already passed by', delay, 's, its too late !! discarding... ')
            elif delay <= 0:
                self.interface.log('WARNING event already passed by', delay, 's, playing late... ')
                self.preProcessor2(data)
            elif delay > 3000:
                self.interface.log('WARNING event in', delay, 's, thats weird, playing now... ')
                self.preProcessor2(data)
            else:
                self.interface.log('programmed event in', delay, 's')
                t = Timer( delay, self.preProcessor2, args=[data])
                t.start()
                self.interface.emit('planned', data)

        else:
            self.preProcessor2(data)

    def preProcessor2(self, data):
        self.interface.emit('event', *[data])
        self.interface.emit(data['event'], *data['args'])


#
#  HPLAYER2 Zyre interface
#

# Path: core/interfaces/base.py
# class BaseInterface(ABC, Module):
# 
#     def  __init__(self, hplayer, name="INTERFACE", color="blue"):
#         super().__init__(hplayer, name, color)
#         self.hplayer = hplayer
# 
#         # stopping flag
#         self.stopped = threading.Event()
#         self.stopped.set()
# 
#         # Listen thread
#         self.recvThread = threading.Thread(target=self.listen)
# 
# 
#     # Receiver THREAD (ABSTRACT)
#     @abstractmethod
#     def listen(self):
#         self.stopped.wait()
# 
#     # Start
#     def start(self):
#         self.stopped.clear()
#         self.recvThread.start()
#         return self
# 
#     # Stop
#     def quit(self):
#         self.log("stopping...")
#         self.stopped.set()
#         self.recvThread.join()
#         self.log("stopped")
# 
# 	# is Running
#     def isRunning(self, state=None):
#         if state is not None:
#             self.stopped.clear() if state else self.stopped.set()
#         return not self.stopped.is_set()


# Path: core/interfaces/zyre.py
from .base import BaseInterface
from zyre import Zyre, ZyreEvent
from czmq import *
from time import sleep
from threading import Timer, Lock
from ctypes import string_at
from sys import getsizeof
from binascii import hexlify
import time, random
import json

        if 'at' in data:
            if self.peer(data['from']):
                data['at'] -= self.peer(data['from']).clockshift()
            delay =  (data['at']) / PRECISION - time.time()

            if delay <= -10000:
                self.interface.log('WARNING event already passed by', delay, 's, its too late !! discarding... ')
            elif delay <= 0:
                self.interface.log('WARNING event already passed by', delay, 's, playing late... ')
                self.preProcessor2(data)
            elif delay > 3000:
                self.interface.log('WARNING event in', delay, 's, thats weird, playing now... ')
                self.preProcessor2(data)
            else:
                self.interface.log('programmed event in', delay, 's')
                t = Timer( delay, self.preProcessor2, args=[data])
                t.start()
                self.interface.emit('planned', data)

        else:
            self.preProcessor2(data)

    def preProcessor2(self, data):
        self.interface.emit('event', *[data])
        self.interface.emit(data['event'], *data['args'])


#
#  HPLAYER2 Zyre interface
#

class ZyreInterface (BaseInterface):