[英]Creating images of notes in music21
运行时出现错误:
from music21 import *
n1 = note.Note('C4', quarterLength=1)
n2 = note.Note('A4', quarterLength=1)
s = stream.Stream()
s.append(n1)
s.append(n2)
s.show('lily.svg')
Traceback (most recent call last):
File "C:\Python34\test.py", line 7, in <module>
s.show('lily.svg')
File "C:\Python34\lib\site-packages\music21\base.py", line 2206, in show
return formatWriter.show(self, regularizedConverterFormat, app=app, subformats=subformats, **keywords)
File "C:\Python34\lib\site-packages\music21\converter\subConverters.py", line 277, in show
returnedFilePath = self.write(obj, fmt, subformats=subformats, **keywords)
File "C:\Python34\lib\site-packages\music21\converter\subConverters.py", line 245, in write
conv = lily.translate.LilypondConverter()
File "C:\Python34\lib\site-packages\music21\lily\translate.py", line 147, in __init__
self.setupTools()
File "C:\Python34\lib\site-packages\music21\lily\translate.py", line 177, in setupTools
versionString = versionString.split()[-1]
IndexError: list index out of range
我已经安装了 scipy 和 mathplotlib,所以 music21 不会再抱怨它们不可用了。 我在 Windows 7 上运行 Python 3.4。
如果我改用s.show('musicxml.png')
来获取我的图像,我会收到错误消息:
Traceback (most recent call last):
File "C:\Python34\test.py", line 7, in <module>
s.show('musicxml.png')
File "C:\Python34\lib\site-packages\music21\base.py", line 2206, in show
return formatWriter.show(self, regularizedConverterFormat, app=app, subformats=subformats, **keywords)
File "C:\Python34\lib\site-packages\music21\converter\subConverters.py", line 147, in show
returnedFilePath = self.write(obj, fmt, subformats=subformats, **keywords)
File "C:\Python34\lib\site-packages\music21\converter\subConverters.py", line 637, in write
fp = self.runThroughMusescore(fp, **keywords)
File "C:\Python34\lib\site-packages\music21\converter\subConverters.py", line 606, in runThroughMusescore
elif not os.path.exists(musescoreFile):
File "C:\Python34\lib\genericpath.py", line 19, in exists
os.stat(path)
TypeError: stat: can't specify None for path argument
我需要做什么才能获取图像(最好是 svg)?
百合
我有同样的错误。 我已设法通过以下方式为 music21 配置 LilyPond:
C:\\Program Files (x86)\\LilyPond\\usr\\bin
到C:\\LilyPond\\usr\\bin
)。 我在 music21 代码中看到,在执行 lilypond 命令时,它没有在路径周围放置必要的配额,因此必须以这种方式解决问题。在music21中创建配置文件并设置lilypondPath
us = environment.UserSettings() us.create() us['lilypondPath'] = 'C:/LilyPond/usr/bin/lilypond.exe'
您可以检查它是否设置正确:
print us['lilypondPath']
好吧,这可能不是必需的,但在我的尝试中,我重新启动了好几次,所以如果一切都不能立即生效,你可以在最后尝试。
音乐节
向环境添加了两次 musescore 路径(找到了这种设置环境变量的新方法),一次为"musescoreDirectPNGPath"
:
environment.set("musescoreDirectPNGPath", "C:/MuseScore2/bin/MuseScore.exe")
然后作为"musicxmlPath"
:
environment.set("musicxmlPath", "C:/MuseScore2/bin/MuseScore.exe")
经过多次尝试、调试等。我了解到,如果我们想使用 Musescore,重要的是传入文件名“.xml”而不是“.png”扩展名:
stream_name.show('musicalxml.xml')
Musescore 不能打开 .png 文件,但它可以打开 .xml 文件。
最后,我可以添加一些无需打开 lilypond 或 musescore 即可生成文件的代码。 希望有人觉得它有用
百合:
# music21object - stream or score or any object that can be showed
conv = music21.converter.subConverters.ConverterLilypond()
scorename = 'myScoreName'
filepath = 'C:/path/to/musical_scores/' + scorename
conv.write(music21object, fmt = 'lilypond', fp=filepath, subformats = ['pdf'])
音乐评分:
from music21.converter.subConverters import ConverterMusicXML
conv_musicxml = ConverterMusicXML()
scorename = 'myScoreName.xml'
filepath = 'C:/path/to/musical_scores/' + scorename
out_filepath = conv_musicxml.write(music21object, 'musicxml', fp=filepath, subformats=['png'])
请注意,该 scorename 具有“.xml”扩展名。
不幸的是,它不会将文件保存在指定的文件路径中。 Musescore 将“-1”添加到文件名,但可以获取此更改后的文件路径(如上面代码中的 out_filepath)并稍后重命名为我们想要的。
我能够使用带空格的路径设置 musescore。 最重要的是确保使用反斜杠。 我是这样做的:
# Create the user environment for music21
us = m21.environment.UserSettings()
us['musicxmlPath'] = 'C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe'
us['musescoreDirectPNGPath'] = 'C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe'
希望能帮助到你!
尝试#sudo apt-get update 安装 lilypond !apt-get update !apt-get -y install lilypond
否则,lilypond 希望下载的附加文件会因系统过时而失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.