def uploadtrack(request,group_short_code,song_short_code): cur_group = Group.objects.get(short_code=group_short_code) cur_song = Song.objects.get(short_code=song_short_code) if request.method == 'POST': form = UploadTrackForm(request.POST, request.FILES) if form.is_valid(): newtrack = Track ( song = cur_song, location = "INVALID", name = form.cleaned_data['name']) newtrack.save(); newfile = request.FILES['file']; temp_dest_filename = localsettings.basedir() + 'static/user/tracks/t_' + str(newtrack.id) + os.path.splitext(newfile.name)[1] simple_dest_filename = str(newtrack.id) + '.wav' dest_filename = localsettings.basedir() + 'static/user/tracks/' + simple_dest_filename#TODO REMOVE HARDCODED EXTENTION destination = open(temp_dest_filename, 'wb+') for chunk in newfile.chunks(): destination.write(chunk) destination.close() soxcommand_clean = "sox "+temp_dest_filename+" "+dest_filename+" channels 1"; #reduces the track to mono os.system(soxcommand_clean) newtrack.location = simple_dest_filename;# str(newchannel.id) + "-" + newfile.name.replace("..", "_").replace("/", "_").replace("~", "_").replace("$", "_").replace("*", "_"); newtrack.save() rmcommand = 'rm '+temp_dest_filename; os.system(rmcommand) return HttpResponseRedirect('/arranger/group/'+group_short_code+'/song/'+song_short_code+'/') else: form = UploadTrackForm() return render(request, 'arranger/uploadchannel.html', {'form': form, "group": cur_group, "song":cur_song })
def deletepdf(request,group_short_code,song_short_code): cur_group = Group.objects.get(short_code=group_short_code) cur_song = Song.objects.get(short_code=song_short_code) command = "rm " + localsettings.basedir() + 'static/user/pdfs/' + cur_song.pdf_location os.system(command) cur_song.pdf_location = ""; cur_song.save(); return HttpResponseRedirect('/arranger/group/'+group_short_code+'/song/'+song_short_code+'/')
def uploadpdf(request,group_short_code,song_short_code): cur_group = Group.objects.get(short_code=group_short_code) cur_song = Song.objects.get(short_code=song_short_code) if request.method == 'POST': form = UploadPDFForm(request.POST, request.FILES) if form.is_valid(): newfile = request.FILES['file']; filename = str(cur_song.id) + ".pdf" destination = open(localsettings.basedir() + 'static/user/pdfs/' + filename, 'wb+') for chunk in newfile.chunks(): destination.write(chunk) destination.close() cur_song.pdf_location = filename; cur_song.save() return HttpResponseRedirect('/arranger/group/'+group_short_code+'/song/'+song_short_code+'/') else: form = UploadPDFForm() return render(request, 'arranger/uploadpdf.html', {'form': form, "song":cur_song, "group":cur_group })
def makeamixdown(request, group_short_code, song_short_code): #create a list to include all temporary files tempfiles = [] #GET THE POST VALUES FROM REQUEST jsonstring = request.POST["json"] #GET THE FILENAME HASH hexhash = hashlib.sha256(jsonstring).hexdigest() #CREATE AN OBJECT OUT OF THE DATA: "json" data = json.loads(jsonstring) #TODO: LATER HERE, ADD IN EFFECT PROCESSING #FROM THAT OBJECT DETERMINE WHAT GOES INTO THE LEFT CHANEL AND WHAT GOES INTO THE RIGHT CHANEL left, right = [], [] for track in data: if track["pan"] == "Center" or track["pan"] == "Left": left.append("static/user/tracks/" + track["filename"]) if track["pan"] == "Center" or track["pan"] == "Right": right.append("static/user/tracks/" + track["filename"]) if not left or not right: #Get sample rate of project if we need silence. sr = os.popen('soxi -r ' + localsettings.basedir() + "static/user/tracks/" + data[0]["filename"]).read() sr = sr[:-1] #COMBINE LEFT CHANEL FILES AND RIGHT CHANEL FILES #TODO: I AM BREAKING (DRY)[wiki]. Factor this out. left_outputfile = localsettings.basedir( ) + "static/user/temp/LEFT_temp_" + hexhash + ".wav" tempfiles.append(left_outputfile) if len(left) > 1: leftmixfiles = "" for a in left: leftmixfiles += localsettings.basedir() + a + " " leftmixcommand = "sox -m " + leftmixfiles + " " + left_outputfile if len(left) == 1: leftmixcommand = "sox " + localsettings.basedir( ) + left[0] + " " + left_outputfile if len(left) == 0: leftmixcommand = "sox -n -r " + sr + " " + left_outputfile + " trim 0.0 1" print(leftmixcommand) os.system(leftmixcommand) right_outputfile = localsettings.basedir( ) + "static/user/temp/RIGHT_temp_" + hexhash + ".wav" tempfiles.append(right_outputfile) if len(right) > 1: rightmixfiles = "" for a in right: rightmixfiles += localsettings.basedir() + a + " " rightmixcommand = "sox -m " + rightmixfiles + " " + right_outputfile if len(right) == 1: rightmixcommand = "sox " + localsettings.basedir( ) + right[0] + " " + right_outputfile if len(right) == 0: rightmixcommand = "sox -n -r " + sr + " " + right_outputfile + " trim 0.0 1" print(rightmixcommand) os.system(rightmixcommand) final_outputfile = localsettings.basedir( ) + "static/user/mixdowns/" + hexhash + ".wav" final_outputfile_url = "/static/user/mixdowns/" + hexhash + ".wav" finalremixcommand = "sox -M " + left_outputfile + " " + right_outputfile + " " + final_outputfile print(finalremixcommand) os.system(finalremixcommand) #Clean up any temporary files for afile in tempfiles: os.system("rm " + afile) #RESPOND WITH THE URL OF THE MIXDOWN FILE return HttpResponse(final_outputfile_url)
def makeamixdown(request, group_short_code, song_short_code): #create a list to include all temporary files tempfiles = [] #GET THE POST VALUES FROM REQUEST jsonstring = request.POST["json"] #GET THE FILENAME HASH hexhash = hashlib.sha256(jsonstring).hexdigest() #CREATE AN OBJECT OUT OF THE DATA: "json" data = json.loads(jsonstring) #TODO: LATER HERE, ADD IN EFFECT PROCESSING #FROM THAT OBJECT DETERMINE WHAT GOES INTO THE LEFT CHANEL AND WHAT GOES INTO THE RIGHT CHANEL left, right = [], []; for track in data: if track["pan"] == "Center" or track["pan"] == "Left": left.append("static/user/tracks/"+track["filename"]) if track["pan"] == "Center" or track["pan"] == "Right": right.append("static/user/tracks/"+track["filename"]) if not left or not right: #Get sample rate of project if we need silence. sr = os.popen('soxi -r ' + localsettings.basedir() + "static/user/tracks/" + data[0]["filename"]).read() sr = sr[:-1] #COMBINE LEFT CHANEL FILES AND RIGHT CHANEL FILES #TODO: I AM BREAKING (DRY)[wiki]. Factor this out. left_outputfile = localsettings.basedir() + "static/user/temp/LEFT_temp_"+hexhash+".wav" tempfiles.append(left_outputfile) if len(left) > 1: leftmixfiles = "" for a in left: leftmixfiles += localsettings.basedir() + a + " " leftmixcommand = "sox -m "+leftmixfiles+" "+left_outputfile if len(left) == 1: leftmixcommand = "sox "+ localsettings.basedir() + left[0]+" "+left_outputfile if len(left) == 0: leftmixcommand = "sox -n -r "+ sr +" "+left_outputfile+" trim 0.0 1" print(leftmixcommand) os.system(leftmixcommand) right_outputfile = localsettings.basedir() + "static/user/temp/RIGHT_temp_"+hexhash+".wav" tempfiles.append(right_outputfile) if len(right) > 1: rightmixfiles = "" for a in right: rightmixfiles += localsettings.basedir() + a + " " rightmixcommand = "sox -m "+rightmixfiles+" "+right_outputfile if len(right) == 1: rightmixcommand = "sox "+localsettings.basedir() + right[0]+" "+right_outputfile if len(right) == 0: rightmixcommand = "sox -n -r "+ sr +" "+right_outputfile+" trim 0.0 1" print(rightmixcommand) os.system(rightmixcommand) final_outputfile = localsettings.basedir() + "static/user/mixdowns/"+hexhash+".wav" final_outputfile_url = "/static/user/mixdowns/"+hexhash+".wav" finalremixcommand = "sox -M "+left_outputfile+" "+right_outputfile+" "+final_outputfile print(finalremixcommand) os.system(finalremixcommand) #Clean up any temporary files for afile in tempfiles: os.system("rm "+afile) #RESPOND WITH THE URL OF THE MIXDOWN FILE return HttpResponse(final_outputfile_url)