def create_response_msg(address, result): msg = OSCMessage() msg.setAddress(address) if not hasattr(result, '__iter__'): result = [result] for arg in result: msg.append(arg) return msg.getBinary()
def testDispatchUnknownCommand(self): message = OSCMessage() message.setAddress("/sample/play") sampler = RecordingSampler((1,2,'a string'), AttributeError('a')) handler = SamplerCallbackManager(sampler) # should not throw resp = handler.handle(message.getBinary()) self.assertEquals(resp, "/sampler/error\x00\x00,ss\x00Failed to execute command /sample/play\x00\x00a\x00\x00\x00") self.assertEquals([], self.sampler.recorded);
def testDispatchInvalidAddress(self): message = OSCMessage() message.setAddress("/sample/play/invalid") # should not throw resp = self.handler.handle(message.getBinary()) self.assertEquals(str(resp), "/sampler/error\x00\x00,ss\x00Execution failed\x00\x00\x00\x00" "Invalid address: '/sample/play/invalid', should have two components\x00") self.assertEquals([], self.sampler.recorded);
def testDispatch(self): message = OSCMessage() message.setAddress("/transfertools/get") message.append("test.wav") response = self.handler.handle(message.getBinary()) self.assertEquals([["transfertools", "get", ["test.wav"]]], self.sampler.recorded) expected = OSCMessage() expected.setAddress("/transfertools/get") expected.append(1) expected.append(2) expected.append('a string') self.assertEquals(str(expected), response)
def testDispatchUnknownCommand(self): message = OSCMessage() message.setAddress("/sample/play") sampler = RecordingSampler((1, 2, 'a string'), AttributeError('a')) handler = SamplerCallbackManager(sampler) # should not throw resp = handler.handle(message.getBinary()) self.assertEquals( resp, "/sampler/error\x00\x00,ss\x00Failed to execute command /sample/play\x00\x00a\x00\x00\x00" ) self.assertEquals([], self.sampler.recorded)
def testDispatchInvalidAddress(self): message = OSCMessage() message.setAddress("/sample/play/invalid") # should not throw resp = self.handler.handle(message.getBinary()) self.assertEquals( str(resp), "/sampler/error\x00\x00,ss\x00Execution failed\x00\x00\x00\x00" "Invalid address: '/sample/play/invalid', should have two components\x00" ) self.assertEquals([], self.sampler.recorded)
def create_alt_req_msg(handle, commands, args, index): bundle = OSCMessage() bundle.setAddress("") bundle.append('#bundle') bundle.append(0) bundle.append(0) alt_req = OSCMessage() alt_req.setAddress('/altoperations') alt_req.append(handle) alt_req.append(index) bundle.append(alt_req.getBinary(), 'b') args = list(args) for cmd in commands: if len(cmd.arg_types) > 0: arg = args.pop(0) else: arg = [] bundle.append(OSCConnector.create_msg(cmd, arg), 'b') return bundle.message
def snd_recv(cmd): m = OSCMessage() m.setAddress(cmd) s.sendall(m.getBinary()) print decodeOSC(s.recv(8192))
def create_error_msg(text, exception): msg = OSCMessage() msg.setAddress('/sampler/error') msg.append(text) msg.append(str(exception)) return msg.getBinary()
def create_msg(command, args): m = OSCMessage() m.setAddress("/" + command.section + "/" + command.name) for arg in args: m.append(arg) return m.getBinary()