钢琴音符的自动指法
piano_fingering的Python项目详细描述
一个python库,用于自动确定一系列注释的指法。
算法是根据 https://github.com/blakewest/performer,布莱克·韦斯特。
安装
要安装此库,请执行以下操作:
$ pip install piano_fingering
用法
单音符
算法以midi音符列表作为输入:
from piano_fingering import computeFingering notes = [ 60, 62, 64, 65, 67, 69, 71, 72, ] fingered_notes = computeFingering(notes, 'right') # or 'left'
上面的代码将产生以下输出:
fingered_notes = [ {'notes': [60], 'fingers': [1]}, {'notes': [62], 'fingers': [2]}, {'notes': [64], 'fingers': [3]}, {'notes': [65], 'fingers': [1]}, {'notes': [67], 'fingers': [2]}, {'notes': [69], 'fingers': [3]}, {'notes': [71], 'fingers': [4]}, {'notes': [72], 'fingers': [5]}, ]
和弦
您也可以将和弦添加到列表中:
notes = [ [60, 62, 64], [67, 71, 74], ] fingered_notes = computeFingering(notes, 'right')
上面的代码将产生以下输出:
fingered_notes = [ {'notes': [60, 62, 64], 'fingers': [1, 2, 3]}, {'notes': [67, 71, 74], 'fingers': [1, 3, 5]}, ]
休息
rest由空列表指定。注意,算法不需要 在考虑之中。支持它们以帮助库的用户 使用结果列表。你得把长时间休息的笔记分开, 所以这首歌的一部分的指法不会影响另一部分。
示例:
notes = [ 60, [], 64, ] fingered_notes = computeFingering(notes, 'right')
上面的代码将产生以下输出:
fingered_notes = [ {'notes': [60], 'fingers': [1]}, {'notes': [], 'fingers': []}, {'notes': [64], 'fingers': [3]}, ]
用户定义的指法
如果算法没有产生一个你认为最佳的指法,你 可以通过在输入上指定自己的手指来约束它:
notes = [ 60, 62, 64, {'notes': [65], 'fingers': [4]}, 67, 69, 71, 72, ] fingered_notes = computeFingering(notes, 'right') # or 'left'
上面的代码将产生以下输出:
fingered_notes = [ {'notes': [60], 'fingers': [1]}, {'notes': [62], 'fingers': [2]}, {'notes': [64], 'fingers': [3]}, {'notes': [65], 'fingers': [4]}, {'notes': [67], 'fingers': [1]}, {'notes': [69], 'fingers': [2]}, {'notes': [71], 'fingers': [3]}, {'notes': [72], 'fingers': [4]}, ]
将音符名称转换为MIDI音符
提供了两个helpers函数来转换便笺名称(例如c5,a,bb3) 到MIDI音符。
要转换单个便笺名称,请使用:
from piano_fingering import nameToMidi midi_note = nameToMidi('C4')
如果没有指示八度音阶,则假定为“5”。
转换注释列表(格式与中的computeFingering()相同 以上示例),使用:
from piano_fingering import listToMidi notes = [ 'C5', ['C5', 'E5', 'G5'], {'notes': ['C5'], 'fingers': [1]}, ] midi_notes = listToMidi(notes)
运行测试
在源程序包中,执行以下操作:
$ python setup.py test
许可证
钢琴指法在麻省理工学院的许可下提供。许可证文本 在文件“license.txt”中。
在麻省理工学院的许可下,你可以使用钢琴指法来达到任何你想要的目的,而不需要 保修,如果需要,请修改,但有一个条件:
“The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.”
实际上,这意味着无论何时将应用程序作为二进制文件分发 或者作为源代码,您必须在发行版的某个地方包含文件中的文本 “license.txt”。这可能在打印文档中,作为交付介质上的文件, 或者甚至运行时应用程序本身的信用/确认;任何 这些可以满足要求。
即使许可证不需要它,请考虑贡献您的修改 回到社区。
特别感谢
布莱克·韦斯特,最初的javascript实现。