# Path: utils.py
# def send_array(socket, A, flags=0, copy=True, track=False):
#     """send a numpy array with metadata"""
#     md = dict(
#         dtype = str(A.dtype),
#         shape = A.shape,
#     )
#     socket.send_json(md, flags|zmq.SNDMORE)
#     return socket.send(A, flags, copy=copy, track=track)
# 
# def recv_array(socket, flags=0, copy=True, track=False):
#     """recv a numpy array"""
#     md = socket.recv_json(flags=flags)
#     msg = socket.recv(flags=flags, copy=copy, track=track)
#     buf = buffer(msg)
#     A = np.frombuffer(buf, dtype=md['dtype'])
#     return A.reshape(md['shape'])


import multiprocessing as mp
import os
import random
import utils
import time
import numpy as np
import zmq
import myCsoundAudioOptions
    import cv2
    import csnd6
from scipy.io import wavfile
from utils import send_array, recv_array

    cv2.namedWindow('Output', cv2.WND_PROP_FULLSCREEN)
    camera = cv2.VideoCapture(0)

    context = zmq.Context()
    publisher = context.socket(zmq.PUB)
    publisher.bind('tcp://*:{}'.format(CAMERA))

    projector = context.socket(zmq.PULL)
    projector.bind('tcp://*:{}'.format(PROJECTOR))
    
    eventQ = context.socket(zmq.SUB)
    eventQ.connect('tcp://localhost:{}'.format(EVENT))
    eventQ.setsockopt(zmq.SUBSCRIBE, b'')

    poller = zmq.Poller()
    poller.register(eventQ, zmq.POLLIN)
    poller.register(projector, zmq.POLLIN)

    while True:
        events = dict(poller.poll(timeout=0))

        if eventQ in events:
            pushbutton = eventQ.recv_json()
            if 'display2' in pushbutton:
                cv2.moveWindow('Output', 2000, 100)
            if 'fullscreen' in pushbutton:
                cv2.setWindowProperty('Output', cv2.WND_PROP_FULLSCREEN, cv2.cv.CV_WINDOW_FULLSCREEN)

        if projector in events:

# Path: utils.py
# def send_array(socket, A, flags=0, copy=True, track=False):
#     """send a numpy array with metadata"""
#     md = dict(
#         dtype = str(A.dtype),
#         shape = A.shape,
#     )
#     socket.send_json(md, flags|zmq.SNDMORE)
#     return socket.send(A, flags, copy=copy, track=track)
# 
# def recv_array(socket, flags=0, copy=True, track=False):
#     """recv a numpy array"""
#     md = socket.recv_json(flags=flags)
#     msg = socket.recv(flags=flags, copy=copy, track=track)
#     buf = buffer(msg)
#     A = np.frombuffer(buf, dtype=md['dtype'])
#     return A.reshape(md['shape'])


# Path: IO.py
import multiprocessing as mp
import os
import random
import utils
import time
import numpy as np
import zmq
import myCsoundAudioOptions
    import cv2
    import csnd6
from scipy.io import wavfile
from utils import send_array, recv_array


    cv2.namedWindow('Output', cv2.WND_PROP_FULLSCREEN)
    camera = cv2.VideoCapture(0)

    context = zmq.Context()
    publisher = context.socket(zmq.PUB)
    publisher.bind('tcp://*:{}'.format(CAMERA))

    projector = context.socket(zmq.PULL)
    projector.bind('tcp://*:{}'.format(PROJECTOR))
    
    eventQ = context.socket(zmq.SUB)
    eventQ.connect('tcp://localhost:{}'.format(EVENT))
    eventQ.setsockopt(zmq.SUBSCRIBE, b'')

    poller = zmq.Poller()
    poller.register(eventQ, zmq.POLLIN)
    poller.register(projector, zmq.POLLIN)

    while True:
        events = dict(poller.poll(timeout=0))

        if eventQ in events:
            pushbutton = eventQ.recv_json()
            if 'display2' in pushbutton:
                cv2.moveWindow('Output', 2000, 100)
            if 'fullscreen' in pushbutton:
                cv2.setWindowProperty('Output', cv2.WND_PROP_FULLSCREEN, cv2.cv.CV_WINDOW_FULLSCREEN)

        if projector in events:

            cv2.imshow('Output', cv2.resize(recv_array(projector), FRAME_SIZE))