Example #1
0
    def __init__(self, tcp_port, osc_port):
                
        self.HOST = ''                 # Symbolic name meaning the local host
        self.PORT = tcp_port               # The port used by the server
        self.serv_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.serv_sock.bind((self.HOST, self.PORT))
        self.serv_sock.listen(1)
        
        
        self.serv_sock.settimeout(10e5)
        o = self.serv_sock.getsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE)
        
        self.osc_clients    = list()
        self.clients        = list()
        self.threads        = list()

        self.dispatcher  = dispatcher.Dispatcher()       
        self.dispatcher.set_default_handler(self.default_handler)
    
        self.server = osc_server.ThreadingOSCUDPServer(( "0.0.0.0", osc_port), self.dispatcher) 
        
        self.server_thread = threading.Thread(target=self.server.serve_forever)
        self.server_thread.deamon = True
        self.server_thread.start() 
        self.threads.append(self.server_thread)

        self.socket_thread = threading.Thread(target=self.connect_sockets)
        self.socket_thread.deamon = True
        self.socket_thread.start()   
        self.threads.append(self.socket_thread)

        self.discon_thread = threading.Thread(target=self.disconnect_sockets)
        self.discon_thread.deamon = True
        self.discon_thread.start()   
        self.threads.append(self.discon_thread)          
Example #2
0
    def __init__(self, ip, port):
        self.dispatcher = dispatcher.Dispatcher()
        self.dispatcher.map("/command", self.command_handler, "")
        self.dispatcher.map("/SQLcommand", self.SQLcommand_handler, "")

        self.server = osc_server.ThreadingOSCUDPServer((ip, port),
                                                       self.dispatcher)
Example #3
0
 def run(self):
     self.gan_dispatcher = dispatcher.Dispatcher()
     self.gan_dispatcher.set_default_handler(self.osc_handler)
     self.server = osc_server.ThreadingOSCUDPServer(("0.0.0.0", 3900),
                                                    self.gan_dispatcher)
     print("Serving OSC on {}".format(self.server.server_address))
     self.server.serve_forever()
Example #4
0
    def start(self):
        """Start receiving and processing EEG data.
        """
        self.started = True

        if isinstance(self.incoming, str):  # LSL inlet
            self.eeg_thread = Thread(target=self._update_eeg_lsl)
            self.eeg_thread.daemon = True
            self.eeg_thread.start()
        else:  # OSC input stream
            if USE_LIBLO:
                self._osc_server.add_method('/muse/eeg', None,
                                            self._update_eeg_liblo_osc)
                self._osc_server.add_method('/muse/acc', None,
                                            self._update_acc_liblo_osc)
                self._osc_server.add_method('/muse/gyro', None,
                                            self._update_gyro_liblo_osc)
                self._osc_server.start()
            else:
                self._dispatcher.map('Person2/eeg',
                                     self._update_eeg_python_osc, 'EEG')
                self._osc_server = osc_server.ThreadingOSCUDPServer(
                    ('127.0.0.1', self.incoming['port']), self._dispatcher)
                print('OSC server initialized at port {}.'.format(
                    self.incoming['port']))
                self._server_thread = Thread(
                    target=self._osc_server.serve_forever)
                self._server_thread.start()
