コード例 #1
0
ファイル: qmConverter.py プロジェクト: chitapenane/music21
        for note in obj.flat.notes:
                music = music + note.name + ' '
        music += '\n'

        with open(fp, 'w') as f:
            f.write(music)

        return fp
    
    
if __name__ == '__main__':
    from music21 import common
    import os
    
    converter.registerSubconverter(QMConverter)
    
    print('\nFILE')
    print('+++++++++++++++++++++++++')

    parserPath = common.getSourceFilePath() + os.path.sep + 'converter'
    testPath = parserPath + os.path.sep + 'quarterMusicTestIn.qm'
    
    a = converter.parse(testPath)
    
    a.show('text')
    
    
    print('\nIn-Line')
    print('+++++++++++++++++++++++++')
    
コード例 #2
0
ファイル: chson.py プロジェクト: bacor/chant21
import json
from music21 import converter
from .chant import Chant
__all__ = ['ConverterCHSON']


class ConverterCHSON(converter.subConverters.SubConverter):
    registerFormats = ('chson', 'CHSON')
    registerInputExtensions = ('chson', 'CHSON')

    def parseData(self, strData, number=None):
        chantObj = json.loads(strData)
        chant = Chant()
        chant.fromObject(chantObj)
        self.stream = chant


converter.registerSubconverter(ConverterCHSON)
コード例 #3
0
def initialize_converter():
    """
    Initializes the music21 converter.
    """
    converter.registerSubconverter(VMFConverter)
コード例 #4
0
    result = []
    for subc in outList:
        if subc.registerOutputExtensions:
            if form in subc.registerFormats:
                for outputExt in subc.registerOutputExtensions:
                    result.append('.' + outputExt)
    return result


# ------------------------------------------------------------------------------
'''
    main entry point (parse arguments and do conversion)
'''
# unregister built-in Humdrum converter, and replace with our better one
converter.unregisterSubconverter(converter.subConverters.ConverterHumdrum)
converter.registerSubconverter(HumdrumConverter)

parser = argparse.ArgumentParser()
parser.add_argument(
    'input_file',
    help='input music file to convert from (extension is used to determine ' +
    'input format if --input-from/-f is not specified)')
parser.add_argument(
    'output_file',
    help='output music file to convert to (extension is NOT used to ' +
    'determine/validate output format, so if you\'re not careful ' +
    'you\'ll end up with contents not matching extension)')
parser.add_argument(
    '-f',
    '--input-from',
    choices=getInputFormatsList(),
コード例 #5
0
        for n in obj.flat.notes:
            music = music + n.name + ' '
        music += '\n'

        with open(fp, 'w') as f:
            f.write(music)

        return fp


if __name__ == '__main__':
    from music21 import common
    import os

    converter.registerSubconverter(QMConverter)

    print('\nFILE')
    print('+++++++++++++++++++++++++')

    parserPath = common.getSourceFilePath() + os.path.sep + 'converter'
    testPath = parserPath + os.path.sep + 'quarterMusicTestIn.qm'

    a = converter.parse(testPath)

    a.show('text')

    print('\nIn-Line')
    print('+++++++++++++++++++++++++')

    b = converter.parse('quarterMusic: G C G')
コード例 #6
0
    def visit_whitespace(self, node, children):
        return None

    def visit_macro(self, node, children):
        return None

    def visit_code(self, node, children):
        return None

    def visit_custos(self, node, children):
        return None

###

class ConverterGABC(converter.subConverters.SubConverter):
    registerFormats = ('gabc', 'GABC')
    registerInputExtensions = ('gabc', 'GABC')

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.parser = ParserGABC(root='file')
        self.visitor = VisitorGABC()

    def parseData(self, strData, number=None):
        parse = self.parser.parse(strData)
        ch = visitParseTree(parse, self.visitor)
        self.stream = ch

converter.registerSubconverter(ConverterGABC)