def __init__(self): self.__dbfile = os.path.join(resource.user_resource_dir('Loop'), 'loops.db') self.__factorydir = os.path.join(picross.global_resource_dir(), 'loop') self.__userdir = resource.user_resource_dir('Loop', '') e = os.path.exists(self.__dbfile) if not e: self.scan() else: self.__check_modtime() self.prime()
def file_bug(user, email, subj, desc): zf = resource.get_bugfile() zip = zipfile.ZipFile(zf, 'w') def_state_file = resource.user_resource_file('global', resource.current_setup) zip.writestr('description', desc) zip.writestr('user', user) zip.writestr('email', email) zip.writestr('subject', subj) zip.write(def_state_file, resource.current_setup, compress_type=zipfile.ZIP_DEFLATED) #core_files = glob.glob('/cores/*') #if core_files: # zip.write( core_files[0],compress_type=zipfile.ZIP_DEFLATED) log_folder = resource.user_resource_dir('log') for file in glob.glob(log_folder + "/*"): path, filename = os.path.split(file) full_path = os.path.join('log', filename) zip.write(file, full_path, compress_type=zipfile.ZIP_DEFLATED) zip.close()
def clr_tmp_setup(): dbdir = resource.user_resource_dir(resource.setup_dir) for g in resource.glob_glob(os.path.join(dbdir, 'tmpsetup*')): try: resource.os_unlink(g) print 'delete', g except: pass
def __check_modtime(self): mtime1 = self.__get_modtime(resource.user_resource_dir('Loop', '')) mtime2 = self.__get_modtime( os.path.join(picross.global_resource_dir(), 'loop')) modtime = self.__modtime() if not modtime or (abs(modtime[0][1] - mtime1) > 1) or (abs(modtime[1][1] - mtime2) > 1): print 'LoopDatabase:database needs rebuilding', modtime, mtime1, mtime2 os.remove(self.__dbfile) self.scan(mtime1=mtime1, mtime2=mtime2)
def file_bug(user, email, subj, desc): try: zf = resource.get_bugfile() zip = zipfile.ZipFile(resource.WC(zf), 'w') zip.writestr('description', desc) zip.writestr('user', user) zip.writestr('email', email) zip.writestr('subject', subj) zip.writestr( 'bugreport.txt', "From: %s <%s>\n\nSubject: %s\n\n%s\n" % (user, email, subj, desc)) def_state_file = resource.user_resource_file(resource.global_dir, resource.current_setup) for statefile in resource.glob_glob(def_state_file + '*'): zip.write(resource.WC(statefile), resource.WC( os.path.join('Setup', os.path.basename(statefile))), compress_type=zipfile.ZIP_DEFLATED) # add the crash reports of today to the bug report if resource.is_macosx(): diag = os.path.expanduser("~/Library/Logs/DiagnosticReports") today = datetime.date.today().strftime("_%Y-%m-%d-") if resource.os_path_isdir(diag): for crashfile in resource.glob_glob("%s/eigen*%s*.crash" % (diag, today)): zip.write(crashfile, os.path.join("Crash", os.path.basename(crashfile)), compress_type=zipfile.ZIP_DEFLATED) for crashfile in resource.glob_glob("%s/Workbench*%s*.crash" % (diag, today)): zip.write(crashfile, os.path.join("Crash", os.path.basename(crashfile)), compress_type=zipfile.ZIP_DEFLATED) #core_files = resource.glob_glob('/cores/*') #if core_files: # zip.write( core_files[0],compress_type=zipfile.ZIP_DEFLATED) log_folder = resource.user_resource_dir(resource.log_dir) for file in resource.glob_glob(os.path.join(log_folder, "*")): path, filename = os.path.split(file) full_path = os.path.join('Log', filename) zip.write(resource.WC(file), resource.WC(full_path), compress_type=zipfile.ZIP_DEFLATED) zip.close() except: utils.log_exception()
def __init__(self, address, ordinal): agent.Agent.__init__(self, signature=version, names='conductor', ordinal=ordinal) self.domain = piw.clockdomain_ctl() self.__timestamp = 0 self[2] = atom.Atom(names='outputs') self[2][1] = bundles.Output(1, True, names='audio output 1') self.output = bundles.Splitter(self.domain, self[2][1]) self.conductor = conductor_native.conductor( self.output.cookie(), self.domain, resource.user_resource_dir(resource.conductor_dir, version='')) self[1] = AudioInputChannelList(self) self.input_clock = bundles.ScalarInput( self.conductor.metronome_cookie(), self.domain, signals=(1, 2, 3, 4)) self[3] = atom.Atom(names='metronome inputs') self[3][1] = atom.Atom(domain=domain.BoundedFloat(0, 10000000), policy=self.input_clock.nodefault_policy( 1, False), names='song beat input') self[3][2] = atom.Atom(domain=domain.BoundedFloat(0, 100), policy=self.input_clock.nodefault_policy( 2, False), names='bar beat input') self[3][3] = atom.Atom(domain=domain.Bool(), init=False, policy=self.input_clock.nodefault_policy( 3, False), names='running input') self[3][4] = atom.Atom(domain=domain.BoundedFloat(0, 100000), init=120, policy=self.input_clock.nodefault_policy( 4, False), names="tempo input") self.add_verb2(1, 'create([],None,role(None,[mass([audio,input])]))', self.__create_audio_input) self.add_verb2(2, 'create([un],None,role(None,[mass([audio,input])]))', self.__uncreate_audio_input) self.add_verb2(3, 'record([],None)', self.__record) self.add_verb2(4, 'stop([],None)', self.__stop) self[10] = atom.Atom("stage") self[10][1] = ClipPoolWidget() self[10][2] = ArrangeViewWidget() self[10][3] = SceneViewWidget()
def __init__(self, master_agent, runner): self.master_agent = master_agent atom.Atom.__init__(self, names='script', protocols='browse') self.__factorydir = os.path.join(picross.release_resource_dir(), 'Scripts') self.__userdir = resource.user_resource_dir('Scripts', '') self.__timestamp = piw.tsd_time() self.__selected = None self.__armed = None self.__status = None self.__runner = runner self.update() self.__build_cache()
def scan(self, mtime1=None, mtime2=None): print 'building database...' cx = sqlite3.connect(resource.WC(self.__dbfile)) cx.execute( """create table files (id int primary key,name text,desc text,file text, basename text)""" ) cx.execute("""create table meta (id int,tag text)""") cx.execute("""create table modtime (id int, time int)""") files = [] meta = [] nxt = 0 nxt = self.__scandir( nxt, files, meta, os.path.join(picross.global_resource_dir(), 'loop')) nxt = self.__scandir(nxt, files, meta, resource.user_resource_dir(resource.loop_dir, '')) print '%d loops indexed' % nxt if not mtime1: mtime1 = self.__get_modtime( resource.user_resource_dir(resource.loop_dir, '')) if not mtime2: mtime2 = self.__get_modtime( os.path.join(picross.global_resource_dir(), 'loop')) modtime = [(1, mtime1), (2, mtime2)] cx.executemany("""insert into modtime(id,time) values (?,?)""", modtime) cx.executemany( """insert into files(id,desc,file,basename) values (?,?,?,?)""", files) cx.executemany("""insert into meta(id,tag) values (?,?)""", meta) cx.execute("""create index mx on meta (tag)""") cx.commit()
def __init__(self, klass): self.__registry = {} self.__alias = {} self.__path = [] self.__vocab = {} self.add_extra() self.add_path(resource.user_resource_dir('Plugins')) self.add_path(os.path.join(picross.release_root_dir(), 'plugins')) self.add_path(os.path.join(picross.contrib_root_dir(), 'plugins')) self.add_path(os.path.join(picross.contrib_compatible_dir(), 'plugins')) for p in self.__path: print 'Agent Path:', p self.scan_path(p, klass)
def get_bug(): dir = resource.user_resource_dir(resource.bugs_dir, version='') print 'checking ' + dir bugs = resource.glob_glob(os.path.join(dir, '*.zip')) return bugs[0] if bugs else None
class Sample(atom.Atom): userdir = os.path.join(resource.user_resource_dir('Soundfont',version='')) reldir = os.path.join(picross.global_resource_dir(),'soundfont') def __init__(self,agent): self.__scan() self.agent = agent atom.Atom.__init__(self,names='sample',protocols='virtual browse',domain=domain.String(),policy=atom.load_policy(self.__loadcurrent)) self.__timestamp = piw.tsd_time() self.__selected=None self.__update() def rpc_displayname(self,arg): a = self.get_description() return a + ' samples' def rpc_setselected(self,arg): (path,selected) = logic.parse_clause(arg) if len(path) == 1: self.__selected=selected def rpc_activated(self,arg): (path,selected) = logic.parse_clause(arg) if len(path) == 1: self.__setcurrent(selected) return logic.render_term(('','')) def __update(self): self.__timestamp = self.__timestamp+1 self.set_property_string('timestamp',str(self.__timestamp)) def __join(self,file,bank,preset): file = os.path.basename(file) return '|'.join((file,str(bank),str(preset))) def __split(self,cookie): if not cookie: return None f,b,p = cookie.split('|',2) q = self.__qualify(f) if q: try: return q,int(b),int(p) except: pass return None def __loadcurrent(self,delegate,v): desc = None cookie = '' if v.is_string(): cookie = v.as_string() if cookie: desc = self.__split(cookie) if not desc: delegate.add_error('Soundfont file %s not found' % cookie.split('|')[0]) cooke = '' self.agent.setup(desc) self.set_value(cookie) self.__update() def __setcurrent(self,cookie): desc = self.__split(cookie) if desc: self.agent.setup(desc) self.set_value(cookie) self.__update() return True return False def __ideals(self,*cookies): return '[%s]' % ','.join([self.__ideal(c) for c in cookies]) def __ideal(self,cookie): return 'ideal([~server,sample],"%s")' % cookie def rpc_fideal(self,arg): (path,cookie) = logic.parse_clause(arg) if self.__split(cookie): i = self.__ideal(cookie) return i return async.failure('invalid cookie') def rpc_resolve(self,arg): (a,o) = logic.parse_clause(arg) if a == ('current',) and o is None: c = self.get_value() if c: return self.__ideals(self.get_value()) return self.__ideals() def rpc_dinfo(self,a): c=self.get_value() l=[] if c: l.append(('dinfo_id',c)) l.append(('Current sample',c.split('|')[0])) return logic.render_term(T('keyval',tuple(l) )) else: n=self.get_description() l.append(('dinfo_id',n)) return logic.render_term(T('keyval',tuple(l) )) def rpc_current(self,arg): c = self.get_value() if not c: return '[]' f,b,p = c.split('|',2) return '[["%s",["%s"]]]' % (c,f) def rpc_enumerate(self,a): path = logic.parse_clause(a) self.__scan() if len(path) == 0: return logic.render_term((0, len(self.__f2p))) if len(path) == 1: p = self.__scanpresets(path[0]) return logic.render_term((len(p), 0)) return logic.render_term((0,0)) def rpc_cinfo(self,a): (path,idx) = logic.parse_clause(a) self.__scan() if len(path) == 0: return render_list(self.__files,idx,lambda i,t: logic.render_term((t))) return logic.render_term(()) def rpc_finfo(self,a): (path,idx) = logic.parse_clause(a) if len(path) == 1: self.__scan() presets = self.__scanpresets(path[0]) #return render_list(presets,idx,lambda i,t: logic.render_term((t[0],t[1],t[2],'autoload'))) return render_list(presets,idx,lambda i,t: logic.render_term((t[0],t[1],t[2]))) return logic.render_term(()) def __scan1(self,pat,f=lambda x:x): g = lambda path: resource.glob_glob(os.path.join(path,pat)) paths = g(self.reldir) + g(self.userdir) b = lambda path: os.path.splitext(os.path.basename(path))[0] return map(b,paths), map(f,paths) def __scan(self): files,paths = self.__scan1('*.[sS][fF]2') self.__f2p = dict(zip(files,paths)) self.__files = self.__f2p.keys() names,cookies = self.__scan1('*.name', lambda p: resource.file_open(p).read().strip()) self.__n2c = dict(zip(names,cookies)) self.__c2n = dict(zip(cookies,names)) def __qualify(self,name): self.__scan() return self.__f2p.get(name) def __scanpresets(self,file): path = self.__f2p.get(file) if not path: return [] ret = [] for n,p,b in sf2.sf_info(path): cookie = self.__join(file,b,p) ret.append((cookie,n,self.__c2n.get(cookie) or 'None')) return ret def choose_cookie(self,c): if self.__setcurrent(c): return action.nosync_return() return async.failure('choose_cookie failed %s' % c) def resolve_name(self,n): if n=='selection': if self.__selected: return self.__ideals(self.__selected) n = n.replace(' ','_') self.__scan() c = self.__n2c.get(n) if c: return self.__ideals(c) return self.__ideals() def current(self): return self.__split(self.get_value()) 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') 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') 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() 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()
class ImpulseBrowser(atom.Atom): userdir = os.path.join( resource.user_resource_dir('ImpulseResponse', version='')) reldir = os.path.join(picross.global_resource_dir(), 'impulseresponse') def __init__(self, agent): self.__scan() self.__selected = None self.agent = agent atom.Atom.__init__(self, names='impulse', protocols='virtual browse', domain=domain.String(), policy=atom.default_policy(self.__setcurrent)) self.__timestamp = piw.tsd_time() self.__update() # --------------------------------------------------------------------------------------------- # functions to support selection of impulse by browsing # --------------------------------------------------------------------------------------------- # update: update the time stamp serial number so that browser can know # if the browsing state has been updated def __update(self): self.__timestamp = self.__timestamp + 1 self.set_property_string('timestamp', str(self.__timestamp)) def rpc_displayname(self, arg): return 'convolver impulses' # setselected: select (highlight) the item in the selection list def rpc_setselected(self, arg): (path, selected) = logic.parse_clause(arg) # __selected is the cookie (unique key), cookie=filename stripped of extension self.__selected = selected # activated: activate choosing the item in the selection list def rpc_activated(self, arg): (path, selected) = logic.parse_clause(arg) # set the current to be the cookie self.__setcurrent(selected) return logic.render_term(('', '')) # setcurrent: set the chosen item in the selection list def __setcurrent(self, cookie): if cookie != self.get_value(): # cookie is the stripped filename if not self.__f2p.has_key(cookie): return False filepath = self.__f2p[cookie] self.agent.load_impulse_response(filepath) self.set_value(cookie) self.__update() return True # current: return the current selection def rpc_current(self, arg): c = self.get_value() # nothing selected yet if not c: return '[["",[]]]' # return cookie, no category return '[["%s",[]]]' % c # enumerate: get the lengths of the selection and subcategory lists def rpc_enumerate(self, a): path = logic.parse_clause(a) self.__scan() # no subcategory, so just return the length of the selection list return logic.render_term((len(self.__f2p), 0)) # cinfo: get the subcategory list def rpc_cinfo(self, a): # no category return '[]' # finfo: get the selection list def rpc_finfo(self, a): (path, idx) = logic.parse_clause(a) self.__scan() if len(path) == 0: # list of tuples for the browser window, [(cookie,textcolumn1,textcolumn2),...] map = tuple([(files, files, self.__c2n.get(files)) for files in self.__files[idx:]]) mapstr = logic.render_term(map) return mapstr return logic.render_term(()) # scan1: scan release and user directories for wav files def __scan1(self, pat, f=lambda x: x): g = lambda path: glob.glob(os.path.join(path, pat)) paths = g(self.reldir) + g(self.userdir) b = lambda path: os.path.splitext(os.path.basename(path))[0] # return filenames without extensions, # and function applied to paths return map(b, paths), map(f, paths) # scan: scan for wav files and create a list of filenames def __scan(self): # look for files ended in .wav files, paths = self.__scan1('*.[wW][aA][vV]') # dict of filenames to their full paths self.__f2p = dict(zip(files, paths)) # list of filenames self.__files = self.__f2p.keys() # read .name files whose filenames are belcanto names (phrases) and contents are the # impulse cookies that the belcanto maps to names, cookies = self.__scan1('*.name', lambda p: open(p).read().strip()) # remove name from filenames names = [name.replace('_', ' ') for name in names] self.__n2c = dict(zip(names, cookies)) self.__c2n = dict(zip(cookies, names)) # --------------------------------------------------------------------------------------------- # functions to support selection of impulse by belcanto # --------------------------------------------------------------------------------------------- # choose_cookie: select from agent choose verb def choose_cookie(self, c): if self.__setcurrent(c): return action.nosync_return() return async .failure('choose_cookie failed %s' % c) # called from resolve def __ideals(self, *cookies): return '[%s]' % ','.join([self.__ideal(c) for c in cookies]) # ideal: return prolog of cookie # called from fideal def __ideal(self, cookie): return 'ideal([~server,impulse],"%s")' % cookie # fideal: # called from the ideal rpc on the agent with type impulse def rpc_fideal(self, arg): (path, cookie) = logic.parse_clause(arg) return self.__ideal(cookie) # resolve: resolve belcanto into def rpc_resolve(self, arg): (a, o) = logic.parse_clause(arg) if a == ('current', ) and o is None: c = self.get_value() if c: return self.__ideals(self.get_value()) return self.__ideals() # resolve_name: # called by agent resolve_ideal rpc def resolve_name(self, n): if n == 'selection': if self.__selected: return self.__ideals(self.__selected) # name filenames have _ separators #n = n.replace(' ','_') self.__scan() c = self.__n2c.get(n) if c: return self.__ideals(c) return self.__ideals()
class Icon(atom.Atom): userdir = os.path.join(resource.user_resource_dir('icons',version='')) reldir = os.path.join(picross.global_resource_dir(),'icons') def __init__(self,agent): print 'Icon: user',self.userdir,'rel',self.reldir self.__scan() self.agent=agent atom.Atom.__init__(self,names='icon',protocols='virtual browse',domain=domain.String()) self.__selection='' self.__timestamp = piw.tsd_time() self.__update() # additional file types? #def __scan1(self,pat,pat2,f=lambda x:x): def __scan1(self,pat,f=lambda x:x): g = lambda path: glob.glob(os.path.join(path,pat)) # + glob.glob(os.path.join(path,pat2)) paths = g(self.reldir) + g(self.userdir) #b = lambda path: os.path.splitext(os.path.basename(path))[0] b = lambda path: os.path.basename(path) return map(b,paths), map(f,paths) def __scan(self): self.__values=[] #files,paths = self.__scan1('*.[pP][nN][gG]','*.[bB][mM][pP]') files,paths = self.__scan1('*.[pP][nN][gG]') self.__f2p = dict(zip(files,paths)) self.__p2f=dict(zip(paths,files)) self.__files = self.__f2p.keys() for f in self.__files: self.__values.append((self.__f2p[f],f)) self.__values.sort(filesort) def rpc_setselected(self,arg): (path,selected)=logic.parse_clause(arg) self.__selection=selected def rpc_activated(self,arg): print 'Icon:activated',arg (path,selected)=logic.parse_clause(arg) print 'Icon_manager:Icon:activated',path,selected return logic.render_term(('','')) def rpc_current(self,arg): return '[]' def rpc_resolve(self,arg): (a,o) = logic.parse_clause(arg) print 'resolving virtual',arg,(a,o) if a or not o: return '[]' o=int(o) if o>0 and o<len(self.__values)+1: return self.__ideal(self.__values[o-1][0]) return '[]' def rpc_fideal(self,arg): (path,uid) = logic.parse_clause(arg) return 'ideal([~server,icon],%s)' % logic.render_term(uid) def __update(self): self.__timestamp = self.__timestamp+1 self.set_property_string('timestamp',str(self.__timestamp)) def rpc_enumerate(self,a): path = logic.parse_clause(a) self.__scan() return logic.render_term((len(self.__f2p),0)) def rpc_cinfo(self,a): return '[]' #return logic.render_term(()) def rpc_finfo(self,a): (dlist,cnum) = logic.parse_clause(a) #map = tuple([(uid,dsc,None,'icon') for (uid,dsc) in self.__values[cnum:]]) map = tuple([(uid,dsc,None,'icon') for (uid,dsc) in self.__values[cnum:]]) return logic.render_term(map) def rpc_auxinfo(self,a): print 'auxinfo',a (dlist,cnum) = logic.parse_clause(a) map = tuple([(dsc,files.get_ideal(logic.make_expansion('~server'),'file_sys:%s'%uid,files.FileSystemFile(uid,dsc),True) ) for (uid,dsc) in self.__values[cnum:]]) return logic.render_term(map) def getIcon(self,a): dsc=logic.parse_clause(a) print 'Icon Manager getIcon: dsc=',dsc if os.path.splitext(dsc)[1]=='': dsc=dsc+'.png' if dsc in self.__f2p: uid=self.__f2p[dsc] print 'uid=',uid if os.path.exists(uid): return logic.render_term((dsc,files.get_ideal(logic.make_expansion('~server'),'file_sys:%s'%uid,files.FileSystemFile(uid,dsc),True))) def resolve_name(self,n): if n=='selection': return self.__ideals(self.__selection) for k,v in self.__values: if n==v: return self.__ideals(k) return self.__ideals() def __ideals(self,*cookies): return '[%s]' % ','.join([self.__ideal(c) for c in cookies]) def __ideal(self,cookie): print '__ideal',cookie return 'ideal([~server,icon],"%s")' % cookie def getIconString(self,path): if path in self.__p2f: return self.__p2f[path]
def get_bug(): dir = resource.user_resource_dir('bugs', version='') bugs = glob.glob(os.path.join(dir, '*.zip')) return bugs[0] if bugs else None