zoukankan      html  css  js  c++  java
  • music21 关联 MuseScore 和 Lilypond

    在python安装 music21后,需要关联 musescore 或 lilypond 才能可以用图形化的形式看到 乐谱。

    因此 在安装 music21后,需要配置环境变量,yvivid 在 music21的官方 doc 没找到简单的指引,后来搜到相关信息,整理如下。

    首先、在 python 中导入music21(安装可以 pip install music21实现):

    from music21 import *

    然后,查看环境变量有哪些:

    >>>environment.keys()
    
    ['directoryScratch', 'lilypondPath', 'lilypondVersion', 'lilypondFormat', 'lilypondBackend', 
    'musicxmlPath', 'midiPath',
    'graphicsPath', 'vectorPath', 'pdfPath', 'braillePath', 'musescoreDirectPNGPath',
    'showFormat', 'writeFormat', 'ipythonShowFormat',
    'autoDownload', 'debug', 'warnings', 'localCorpusSettings',
    'localCorporaSettings', 'manualCoreCorpusPath', 'localCorpusPath']

    或者是 

    >>> us = environment.UserSettings()
    >>> us.keys()
    ['directoryScratch', 'lilypondPath', 'lilypondVersion', 'lilypondFormat', 'lilypondBackend', 'musicxmlPath', 
    'midiPath', 'graphicsPath', 'vectorPath', 'pdfPath', 'braillePath', 'musescoreDirectPNGPath', 'showFormat',
    'writeFormat', 'ipythonShowFormat', 'autoDownload', 'debug', 'warnings', 'localCorpusSettings',
    'localCorporaSettings', 'manualCoreCorpusPath', 'localCorpusPath']

    后续统一使用后者进行配置。

    对于 lilypond的配置(路径请自行编写):

    us['lilypondPath'] = 'C:/Program Files (x86)/LilyPond/usr/bin/lilypond.exe'

    对于 musescore的配置: 

    us['musescoreDirectPNGPath'] = "C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe"
    us['musicxmlPath'] = "C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe"

    如果 keys()里面没有 相关配置,可以先set出相关配置项。

    environment.set("musescoreDirectPNGPath", "C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe")
    environment.set("musicxmlPath", "C:/Program Files (x86)/MuseScore 2/bin/MuseScore.exe")

    最后,yvivid做个验证测试:

    from music21 import *
    littleMelody = converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#")
    littleMelody.show()

    作者:www.cnblogs.com/yvivid

    参考文献:

    1、http://web.mit.edu/music21/doc/usersGuide/usersGuide_08_installingMusicXML.html

    2、https://stackoverflow.com/questions/25879764/creating-images-of-notes-in-music21

  • 相关阅读:
    C++中的动态内存管理
    Harbor镜像仓库搭建
    nexus私服搭建
    Tekton ACK安装
    容器监控实践,从入门到放弃
    Bitwarden_搭建密码服务器
    Jenkins-部署文档
    Mysql-基本的
    Zabbix添加-钉钉故障报警
    ZABBIX-4.4 yum安装
  • 原文地址:https://www.cnblogs.com/yvivid/p/music21_setting.html
Copyright © 2011-2022 走看看