def save_pedalboard(self, bundlepath, title, callback): def callback2(ok): self.bundlepath = bundlepath if ok else None callback(ok) self.host.set_pedalboard_name(title) self.host.save(os.path.join(bundlepath, "%s.ttl" % symbolify(title)), callback2)
def post(self): title = self.get_argument('title') asNew = bool(int(self.get_argument('asNew'))) titlesym = symbolify(title) # Save over existing bundlepath if SESSION.bundlepath and os.path.exists(SESSION.bundlepath) and os.path.isdir(SESSION.bundlepath) and not asNew: bundlepath = SESSION.bundlepath # Save new else: lv2path = os.path.expanduser("~/.lv2/") # FIXME: cross-platform trypath = os.path.join(lv2path, "%s.pedalboard" % titlesym) # if trypath already exists, generate a random bundlepath based on title if os.path.exists(trypath): from random import randint while True: trypath = os.path.join(lv2path, "%s-%i.pedalboard" % (titlesym, randint(1,99999))) if os.path.exists(trypath): continue bundlepath = trypath break # trypath doesn't exist yet, use it else: bundlepath = trypath # just in case.. if not os.path.exists(lv2path): os.mkdir(lv2path) os.mkdir(bundlepath) # callback for when ingen is done doing its business def callback(ok): if not ok: self.write(json.dumps({ 'ok': False, 'error': "Failed" })) # TODO more descriptive error? self.finish() return # Create a custom manifest.ttl, not created by ingen because we want *.pedalboard extension with open(os.path.join(bundlepath, "manifest.ttl"), 'w') as fd: fd.write('''\ @prefix ingen: <http://drobilla.net/ns/ingen#> . @prefix lv2: <http://lv2plug.in/ns/lv2core#> . @prefix pedal: <http://portalmod.com/ns/modpedal#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . <%s.ttl> lv2:prototype ingen:GraphPrototype ; a lv2:Plugin , ingen:Graph , pedal:Pedalboard ; rdfs:seeAlso <%s.ttl> . ''' % (titlesym, titlesym)) # All ok! self.set_header('Content-Type', 'application/json') self.write(json.dumps({ 'ok': True, 'bundlepath': bundlepath }, default=json_handler)) self.finish() # Ask ingen to save SESSION.save_pedalboard(bundlepath, title, callback)
def web_save_pedalboard(self, title, asNew, callback): titlesym = symbolify(title) # Save over existing bundlepath if self.bundlepath and os.path.exists( self.bundlepath) and os.path.isdir( self.bundlepath) and not asNew: bundlepath = self.bundlepath # Save new else: lv2path = os.path.expanduser("~/.lv2/") # FIXME: cross-platform trypath = os.path.join(lv2path, "%s.pedalboard" % titlesym) # if trypath already exists, generate a random bundlepath based on title if os.path.exists(trypath): from random import randint while True: trypath = os.path.join( lv2path, "%s-%i.pedalboard" % (titlesym, randint(1, 99999))) if os.path.exists(trypath): continue bundlepath = trypath break # trypath doesn't exist yet, use it else: bundlepath = trypath # just in case.. if not os.path.exists(lv2path): os.mkdir(lv2path) os.mkdir(bundlepath) # Various steps triggered by callbacks def step1(ok): if ok: self.host.save(os.path.join(bundlepath, "%s.ttl" % titlesym), step2) else: callback(False) def step2(ok): if ok: self.bundlepath = bundlepath self.title = title else: self.bundlepath = None self.title = None self.pedalboard_changed_callback(ok, bundlepath, title) if not ok: callback(False) return # Create a custom manifest.ttl, not created by ingen because we want *.pedalboard extension with open(os.path.join(bundlepath, "manifest.ttl"), 'w') as fh: fh.write("""\ @prefix ingen: <http://drobilla.net/ns/ingen#> . @prefix lv2: <http://lv2plug.in/ns/lv2core#> . @prefix pedal: <http://moddevices.com/ns/modpedal#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . <%s.ttl> lv2:prototype ingen:GraphPrototype ; a lv2:Plugin , ingen:Graph , pedal:Pedalboard ; rdfs:seeAlso <%s.ttl> . """ % (titlesym, titlesym)) # Create a addressings.json file addressings = self.addressings.get_addressings( ) if self.addressings is not None else {} with open(os.path.join(bundlepath, "addressings.json"), 'w') as fh: json.dump(addressings, fh) # All ok! callback(True) # start here self.host.set_pedalboard_name(title, step1)
def web_save_pedalboard(self, title, asNew, callback): titlesym = symbolify(title) # Save over existing bundlepath if self.bundlepath and os.path.exists(self.bundlepath) and os.path.isdir(self.bundlepath) and not asNew: bundlepath = self.bundlepath # Save new else: lv2path = os.path.expanduser("~/.lv2/") # FIXME: cross-platform trypath = os.path.join(lv2path, "%s.pedalboard" % titlesym) # if trypath already exists, generate a random bundlepath based on title if os.path.exists(trypath): from random import randint while True: trypath = os.path.join(lv2path, "%s-%i.pedalboard" % (titlesym, randint(1,99999))) if os.path.exists(trypath): continue bundlepath = trypath break # trypath doesn't exist yet, use it else: bundlepath = trypath # just in case.. if not os.path.exists(lv2path): os.mkdir(lv2path) os.mkdir(bundlepath) # Various steps triggered by callbacks def step1(ok): if ok: self.host.save(os.path.join(bundlepath, "%s.ttl" % titlesym), step2) else: callback(False) def step2(ok): if ok: self.bundlepath = bundlepath self.title = title else: self.bundlepath = None self.title = None self.pedalboard_changed_callback(ok, bundlepath, title) if not ok: callback(False) return # Create a custom manifest.ttl, not created by ingen because we want *.pedalboard extension with open(os.path.join(bundlepath, "manifest.ttl"), 'w') as fh: fh.write("""\ @prefix ingen: <http://drobilla.net/ns/ingen#> . @prefix lv2: <http://lv2plug.in/ns/lv2core#> . @prefix pedal: <http://moddevices.com/ns/modpedal#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . <%s.ttl> lv2:prototype ingen:GraphPrototype ; a lv2:Plugin , ingen:Graph , pedal:Pedalboard ; rdfs:seeAlso <%s.ttl> . """ % (titlesym, titlesym)) # Create a addressings.json file addressings = self.addressings.get_addressings() if self.addressings is not None else {} with open(os.path.join(bundlepath, "addressings.json"), 'w') as fh: json.dump(addressings, fh) # All ok! callback(True) # start here self.host.set_pedalboard_name(title, step1)