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('+++++++++++++++++++++++++')
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)
def initialize_converter(): """ Initializes the music21 converter. """ converter.registerSubconverter(VMFConverter)
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(),
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')
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)