Example #5
0
    def setup_osc_server(self):
        server_parser = argparse.ArgumentParser()
        server_parser.add_argument("--ip", default="127.0.0.1", help="the ip")
        server_parser.add_argument("--port",
                                   type=int,
                                   default=9000,
                                   help="the port")

        server_args = server_parser.parse_args()

        this_dispatcher = dispatcher.Dispatcher()
        this_dispatcher.map("/player/a/position",
                            self.video_driver.receive_position, "a.a")
        this_dispatcher.map("/player/b/position",
                            self.video_driver.receive_position, "b.b")
        this_dispatcher.map("/player/c/position",
                            self.video_driver.receive_position, "c.c")
        this_dispatcher.map("/player/a/status",
                            self.video_driver.receive_status, "a.a")
        this_dispatcher.map("/player/b/status",
                            self.video_driver.receive_status, "b.b")
        this_dispatcher.map("/player/c/status",
                            self.video_driver.receive_status, "c.c")
        this_dispatcher.map("/detour/detour_info", self.receive_detour_info)
        this_dispatcher.map("/capture/recording_finished",
                            self.capture.receive_recording_finished)
        this_dispatcher.map("/shutdown", self.exit_osc_server)
        #this_dispatcher.map("/player/a/status", self.set_status)

        server = osc_server.ThreadingOSCUDPServer(
            (server_args.ip, server_args.port), this_dispatcher)
        server_thread = threading.Thread(target=server.serve_forever)
        server_thread.start()
        return server
def main(args):
    includes = DEFAULT_INCLUDES + args.include

    dispatcher = Dispatcher()
    dispatcher.map("/remove", remove_handler, "Remove")
    dispatcher.map("/detach", detach_handler, "Detach")
    dispatcher.map("/slur_oneshot", slur_handler, "Slur")
    dispatcher.map("/tie_oneshot", tie_handler, "Tie")
    dispatcher.map("/text_spanner_oneshot", text_spanner_handler,
                   "Text Spanner")
    dispatcher.map("/notehead_oneshot", notehead_handler, "Notehead")
    dispatcher.map("/bar_line_oneshot", bar_line_handler, "BarLine")
    dispatcher.map("/articulation_oneshot", articulation_handler,
                   "Articulation")
    dispatcher.map("/dynamic_oneshot", dynamic_handler, "Dynamic")
    dispatcher.map("/dynamicTrend_oneshot", dynamicTrend_handler,
                   "DynamicTrend")
    dispatcher.map("/literal_oneshot", literal_handler, "Literal")
    dispatcher.map("/markup_oneshot", markup_handler, "Markup")
    dispatcher.map("/note_event", note_handler, "Note")
    dispatcher.map("/display", display_handler, "Display")

    server = osc_server.ThreadingOSCUDPServer((args.host, args.port),
                                              dispatcher)

    print("Serving on {}".format(server.server_address))
    server.serve_forever()
Example #7
0
    def __init__(self):
        super().__init__()

        self.cache = {}
        log.info("Starting X32 connection")
        dispatch = dispatcher.Dispatcher()
        dispatch.set_default_handler(self.dispatch_to_room)
        server = osc_server.ThreadingOSCUDPServer(("0.0.0.0", 10033), dispatch)
        self.client = X32UdpClient("192.168.178.21", 10023, server)

        log.info("Starting keep_alive thread")
        Thread(target=self.keep_alive).start()
        log.info("Starting osc event handler thread")
        Thread(target=server.serve_forever).start()

        self.messages = OrderedDict()
        for channel in range(1, 33):
            self.messages[f'/ch/{channel:02}/mix/fader'] = float
            self.messages[f'/ch/{channel:02}/mix/on'] = int
            self.messages[f'/ch/{channel:02}/config/name'] = str
            self.messages[f'/ch/{channel:02}/config/color'] = str
            self.messages[f'/-ha/{channel-1:02}/index'] = int


        for headamp in range(127):
            self.messages[f'/headamp/{headamp:03}/gain'] = float
            self.messages[f'/headamp/{headamp:03}/phantom'] = int

        log.debug("Requesting %i properties" % len(self.messages))


        self.full_sync()
Example #8
0
def start_server_comms(ip, port, paths):
    # paths = ['random_integer', 'circle']

    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", default=ip, help="The ip to listen on")
    parser.add_argument("--port",
                        type=int,
                        default=port,
                        help="The port to listen on")
    args = parser.parse_args()
    osc_statemachine['args'] = args

    dispatch = dispatcher.Dispatcher()

    for path in paths:
        dispatch.map("/" + path, general_handler)

    osc_statemachine['dispatcher'] = dispatch

    try:
        server = osc_server.ThreadingOSCUDPServer((args.ip, args.port),
                                                  dispatch)
        print("Serving on {}".format(server.server_address))

        # makes it non blocking, and serves on another thread, how exactly the dispatch
        # commands are able to callback into the current thread is kinda magical. This
        # seems to work, but something tells me this is brittle af.
        server_thread = threading.Thread(target=server.serve_forever)
        server_thread.start()
        osc_statemachine['server_thread'] = server_thread
        osc_statemachine['server'] = server

    except:

        print('already active')
