Exemplo n.º 1
0
    def next(self):
        self.__scan()

        c = self.get_value()
        if not c:
            return action.nosync_return()
        f,b,p = c.split('|',2)

        if self.__files: 
            if f in self.__files:
                all=[]
                for ps in self.__scanpresets(f):
                    all.append(ps[0])

                i=all.index(c)+1
                if i<len(all):
                    self.__setcurrent(all[i])
                    return action.nosync_return()
                else:
                    findex=(self.__files.index(f))+1
                    if findex>=len(self.__files):
                        findex=0
                    f=self.__files[findex]
                    for ps in self.__scanpresets(f):
                        self.__setcurrent(ps[0])
                        return action.nosync_return()
            else:
                ps=self.__scanpresets(self.__files[0])
                self.__setcurrent(ps[0])   
                return action.nosync_return()

        return async.failure('no files')
Exemplo n.º 2
0
    def __add(self,subj,arg):
        if arg is None:
            return action.nosync_return()

        (type,id) = action.crack_ideal(action.arg_objects(arg)[0])

        if id >= self.loopdb.size():
            return async.success(errors.doesnt_exist('loop %s' % str(id),'add'))

        file = self.loopdb.basename(id)
        voice = self[5].new_voice()
        voice.set_current(id,file)

        return action.nosync_return()
Exemplo n.º 3
0
    def unname(self,cookie):
        self.__scan()
        n = self.__c2n.get(cookie)

        if n is None:
            return action.nosync_return()

        n = '%s.name' % n.replace(' ','_')
        path = os.path.join(self.userdir,n)
        try: resource.os_unlink(path)
        except: pass

        self.__scan()
        self.__update()
        return action.nosync_return()
Exemplo n.º 4
0
 def __tune_tonic(self,subj,dummy,arg):
     print 'tune tonic',arg
     type,thing = action.crack_ideal(action.arg_objects(arg)[0])
     tonic = int(thing)
     self[2][3].get_policy().set_value(tonic)
     self.illuminator.reference_tonic(tonic);
     return action.nosync_return()
Exemplo n.º 5
0
 def __tune_tonic(self, subj, dummy, arg):
     print 'tune tonic', arg
     type, thing = action.crack_ideal(action.arg_objects(arg)[0])
     tonic = int(thing)
     self[2][3].get_policy().set_value(tonic)
     self.illuminator.reference_tonic(tonic)
     return action.nosync_return()
Exemplo n.º 6
0
 def __tune_scale(self, subj, dummy, arg):
     print 'tune scale', arg
     type, thing = action.crack_ideal(action.arg_objects(arg)[0])
     scale = action.marshal(thing)
     self[2][2].get_policy().set_value(scale)
     self.illuminator.reference_scale(scale)
     return action.nosync_return()
Exemplo n.º 7
0
 def first(self):
     self.__scan()
     p = self.__scanpresets(self.__files[0])
     if p:
         self.__setcurrent(p[0][0])
         return action.nosync_return()
     return async.failure('first failed')
Exemplo n.º 8
0
 def __tune_scale(self,subj,dummy,arg):
     print 'tune scale',arg
     type,thing = action.crack_ideal(action.arg_objects(arg)[0])
     scale = action.marshal(thing)
     self[2][2].get_policy().set_value(scale)
     self.illuminator.reference_scale(scale);
     return action.nosync_return()
Exemplo n.º 9
0
 def __set_course_int(self,subject,course,interval):
     (typ,id) = action.crack_ideal(action.arg_objects(course)[0])
     course = int(id)
     ints = action.mass_quantity(interval)
     print 'set course',course,'ints',ints
     self.controller.set_course_steps(int(course),ints)
     return action.nosync_return()
Exemplo n.º 10
0
    def __record(self,subject,duration,mode):

        duration = action.mass_quantity(duration)
        mode = self.__crack_mode(mode)

        if not self.__schedready:
            print 'no scheduler'
            return async.success(errors.state_error1('scheduler','use'))

        result,started,done = self.recorder.record_start(duration)

        if result==record_err_no_clock:
            print 'metronome isnt started'
            return async.success(errors.state_error1('metronome','start'))

        if result==record_err_in_prog:
            print 'recording already in progress'
            return async.success(errors.message('recording already in progress'))

        id = self.library.nextid()
        if not self.__is_overdub_enabled():
            self.__unplay_auto()

        print 'recording',duration,'bars',id

        def trigger_ok(r,trigger):
            cookie = self.player.load(id,r,0)
            event,status = self.verb_defer(3,(True,trigger,2,mode),trigger,None,self.cookie_arg(id))
            self.player.unload(cookie,False)
            self[5].update()
            print 'trigger created',trigger,'cookie is', cookie

        def trigger_failed(msg):
            print 'cannot create trigger',msg

        def started_ok(r):
            start = r.get_tag(3).as_float()
            duration = r.get_tag(4).as_float()
            desc = "take %s at song beat %g every %g song beat" % (id,start,duration)
            self.library.write(recorder_native.recording(),id)
            trigger = self.__scheduler.create_trigger('schema("%s",[m(3,%f,%f)])' % (desc,duration,start%duration))
            trigger.setCallback(trigger_ok,r).setErrback(trigger_failed)
            print 'record started: start=',start,'duration=',duration

        def started_failed(msg):
            print 'record failed:',msg
            
        def done_ok(r):
            print 'record completed: signals=',r.signals(),'wires=',r.wires(),'start=',r.get_tag(2)
            self.library.write(r,id)

        def done_failed(msg):
            print 'record failed:',msg
            self.__unplay_auto()
            
        done.setCallback(done_ok).setErrback(done_failed)
        started.setCallback(started_ok).setErrback(started_failed)

        return action.nosync_return()
