Пример #1
0
def setup_service():
    Logger.info('service: setup_service')
    setup_logger('mi')

    # add this dir to module search path
    app_dir = os.path.join(mi2app_utils.get_files_dir(), "app")
    sys.path.append(os.path.join(app_dir, 'service'))
    Logger.info('service: sys path added: ' + str(sys.path))

    # setup control and listen to osc signal
    control = Control()
    Logger.info('service: control created' + repr(control))

    osc.init()
    OSCID = osc.listen(port=OSCConfig.service_port)
    # def dummy_callback(msg, *args):
    #     Logger.info('service: dummy callback: ' + str(msg))
    # osc.bind(OSCID, dummy_callback, OSCConfig.control_addr)
    osc.bind(OSCID, control.osc_callback, OSCConfig.control_addr)
    Logger.info('service: osc setup, id: ' + OSCID)

    gps_provider = GpsListener(on_gps)
    gps_provider.start()

    osc.sendMsg(OSCConfig.control_addr,
                dataArray=[
                    'service ready',
                ],
                port=OSCConfig.app_port)
    Logger.info('service SEND>: service ready msg sent')
    while True:
        osc.readQueue(thread_id=OSCID)
        time.sleep(.5)
Пример #2
0
    def build(self):
        # Starts OSC
        oscAPI.init()
        # Instanciates OSC listener
        oscid = oscAPI.listen(ipAddr=self.ip, port=self.port)
        # listens for osc messages every screen refresh
        Clock.schedule_interval(lambda *x: oscAPI.readQueue(oscid), 0)

        # binds messages - this listens to messages if prefix /1/tok
        oscAPI.bind(oscid, self.receivedegrees, 0)

        # add a label to the screen
        root = BoxLayout(orientation='vertical')
        self.label = Label(text="This is our vertical sceen!",
                           font_size='50sp')
        root.add_widget(self.label)

        # console message - ready!
        print "Ready to receive!"
        self.receivedegrees(0)
        self.receivedegrees(90)
        self.receivedegrees(180)
        self.receivedegrees(270)
        # return root
        return root
Пример #3
0
def setup_osc():
    osc.init()
    OSCConfig.oscid = osc.listen(port=OSCConfig.app_port)
    Clock.schedule_interval(
        lambda *x: osc.readQueue(thread_id=OSCConfig.oscid), .5)
    Logger.info('coordinator: setup osc at ' + str(OSCConfig.app_port))
    Logger.info('coordinator: osc id: ' + OSCConfig.oscid)
Пример #4
0
    def build(self):
        Window.size = (1366, 768)
        Window.borderless = True
        Window.fullscreen = True
        scat = Scatter()
        # Starts OSC
        oscAPI.init()
        # Instanciates OSC listener
        oscid = oscAPI.listen(ipAddr=self.ip, port=self.port)
        # listens for osc messages every screen refresh
        Clock.schedule_interval(lambda *x: oscAPI.readQueue(oscid), 0)
        # binds messages - this listens to messages if prefix /1/tok
        oscAPI.bind(oscid, self.token_on, '0')

        # add a label to the screen
        root = FloatLayout(size=(2950, 1650), orientation='vertical')
        #self.label = Label(text="This is our vertical sceen!", font_size='50sp')
        #root.add_widget(self.label)

        root_image = Image(source='PauseScreen.png',
                           size_hint_x=None,
                           width=1366,
                           size_hint_y=None,
                           height=768,
                           allow_stretch=True,
                           keep_ratio=True)
        root.add_widget(root_image)
        # console message - ready!
        print "Ready to receive!"
        #self.receivedegrees(0,0)
        #self.receivedegrees(90,1)
        #   self.receivedegrees(180)
        #   self.receivedegrees(270)
        # return root
        return root
Пример #5
0
    def initialise_osc(self):
        oscAPI.init()

        oscid = oscAPI.listen(ipAddr='127.0.0.1', port=osc_listen_port)
        oscAPI.bind(oscid, self.poem_position_changed, osc_poem_position)
        oscAPI.bind(oscid, self.rhythm_position_changed, osc_rhythm_position)
        self.osc_poll = Clock.schedule_interval(lambda *x: oscAPI.readQueue(oscid), 0.01)

        send_osc_message('/osc/respond_to', [osc_listen_port])
        send_osc_message(osc_poem_position, [0.0001], typehint=1.0)
        send_osc_message(osc_rhythm_position, [0.0001], typehint=1.0)
Пример #6
0
    def __init__(self, **kwargs):
        self.sendip = sys.argv[len(sys.argv)-1]

        self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
        self._keyboard.bind(on_key_down=self._on_keyboard_down)

        self.renderer = kwargs['renderer']

        self._prevKnob = [0.,0.,0.]
        self._touches = []

        oscAPI.init()  
        oscid = oscAPI.listen(ipAddr="0.0.0.0", port= 5000) 
        Clock.schedule_interval(lambda *x: oscAPI.readQueue(oscid), 0)
        oscAPI.bind(oscid, self.dialListener, '/tuios/tok')
        oscAPI.bind(oscid, self.receive, '/tuios/intra')
Пример #7
0
class Session:
    # OSC server init - Broadcast listener on port 57121
    oscAPI.init()
    oscAPI.outSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
    oscAPI.outSocket.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
    osc_listener = oscAPI.listen('0.0.0.0', 57121)

    # Session instances collector
    instances = {}

    # Threading Syncronization Events
    resources_lock = Condition()

    # Session Constructor and Creation Conditions
    def __init__(self, session_id):
        # set-up session
        if Session.check(session_id):
            # session already defined
            self = Session.instances[session_id]
        else:
            # instance properties
            self.session_id = session_id
            # add instance to the collector
            Session.instances.setdefault(self.session_id, self)
            # other collectors
            self.connected_surfaces = {}

    # Class methods driven by IDs
    @classmethod
    def check(cls, session_id):
        if session_id in Session.instances:
            return True
        else:
            return False

    @classmethod
    def check_connected_surface(cls, session_id, control_surface_id):
        if Session.check(session_id):
            # Multiple control surfaces with the same ID in the same session are not allowed
            if Session.instances[session_id].connected_surfaces[control_surface_id]:
                return True
            else:
                return False
        else:
            return False

    @classmethod
    def get_connected_surface(cls, session_id, control_surface_id):
        if Session.check_connected_surface(session_id, control_surface_id):
            return Session.instances[session_id].connected_surfaces[control_surface_id]

    # OSC Communication
    def send(self, widget_id, value):
        '''Send the passed value over network to all devices in the same session

        :attr:`widget_id` it refers to the assigned id of given widget producing the value.
        :attr:`value` can be any type of value accepted from OSC standard.
        '''
        completePath = "/" + str(self.session_id) + "/" + str(widget_id)
        oscAPI.sendMsg(completePath, [value], '255.255.255.255', 57120)

    def set_responder(self, widget_id, opcode, function):
        '''Send the passed value over network to all devices in the same session.

        :attr:`widget_id` it refers to the assigned id of given widget producing the value.
        :attr:`opcode` is the operation name assigned to the passed function.
        :attr:`function` the definition of function respond.
        '''
        completePath = "/" + str(self.session_id) + "/" + str(widget_id) + "/" + str(opcode)
        oscAPI.bind(Session.osc_listener, function, completePath.strip())
        Clock.schedule_interval(lambda *x: oscAPI.readQueue(Session.osc_listener), 0)