Example #9
0
def main():
    try:
        # Set PIN states
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        GPIO.setup(COIL_A_1_PIN, GPIO.OUT)
        GPIO.setup(COIL_A_2_PIN, GPIO.OUT)
        GPIO.setup(COIL_B_1_PIN, GPIO.OUT)
        GPIO.setup(COIL_B_2_PIN, GPIO.OUT)
        GPIO.setup(IRSENSE_PIN, GPIO.IN)
        GPIO.setup(LED_PIN, GPIO.OUT)

        d = dispatcher.Dispatcher()
        d.map("/forward", forward_handler, "Clock forwards (hours)")
        d.map("/backward", backward_handler, "Clock backwards (hours)")
        d.map("/shutdown", shutdown_handler, "Shutdown Pi nicely")
        d.map("/reboot", reboot_handler, "Reboot Pi nicely")

        server = osc_server.ThreadingOSCUDPServer((OSC_LISTEN, OSC_PORT), d)
        print("OSC listening on {} port {}".format(OSC_LISTEN, OSC_PORT))
        server.serve_forever()
    except KeyboardInterrupt:
        print("Closing down")
        setStep(0, 0, 0, 0)
    except Exception:
        traceback.print_exc(file=sys.stdout)
        setStep(0, 0, 0, 0)

    # We'll never get here!
    sys.exit(0)
Example #10
0
 def run(self):
   # Start listening server
   ip = self.myConfig["settings"]["listenIP"]
   port = self.myConfig["settings"]["port"]
   d = dispatcher.Dispatcher()
   # Catch workspace updates which tell us we have a new cue position
   d.map("/update/workspace/*/cueList/*/playbackPosition", self.updatePlaybackPosition)
   d.map("/reply/cue_id/*/displayName", self.updateNextCueName)
   d.map("/reply/workspace/*/runningCues", self.updateCurrentCue)
   d.map("/reply/workspace/*/runningOrPausedCues", self.updateCurrentCue)
   d.map("/reply/workspace/*/cueList", self.updateCurrentCue)
   d.map("/reply/cue_id/*/isPaused", self.updateCurrentCueStatus)
   d.map("/reply/cue_id/*/isRunning", self.updateCurrentCueStatus)
   for action in self.myConfig["actions"]:
     for actionName in action.keys():
       if isinstance(action[actionName], dict):
         if re.match("OSC-", actionName, re.I):
           n = re.sub("OSC-", "", actionName, flags=re.I)
           self.logger.debug("Registering action for {}".format(n))
           d.map(n, self.receiveOSCMessage,  actionName)
   self.logger.debug("Starting OSC server on {} port {}".format(ip, port))
   server = osc_server.ThreadingOSCUDPServer((ip, port), d)
   self.server_thread = threading.Thread(target = server.serve_forever)
   self.server_thread.start()
   
   while self.running:
     pass
   
   self.logger.debug("Stopping server")
   server.shutdown()
