Esempio n. 1
0
    def post(self):
        title = self.get_argument('title')
        as_new = bool(int(self.get_argument('asNew')))

        try:
            uid = SESSION.save_pedalboard(title, as_new)
        except Pedalboard.ValidationError as e:
            self.write(json.dumps({ 'ok': False, 'error': str(e) }))
            self.finish()
            raise StopIteration

        THUMB_GENERATOR.schedule_thumbnail(uid)

        self.set_header('Content-Type', 'application/json')
        self.write(json.dumps({ 'ok': True, 'uid': uid }, default=json_handler))
        self.finish()
Esempio n. 2
0
    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)