Exemplo n.º 11
0
 def __delete(self,subj,thing):
     self.__unplay(subj,thing)
     cookie = self.__crack_arg(thing)
     try:
         self.library.delete(cookie)
         return action.nosync_return()
     except:
         return async.success(errors.invalid_value(cookie,'delete'))
Exemplo n.º 12
0
    def __select(self,subj,voice):
        id = self.crack_voice(voice)

        if self[5].choose_voice(id):
            return action.nosync_return()

        thing='voice %s' %str(id)
        return async.success(errors.invalid_thing(thing,'select'))
Exemplo n.º 13
0
    def __next(self,subj):
        v = self[5].current_voice()

        if not v:
            return async.success(errors.no_current_voice('','next'))

        v.next()
        return action.nosync_return()
Exemplo n.º 14
0
    def __unplay(self,subj,arg):
        #print 'unplaying',arg

        if arg is None:
            latest_cookie=0
            latest_ctx=None
            latest_id=None

            for (id,ctx,cookie) in self.verb_events(lambda l,i: i==3):
                if cookie>latest_cookie:
                    latest_cookie=cookie
                    latest_ctx=ctx
                    latest_id=id

            if latest_cookie:
                (autor,trigger,poly,mode) = latest_ctx
                self.__scheduler.delete_trigger(trigger)
                self.verb_cancel(latest_id)
                self[5].update()
                self.player.abortcookie(latest_cookie)
                #self.set_all_status(const.status_inactive)

            return action.nosync_return()

        arg = self.__crack_arg(arg)

        if arg:
            c = self.player.getcookie(arg)

            while c:
                #print 'clearing cookie',c

                for (id,ctx,cookie) in self.verb_events(lambda l,i: i==3):
                    if c==cookie:
                        (autor,trigger,poly,mode) = ctx
                        #print 'tear down',id,trigger,cookie
                        self.__scheduler.delete_trigger(trigger)
                        self.verb_cancel(id)
                        self[5].update()

                c = self.player.getcookie(arg)
            self.player.abort(arg)

        return action.nosync_return()
Exemplo n.º 15
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'))
Exemplo n.º 16
0
 def rename(self,cookie,name):
     n = '%s.name' % name.replace(' ','_')
     path = os.path.join(self.userdir,n)
     try: resource.os_unlink(path)
     except: pass
     f = resource.file_open(path,'w')
     f.write(cookie)
     f.close()
     self.__update()
     return action.nosync_return()
Exemplo n.º 17
0
    def __do_play_now(self,arg,mode):
        cookie = self.__load(arg,1)

        if not cookie:
            thing= 'take %s' %str(arg)
            return async.success(errors.invalid_thing(thing,'play'))

        f = self.player.player(cookie,mode)
        ff = piw.fastchange(f)
        ff(piw.makefloat_bounded_nb(1,0,0,1,0))
        self.player.unload(cookie,False)
        return action.nosync_return()
Exemplo n.º 18
0
    def __choose(self,subj,arg):
        (type,id) = action.crack_ideal(action.arg_objects(arg)[0])

        if id >= self.loopdb.size():
            return async.success(errors.doesnt_exist('loop %s' % id,'choose'))

        file = self.loopdb.basename(id)
        voice = self[5].current_voice()

        if not voice:
            return async.success(errors.no_current_voice('','choose'))

        voice.set_current(id,file)
        return action.nosync_return()
Exemplo n.º 19
0
    def __remove(self,subj,voice):
        if voice is None:
            voice = self[5].current_voice()
            if not voice:
                return async.success(errors.no_current_voice('','remove'))
            id = voice.voice
        else:
            id = self.crack_voice(voice)

        if self[5].remove_voice(id):
            return action.nosync_return()

        thing='voice %s' %str(id)
        return async.success(errors.invalid_thing(thing,'remove'))
Exemplo n.º 20
0
    def __copy(self,sub,take):
        type,thing = action.crack_ideal(action.arg_objects(take)[0])
        id = self.library.nextid()
        fn = self.library.perm_path(id,None)

        print 'copy',type,thing,'to',self.id(),fn

        r = files.copy_file(logic.render_term(thing),fn)
        yield r

        if not r.status():
            yield async.Coroutine.failure(*r.args())

        print 'transfer complete'

        self.library.add_file(fn)
        self[5].update()
        yield async.Coroutine.success(action.nosync_return())