Example #11
0
def osc_thread(name):
    dispatcher.map("/video/song", song_osc_receive, "song_osc_receive")
    dispatcher.map("/video/slideshow", slideshow_osc_receive,
                   "slideshow_osc_receive")

    dispatcher.map("/video/obs", obs_osc_receive, "obs_osc_receive")
    dispatcher.map("/video/visualizer/preset", projectm_preset_osc_receive,
                   "projectm_preset_osc_receive")
    dispatcher.map("/video/visualizer/lock", projectm_lock_osc_receive,
                   "projectm_lock_osc_receive")
    dispatcher.map("/video/visualizer/random", projectm_random_osc_receive,
                   "projectm_random_osc_receive")

    try:
        server = osc_server.ThreadingOSCUDPServer(
            (OSC_LOCALHOST_IP, OSC_LOCALHOST_PORT), dispatcher)
        print("Starting OSC server")
        try:
            server.serve_forever()
        except (KeyboardInterrupt, SystemExit):
            print('The END in OSC server.')
    except (OSError):
        print(
            "Could not connect to Liveserver on RASPI. If you're not in simulation mode, please check you're connected to the RASPI hotspot"
        )
        print("Exiting OSC thread")
def osc_receive():
    disp = dispatcher.Dispatcher()
    disp.map(conf["address"], _osc_sample)
    server = osc_server.ThreadingOSCUDPServer(
        (conf["ip"], conf["ports"]["send"]), disp)
    server.serve_forever()
    return
Example #13
0
def main():
    # Have to import it locally, don't know why
    from pythonosc import osc_server
    from pythonosc import dispatcher

    # OSC Server thread
    print("Starting OSC dispatcher")
    dispatcher = dispatcher.Dispatcher()
    dispatcher.map("/muse/elements/gamma_absolute", gamma_handler,
                   "GAMMA_HANDLER")

    server = osc_server.ThreadingOSCUDPServer((args.ip, args.port), dispatcher)

    serverThread = Thread(target=server.serve_forever)
    serverThread.start()

    # Web server thread
    print("Starting web server")
    flaskThread = Thread(target=flaskServer)
    flaskThread.start()

    # Session thread
    print("Starting session thread")
    sessionThread = Thread(target=startSession)
    sessionThread.start()

    sessionThread.join()
Example #14
0
def collectData(signal="eeg"):
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip",
                        default="127.0.0.1",
                        help="The ip to listen on")
    parser.add_argument("--port",
                        type=int,
                        default=5001,
                        help="The port to listen on")
    args = parser.parse_args()

    dispatch = dispatcher.Dispatcher()
    dispatch.map("/debug", print)
    dispatch.map("/muse/" + signal, handler, "EEG")
    # dispatch.map("/muse/elements/")

    server = osc_server.ThreadingOSCUDPServer((args.ip, args.port), dispatch)
    server_thread = threading.Thread(target=server.serve_forever)
    print("Serving on {}".format(server.server_address))
    server_thread.start()

    time.sleep(5)
    global STATE
    STATE = analysis(rows_list)

    server.shutdown()
    print("Done serving on {}".format(server.server_address))
Example #15
0
def start_server(ip, port):

    print("Starting Server")
    server = osc_server.ThreadingOSCUDPServer((ip, port), dispatcher)
    print("Serving on {}".format(server.server_address))
    thread = threading.Thread(target=server.serve_forever)
    thread.start()
Example #16
0
def start_osc_server():
    global server
    print("*** STARTE OSC SERVER ***", flush=True)
    dispat = dispatcher.Dispatcher()

    dispat.map("/counter/reset_inside",
               got_set_inside,
               needs_reply_address=True)
    dispat.map("/counter/reset_max", got_set_maximum, needs_reply_address=True)
    dispat.map("/counter/inside_plus",
               got_inside_plus,
               needs_reply_address=True)
    dispat.map("/counter/inside_minus",
               got_inside_minus,
               needs_reply_address=True)
    dispat.map("/counter/max_plus", got_maximum_plus, needs_reply_address=True)
    dispat.map("/counter/max_minus",
               got_maximum_minus,
               needs_reply_address=True)
    dispat.map("/counter/counter_info",
               got_counter_info,
               needs_reply_address=True)
    try:
        hostname = socket.gethostname()
        local_ip = socket.gethostbyname(hostname + ".local")
    except:
        local_ip = "192.168.4.1"
    local_ip = "192.168.4.1"
    print(local_ip, flush=True)
    server = osc_server.ThreadingOSCUDPServer((local_ip, 9001), dispat)

    server.serve_forever()
