示例#1
0
    def runThroughMusescore(self, fp, **keywords):
        musescorePath = environLocal['musescoreDirectPNGPath']
        if musescorePath == "":
            raise SubConverterException(
                "To create PNG files directly from MusicXML you need to download MuseScore"
            )
        elif not os.path.exists(musescorePath):
            raise SubConverterException(
                "Cannot find a path to the 'mscore' file at %s -- download MuseScore"
                % musescorePath)

        fpOut = fp[0:len(fp) - 3]
        fpOut += "png"
        musescoreRun = '"' + musescorePath + '" ' + fp + " -o " + fpOut + " -T 0 "
        if 'dpi' in keywords:
            musescoreRun += " -r " + str(keywords['dpi'])
        if common.runningUnderIPython():
            musescoreRun += " -r " + str(defaults.ipythonImageDpi)

        storedStrErr = sys.stderr
        fileLikeOpen = six.StringIO()
        sys.stderr = fileLikeOpen
        os.system(musescoreRun)
        fileLikeOpen.close()
        sys.stderr = storedStrErr

        fp = fpOut[0:len(fpOut) - 4] + "-1.png"
        #common.cropImageFromPath(fp)
        return fp
示例#2
0
    def runThroughMusescore(self, fp, **keywords):
        '''
        Take the output of the conversion process and run it through musescore to convert it
        to a png.
        '''
        musescorePath = environLocal['musescoreDirectPNGPath']
        if not musescorePath:
            raise SubConverterException(
                "To create PNG files directly from MusicXML you need to download MuseScore and " +
                "put a link to it in your .music21rc via Environment.")
        elif not os.path.exists(musescorePath):
            raise SubConverterException(
                        "Cannot find a path to the 'mscore' file at " + 
                        "%s -- download MuseScore" % musescorePath)

        fpOut = fp[0:len(fp) - 3]
        fpOut += "png"
        musescoreRun = '"' + musescorePath + '" ' + fp + " -o " + fpOut + " -T 0 "
        if 'dpi' in keywords:
            musescoreRun += " -r " + str(keywords['dpi'])
        if common.runningUnderIPython():
            musescoreRun += " -r " + str(defaults.ipythonImageDpi)

        storedStrErr = sys.stderr
        fileLikeOpen = six.StringIO()
        sys.stderr = fileLikeOpen
        os.system(musescoreRun)
        fileLikeOpen.close()
        sys.stderr = storedStrErr
        return self.findPNGfpFromXMLfp(fpOut)