Python music21 库从流创建 png

标签 python music21 music-notation

我在从 music21 中的 stream 对象生成 png 文件时遇到问题。我阅读文档并使用 ConverterLilypond 来执行此操作。

  chords = stream.Stream()

  d7 = chord.Chord(['D4', 'F4', 'A4', 'C5'])
  dmin7 = chord.Chord(['D4', 'F-4', 'A4', 'C5'])
  dmaj7 = chord.Chord(['D4', 'F#4', 'A4', 'C#5'])
  chords.append(d7)
  chords.append(dmin7)
  chords.append(dmaj7)
  conv = converter.subConverters.ConverterLilypond()
  conv.write(chords, fmt='lilypond', fp='file', subformats=['png'])

此代码将生成 png 文件、eps 文件计数文件、tex 和 texi 文件。为什么?如何只生成一个文件,PNG 文件?

当我尝试在 jupyter 中运行这段代码时,我会使用 chords.show() 来显示图像,但通常在脚本中 show 会生成一个文件,不是图形。

编辑:

带有环境变量的代码

from music21 import *

us = environment.UserSettings()
us['lilypondPath'] = 'C:/Program Files (x86)/LilyPond/usr/bin/lilypond.exe'
us['musescoreDirectPNGPath'] = 'C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe'
us['musicxmlPath'] = 'C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe'

d7 = chord.Chord(['D4', 'F4', 'A4', 'C5'])

stream = stream.Stream()
stream.show('musicxml.png')

最佳答案

最好的接口(interface)是调用:

chords.show('lily.png')

这将运行一切。但是 Lilypond 接口(interface)不是那么强大,所以最好安装 MuseScore 并将 .music21rc 中的 MusescoreDirectPNGPath 设置为指向 mscore 可执行文件,然后调用 chords.show('musicxml.png') 它将通过 MusicXML 进行更好的翻译。

关于Python music21 库从流创建 png,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49939275/

相关文章:

python - 在 Python 应用程序中排除 'duplicated' 抓取的 URL?

python - 如何使用 music21 显示空的五线谱?

xml - MusicXML 规范和和弦符号

wpf - 音乐编辑器的歌词

Python:从列表中获取前 10 个结果

python - z3 python代码中的错误

python - 计算有向图中每条边的权重累积(河网)

python - 迭代 Music21 中的所有音符

python - Music21 操作特定乐器

audio - 吉他和弦检测