Example #17
0
def start_osc_server():
    global server
    print("*** STARTE OSC SERVER ***", flush=True)
    dispat = dispatcher.Dispatcher()

    # Empfangbare Messeges mit Functioncalls
    dispat.map("/counter/reset_inside",
               got_set_inside,
               needs_reply_address=True)
    dispat.map("/counter/reset_max", got_set_maximum, needs_reply_address=True)
    dispat.map("/counter/inside_plus",
               got_inside_plus,
               needs_reply_address=True)
    dispat.map("/counter/inside_minus",
               got_inside_minus,
               needs_reply_address=True)
    dispat.map("/counter/max_plus", got_maximum_plus, needs_reply_address=True)
    dispat.map("/counter/max_minus",
               got_maximum_minus,
               needs_reply_address=True)
    dispat.map("/counter/counter_info",
               got_counter_info,
               needs_reply_address=True)
    dispat.map("/counter_info", got_slave_info, needs_reply_address=True)
    print(local_ip, flush=True)
    server = osc_server.ThreadingOSCUDPServer((local_ip, 9001), dispat)

    server.serve_forever()
Example #18
0
def setup_OSC(new_ip, new_port):
    disp = dispatcher.Dispatcher()
    disp.map("/red/mode", standard_handler, redGen.set_mode)
    disp.map("/green/mode", standard_handler, grnGen.set_mode)
    disp.map("/blue/mode", standard_handler, bluGen.set_mode)
    disp.map("/red/offset", standard_handler, redGen.set_offset)
    disp.map("/red/scale", standard_handler, redGen.set_scale)
    disp.map("/green/offset", standard_handler, grnGen.set_offset)
    disp.map("/green/scale", standard_handler, grnGen.set_scale)
    disp.map("/blue/offset", standard_handler, bluGen.set_offset)
    disp.map("/blue/scale", standard_handler, bluGen.set_scale)
    disp.map("/blue/shape", standard_handler, bluGen.set_shape_8bit)
    disp.map("/green/shape", standard_handler, grnGen.set_shape_8bit)
    disp.map("/red/shape", standard_handler, redGen.set_shape_8bit)
    disp.map("/red/speed", speed_handler, redGen.set_increment_8bit)
    disp.map("/green/speed", speed_handler, grnGen.set_increment_8bit)
    disp.map("/blue/speed", speed_handler, bluGen.set_increment_8bit)
    disp.map("/shape/sides", standard_handler, shape_drawer.set_sides8bit)
    disp.map("/shape/size", standard_handler, shape_drawer.set_size8bit)
    disp.map("/shape/xinc", standard_handler, shape_drawer.set_xincrement8bit)
    disp.map("/shape/yinc", standard_handler, shape_drawer.set_yincrement8bit)
    disp.map("/shape/xcenter", standard_handler, shape_drawer.set_centerx8bit)
    disp.map("/shape/ycenter", standard_handler, shape_drawer.set_centery8bit)
    disp.map("/shape/shapecount", standard_handler,
             shape_drawer.set_shape_count8bit)
    disp.map("/shape/shapeskip", standard_handler,
             shape_drawer.set_shape_space8bit)
    disp.map("/global/strobe", global_strobe_handler, "zz")

    server = osc_server.ThreadingOSCUDPServer((new_ip, new_port), disp)
    server_thread = threading.Thread(target=server.serve_forever)
    server_thread.start()
    return server, server_thread
Example #19
0
 def run(self):
     dispatch = dispatcher.Dispatcher()
     dispatch.map(self._osc_url, self.handle_data)
     server = osc_server.ThreadingOSCUDPServer(
         (self._osc_ip, self._osc_port), dispatch)
     print("Serving now")
     server.serve_forever()
