我希望使用MIDIUtil在每个音符中有一个渐强(音量增加)。有没有办法做到这一点?我有简单的MIDIUtil演示代码并对其进行了修改,因此每个音符持续5个节拍。我有一个像这样的基本代码:
from midiutil.MidiFile import *
degrees = [60, 62, 64, 65, 67, 69, 71, 72]
track = 0
channel = 0
time = 0
duration = 5
tempo = 120
volume = 100
MyMIDI = MIDIFile(1)
MyMIDI.addTempo(track,time, tempo)
for pitch in degrees:
MyMIDI.addNote(track, channel, pitch, time, duration, volume)
time = time + 1
with open("major-scale.mid", "wb") as output_file:
MyMIDI.writeFile(output_file)
非常感谢。
答案 0 :(得分:0)
您可以通过增加volume
参数的值来增加每个音符的速度。像这样:
from midiutil.MidiFile import *
degrees = [60, 62, 64, 65, 67, 69, 71, 72]
track = 0
channel = 0
time = 0
duration = 4
tempo = 120
volume = 15
MyMIDI = MIDIFile(1)
MyMIDI.addTempo(track,time, tempo)
for pitch in degrees:
MyMIDI.addNote(track, channel, pitch, time, duration, volume)
time = time + 4
volume = volume + 15
with open("major-scale.mid", "wb") as output_file:
MyMIDI.writeFile(output_file)
这将使每个音符的速度高于前一音符,但音符发声时音量不会增加。 (另请注意,我将持续时间更改为4,并将每个音符的time
增加4。这使得每个音符都是一个没有重叠的音符。在您的示例中,每个音符都是五个节拍,并且在前一个音符后开始一个节拍注意,造成很多重叠。)
调用此参数volume
是MIDIUtil实现者的错误。它应该被称为"速度"。音量是MIDI中完全不同的东西。音量是连续的控制器#7,并影响该MIDI通道上发出的所有声音的音量。速度是敲击单个音符的强度。甚至都不保证速度会影响音符的音量。它很常见,但声音可以编程,以便速度影响声音的任何方面,而不仅仅是响度。
这是一个类似的程序,它使用音量连续控制器来增加音量,同时每个音符(都是速度为80)都在发声。 (这不是优雅的代码。我不是一个Python程序员,而且它超过了我的睡觉时间。)
from midiutil.MidiFile import *
degrees = [60, 62, 64, 65, 67, 69, 71, 72]
track = 0
channel = 0
time = 0
duration = 4
tempo = 120
volume = 8
MyMIDI = MIDIFile(1)
MyMIDI.addTempo(track, time, tempo)
for pitch in degrees:
MyMIDI.addNote(track, channel, pitch, time, duration, 80)
for i in range (0, 15):
MyMIDI.addControllerEvent(track, channel, time + i * 4 / 15, 7, volume)
volume = volume + 1
time = time + 4
with open("major-scale-with-volume.mid", "wb") as output_file:
MyMIDI.writeFile(output_file)
这是前几个措施的样子: