Ejemplo n.º 1
0
    def __all_color_verb(self,subject,k,c,f):
        k = int(action.abstract_string(k))
        c = int(action.abstract_string(c))
        f = int(action.abstract_string(f))

        for (i,t) in self[3].items():
            t.set_color(c if (k==i) else f)
Ejemplo n.º 2
0
    def __cquery(self,k,c,u):
        k = int(action.abstract_string(k))
        c = int(action.abstract_string(c))

        if k in self[3]:
            if c in self[3][k]:
                return [ self[3][k][c].id() ]
        else:
            return []
Ejemplo n.º 3
0
    def __cancel_verb_called(self,subject,key,called):
        key = int(action.abstract_string(key))
        called = int(action.abstract_string(called))

        rv=[]
        if key in self[3]:
            if called in self[3][key]:
                rv.append(action.cancel_return(self.id(),4,self[3][key][called].id()))
                
        return rv
Ejemplo n.º 4
0
 def __move_mouse(self,ctx,subj,dummy,v1,v2):
     x = int(action.abstract_string(v1))
     y = int(action.abstract_string(v2))
     if x < 0:
         return errors.invalid_thing(v1, 'move')
     if y < 0:
         return errors.invalid_thing(v2, 'move')
     v = piw.tuplenull_nb(0)
     v = piw.tupleadd_nb(v, piw.makelong_nb(x,0))
     v = piw.tupleadd_nb(v, piw.makelong_nb(y,0))
     return piw.trigger(self.sysin_events.move_mouse(),v),None
Ejemplo n.º 5
0
 def __move_mouse(self, ctx, subj, dummy, v1, v2):
     x = int(action.abstract_string(v1))
     y = int(action.abstract_string(v2))
     if x < 0:
         return errors.invalid_thing(v1, 'move')
     if y < 0:
         return errors.invalid_thing(v2, 'move')
     v = piw.tuplenull_nb(0)
     v = piw.tupleadd_nb(v, piw.makelong_nb(x, 0))
     v = piw.tupleadd_nb(v, piw.makelong_nb(y, 0))
     return piw.trigger(self.sysin_events.move_mouse(), v), None
Ejemplo n.º 6
0
    def __do_verb(self, subject, text, at, until, every, called):
        text = action.abstract_string(text)
        schema = schedproxy.make_schema(at, until, every)
        called = int(action.abstract_string(called)) if called else None
        print 'mode schema is:', schema

        if called and called in self[3]:
            yield async .Coroutine.success(
                action.error_return('name in use', '', 'do'))

        e = self.__create_event(schema, called)
        r = e.set_phrase(text)
        yield r
        yield async .Coroutine.success()
Ejemplo n.º 7
0
    def __cmode(self,text,k,c,u):
        k = int(action.abstract_string(k))
        c = int(action.abstract_string(c))

        if k not in self[3]:
            self.__update_lights(k)
            self[3][k] = Key(self,self.controller,k)

        id = self[3][k].eventcalled(text,c)

        if id is None:
            return async.failure('mode in use')

        self[4].update()
        return logic.render_term((id,('echo',)))
Ejemplo n.º 8
0
    def __createverb(self, subject, plugin):
        plugin = action.abstract_string(plugin)
        plugin = '_'.join(plugin.split())
        factory = self.__registry.get_module(plugin)

        if not factory:
            return async .failure('no such agent')

        class DummyDelegate():
            def __init__(self):
                self.errors = []

            def add_error(self, msg):
                self.errors.append(msg)

        delegate = DummyDelegate()
        address = self.__workspace.create(factory, delegate)

        if not address:
            return [
                action.error_return(m, plugin, 'create', ENG)
                for m in delegate.errors
            ]

        return action.concrete_return(address)
Ejemplo n.º 9
0
 def __position_create(self, ctx, subj, dummy, arg):
     v = int(action.abstract_string(arg))
     if v < 1 or v > 10000:
         print 'position out of range'
         return async .success(errors.out_of_range('1 to 10000', 'set'))
     return piw.trigger(self.__agent.model.set_position(),
                        piw.makelong_nb(v - 1, 0)), None
Ejemplo n.º 10
0
 def __fraction_create(self, ctx, subj, dummy, arg):
     v = float(action.abstract_string(arg))
     if v < 1 or v > 100:
         print 'fraction out of range'
         return async .success(errors.out_of_range('1 to 100', 'set'))
     return piw.trigger(self.__agent.model.set_stepdenominator(),
                        piw.makefloat_nb(v, 0)), None
Ejemplo n.º 11
0
    def __loadverb(self,subject,t):

        tag = self.__process_tag(action.abstract_string(t))
        path = find_setup(tag)

        if not path:
            print 'no such state',tag
            thing= 'setup %s' %str(tag)
            return async.success(errors.doesnt_exist(thing,'load'))


        def deferred_load():
            self.__thing.cancel_timer_slow()
            self.__thing = None
            snap = self.prepare_file(path,self.uid,version.version)

            if not snap:
                print 'no such state'
                return async.failure('no such state %s' % tag)

            print 'loading from version',snap.version(),'in',tag
            self.setups_changed(path)
            self.__load(snap,tag)

        self.__thing = piw.thing()
        piw.tsd_thing(self.__thing)
        self.__thing.set_slow_timer_handler(utils.notify(deferred_load))
        self.__thing.timer_slow(500)
        return async.success()
Ejemplo n.º 12
0
    def __redo_k_verb(self, subject, k):
        k = int(action.abstract_string(k))

        if k in self[3]:
            yield self[3][k].redo()

        yield async .Coroutine.success()
Ejemplo n.º 13
0
    def __verb_builtin_down_by(self, subject, target, inc):
        inc = float(action.abstract_string(inc))

        def op(c):
            return c.builtin_down_by(inc)

        return self.__verb_builtin(target, op)
Ejemplo n.º 14
0
    def __set_scope(self, a, prop, fr, fo, to):
        to_str = action.abstract_string(to).lower()
        to_val = -1
        to_match = None
        if to_str == 'note':
            to_val = const.scope_pernote
        elif to_str == 'global':
            to_val = const.scope_global
        else:
            to_match = re.match('^channel\s(\d+)$', to_str, re.IGNORECASE)
            if to_match:
                to_val = int(to_match.group(1))
                if to_val < 1 or to_val > 16:
                    return errors.invalid_thing(to_str, 'set')
            else:
                return errors.invalid_thing(to_str, 'set')

        try:
            (iparam, oparam, midi, info) = self.__map_from_for(fr, fo)
            if to_match:
                if oparam != -1:
                    self.__delegate.map_param(
                        iparam, info.clone_with_channelscope(to_val))
                elif midi != -1:
                    self.__delegate.map_midi(
                        iparam, info.clone_with_channelscope(to_val))
            else:
                if oparam != -1:
                    self.__delegate.map_param(iparam,
                                              info.clone_with_scope(to_val))
                elif midi != -1:
                    self.__delegate.map_midi(iparam,
                                             info.clone_with_scope(to_val))
        except RuntimeError, e:
            return e.message
Ejemplo n.º 15
0
    def __verb_builtin_set_value(self, subject, target, value):
        value = action.abstract_string(value)

        def op(c):
            return c.builtin_set_value(value)

        return self.__verb_builtin(target, op)
Ejemplo n.º 16
0
 def __set_minimum_decimation(self, a, prop, to):
     try:
         to_str = action.abstract_string(to)
         to_val = float(to_str)
         self.__delegate.set_minimum_decimation(to_val)
     except RuntimeError, e:
         return e.message
Ejemplo n.º 17
0
    def __do_verb(self, subject, t, k, c):
        t = action.abstract_string(t)
        k = int(action.abstract_string(k))
        c = int(action.abstract_string(c)) if c else None

        if k not in self[3]:
            self.__update_lights(k)
            self[3][k] = Key(self, self.controller, k)

        if c and c in self[3][k]:
            yield async .Coroutine.success(
                action.error_return('name in use', '', 'do'))

        r = self[3][k].create_event(t, c)
        yield r
        yield async .Coroutine.success()
Ejemplo n.º 18
0
 def __set_pitch_range_lower(self, a, prop, to):
     try:
         to_str = action.abstract_string(to)
         to_val = float(to_str)
         self.__delegate.set_pitchbend_down(to_val)
     except RuntimeError, e:
         return e.message
Ejemplo n.º 19
0
    def __query(self,k,u):
        k = int(action.abstract_string(k))

        if k in self[3]:
             return [ v.id() for v in self[3][k].itervalues() ]
        else:
             return []
Ejemplo n.º 20
0
 def __crack_mode(self,mode):
     if mode:
         mode = action.abstract_string(mode)
         if mode == 'stretch': return mode_stretch
         if mode == 'unstretch': return mode_unstretch
         if mode == 'chop': return mode_chop
     return mode_stretch
Ejemplo n.º 21
0
    def __runscript(self,subject,arg):
        name = action.abstract_string(arg)
        print 'script',name
        r = self[12].run_script(name)

        if not r:
            yield async.Coroutine.success(errors.doesnt_exist(name,'execute'))

        yield r
Ejemplo n.º 22
0
    def __uncreate(self,subj,channel):
        id = int(action.abstract_string(channel))
        channel = self[1].get_input(id)

        if channel is None:       
            thing='channel %s' %str(id)
            return async.success(errors.invalid_thing(thing,'un create'))

        self[1].del_input(id)
Ejemplo n.º 23
0
    def __save_inst(self,subject,arg,name):
        id = action.concrete_object(arg)
        name = action.abstract_string(name)
        rig = self.__instances.find(lambda v,i: v==id)

        if rig is None:
            return async.failure('not a rig')

        return rig.save(name)
Ejemplo n.º 24
0
    def __cancel_verb(self, subject, k, c):
        k = int(action.abstract_string(k))
        c = int(action.abstract_string(c)) if c else None

        if k not in self[3]:
            yield async .Coroutine.success()

        if c and c not in self[3][k]:
            yield async .Coroutine.success()

        r = self[3][k].cancel_event(c)

        if c is None:
            self[3][k].detach_key()
            del self[3][k]

        yield r
        yield async .Coroutine.success()
Ejemplo n.º 25
0
    def __create1(self,subj,voice):
        id = int(action.abstract_string(voice))
        voice = self[5].get_voice(id)

        if voice is not None:
            thing='voice %s' %str(id)
            return async.success(errors.already_exists(thing,'create'))
        
        self[5].create_voice(id)
Ejemplo n.º 26
0
 def __rigcreateverb(self, subject, plugin, rig):
     rig = action.concrete_object(rig)
     plugin = action.abstract_string(plugin)
     result = rpc.invoke_rpc(rig, "createagent", plugin)
     yield result
     if result.status():
         yield async .Coroutine.success(logic.parse_clause(
             result.args()[0]))
     yield async .Coroutine.failure(*result.args())
Ejemplo n.º 27
0
    def __mode(self,text,k,u):
        k = int(action.abstract_string(k))

        if k not in self[3]:
            self.__update_lights(k)
            self[3][k] = Key(self,self.controller,k)

        id = self[3][k].event(text)
        self[4].update()
        return logic.render_term((id,('echo',)))
Ejemplo n.º 28
0
 def __name(self,subj,thing,name):
     thing = self.__crack_arg(thing)
     name = action.abstract_string(name)
     try:
         self.library.rename(thing,name)
         self[5].update()
         return action.nosync_return()
     except:
         utils.log_exception()
         return async.success(errors.invalid_value(thing,'name'))
Ejemplo n.º 29
0
    def __query(self,k,u):
        print '__query',k,u
        row = int(action.abstract_string(k))-1

        for v in self[5].values():
            d = v.target.get_data()
            if d.is_long() and d.as_long()==row:
                return [ v.id() ]

        return []
Ejemplo n.º 30
0
 def __ocreate(self, ctx, subj, dummy, arg):
     val = float(action.abstract_string(arg))
     print 'ocreate', ctx, subj, arg, val
     if val < -72 or val > 72:
         return async .failure('offset inappropriate')
     b = piw.change2(
         self.bender.set_offset(),
         piw.slowchange_polled(
             utils.changify(self[9].get_policy().set_data), 5000))
     return piw.trigger(b, piw.makefloat_nb(val, 0)), None
Ejemplo n.º 31
0
    def __define_fast(self, ctx, subject, value, name):
        n = action.abstract_string(name)
        v = logic.render_term(value)
        var, ind = self.create_alternative(n, v)

        def changer(dummy):
            if not dummy.is_null() and dummy.as_norm() != 0.0:
                self.set_var(n, v)

        return (piw.slowchange(utils.changify(changer)), (var, ind))
Ejemplo n.º 32
0
 def __press_character(self,ctx,subj,dummy,val):
     v = action.abstract_string(val)
     if v.startswith('!'): v=v[1:]
     return piw.trigger(self.sysin_events.press_key(),piw.makestring_nb(v,0)),None