Example #20
0
    def _start_osc(self):
        if not importlib.util.find_spec("pythonosc"):
            logger.critical("错误:请先安装 python-osc !")
            return

        from pythonosc import dispatcher as dsp
        from pythonosc import osc_server

        dispatcher = dsp.Dispatcher()
        dispatcher.map("/muse/elements/blink", self.blink_handler, "EEG")
        dispatcher.map("/muse/elements/jaw_clench", self.jaw_clench_handler,
                       "EEG")

        try:
            server = osc_server.ThreadingOSCUDPServer(
                (
                    config.get("/muse/ip", "127.0.0.1"),
                    int(config.get("/muse/port", "5001")),
                ),
                dispatcher,
            )
            logger.info("Muse serving on {}".format(server.server_address))
            server.serve_forever()
        except Exception as e:
            logger.error(e)
def start_viewer(sender):
	global viewer

	### OSC Server ###
	local_address = socket.gethostbyname(socket.gethostname())
	dispatch = dispatcher.Dispatcher()
	
	for i, id in enumerate(used_device_ids):
		dispatch.map('/{}'.format(id), raw_osc_handler, id)

	server = osc_server.ThreadingOSCUDPServer((local_address, 5005), dispatch)
	server.socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 512000)
	server.socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVLOWAT, 1)

	viewer = Viewer(device_ids=used_device_ids, nChannel=4, server=server, lock=lock)
	
	### START SERVER ###	
	server_thread = Thread(target=server.serve_forever)
	server_thread.setDaemon(True)
	server_thread.start()
	print('serving at {}:{}'.format(local_address, 5005))

		
	sceneView = SceneView()
	sceneView.scene = viewer
	sceneView.flex = 'LRHWT' 
	sceneView.present('full_screen')
Example #22
0
    def setup_osc_server(self):
        server_parser = argparse.ArgumentParser()
        server_parser.add_argument("--ip", default="127.0.0.1", help="the ip")
        server_parser.add_argument("--port", type=int, default=9000, help="the port")
        
        server_args = server_parser.parse_args()

        this_dispatcher = dispatcher.Dispatcher()

        this_dispatcher.map("/sampleList", self.set_sample_list)
        this_dispatcher.map("/shaderList", self.set_shader_list)
        this_dispatcher.map("/fxList", self.set_fx_list)
        this_dispatcher.map("/cameraList", self.set_camera_list)
        this_dispatcher.map("/selectedRow", self.set_selected_row)
        this_dispatcher.map("/selectedFxRow", self.set_selected_fx_row)
        this_dispatcher.map("/inputMode", self.set_input_mode)
        this_dispatcher.map("/fxScreenVisible", self.set_fx_screen_visible)
        this_dispatcher.map("/playOn", self.set_play_on)
        this_dispatcher.map("/fxOn", self.set_fx_on)
        this_dispatcher.map("/isCameraOn", self.set_is_camera_on)
        this_dispatcher.map("/playingSampleRow", self.set_playing_sample_row)
        this_dispatcher.map("/playingShaderRow", self.set_playing_shader_row)
        this_dispatcher.map("/playingFxRow", self.set_playing_fx_row)



        server = osc_server.ThreadingOSCUDPServer((server_args.ip, server_args.port), this_dispatcher)
        server_thread = threading.Thread(target=server.serve_forever)
        server_thread.start()
        return server
Example #23
0
def main():
    # intialise the client and server_thread
    client = udp_client.SimpleUDPClient(cfg.UDP_IP, cfg.UDP_S_PORT)

    server = osc_server.ThreadingOSCUDPServer((cfg.UDP_IP, cfg.UDP_R_PORT),
                                              dispatcher)
    server_thread = threading.Thread(target=receive_server,
                                     args=[server],
                                     daemon=True)
    server_thread.start()

    print("OSC server online.")
    while not glob.terminate_flag:
        if glob.osc_commands:
            new_commands = glob.osc_commands[:]
            glob.osc_commands.clear()

            for command in new_commands:
                route, msg = command
                client.send_message(route, msg)
                print(f"sent {route} {msg} to osc")

        sleep(cfg.threads_delay)

    print("OSC server terminated.")
