예제 #1
0
def upload_score(request):
    '''
    Handle score file upload
    '''

    if request.method == 'POST':
        # deal with the form input
        form = UploadScoreForm(request.POST, request.FILES)
        if form.is_valid():
            # check extension of uploaded score file
            input_file = request.FILES['score_file']

            # TODO: try and parse this information from the XML file
            meta = MetaMusic(title=request.POST['title'],
                             artist=request.POST['artist'],
                             copyright=request.POST['copyright'])
            meta.save()

            filename, input_ext = os.path.splitext(input_file.name)
            if input_ext == '.xml':
                # convert the MusicXML file to Mei format
                pmei = MeiPitch(fk_mid=meta)
                pmei.convert_musicxml(filename + '.mei',
                                      request.FILES['score_file'].read())
            elif input_ext == '.mei':
                # the uploaded file is an mei file, put it directly into the model
                pmei = MeiPitch(mei_file=input_file, fk_mid=meta)
                pmei.save()
            else:
                raise ValueError('Input file must be a MusicXML or Mei file')

            frets = request.POST['num_frets']
            capo = request.POST['capo']
            tuning = request.POST['tuning']
            sanitize = request.POST['pitch_sanitize']

            # redirect and construct the Tabulate object in the process view to allow
            # the input file to be processed multiple times by the user
            # to get different tablature output, if desired.
            return HttpResponseRedirect(
                '/tabulate/%d/?frets=%s&capo=%s&tuning=%s&sanitize=%s' %
                (pmei.id, frets, capo, tuning, sanitize))
    else:
        # serve the form
        form = UploadScoreForm()

    return render_to_response('uploadscore.html', {'form': form},
                              context_instance=RequestContext(request))
예제 #2
0
def upload_audio(request):
    '''
    Handle an audio file upload
    '''

    if request.method == 'POST':
        # deal with the form input
        form = UploadAudioForm(request.POST, request.FILES)
        if form.is_valid():
            # check extension of uploaded audio file
            input_file = request.FILES['audio_file']
            filename, input_ext = os.path.splitext(input_file.name)
            if input_ext != '.wav':
                raise ValueError('Input file must be a .wav file')

            # enter metadata of the uploaded audio into the db
            # TODO: hook up to musicbrainz to gather this information
            meta = MetaMusic(title=request.POST['title'],
                             artist=request.POST['artist'],
                             copyright=request.POST['copyright'])
            meta.save()

            audio = Audio(fk_mid=meta, audio_file=input_file)
            audio.save()

            frets = request.POST['num_frets']
            capo = request.POST['capo']
            tuning = request.POST['tuning']
            sanitize = request.POST['pitch_sanitize']

            return HttpResponseRedirect(
                '/transcribe/%d/?frets=%s&capo=%s&tuning=%s&sanitize=%s' %
                (audio.id, frets, capo, tuning, sanitize))
    else:
        # serve the form
        form = UploadAudioForm()

    return render_to_response('uploadtranscribe.html', {'form': form},
                              context_instance=RequestContext(request))
예제 #3
0
def upload_tablature(request):
    '''
    Handle score file upload
    '''

    if request.method == 'POST':
        # deal with the form input
        form = UploadTablatureForm(request.POST, request.FILES)
        if form.is_valid():
            # check extension of uploaded score file
            input_file = request.FILES['score_file']

            # TODO: try and parse this information from the XML file
            meta = MetaMusic(
                title=request.POST['title'], 
                artist=request.POST['artist'],
                copyright=request.POST['copyright']
            )
            meta.save()

            filename, input_ext = os.path.splitext(input_file.name)
            if input_ext == '.xml':
                # convert the MusicXML file to Mei format
                tmei = MeiTab(fk_mid=meta)
                tmei.convert_musicxml(filename+'.mei', request.FILES['score_file'].read())
            elif input_ext == '.mei':
                # the uploaded file is an mei file, put it directly into the model
                tmei = MeiTab(mei_file=input_file, fk_mid=meta)
                tmei.save()
            else:
                raise ValueError('Input file must be a MusicXML or Mei file')

            # display the uploaded tab
            return HttpResponseRedirect('/display/%d' % tmei.id)
    else:
        # serve the form
        form = UploadTablatureForm()

    return render_to_response('uploadtablature.html', {'form': form}, context_instance=RequestContext(request))