gpt4 book ai didi

parsing - 如何在 Music21 中为独奏钢琴读取 midi/musicxml 文件,其中一个声音中可以同时有多个音符?

转载 作者:行者123 更新时间:2023-12-04 07:14:16 25 4
gpt4 key购买 nike

我已经编写了一个python脚本来处理带有music21的midi文件并再次编写一个midi文件。如果独奏钢琴在某种意义上是“简单的”,即没有在一个声音中同时演奏多个音高/音符,则此方法有效。
https://github.com/githubuser1983/algorithmic_python_music/blob/main/12RootOf2.py
上面的相关部分是:

def parseMidi(fp,part=0):
import os
from music21 import converter
print(fp)
score = converter.parse(fp,quantizePost=True)
print(list(score.elements[0].notesAndRests))
#print([e.partAbbreviation for e in score.elements][0])
from music21 import chord
durs = []
ll0 = []
vols = []
isPauses = []
for p in score.elements[part].notesAndRests:
#print(p)
if type(p)==chord.Chord:
pitches = median([e.pitch.midi-21 for e in p]) # todo: think about chords
vol = median([e.volume.velocity for e in p])
dur = float(p.duration.quarterLength)
#print(pitches)
ll0.append(pitches)
isPause = False
elif (p.name=="rest"):
pitches = 89
vol = 1
dur = float(p.duration.quarterLength)
ll0.append(pitches)
isPause = True
else:
pitches = p.pitch.midi-21
vol = p.volume.velocity
dur = float(p.duration.quarterLength)
ll0.append(pitches)
isPause = False
durs.append(dur/(12*4.0))
vols.append(vol*1.0/127.0)
isPauses.append(isPause)
#print(p.name,p.octave,p.duration.quarterLength)
#print(dir(score))
#print(ll0)
#print(durs)
return ll0,durs,vols,isPauses
另一种选择是读取musicxml而不是midi。我需要算法工作,是每个声音的音符列表=(音高,持续时间,音量,isPause)。
谢谢你的帮助。

最佳答案

目前,在music21,stream.Voice对象更像是一个显示概念而不是一个逻辑概念。声音和和弦都是同时发生的,这就是 MIDI 文件的全部内容。 (实际上,本周将发布的第 7 版中的 pending changes 除了制作小节外,还可以从 MIDI 文件中生成更少的声音和更多的和弦。如果混响或录制的演奏有小的重叠,您可能会获得雕刻师永远不会在乐谱中打印的“声音”。)
在你的情况下,我可能只需要一个 .flatPart对象摆脱声音(最终在 v.7 中测量),然后运行 ​​chordify()如果你想确保没有重叠。否则,如果您根本不需要和弦,您仍然可以获取 chordify() 的输出并找到每个和弦的根音。几种可能性都取决于您的来源是什么样的。

关于parsing - 如何在 Music21 中为独奏钢琴读取 midi/musicxml 文件,其中一个声音中可以同时有多个音符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68881287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com