Example #24
0
    def __init__(self,
                 action_space,
                 observation_space,
                 reward_function=None,
                 observation_address="/env/observation",
                 action_address="/env/action",
                 observation_port=8000,
                 action_port=8001,
                 action_ip="127.0.0.1"):
        self.action_space = action_space
        self.observation_space = observation_space
        self.reward_function = reward_function
        self.observation_address = observation_address
        self.action_address = action_address

        self.dispatcher = dispatcher.Dispatcher()
        self.dispatcher.map("/", print)
        self.dispatcher.map(observation_address, _receive_observation, self)

        self.server = osc_server.ThreadingOSCUDPServer(
            ("127.0.0.1", observation_port), self.dispatcher)
        self.client = udp_client.SimpleUDPClient(action_ip, action_port)
        server_thread = threading.Thread(target=self.server.serve_forever)
        server_thread.start()

        print("OSCEnv client/action={}:{} server/observation=localhost:{}".
              format(action_ip, action_port, observation_port))
Example #25
0
    def start_server(self, ip, po, op):

        self.outpath = op
        self.port = po
        self.ip = ip

        if self.timer == 'jack':
            self.jack_client = jack.Client('osc-recorder')
            self.jack_client.activate()

        # client.inports.register('input_1')

        if not os.path.exists(self.outpath):
            os.makedirs(self.outpath)

        self.dispatcher = dispatcher.Dispatcher()

        self.dispatcher.map("/*", self.generic_handler)

        self.dispatcher.map("/timer", self.external_time_handler)

        self.server = osc_server.ThreadingOSCUDPServer((self.ip, self.port),
                                                       self.dispatcher)

        print("Generic OSC recorder serving on {}".format(
            self.server.server_address))

        print("Writing files to " + self.outpath)

        #self.server.server_activate()

        self.server.serve_forever()
Example #26
0
    def __init__(self):

        self.log = logging.getLogger("pybinsim.OscReceiver")
        self.log.info("oscReceiver: init")

        # Basic settings
        self.ip = '127.0.0.1'
        self.port = 10000
        self.maxChannels = 100

        # Default values; Stores filter keys for all channles/convolvers
        self.filters_updated = [True] * self.maxChannels

        self.defaultValue = (0, 0, 0, 0, 0, 0, 0, 0, 0)
        self.valueList = [self.defaultValue] * self.maxChannels
        # self.valueList = [()] * self.maxChannels
        self.soundFileList = ''
        self.soundFileNew = False
        self.soundevent = False
        self.soundevent_data = []

        osc_dispatcher = dispatcher.Dispatcher()
        osc_dispatcher.map("/pyBinSim", self.handle_filter_input)
        osc_dispatcher.map("/pyBinSimFile", self.handle_file_input)
        osc_dispatcher.map("/pyBinSimSoundevent", self.handle_soundevent)

        self.server = osc_server.ThreadingOSCUDPServer(
            (self.ip, self.port), osc_dispatcher)
Example #27
0
    def __init__(self):
        self._bpm = 120
        subprocess.call(['killall', 'klick'])

        # Start klick process in background
        self._klick_process = subprocess.Popen(
            ['klick', '-o', str(self.PORT), '-P'])
        time.sleep(1)

        self._running = True

        # Communicate with klick via OSC
        self._klick_osc = udp_client.SimpleUDPClient('127.0.0.1', self.PORT)

        # Set sensible default volume and max bpm
        self._klick_osc.send_message('/klick/config/set_volume', 0.5)
        self._klick_osc.send_message('/klick/simple/set_tempo_limit', 300)

        # Start OSC server for receiving responses
        self._dispatcher = dispatcher.Dispatcher()
        self._dispatcher.map('/*', self._osc_response)
        self._server = osc_server.ThreadingOSCUDPServer(
            ('0.0.0.0', self.PORT + 1), self._dispatcher)
        self._thread = Thread(target=self._server.serve_forever)
        self._thread.start()
