Пример #1
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)
Пример #2
0
 def show(self, obj, fmt, app=None, subformats=None, **keywords):
     if not common.runningUnderIPython():
         super(ConverterBraille, self).show(obj, fmt, app=None, subformats=None, **keywords)
     else:
         from music21 import braille
         dataStr = braille.translate.objectToBraille(obj)
         print(dataStr)
Пример #3
0
    def runThroughMusescore(self, fp, **keywords):
        import sys
        musescoreFile = environLocal['musescoreDirectPNGPath']
        if musescoreFile == "":
            raise SubConverterException("To create PNG files directly from MusicXML you need to download MuseScore")
        elif not os.path.exists(musescoreFile):
            raise SubConverterException("Cannot find a path to the 'mscore' file at %s -- download MuseScore" % musescoreFile)

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

        storedStrErr = sys.stderr
        if six.PY2:
            from StringIO import StringIO # @UnusedImport
        else:
            from io import StringIO # @Reimport
        fileLikeOpen = StringIO()
        sys.stderr = fileLikeOpen
        os.system(musescoreRun)
        fileLikeOpen.close()
        sys.stderr = storedStrErr

        fp = fpOut[0:len(fpOut) - 4] + "-1.png"
        return fp
Пример #4
0
    def runThroughMusescore(self, fp, **keywords):
        import sys
        musescoreFile = environLocal['musescoreDirectPNGPath']
        if musescoreFile == "":
            raise SubConverterException(
                "To create PNG files directly from MusicXML you need to download MuseScore"
            )
        elif not os.path.exists(musescoreFile):
            raise SubConverterException(
                "Cannot find a path to the 'mscore' file at %s -- download MuseScore"
                % musescoreFile)

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

        storedStrErr = sys.stderr
        if six.PY2:
            from StringIO import StringIO  # @UnusedImport
        else:
            from io import StringIO  # @Reimport
        fileLikeOpen = StringIO()
        sys.stderr = fileLikeOpen
        os.system(musescoreRun)
        fileLikeOpen.close()
        sys.stderr = storedStrErr

        fp = fpOut[0:len(fpOut) - 4] + "-1.png"
        return fp
Пример #5
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
Пример #6
0
 def show(self, obj, fmt, app=None, subformats=None, **keywords): # pragma: no cover
     if not common.runningUnderIPython():
         super().show(obj, fmt, app=None, subformats=None, **keywords)
     else:
         from music21 import braille
         dataStr = braille.translate.objectToBraille(obj)
         print(dataStr)
Пример #7
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
Пример #8
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)
Пример #9
0
def loadNoMagic():
    '''
    Load the magic functions when running iPython
    '''
    if common.runningUnderIPython():
        from IPython.core.interactiveshell import InteractiveShell
        if InteractiveShell.initialized():        
            localIP = InteractiveShell.instance()    
            load_ipython_extension(localIP)
Пример #10
0
def loadNoMagic():
    '''
    Load the magic functions when running iPython
    '''
    if common.runningUnderIPython():
        from IPython.core.interactiveshell import InteractiveShell
        if InteractiveShell.initialized():
            localIP = InteractiveShell.instance()
            load_ipython_extension(localIP)
Пример #11
0
def inGoogleColabNotebook():
    if not common.runningUnderIPython():
        return False
    try:
        # get_ipython is loaded into global scope in IPython and Google Colab
        # because we already returned False above, the NameError should never
        # be triggered, but better safe than sorry.  And helps type checkers.
        return get_ipython().__class__.__module__ == "google.colab._shell"
    except NameError:
        return False
Пример #12
0
def loadNoMagic():
    '''
    Load the magic functions of load_ipython_extension when running IPython
    '''
    if common.runningUnderIPython():
        # noinspection PyPackageRequirements
        from IPython.core.interactiveshell import InteractiveShell  # type: ignore
        if InteractiveShell.initialized():
            localIP = InteractiveShell.instance()
            load_ipython_extension(localIP)
Пример #13
0
    def runThroughMusescore(self, fp, subformats=None, **keywords): # pragma: no cover
        '''
        Take the output of the conversion process and run it through musescore to convert it
        to a png.
        '''
        if isinstance(fp, pathlib.Path):
            fp = str(fp)

        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 musescorePath.exists():
            raise SubConverterException(
                        "Cannot find a path to the 'mscore' file at " +
                        "%s -- download MuseScore" % str(musescorePath))

        if subformats is None:
            subformatExtension = 'png'
        else:
            subformatExtension = subformats[0]

        fpOut = fp[0:len(fp) - 3]
        fpOut += subformatExtension

        musescoreRun = '"' + str(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 = io.StringIO()
        sys.stderr = fileLikeOpen
        os.system(musescoreRun)
        fileLikeOpen.close()
        sys.stderr = storedStrErr

        if subformatExtension == 'png':
            return self.findPNGfpFromXMLfp(fpOut)
        else:
            return fpOut
Пример #14
0
iPython extension to music21.  In IPython Notebook call:

   %load_ext music21.ipython21
   
and show will take place inside the browser
'''
__all__ = ['ipExtension', 'objects']

from music21.ipython21 import ipExtension
from music21.ipython21 import objects
from music21.ipython21.ipExtension import load_ipython_extension

from music21 import common

def loadNoMagic():
    '''
    Load the magic functions when running iPython
    '''
    if common.runningUnderIPython():
        from IPython.core.interactiveshell import InteractiveShell
        if InteractiveShell.initialized():        
            localIP = InteractiveShell.instance()    
            load_ipython_extension(localIP)
            
# if we are imported in an IPython environment, then load magic after half a second
if common.runningUnderIPython(): # @UndefinedVariable
    from threading import Timer
    t = Timer(2, loadNoMagic)
    t.start()
    #ipython21.load_no_magic() # @UndefinedVariable
Пример #15
0
   %load_ext music21.ipython21

and show will take place inside the browser
'''
__all__ = ['ipExtension', 'objects']

from music21.ipython21 import ipExtension
from music21.ipython21 import objects
from music21.ipython21.ipExtension import load_ipython_extension

from music21 import common


def loadNoMagic():
    '''
    Load the magic functions when running iPython
    '''
    if common.runningUnderIPython():
        from IPython.core.interactiveshell import InteractiveShell
        if InteractiveShell.initialized():
            localIP = InteractiveShell.instance()
            load_ipython_extension(localIP)


# if we are imported in an IPython environment, then load magic after half a second
if common.runningUnderIPython():  # @UndefinedVariable
    from threading import Timer
    t = Timer(2, loadNoMagic)
    t.start()
    #ipython21.load_no_magic() # @UndefinedVariable
Пример #16
0
   %load_ext music21.ipython21

and show will take place inside the browser
'''
__all__ = ['ipExtension', 'objects', 'loadNoMagic', 'load_ipython_extension']

from music21.ipython21 import ipExtension
from music21.ipython21 import objects
from music21.ipython21.ipExtension import load_ipython_extension

from music21 import common

def loadNoMagic():
    '''
    Load the magic functions when running iPython
    '''
    if common.runningUnderIPython():
        # noinspection PyPackageRequirements
        from IPython.core.interactiveshell import InteractiveShell
        if InteractiveShell.initialized():
            localIP = InteractiveShell.instance()
            load_ipython_extension(localIP)


# if we are imported in an IPython environment, then load magic after half a second
if common.runningUnderIPython():
    from threading import Timer
    t = Timer(2, loadNoMagic)
    t.start()
    # ipython21.load_no_magic()