Esempio n. 1
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)
def updateAbcTune(context, event):
    """TODO : see newAbcTune
    """
    portal = api.portal.get()
    try:
        context.abc = removeNonAscii(context.abc)
        addQ(context)
        addTuneType(context)
        addOrigins(context)
        addKeys(context)
        pt = getToolByName(portal, "portal_transforms")
        midi = pt.convertTo("audio/x-midi", context.abc)
        context.midi = midi.getData()
        score = pt.convertTo("image/png", context.abc)
        context.score = score.getData()
        sound = pt.convertTo("audio/mpeg", context.abc)
        context.sound = sound.getData()
        """
        This event notifier should be in module
        collective.abctuneset

        if parent.portal_type == 'abctuneset':
            log = '(IObjectModifiedEvent)abctune.updateAbcTune '
            log += parent.portal_type
            logger.info(log)
            notify(TuneInTuneSetModified(context))
        # _make_mp3(context)
        """

    except Exception:
        logger.info("updateAbcTune : abctune not modified...")
Esempio n. 3
0
 def processABC(self, data):
     data = removeNonAscii(data)
     rawtunes = data.split('X:')
     for rawtune in rawtunes:
         # logger.info(line)
         # logger.info('-----------')
         tune = rawtune.split('\n')[1:]
         tune.insert(0, 'X:1')
         newtune = ('\n').join(self.cleanup(tune))
         tuneId = self.getTuneId(tune)
         tuneTitle = self.getTuneTitle(tune)
         tuneSubject = self.getSubject(tune)
         if tuneId != 'collective.abctune.NoId':
             self.createTune(newtune=newtune,
                             tuneId=tuneId,
                             tuneTitle=tuneTitle,
                             tuneSubject=tuneSubject)
def newAbcTune(context, event):
    portal = api.portal.get()
    """TODO : add %abc at the begining of the file if
    not present (for mimetype recognition)
    Create mp3 (sound field) only when asked
    """
    try:
        context.abc = removeNonAscii(context.abc)
        addQ(context)
        addTuneType(context)
        addOrigins(context)
        addKeys(context)
        pt = getToolByName(portal, "portal_transforms")
        midi = pt.convertTo("audio/x-midi", context.abc)
        context.midi = midi.getData()
        score = pt.convertTo("image/png", context.abc)
        context.score = score.getData()
        sound = pt.convertTo("audio/mpeg", context.abc)
        context.sound = sound.getData()
        logger.info("abc created !")
    except Exception:
        logger.info("abctune not created...")