Beispiel #1
0
def main():
    def on_osc_message(addr, args):
        print(addr, args)

    dispatcher = pythonosc.dispatcher.Dispatcher()
    dispatcher.set_default_handler(on_osc_message)

    server = pythonosc.osc_server.ThreadingOSCUDPServer(('0.0.0.0', 11543),
                                                        dispatcher)
    server.serve_forever()
Beispiel #2
0
def _start():
    '''Start the module
    This uses the global variables from setup and adds a set of global variables
    '''
    global parser, args, config, r, response, patch, name
    global use_old_version, dispatcher, osc_server
    global monitor, debug, osc_address, osc_port, prefix, output_scale, output_offset

    # this can be used to show parameters that have changed
    monitor = EEGsynth.monitor(name=name,
                               debug=patch.getint('general', 'debug'))

    # get the options from the configuration file
    debug = patch.getint('general', 'debug')
    osc_address = patch.getstring('osc',
                                  'address',
                                  default=socket.gethostbyname(
                                      socket.gethostname()))
    osc_port = patch.getint('osc', 'port')
    prefix = patch.getstring('output', 'prefix')

    # the scale and offset are used to map OSC values to Redis values
    output_scale = patch.getfloat('output', 'scale', default=1)
    output_offset = patch.getfloat('output', 'offset', default=0)

    try:
        if use_old_version:
            monitor.success('Starting old version with', osc_address, osc_port)
            s = OSC.OSCServer((osc_address, osc_port))
            s.noCallback_handler = python2_message_handler
            # s.addMsgHandler("/1/faderA", test_handler)
            s.addDefaultHandlers()
            # just checking which handlers we have added
            monitor.info("Registered Callback functions are :")
            for addr in s.getOSCAddressSpace():
                monitor.info(addr)
            # start the server thread
            st = threading.Thread(target=s.serve_forever)
            st.start()
        else:
            monitor.success('Starting new version with', osc_address, osc_port)
            dispatcher = dispatcher.Dispatcher()
            dispatcher.set_default_handler(python3_message_handler)
            server = osc_server.ThreadingOSCUDPServer((osc_address, osc_port),
                                                      dispatcher)
            server.serve_forever()  # this is blocking
        monitor.success("Started OSC server")
    except:
        raise RuntimeError("Cannot start OSC server")

    # there should not be any local variables in this function, they should all be global
    if len(locals()):
        print('LOCALS: ' + ', '.join(locals().keys()))
Beispiel #3
0
from pythonosc import dispatcher, osc_server
import asyncio

if __name__ == "__main__":
    ip = '127.0.0.1'

    dispatcher = dispatcher.Dispatcher()
    dispatcher.set_default_handler(print)

    server = osc_server.ThreadingOSCUDPServer((ip, 9000), dispatcher)
    print("Serving on {}".format(server.server_address))
    server.serve_forever()
Beispiel #4
0
    if use_old_version:
        s = OSC.OSCServer((osc_address, osc_port))
        s.noCallback_handler = python2_message_handler
        # s.addMsgHandler("/1/faderA", test_handler)
        s.addDefaultHandlers()
        # just checking which handlers we have added
        monitor.info("Registered Callback functions are :")
        for addr in s.getOSCAddressSpace():
            monitor.info(addr)
        # start the server thread
        st = threading.Thread(target=s.serve_forever)
        st.start()
    else:
        dispatcher = dispatcher.Dispatcher()
        # dispatcher.map("/1/faderA", test_handler)
        dispatcher.set_default_handler(python3_message_handler)
        server = osc_server.ThreadingOSCUDPServer((osc_address, osc_port),
                                                  dispatcher)
        monitor.info("Serving on {}".format(server.server_address))
        # the following is blocking
        server.serve_forever()
    monitor.success("Started OSC server")
except:
    raise RuntimeError("cannot start OSC server")

# keep looping while incoming OSC messages are being handled
# the code will never get here when using pythonosc with Python3, since that is blocking
try:
    while True:
        monitor.loop()
        time.sleep(patch.getfloat('general', 'delay'))
