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)
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)
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
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
def build(self): oscAPI.init() main_layout = StackLayout() for i in range(4): xy_pad = XyPad(size_hint=(0.5, 0.5)) xy_pad.x_msg = '/fxparam/{0}/value'.format(i*2 + 1) xy_pad.y_msg = '/fxparam/{0}/value'.format(i*2 + 2) main_layout.add_widget(xy_pad) return main_layout
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)
def build(self): oscAPI.init() layout = BoxLayout(orientation='horizontal') button = Button(text='Touch me!', font_size=120) button.bind(on_press=self.pressBtn) button.bind(on_release=self.releaseBtn) self.label = Label(text="------------", font_size=50) layout.add_widget(button) layout.add_widget(self.label) return layout
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')
def build(self): oscAPI.init()
def build(self): oscAPI.init() root = FloatLayout(size=(self.tray_width,300), pos = (0,0)) # Creates an image widget for the root root_image = Image(source='img/black.jpg', size_hint_x=None, width=self.tray_width, size_hint_y=None, height=300, allow_stretch = True, keep_ratio = False) root.add_widget(root_image) tray = GridLayout(rows = 1, cols = 4, spacing = 10, padding = 0) scatter = Scatter() leftLabel = Label(valign="middle", halign="left", text="Use an appropriate token\nor three fingers to\nexplore the object\nusing the knobs", italic=True, color=(255, 255, 255, 0.75), font_size='20sp') # Creates a MyKnob object widgetA = RelativeLayout(size_hint = (None, None), size = (300,300)) knobA = MyKnob(size = (300, 300), min = 0, max = 360, step = 1, show_marker = True, knobimg_source = "img/knob_metal.png", marker_img = "img/bline.png", markeroff_color = (0.3, 0.3, .3, 1), pattern_id= 99, #(ids 1 to 8, or 99 for no id) debug = False, obj = scatter, # Passes the object to the knob knob_id = 001) labelA = Label(text = "Rotate object\nhorizontally", font_size = '20sp', italic = True, bold = True, color = (0, 0, 0, 0.75), halign = "center") widgetA.add_widget(knobA) widgetA.add_widget(labelA) # Creates a MyKnob object widgetB = RelativeLayout(size_hint = (None, None), size = (300,300)) knobB = MyKnob(size = (300, 300), min = 0, max = 360, step = 1, show_marker = True, knobimg_source = "img/knob_metal.png", marker_img = "img/bline.png", markeroff_color = (0.3, 0.3, .3, 1), pattern_id= 99, #(ids 1 to 8, or 99 for no id) debug = False, obj = scatter, # Passes the object to the knob knob_id = 002) labelB = Label(text = "Rotate object\nvertically", font_size = '20sp', italic = True, bold = True, color = (0, 0, 0, 0.75), halign = "center") widgetB.add_widget(knobB) widgetB.add_widget(labelB) # Creates a MyKnob object widgetC = RelativeLayout(size_hint = (None, None), size = (300,300)) knobC = MyKnob(size = (300, 300), min = 0, max = 360, step = 1, show_marker = True, knobimg_source = "img/knob_metal.png", marker_img = "img/bline.png", markeroff_color = (0.3, 0.3, .3, 1), pattern_id= 99, #(ids 1 to 8, or 99 for no id) debug = False, obj = scatter, # Passes the object to the knob knob_id = 003) labelC = Label(text = "Zoom", font_size = '20sp', italic = True, bold = True, color = (0, 0, 0, 0.75), halign = "center") widgetC.add_widget(knobC) widgetC.add_widget(labelC) # Adds objects to the root tray.add_widget(leftLabel) tray.add_widget(widgetA) tray.add_widget(widgetB) tray.add_widget(widgetC) root.add_widget(tray) return root
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)
def build(self): oscAPI.init() root = FloatLayout(size=(self.tray_width, 300), pos=(0, 0)) #sameer # Creates an image widget for the root '''root_image = Image(source='img/black.jpg', size_hint_x=None, width=self.tray_width, size_hint_y=None, height=300, allow_stretch = True, keep_ratio = False)''' #---------------------- # Modified by Sarah root_image = Image(source='img/Blue-Background.jpg', size_hint=(1, 1), allow_stretch=True, keep_ratio=False) #---------------------- root.add_widget(root_image) tray = GridLayout(rows=1, cols=5, spacing=10, padding=0) scatter = Scatter() #---------------------- # Modified by Sarah infoLabel = Label( #valign="middle", #halign="left", text="Use token or three \nfingers on the knobs", font_name='fonts/CreatorCreditsBB_ital.ttf', color=(255, 255, 255, 0.75), font_size='40sp') infoLabel.pos = (1150, 100) infoLabelWid = Widget(pos=(0, 0)) infoLabelWid.add_widget(infoLabel) #---------------------- widgetR = Widget() resetb = ImageButton(source="img/reset.png", size_hint=(1, 1), allow_stretch=True, keep_ratio=True, pos=(500, 150), size=(100, 100), valign="top", halign="left", text="RESET", on_press=self.resetb) # Creates a MyKnob object widgetR.add_widget(resetb) # Creates a MyKnob object widgetA = RelativeLayout(size_hint=(None, None), size=(300, 300)) self.knobA = MyKnob( size=(300, 300), min=0, max=360, step=1, show_marker=True, knobimg_source="img/knob1.png", marker_img="img/bline.png", markeroff_color=(0.3, 0.3, .3, 1), pattern_id=99, #(ids 1 to 8, or 99 for no id) debug=False, obj=scatter, # Passes the object to the knob knob_id=001) widgetA.add_widget(self.knobA) # Creates a MyKnob object widgetB = RelativeLayout(size_hint=(None, None), size=(300, 300)) self.knobB = MyKnob( size=(300, 300), min=0, max=360, step=1, show_marker=True, knobimg_source="img/knob2.png", marker_img="img/bline.png", markeroff_color=(0.3, 0.3, .3, 1), pattern_id=99, #(ids 1 to 8, or 99 for no id) debug=False, obj=scatter, # Passes the object to the knob knob_id=002) widgetB.add_widget(self.knobB) # Creates a MyKnob object widgetC = RelativeLayout(size_hint=(None, None), size=(300, 300)) self.knobC = MyKnob( size=(300, 300), min=0, max=360, step=1, show_marker=True, knobimg_source="img/knob3.png", marker_img="img/bline.png", markeroff_color=(0.3, 0.3, .3, 1), pattern_id=99, #(ids 1 to 8, or 99 for no id) debug=False, obj=scatter, # Passes the object to the knob knob_id=003) widgetC.add_widget(self.knobC) # Adds objects to the root tray.add_widget(infoLabelWid) #tray.add_widget(infoLabel) tray.add_widget(widgetR) tray.add_widget(widgetA) tray.add_widget(widgetB) tray.add_widget(widgetC) root.add_widget(tray) return root