How to use the tabulate.models.MeiTab function in tabulate

To help you get started, we’ve selected a few tabulate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gburlet / robotaba / tabulate / models.py View on Github external
def gen_tab(self):
        input_mei_path = os.path.join(settings.MEDIA_ROOT, self.fk_pmei.mei_file.name)
        filename = os.path.split(input_mei_path)[1]

        # sanitize pitches to conform with the guitar model
        # don't clobber original pmei file, since the tablature should be able to be arranged
        # with different guitar models
        guitarify = Guitarify(self.fk_guitar.num_frets, self.fk_guitar.tuning, self.fk_guitar.capo)
        sanitized_mei_str = guitarify.sanitize_mei_file(self.fk_pmei.get_abs_path(), None, prune=self.pitch_sanitize_prune)

        # perform the tablature arrangement of the input mei
        ta = TablatureArrangement()
        mei_str = ta(self.fk_guitar.num_frets, self.fk_guitar.tuning, self.fk_guitar.capo, sanitized_mei_str)

        file_contents = ContentFile(mei_str)
        tab = MeiTab(fk_mid=self.fk_pmei.fk_mid)
        tab.mei_file.save(filename, file_contents, save=True)
           
        # append data about the guitar to the MEI document
        tab.append_guitar_data(self.fk_guitar.tuning, self.fk_guitar.capo)

        # attach the tab to the Tabulate object
        self.fk_tmei = tab
        # Note that saving also updates self.output_ts to clock out the
        # analysis time
        self.save()
github gburlet / robotaba / tabulate / models.py View on Github external
staff_def.addAttribute('lines', str(len(sounding_pitches)))
        staff_def.addAttribute('tab.strings', " ".join(written_pitches))

        # Capo could be implicitly encoded by setting the pitches of the open strings
        # but I really don't like this solution. Instructions are lost about how to tune
        # and perform the piece on the guitar.
        # TODO: this attribute doesn't exist in MEI, make a custom build
        if capo > 0:
            staff_def.addAttribute('tab.capo', str(capo))

        XmlExport.meiDocumentToFile(mei_doc, mei_path)

class Tabulate(models.Model):
    fk_pmei = models.ForeignKey(MeiPitch)
    fk_tmei = models.ForeignKey(MeiTab, null=True)
    fk_guitar = models.ForeignKey(GuitarModel) 
    pitch_sanitize_prune = models.NullBooleanField(null=True)
    # timestamp when processing begins
    process_ts = models.DateTimeField(auto_now_add=True)
    # timestamp when processing has completed
    output_ts = models.DateTimeField(auto_now=True)

    def gen_tab(self):
        input_mei_path = os.path.join(settings.MEDIA_ROOT, self.fk_pmei.mei_file.name)
        filename = os.path.split(input_mei_path)[1]

        # sanitize pitches to conform with the guitar model
        # don't clobber original pmei file, since the tablature should be able to be arranged
        # with different guitar models
        guitarify = Guitarify(self.fk_guitar.num_frets, self.fk_guitar.tuning, self.fk_guitar.capo)
        sanitized_mei_str = guitarify.sanitize_mei_file(self.fk_pmei.get_abs_path(), None, prune=self.pitch_sanitize_prune)
github gburlet / robotaba / robotaba / views.py View on Github external
# 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))
github gburlet / robotaba / robotaba / views.py View on Github external
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))
github gburlet / robotaba / robotaba / views.py View on Github external
def search(request):
    '''
    Search for tabs
    '''

    q = request.GET.get('q')
    if q:
        mm = [m.id for m in MetaMusic.objects.filter(Q(title__icontains=q) | Q(artist__icontains=q))]
        tabs = MeiTab.objects.filter(pk__in=mm)
        page_numbers = [i+1 for i in range(int(math.ceil(len(tabs) / settings.NUM_RESULTS)))]

        p = int(request.GET.get('p', 1))
        i_start = (p-1) * settings.NUM_RESULTS
        i_end = i_start + settings.NUM_RESULTS
        if i_end >= len(tabs):
            i_end = len(tabs)
        tabs = tabs[i_start:i_end]
    else:
        tabs = []
        page_numbers = []

    return render_to_response('results.html', {'tabs': tabs, 'pages': page_numbers}, context_instance=RequestContext(request))