Esempio n. 1
0
def updatePDF(context, normalizedTitle, pt):
    """
    :param context: an object with a ``pdfscore`` field
    :type context: usualy a ABC object
    :param normalizedTitle: used for the blob filename
    :type normalizedTitle: string
    :param pt: tool
    :type pt: portal_tranform tool
    :returns: nothing, update the ``pdfscore`` field of the object
    """
    try:
        pdfData = pt.convertTo(
            'application/pdf',
            context.abc,
            context=context,
            annotate=True,
            )
        pdfFilename = normalizedTitle + u'.pdf'
        pdfContenType = 'application/pdf'
        context.pdfscore = NamedBlobImage()
        context.pdfscore.data = pdfData.getData()
        context.pdfscore.filename = pdfFilename
        context.pdfscore.contentType = pdfContenType
    except Exception:
        msg = u'Failed to create PDF score'
        logger.info(msg)
        annotateObject(context, msg=msg, key='ABC_ERRORS')
Esempio n. 2
0
def updateSVG(context, normalizedTitle, pt):
    """
    :param context: an object with ``abc`` and ``svgscore`` fields
    :type context: usualy a ABC object
    :param normalizedTitle: used for the blob filename
    :type normalizedTitle: string
    :param pt: tool
    :type pt: portal_tranform tool
    :returns: nothing, update the ``svgscore`` field of the object
    """
    try:
        svgData = pt.convertTo(
            'image/svg+xml',
            context.abc,
            context=context,
            annotate=True
            )
        svgFilename = normalizedTitle + u'.svg'
        svgContenType = 'image/svg+xml'
        context.svgscore = NamedBlobImage()
        context.svgscore.data = svgData.getData()
        context.svgscore.filename = svgFilename
        context.svgscore.contentType = svgContenType
    except Exception:
        msg = u'Failed to create SVG score'
        logger.info(msg)
        annotateObject(context, msg=msg, key='ABC_ERRORS')
Esempio n. 3
0
def updateOGG(context, normalizedTitle, pt):
    """
    :param context: an object with a ``ogg`` field
    :type context: usualy a ABC object
    :param normalizedTitle: used for the blob filename
    :type normalizedTitle: string
    :param pt: tool
    :type pt: portal_tranform tool
    :returns: nothing, update the ``ogg`` field of the object
    """
    try:
        oggData = pt.convertTo(
            'audio/ogg',
            context.abc,
            context=context,
            annotate=True,
            )
        oggFilename = normalizedTitle + u'.ogg'
        oggContenType = 'audio/ogg'
        context.ogg = NamedBlobImage()
        context.ogg.data = oggData.getData()
        context.ogg.filename = oggFilename
        context.ogg.contentType = oggContenType
    except Exception:
        msg = u'Failed to create OGG sound'
        logger.info(msg)
        annotateObject(context, msg=msg, key='ABC_ERRORS')
Esempio n. 4
0
def makeFullTune(context, updateSound=True):
    validMIMEType(context)
    normalizer = getUtility(INormalizer)
    normalizedTitle = normalizer.normalize(context.title, locale='fr')
    try:
        context.abc = removeNonAscii(context.abc)
        addQ(context)
        addTuneType(context)
        addOrigins(context)
        addKeys(context)
    except Exception:
        msg = u'cannot add misc fields...!!!'
        logger.info(msg)
        annotateObject(context, msg=msg, key='ABC_ERRORS')
    try:
        pt = api.portal.get_tool('portal_transforms')
    except Exception:
        msg = u'cannot get portal_transforms tool'
        logger.info(msg)
        annotateObject(context, msg=msg, key='ABC_ERRORS')
    # For now, we only make SVG, PDF and OGG !
    updateSVG(context, normalizedTitle, pt)
    updatePDF(context, normalizedTitle, pt)
    # updatePNG(context, normalizedTitle, pt)
    if updateSound:
        updateOGG(context, normalizedTitle, pt)
Esempio n. 5
0
def updateMIDI(context, normalizedTitle, pt):
    """
    :param context: an object with a ``midi`` field
    :type context: usualy a ABC object
    :param normalizedTitle: used for the blob filename
    :type normalizedTitle: string
    :param pt: tool
    :type pt: portal_tranform tool
    :returns: nothing, update the ``midi`` field of the object
    """
    try:
        midiData = pt.convertTo(
            'audio/x-midi',
            context.abc,
            context=context,
            annotate=True,
            )
        midiFilename = normalizedTitle + u'.mid'
        midiContentType = u'audio/mid'
        context.midi = NamedBlobFile()
        context.midi.data = midiData.getData()
        context.midi.contentType = midiContentType
        context.midi.filename = midiFilename
    except Exception:
        msg = u'Failed to create MIDI'
        logger.info(msg)
        annotateObject(context, msg=msg, key='ABC_ERRORS')