def _make_mp3(context): midi = context.midi mididata = midi.data miditemp = tf.NamedTemporaryFile(mode='w+b', suffix='.mid', delete=False).name fmiditemp = open(miditemp, 'w') fmiditemp.write(mididata) fmiditemp.close() aifftemp = tf.NamedTemporaryFile(mode='w+b', suffix='.aiff', delete=False).name timidity = ["timidity", '-A 400', '-EFchorus=2,50', '-EFreverb=2', miditemp, '-o', aifftemp, '-Oa'] p = sp.Popen(timidity, stdout=sp.PIPE, stderr=sp.PIPE) p.wait() output, errors = p.communicate() logger.info('in _make_mp3') logger.info(errors) logger.info(output) # mp3temp = tf.NamedTemporaryFile(mode='w+b', suffix='.mp3', delete=False).name lame = ["lame", '--cbr', '-b 32', '-f', '--quiet', aifftemp, mp3temp] p = sp.Popen(lame, stdout=sp.PIPE, stderr=sp.PIPE) p.wait() output, errors = p.communicate() # logger.info(errors) # logger.info(output) # iomp3 = StringIO() fmp3temp = open(mp3temp, 'r') buff_mp3 = fmp3temp.read() fmp3temp.close() iomp3.write(buff_mp3) # MP3Filename = u'sound.mp3' MP3Data = iomp3.getvalue() MP3ContentType = u'audio/mp3' blobMP3 = nbf(MP3Data, contentType=MP3ContentType, filename=MP3Filename) context.sound = blobMP3 unlink(miditemp) unlink(aifftemp) unlink(mp3temp) return output, errors
def _make_mp3(context): midi = context.midi mididata = midi.data miditemp = tf.NamedTemporaryFile(mode='w+b', suffix='.mid', delete=False).name fmiditemp = open(miditemp, 'w') fmiditemp.write(mididata) fmiditemp.close() aifftemp = tf.NamedTemporaryFile(mode='w+b', suffix='.aiff', delete=False).name timidity = [ "timidity", '-A 400', '-EFchorus=2,50', '-EFreverb=2', miditemp, '-o', aifftemp, '-Oa' ] p = sp.Popen(timidity, stdout=sp.PIPE, stderr=sp.PIPE) p.wait() output, errors = p.communicate() logger.info('in _make_mp3') logger.info(errors) logger.info(output) # mp3temp = tf.NamedTemporaryFile(mode='w+b', suffix='.mp3', delete=False).name lame = ["lame", '--cbr', '-b 32', '-f', '--quiet', aifftemp, mp3temp] p = sp.Popen(lame, stdout=sp.PIPE, stderr=sp.PIPE) p.wait() output, errors = p.communicate() # logger.info(errors) # logger.info(output) # iomp3 = StringIO() fmp3temp = open(mp3temp, 'r') buff_mp3 = fmp3temp.read() fmp3temp.close() iomp3.write(buff_mp3) # MP3Filename = u'sound.mp3' MP3Data = iomp3.getvalue() MP3ContentType = u'audio/mp3' blobMP3 = nbf(MP3Data, contentType=MP3ContentType, filename=MP3Filename) context.sound = blobMP3 unlink(miditemp) unlink(aifftemp) unlink(mp3temp) return output, errors
def _make_midi(context): """ peut etre utile : http://stackoverflow.com/questions/12298136/\ dynamic-source-for-plone-dexterity-relationlist pour les donnees binaires : http://plone.org/products/dexterity/\ documentation/manual/developer-manual/advanced/files-and-images """ abc = context.abc abctemp = tf.NamedTemporaryFile(mode='w+b', suffix='.abc', delete=False).name fabctemp = open(abctemp, 'w') for l in abc: fabctemp.write(l) fabctemp.write('\n\n') fabctemp.close() miditemp = tf.NamedTemporaryFile(mode='w+b', suffix='.mid', delete=False).name p = sp.Popen(["abc2midi", abctemp, '-o', miditemp], stdout=sp.PIPE, stderr=sp.PIPE ) p.wait() iomidi = StringIO() fmiditemp = open(miditemp, 'r') buffmidi = fmiditemp.read() iomidi.write(buffmidi) title = context.title normalizer = getUtility(INormalizer) normalizedTitle = normalizer.normalize(title, locale='fr') midiFilename = unicode(normalizedTitle + '.mid') midiData = iomidi.getvalue() midiContentType = u'audio/mid' blobMidi = nbf(midiData, contentType=midiContentType, filename=midiFilename ) context.midi = blobMidi output, errors = p.communicate() # logger.info(errors) # logger.info(output) unlink(abctemp) unlink(miditemp) return output
def _make_midi(context): """ peut etre utile : http://stackoverflow.com/questions/12298136/\ dynamic-source-for-plone-dexterity-relationlist pour les donnees binaires : http://plone.org/products/dexterity/\ documentation/manual/developer-manual/advanced/files-and-images """ abc = context.abc abctemp = tf.NamedTemporaryFile(mode='w+b', suffix='.abc', delete=False).name fabctemp = open(abctemp, 'w') for l in abc: fabctemp.write(l) fabctemp.write('\n\n') fabctemp.close() miditemp = tf.NamedTemporaryFile(mode='w+b', suffix='.mid', delete=False).name p = sp.Popen(["abc2midi", abctemp, '-o', miditemp], stdout=sp.PIPE, stderr=sp.PIPE) p.wait() iomidi = StringIO() fmiditemp = open(miditemp, 'r') buffmidi = fmiditemp.read() iomidi.write(buffmidi) title = context.title normalizer = getUtility(INormalizer) normalizedTitle = normalizer.normalize(title, locale='fr') midiFilename = unicode(normalizedTitle + '.mid') midiData = iomidi.getvalue() midiContentType = u'audio/mid' blobMidi = nbf(midiData, contentType=midiContentType, filename=midiFilename) context.midi = blobMidi output, errors = p.communicate() # logger.info(errors) # logger.info(output) unlink(abctemp) unlink(miditemp) return output
def _make_score(context): """Make score as png AND PDF :param context: this method is always applied on an abctune :type context: abctune :returns: """ # First, we create a file with abc text abc = context.abc title = context.title normalizer = getUtility(INormalizer) normalizedTitle = normalizer.normalize(title, locale='fr') abctemp = tf.NamedTemporaryFile(mode='w+b', suffix='.abc', delete=False).name fabctemp = open(abctemp, 'w') for l in abc: fabctemp.write(l) fabctemp.write('\n\n') fabctemp.close() # then call abcm2ps to create an eps file epstemp = tf.NamedTemporaryFile(mode='w+b', suffix='.eps', delete=False).name p = sp.Popen(["abcm2ps", abctemp, '-E -O', epstemp], stdout=sp.PIPE, stderr=sp.PIPE) p.wait() # with this eps, create the png score # convert ${PSFILE} -filter Catrom -resize 600 $PNG" pngtemp = tf.NamedTemporaryFile(mode='w+b', suffix='.png', delete=False).name p = sp.Popen(["convert", epstemp.split('.eps')[0] + '001.eps', '-filter', 'Catrom', '-resize', '600', pngtemp], stdout=sp.PIPE, stderr=sp.PIPE) p.wait() iopng = StringIO() fpngtemp = open(pngtemp, 'r') buff_score = fpngtemp.read() iopng.write(buff_score) scoreData = iopng.getvalue() scoreFilename = unicode(normalizedTitle + '.png') scoreContentType = u'image/png' # the png score is stored in the object (attr : score) blobScore = nbi(scoreData, contentType=scoreContentType, filename=scoreFilename) context.score = blobScore output, errors = p.communicate() logger.info(errors) logger.info(output) # logger.info(abctemp) # then create a ps file for PDF transform pstemp = tf.NamedTemporaryFile(mode='w+b', suffix='.ps', delete=False).name p = sp.Popen(["abcm2ps", abctemp, '-O', pstemp], stdout=sp.PIPE, stderr=sp.PIPE ) p.wait() pdftemp = tf.NamedTemporaryFile(mode='w+b', suffix='.pdf', delete=False).name pdf_create = sp.Popen(["ps2pdf", pstemp, pdftemp], stdout=sp.PIPE, stderr=sp.PIPE) pdf_create.wait() iopdf = StringIO() fpdftemp = open(pdftemp, 'r') buff_pdfscore = fpdftemp.read() iopdf.write(buff_pdfscore) # The PDF score is stored in the object (attr: pdfscore) PDFScoreFilename = unicode(normalizedTitle + '.pdf') PDFScoreData = iopdf.getvalue() PDFScoreContentType = u'application/pdf' blobPDFScore = nbf(PDFScoreData, contentType=PDFScoreContentType, filename=PDFScoreFilename) context.pdfscore = blobPDFScore logger.info(pdftemp) output, errors = pdf_create.communicate() # logger.info(errors) logger.info(epstemp) unlink(abctemp) unlink(pstemp) unlink(epstemp.split('.eps')[0] + '001.eps') unlink(epstemp) unlink(pngtemp) unlink(pdftemp) return output