【问题标题】:How to convert abc file to a musicxml file using music21?如何使用 music21 将 abc 文件转换为 musicxml 文件?
【发布时间】:2019-12-26 18:11:08
【问题描述】:

我正在写我的论文,我需要一些帮助来了解如何使用music21 将一组abc 文件转换为一组musicxml 文件。我需要编写一个自动流来帮助我将所有notthingam 数据集转换为一组musicxml 文件,我将使用它来创建数据库。

我找到了这个类,但我不知道如何管理它:

class ConverterABC(object):

    Simple class wrapper for parsing ABC.

    def __init__(self):
        # always create a score instance
        self._stream = stream.Score()

    def parseData(self, strData, number=None):

        # Get ABC data, as token list, from a string representation.
        # If more than one work is defined in the ABC data, a
        # :class:`~music21.stream.Opus` object will be returned;
        # otherwise, a :class:`~music21.stream.Score` is returned.

        af = abc.ABCFile()
        # do not need to call open or close
        abcHandler = af.readstr(strData, number=number)
        # set to stream
        if abcHandler.definesReferenceNumbers():
            # this creates an Opus object, not a Score object
            self._stream = abc.translate.abcToStreamOpus(abcHandler,
                number=number)
        else: # just one work
            abc.translate.abcToStreamScore(abcHandler, self._stream)

    def parseFile(self, fp, number=None):
        # Get MIDI data from a file path.  
        # If more than one work is defined in the ABC data,  
        # a  :class:`~music21.stream.Opus` object will be returned;  
        # otherwise, a :class:`~music21.stream.Score` is returned.

        # If `number` is provided, and this ABC file defines multiple works with a X: tag, just the specified work will be returned.

        #environLocal.printDebug(['ConverterABC.parseFile: got number', number])

        af = abc.ABCFile()
        af.open(fp)
        # returns a handler instance of parse tokens
        abcHandler = af.read(number=number)
        af.close()

        # only create opus if multiple ref numbers
        # are defined; if a number is given an opus will no be created
        if abcHandler.definesReferenceNumbers():
            # this creates a Score or Opus object, depending on if a number
            # is given
            self._stream = abc.translate.abcToStreamOpus(abcHandler,
                           number=number)
        # just get a single work
        else:
            abc.translate.abcToStreamScore(abcHandler, self._stream)

    def _getStream(self):
        return self._stream

    stream = property(_getStream)

【问题讨论】:

    标签: python converters abc music21 musicxml


    【解决方案1】:

    https://wim.vree.org/js/index.html 中的代码将 XML 转换为 ABC,将 ABC 转换为 SVG(信号)。看看吧,也许它可以帮助你将 ABC 转换为 XML。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-28
      • 1970-01-01
      • 1970-01-01
      • 2021-06-13
      • 2019-12-01
      • 2020-02-29
      • 2015-01-24
      相关资源
      最近更新 更多