写入midi文件

问题描述 投票:0回答:1

我想编写一个MIDI文件,其中包括我从数字钢琴中收到的输入。我正在使用pygame.midi打开输入端口和Midiutil来编写MIDI文件。我无法缠绕的是时机。例如,在

addNote(track, channel, pitch, time, duration, volume)
中,我怎么知道音符是什么?阅读笔记时,我会得到音调,而且音量还不错,但是我不知道的其他人...我尝试使用时间戳,但无济于事,它确实将音符放在MIDI文件中。
所以,如何计算音符的“时间”和“持续时间”?
    

time

决定了音乐时代的立场应该演奏音符。确切的参数应取决于部分构建MIDI文件对象的部分(很快详细介绍)

python time pygame midi
1个回答
10
投票
duration

消息和

time
消息。

NOTE On

将指示何时应发送

NOTE Off
消息,相对于注释的开始。同样,应如何形成参数取决于文件对象的构造方式。
midiutildocs

时间 - 音符听起来的时间。该值可以是四分之一笔记[float],也可以是 tick [整数]。可以通过通过EventTime_is_ticks = true to Midfile来指定刻度 构造函数。默认值为四分之一说明。 duration-笔记的持续时间。像时间参数一样,值可以是 季度注释[float]或ticks [整数]

完整的示例,该示例扮演C主要量表
    duration
  • 文件的组合
  • Note Off
  • (在当前的
Time
)与音符的位置(

from midiutil import MIDIFile degrees = [60, 62, 64, 65, 67, 69, 71, 72] # MIDI note number track = 0 channel = 0 time = 0 # In beats duration = 1 # In beats tempo = 60 # In BPM volume = 100 # 0-127, as per the MIDI standard MyMIDI = MIDIFile(1) # One track, defaults to format 1 (tempo track # automatically created) 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)

)和
tempo
(根据多少节拍)相结合,库可以合成在正确的时间播放(启动/停止)Note所需的所有MIDI消息。 另一个例子

llet尝试将其应用于以下音乐词:


首先,设置所有内容。
time

在g上添加上半便条和四分之一注:

duration

现在让我们添加剩下的笔记:

from midiutil import MIDIFile track = 0 channel = 0 time = 0 # In beats duration = 1 # In beats tempo = 60 # In BPM volume = 100 # 0-127, as per the MIDI standard MyMIDI = MIDIFile(1) # One track, defaults to format 1 (tempo track # automatically created) MyMIDI.addTempo(track,time, tempo) musical phrase

time = 0 # it's the first beat of the piece quarter_note = 1 # equal to one beat, assuming x/4 time half_note = 2 # Half notes are 2x value of a single quarter note E3 = 64 # MIDI note value for E3 G3 = 67 # Add half note MyMIDI.addNote(track, channel, pitch=E3, duration=half_note, time=0, volume=volume) # Add quarter note MyMIDI.addNote(track, channel, pitch=G3, duration=quarter_note, time=0, volume=volume)

	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.