def verb2_3_name(self, subject, thing, value): """ name([],global_name,role(None,[concrete]),role(to,[abstract])) """ words = action.abstract_wordlist(value) thing = action.concrete_object(thing) ordinal = None try: ordinal = int(words[-1]) words = words[:-1] except: pass print 'set type name of ', thing, ' to ', words, ordinal proxy = self.database.find_item(thing) if not proxy: return async .failure('internal error: no proxy') def co(): yield interpreter.RpcAdapter( proxy.invoke_rpc('set_names', ' '.join(words))) if ordinal is not None: yield interpreter.RpcAdapter( proxy.invoke_rpc('set_ordinal', str(ordinal))) else: yield interpreter.RpcAdapter( proxy.invoke_rpc('clear_ordinal', '')) return async .Coroutine(co(), interpreter.rpcerrorhandler)
def __set_bank_change(self, ctx, subj, dummy, val): to = action.abstract_wordlist(val)[0] to_val = int(to) if to_val < 0 or to_val > 127: return errors.invalid_thing(to, 'set') return piw.trigger(self.host.change_bank(), piw.makelong_nb(to_val, 0)), None
def verb2_31_do(self, subject, arg): """ do([],None,role(None,[abstract])) """ words = action.abstract_wordlist(arg) interp = interpreter.Interpreter(self.agent, self.database, SubDelegate(self.agent)) if not len(words): print 'nothing to do', arg return print 'doing', words self.agent.register_interpreter(interp) try: r = interp.process_block(words) yield r if r.status(): print 'SUCCEEDED', words else: print 'FAILED', words finally: self.agent.unregister_interpreter(interp)
def verb2_6_renumber(self, subj, things, names): """ renumber([],global_renumber,role(None,[concrete]),role(with,[abstract])) """ things = tuple(action.concrete_objects(things)) names = action.abstract_wordlist(names) name_cache = self.database.get_propcache('name') ord_cache = self.database.get_propcache('ordinal') world = self.database.get_propcache('props').get_idset('agent') a = world for nn in names: a = a.intersection(name_cache.get_idset(nn)) a = a.difference(set(things)) d = [int(o) for oo in a for o in ord_cache.get_valueset(oo)] x = reduce(lambda a, b: a if a > b else b, d, 0) def co(x): for thing in things: x += 1 print 'renumbering', thing, 'with', names, 'ordinal', x yield interpreter.RpcAdapter( rpc.invoke_rpc(thing, 'set_names', ' '.join(names))) yield interpreter.RpcAdapter( rpc.invoke_rpc(thing, 'set_ordinal', str(x))) return async .Coroutine(co(x), interpreter.rpcerrorhandler)
def __set_program_change(self, ctx, subj, dummy, val): to = action.abstract_wordlist(val)[0] to_val = int(to) if to_val < 0 or to_val > 127: return errors.invalid_thing(to, 'set') return piw.trigger(self.__midi_from_belcanto.change_program(), piw.makelong_nb(to_val, 0)), None
def __press_key(self, ctx, subj, dummy, val): v = action.abstract_wordlist(val)[0] v_val = int(v) if v_val < 0: return errors.invalid_thing(val, 'press') return piw.trigger(self.sysin_events.press_key(), piw.makelong_nb(v_val, 0)), None
def verb2_29_say(self, subject, arg): """ say([],None,role(None,[abstract])) """ words = action.abstract_wordlist(arg) print 'injecting', words for w in words: self.agent.inject(w)
def __set_midi_control(self, ctx, subj, ctl, val): c = action.mass_quantity(ctl) to = action.abstract_wordlist(val)[0] c_val = int(c) to_val = int(to) if c_val < 0 or c_val > 127: return errors.invalid_thing(c, 'set') if to_val < 0 or to_val > 127: return errors.invalid_thing(to, 'set') return piw.trigger( self.host.change_cc(), utils.makedict_nb( { 'ctl': piw.makelong_nb(c_val, 0), 'val': piw.makelong_nb(to_val, 0) }, 0)), None
def __message(self,subject,arg): if self.__messages_on: words = action.abstract_wordlist(arg) print 'message',words self.message(words)
def __press_key(self,ctx,subj,dummy,val): v = action.abstract_wordlist(val)[0] v_val = int(v) if v_val < 0: return errors.invalid_thing(val, 'press') return piw.trigger(self.sysin_events.press_key(),piw.makelong_nb(v_val,0)),None