def saveShape(request, slugName, env): if request.user.is_authenticated(): player = request.user.get_profile() try: slug = player.slug_set.get(name=slugName) env = simplejson.loads(env) shape = Shape(name="none", last_used=tDate(), shape = simplejson.dumps(env['shape']), attack = env['A'], decay = env['D'], sustainLevel = env['S'], release = env['R'], sustainLengthDefault=env['duration'], octave = env['octave'], favorite = env['favorite']) shape.save() slug.shapes.add(shape) #return simplejson.dumps({'message':'slug named %s, owned by %s, has been found. shape has been saved.'%(slug, player)}) return simplejson.dumps({'pk': shape.pk}) except Slug.DoesNotExist: return simplejson.dumps({'message':'no slug names %s found for user %s'%(slugName, player)}) else: return simplejson.dumps({'message':'you must be logged in to save a slug.'})
def makeStarterPallette(player): from slugs.models import Shape, Slug, Sound names = randomNames() shape1 = Shape(attack=0.06, decay= 0.08, sustainLevel=0.71, sustainLengthDefault=17180, release=0.1,shape=DEFAULT_SLUG_PATH, name='shape', last_used = tDate(), octave=4, favorite=True) shape1.save() slug1 = Slug(owner = player, name=names[0], birthday = tDate(), color = random.randint(0,255)) slug1.save() sound1 = Sound(waveForm = 'sine', amp=0.2, overTones = "[[1,1]]", noise=0,slug=slug1) sound1.save() slug1.shapes.add(shape1) slug1.save() shape2 = Shape(attack=0.06, decay= 0.08, sustainLevel=0.71, sustainLengthDefault=17180, release=0.1,shape=DEFAULT_SLUG_PATH, name='shape', last_used = tDate(), octave= 4, favorite=True) shape2.save() slug2 = Slug(owner = player, name=names[1], birthday = tDate(), color = random.randint(0,180)) slug2.save() sound2 = Sound(waveForm = 'square', amp=0.15, overTones = "[[1,1]]", noise=0,slug=slug2) sound2.save() slug2.shapes.add(shape2) slug2.save() shape3 = Shape(attack=0.06, decay= 0.08, sustainLevel=0.71, sustainLengthDefault=17180, release=0.1,shape=DEFAULT_SLUG_PATH, name='shape', last_used = tDate(), octave=4, favorite=True) shape3.save() slug3 = Slug(owner = player, name=names[2], birthday = tDate(), color = random.randint(0,180)) slug3.save() sound3 = Sound(waveForm = 'sine', amp=0.2, overTones = randomOvertones(0.05,4,3), noise=0,slug=slug3) sound3.save() slug3.shapes.add(shape3) slug3.save() shape4 = Shape(attack=0.06, decay= 0.08, sustainLevel=0.71, sustainLengthDefault=17180, release=0.1,shape=DEFAULT_SLUG_PATH, name='shape', last_used = tDate(), octave=3, favorite=True) shape4.save() slug4 = Slug(owner = player, name=names[3], birthday = tDate(), color = random.randint(0,180)) slug4.save() sound4 = Sound(waveForm = 'sine', amp=0.15, overTones = randomOvertones(0.4,0.5,3), noise=0,slug=slug4) sound4.save() slug4.shapes.add(shape4) slug4.save()
def saveSong(request,songString): if request.user.is_authenticated(): player = request.user.get_profile() songObj = simplejson.loads(songString) song = Loop(creator = player,name=songObj['name'],tempo=songObj['tempo'],scale=songObj['scale'], length=songObj['length'], notes = simplejson.dumps(songObj['notes']),baseFreq = songObj['baseFreq'],last_used = tDate(),public=True,public_edit = True) try: if songObj['songPK']: song.parent = Loop.objects.get(pk=songObj['songPK']) song.save() song.addShapes() song.set_tags(songObj['tags']) player.points += 5 player.save() except Loop.IntegrityError: return simplejson.dumps({'message':'error saving song'}) # song.save() tasks.drawSongTask.delay(song) return simplejson.dumps({'message':'saved song %s'% song.name})