python - How to convert abc file to a musicxml file using music21?
问题描述
I'm writing my thesis and I need some help to understand how I can convert using music21
a set of abc
files to a set of musicxml
files. I need to write a automatic stream that helps me to convert all the notthingam
dataset into a set of musicxml
file that I'll use to create a database.
I've found this class but I don't know how to manage with it:
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)
解决方案
那里的代码https://wim.vree.org/js/index.html正在将 XML 转换为 ABC 并将 ABC 转换为 SVG(信号)。看一下,也许它可以帮助您将 ABC 转换为 XML。
推荐阅读
- python - 如何关闭 Seaborn 地块
- java - netty 会自动刷新写入的数据吗?
- java - ByteBuddy 泛型方法返回转换为具体类型
- laravel - 有什么方法可以更改 spipu/html2pdf 中的创建者 PDF 生成
- google-maps - 存储与地点详细信息一起返回的照片参考
- java - 从集合中返回值作为数组
- dictionary - 如何在张量流中正确输入数据
- c# - Blazor 文本字段 Oninput 用户键入延迟
- twilio - Authy注册用户,无需提供电子邮件和电话号码
- validation - 自定义 ASP.NET Core MVC 验证响应