Beispiel #5
0
                        default="0.0.0.0",
                        help="The ip to listen on (default=0.0.0.0)")
    parser.add_argument("--port",
                        type=int,
                        default=5005,
                        help="The port to listen on (default=5005)")
    parser.add_argument("--midi",
                        type=int,
                        default=0,
                        help="The MIDI device index (default=0)")
    parser.add_argument("--mapping-file-in",
                        default="mapping.json",
                        help="File to read for the OSC to MIDI mapping (default=mapping.json)")
    parser.add_argument("--mapping-file-out",
                        default="mapping.json",
                        help="File for saving the mapping (default=mapping.json)")
    parser.add_argument("--no-learn",
                        action="store_true",
                        help="Map new OSC paths to MIDI")
    args = parser.parse_args()

    with OscMidi(args.midi, not args.no_learn, args.mapping_file_in,
                 args.mapping_file_out) as oscmidi:
        dispatcher = dispatcher.Dispatcher()
        dispatcher.set_default_handler(oscmidi.send_message)

        server = osc_server.ThreadingOSCUDPServer((args.ip, args.port),
                                                  dispatcher)
        print("Serving OSC on {}".format(server.server_address))
        server.serve_forever()
Beispiel #6
0
numchannels = 32
channel_grid_dict = {}
channel_grid_dict[8] = [8, 1]
channel_grid_dict[16] = [4, 4]
channel_grid_dict[32] = [8, 4]
channel_grid_dict[64] = [8, 8]

sample_frequency = 2000
buffer_length = 50
seconds_per_trial = 10
buffers_per_trial = (sample_frequency // buffer_length) * seconds_per_trial

# when bonsai starts, it cant record because it needs metadata for the recording

dispatcher = dispatcher.Dispatcher()
dispatcher.set_default_handler(default_handler)

client = udp_client.SimpleUDPClient("127.0.0.1", 5005)
with osc_server.BlockingOSCUDPServer(("127.0.0.1", 5006),
                                     dispatcher) as server:

    # we are acquiring data from the device
    # send the metadata
    client.send_message(
        "/metadata",
        [numchannels, "../../data/andy/dot_calibration", buffers_per_trial])
    # get an "initialized" response
    msg = server.handle_request()
    print(msg)

    # all set up, waiting for grid
Beispiel #7
0
from osc_record import *
from pythonosc import dispatcher
from pythonosc import osc_server


if __name__ == '__main__':

	record_test = Record()
	record_test.start_recording()
	dispatcher = dispatcher.Dispatcher()
	dispatcher.set_default_handler(record_test.listen)
	server = osc_server.ThreadingOSCUDPServer(
	    ("127.0.0.1", 7000), dispatcher)
	print("Serving on {}".format(server.server_address))
	server.serve_forever()
Beispiel #8
0
signal.signal(signal.SIGTERM, print_data_info)
signal.signal(signal.SIGINT, print_data_info)

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip",
                        default="192.168.0.50",
                        help="The ip to listen on")
    parser.add_argument("--port",
                        type=int,
                        default=5010,
                        help="The port to listen on")
    args = parser.parse_args()

    dispatcher = dispatcher.Dispatcher()
    #dispatcher.set_default_handler(print, needs_reply_address=True)
    dispatcher.set_default_handler(log_message, needs_reply_address=False)
    #dispatcher.map("/filter", print)
    #dispatcher.map("/volume", print_volume_handler, "Volume")
    #dispatcher.map("/logvolume", print_compute_handler, "Log volume", math.log)
    #dispatcher.map("/iPhone/x", print)
    #dispatcher.map("/iPhone/y", print)
    #dispatcher.map("/iPhone/z", print)
    #dispatcher.map("/iPhone/*", print)

    server = osc_server.ThreadingOSCUDPServer((args.ip, args.port), dispatcher)
    #server = osc_server.BlockingOSCUDPServer(
    #    (args.ip, args.port), dispatcher)
    print("Serving on {}".format(server.server_address))
    server.serve_forever()