Exemplo n.º 21
0
 def choose_cookie(self,c):
     if self.__setcurrent(c):
         return action.nosync_return()
     return async.failure('choose_cookie failed %s' % c) 
Exemplo n.º 22
0
 def set_time_beats_default(self, subj, dummy, arg):
     time_beats = float(action.abstract_string(arg))
     print "set time beats default", arg, "->", time_beats, self.id()
     self[1].get_policy().set_value(time_beats)
     return action.nosync_return()
Exemplo n.º 23
0
 def set_time_beats(self, subj, dummy, arg):
     time_beats = action.mass_quantity(arg)
     print "set time beats", arg, "->", time_beats, self.id()
     self[1].get_policy().set_value(time_beats)
     return action.nosync_return()
Exemplo n.º 24
0
    def save(self,name):
        dir = resource.user_resource_dir(resource.instrument_dir)
        file = os.path.join(dir,name)

        if os.path.exists(file):
            os.unlink(file)

        agg = async.Aggregate()
        map = state.create_mapping(True)
        ctl = []
        ssctl=[]
        id =self.id()
        all=[id]
        for a in self.iterall():
            all.append(a)

            if isrig(a):
                rr=self.__get_rig_agents(a)
                yield rr
                if not rr.status():
                    yield async.Coroutine.failure('error getting agents in rig')
                rigall=rr.args()[0]
                all.extend(rigall)
        subs={}       

        for a in all:
            r=rpc.invoke_rpc(a,'subsystems',logic.render_term(self.id()))
            yield r
            if not r.status():
                yield async.Coroutine.failure('rpc error')
            if r.args()[0]:
                ss=logic.parse_clause(r.args()[0])
                print 'subsystems of %s' %a,ss
                subs[a]=ss
 
        for i,a in enumerate(all):
            c = Controller(a)
            ctl.append(c)
            agg.add(c,c.add_sync())
            map.add(a,'|rig-%d-rig|' % i)
            print 'adding to map',a,'|rig-%d-rig|' % i
            if a in subs:
                for s in subs[a]:
                    ss=getssid(s,a)
                    c = Controller(ss)
                    #ctl.append(c)
                    agg.add(c,c.add_sync())
                    ssname=self.__getssname(ss)
                    ssctl.append((c,str(i) +'/'+ ssname))
                    map.add(ss,'|rig-%d/%s-rig|' % (i,ssname))
                    print 'adding to map',ss,'|rig-%d/%s-rig|' % (i,ssname)
                    
        agg.enable()

        yield agg

        db = state.open_database(file,True)
        snap = db.get_trunk()

        for i,c in enumerate(ctl):
            a = snap.get_agent_address(0,str(i),True)
            c.save_template(a.get_root(),map)
            a.set_checkpoint()

        for c,name in ssctl:
            a = snap.get_agent_address(0,name,True)
            c.save_template(a.get_root(),map)
            a.set_checkpoint()

        snap.save(0,'')
        db.flush()
        db.close()

        yield async.Coroutine.success(action.nosync_return())
Exemplo n.º 25
0
 def __unbypass(self,*arg):
     self.__host.set_bypassed(False)
     self.set_light(1,False)
     return action.nosync_return()
Exemplo n.º 26
0
 def __bypass(self,*arg):
     self.__host.set_bypassed(True)
     self.set_light(1,True)
     return action.nosync_return()
Exemplo n.º 27
0
 def __tog_show(self,*arg):
     self.__host.set_showing(not self.__host.is_showing())
     self.set_light(2,self.__host.is_showing())
     return action.nosync_return()
Exemplo n.º 28
0
 def __unshow(self,*arg):
     self.__host.set_showing(False)
     self.set_light(2,False)
     return action.nosync_return()
Exemplo n.º 29
0
 def __show(self,*arg):
     self.__host.set_showing(True)
     self.set_light(2,True)
     return action.nosync_return()
Exemplo n.º 30
0
 def __tog_bypass(self,*arg):
     self.__host.set_bypassed(not self.__host.is_bypassed())
     self.set_light(1,self.__host.is_bypassed())
     return action.nosync_return()
Exemplo n.º 31
0
 def set_time_secs(self, subj, dummy, arg):
     time_secs = action.mass_quantity(arg)
     print "set time secs", arg, "->", time_secs, self.id()
     # time in seconds is -ve for now!
     self[1].get_policy().set_value(-time_secs)
     return action.nosync_return()
Exemplo n.º 32
0
 def __calibrate(self, *arg):
     self.cv_calibration.calibrate()
     return action.nosync_return()
Exemplo n.º 33
0
 def __calibrate(self,*arg):
     self.cv_calibration.calibrate()
     return action.nosync_return()