Example #28
0
    def __init__(self, mpstate):
        super(RCModule, self).__init__(mpstate,
                                       "rc",
                                       "rc command handling",
                                       public=True)
        self.override = [0] * 16
        self.last_override = [0] * 16
        self.override_counter = 0
        self.add_command('rc', self.cmd_rc, "RC input control",
                         ['<1|2|3|4|5|6|7|8|all>'])
        self.add_command('switch', self.cmd_switch,
                         "flight mode switch control", ['<0|1|2|3|4|5|6>'])
        if self.sitl_output:
            self.override_period = mavutil.periodic_event(20)
        else:
            self.override_period = mavutil.periodic_event(1)

        # for osc server
        self.dispatcher = dispatcher.Dispatcher()
        self.dispatcher.map("/debug_from_max", self.osc_debug)
        self.dispatcher.map("/thrust_from_max", self.osc_thrust)
        self.dispatcher.map("/roll_from_max", self.osc_roll)
        self.dispatcher.map("/pitch_from_max", self.osc_pitch)
        self.dispatcher.map("/yaw_from_max", self.osc_yaw)
        self.server = osc_server.ThreadingOSCUDPServer(("127.0.0.1", 10000),
                                                       self.dispatcher)
        print("Serving on {}".format(self.server.server_address))
        server_thread = threading.Thread(target=self.server.serve_forever)
        server_thread.daemon = True
        server_thread.start()
Example #29
0
    def execute(self, context):
        global _report 
        bcw = bpy.context.window_manager
        
        #For sending
        try:
            self.client = udp_client.UDPClient(bcw.addosc_udp_out, bcw.addosc_port_out)
            msg = osc_message_builder.OscMessageBuilder(address="/blender")
            msg.add_arg("Hello from Blender, simple test.")
            msg = msg.build()
            self.client.send(msg)
        except OSError as err: 
            _report[1] = err
            return {'CANCELLED'}    
    
        #Setting up the dispatcher for receiving
        try:
            self.dispatcher = dispatcher.Dispatcher()
            self.dispatcher.set_default_handler(OSC_callback)
            self.server = osc_server.ThreadingOSCUDPServer((bcw.addosc_udp_in, bcw.addosc_port_in), self.dispatcher)
            self.server_thread = threading.Thread(target=self.server.serve_forever)
            self.server_thread.start()
        except OSError as err:
            _report[0] = err
            return {'CANCELLED'}

          
        #inititate the modal timer thread
        context.window_manager.modal_handler_add(self)
        self._timer = context.window_manager.event_timer_add(bcw.addosc_rate/1000, context.window)
        context.window_manager.status = "Running"
        
        return {'RUNNING_MODAL'}
Example #30
0
def start_osc_server():
    global RAILS_CLIENT

    def osc_callback(path, value):
        print(f"----> OSC path: {path}, value: {value}")
        if rails_process_osc(path, value):
            return 1
        if GLOBAL.mixes is not None and GLOBAL.mixes.process_osc(path, value):
            return 1
        if GLOBAL.simpledaw is not None and GLOBAL.simpledaw.process_osc(path, value):
            return 1
        if GLOBAL.recording_engine is not None and GLOBAL.recording_engine.process_osc(path, value):
            return 1
        print("----> OSC missed")

    ########################################################
    # I hate importing inside a function but it doesn't seem
    #  to want to work any other way..
    from pythonosc import dispatcher
    ########################################################

    # accept osc data from rails
    disp = dispatcher.Dispatcher()
    disp.map("/*", osc_callback)
    server = osc_server.ThreadingOSCUDPServer((IP, OSC_INPORT), disp)
    threading.Thread(target=server.serve_forever).start()
    print(f"----> Listening on port udp:{OSC_INPORT}")

    # send osc data to rails
    RAILS_CLIENT = udp_client.SimpleUDPClient(IP, RAILS_OUTPORT)
    print(f"----> UDP client to rails active")