将 midi 文件转为简谱 pdf.
Convert MIDI files to numbered musical notation (jianpu) PDF.
好听的歌想要弹但是网上找不到简谱资源, 可以尝试使用这个脚本.
If you want to play a nice song but can't find jianpu sheet music online, give this script a try.
需要 pypi mido 库以读取 midi 文件.
Requires the pypi mido library to read MIDI files.
需要 pypi jianpu-ly 库以转换数字谱为简谱.
Requires the pypi jianpu-ly library to convert numbered notation to jianpu.
pip install jianpu-ly mido需要 GNU LilyPond 编译乐谱.
Requires GNU LilyPond to compile the score.
您可以在 这里 下载, 或者使用系统包管理器.
You can download it from here, or use your system package manager.
注意: 不支持 Windows 7 和 Windows 8.x.
Note: Windows 7 and Windows 8.x are not supported.
python main.py -i input.mid(i)生成的文件会在当前工作目录.
Generated files will be placed in the current working directory.
要注意的是, 程序无法分辨哪个乐器段才是真正的旋律, 因此请您自行删改 midi 文件, 只有一个活跃音轨, 没有重叠音符.
Please note that the program cannot distinguish which instrument track contains the actual melody, so you should edit the MIDI file yourself to keep only one active track with no overlapping notes.
遇到音符重叠混乱的 midi, 可以先用 convert.py 处理: 它会把音符起止吸附到量化网格, 再删除被更高音音符重叠的音符 (同音高重叠则保留先开始的), 从而得到干净的单音旋律.
If a MIDI file has messy overlapping notes, run it through convert.py first: it snaps note starts and ends to the quantization grid, then removes notes overlapped by higher-pitched notes (for same-pitch overlaps the earlier one is kept), producing a clean monophonic melody.
python convert.py input.mid output.mid -r 8
python main.py -i output.mid-r 的取值和 main.py 一致, 可选 2, 4, 8, 16, 32, 64, 默认 8.
The -r values match main.py: 2, 4, 8, 16, 32, 64; default is 8.
如果旋律分散在多个音轨, 用 -m 或 --merge 先把所有音轨混合成一条再执行逻辑, 常用于伴奏和旋律分轨的 midi.
If the melody is spread across multiple tracks, use -m or --merge to mix all tracks into one stream before running the logic. This is common in MIDI files where accompaniment and melody are on separate tracks.
python convert.py input.mid output.mid -r 8 -m
python main.py -i output.mid由于技术限制, 当前只能以四分音符为 1 拍, 不过我们会在将来版本加入.
Due to technical limitations, currently only quarter note = 1 beat is supported. However, we will add support in future versions.
要指定每小节拍数, 请用 -b 或 --beats 参数, 默认每小节 4 拍.
To specify beats per measure, use the -b or --beats parameter. Default is 4 beats per measure.
python main.py -i input.mid -b 2使用 -k 或 --key-signature 参数指定调号, 默认选择最优调号.
Specify the key signature using the -k or --key-signature parameter. By default, the optimal key is chosen automatically.
您可以在 Songbpm 查看歌曲的调号.
You can check the key of a song at Songbpm.
升降号放在字母前后均可.
Sharps/flats can be placed before or after the letter.
python main.py -i input.mid -k Bb使用 -o 或 --octave-shift 参数指定整体八度偏移, 数值为正则升高, 为负则降低.
Use the -o or --octave-shift parameter to shift the whole song by octaves. Positive values raise it, negative values lower it.
python main.py -i input.mid -o 2使用 -r 或 --resolution 参数指定音符量化精度, 可选值为 2, 4, 8, 16, 32, 64, 默认 8. 该值是 1/x 拍, 而非 x 分音符.
Use the -r or --resolution parameter to specify note quantization resolution. Allowed values are 2, 4, 8, 16, 32, 64; default is 8. The value is 1/x beat, not an x-th note.
一些作者为了表现急促感会将音符削去极短的长度, 导致谱面上出现 32 分甚至更短的休止符. 此时可以降低精度以消除它们.
Some composers trim notes to extremely short lengths to convey urgency, which causes 32nd-note or even shorter rests to appear in the score. Lower the resolution in this case to eliminate them.
python main.py -i input.mid -r 4使用 -ws 或 --with-staff 参数生成简谱/五线谱对照.
Use the -ws or --with-staff parameter to generate the jianpu/staff comparison.
python main.py -i input.mid -ws使用 -s 或 --staff 参数仅生成五线谱.
Use the -s or --staff parameter to output staff notation only.
python main.py -i input.mid -s使用 -d 参数开启调试输出.
Use the -d parameter to enable debug output.
程序会生成临时文字谱, 如果需要微调可以编辑 score.txt, 使用 python main.py -i score.txt 重新编译.
The script generates a temporary text score; if you need fine-tuning, you can edit score.txt. Then regenerate with python main.py -i score.txt.
- 移调
- 八度偏移
- 输出五线谱
- 支持多音轨
- 自定义拍号
- 最后一个小节不完整时补休止符而不是报错
- 音符跨过小节线自己处理而不是jianpu-ly
- 简谱/五线谱对照
- Transposition
- Octave shift
- Output staff notation
- Support multiple tracks
- Custom time signature
- Fill incomplete last measure with rests instead of error
- Handle notes crossing barlines internally instead of relying on jianpu-ly
- Shared jianpu/staff notation comparison


