show | version | enable_checker |
---|---|---|
step |
1.0 |
true |
- 我们首先要从零开始
- 安装midi软件
sudo apt update
yes | sudo apt install rosegarden
- 也可以直接运行
rosegarden
- 运行成功
- 尝试使用python写mid文件
pip install MIDIUtil
- 安装成功后
- 准备用python写midi文件
from midiutil import MIDIFile
# create MIDI file
midi_file = MIDIFile(1)
# add a track
track = 0
time = 0
midi_file.addTrackName(track, time, "Sample Track")
midi_file.addTempo(track, time, 120)
# add notes to the track
channel = 0
pitch = 60 # C3
duration = 1 # 1 beat
volume = 100 # max volume
for i in range(0, 8):
midi_file.addNote(track, channel, pitch+i, time+i*duration, duration, volume)
# write MIDI file to disk
with open("output.mid", "wb") as output_file:
midi_file.writeFile(output_file)
- 运行之后
- 尝试打开output.mid
- 查看钢琴卷帘
- 可以修改为大调音阶吗?
from midiutil import MIDIFile
# create MIDI file
midi_file = MIDIFile(1)
# add a track
track = 0
time = 0
midi_file.addTrackName(track, time, "Sample Track")
midi_file.addTempo(track, time, 120)
# add notes to the track
channel = 0
pitch = 72 # C4
duration = 1 # 1 beat
volume = 100 # max volume
j = 0
for i in [0,2,4,5,7,9,11,12]:
midi_file.addNote(track, channel, pitch+i, time+j*duration, duration, volume)
j = j + 1
# write MIDI file to disk
with open("output.mid", "wb") as output_file:
midi_file.writeFile(output_file)
- 修改后结果
- 有更标准的写法吗?
firefox https://pypi.org/project/MIDIUtil/
- 文档状态
- 可以跑跑其中的代码吗?
#!/usr/bin/env python
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 is created
# automatically)
MyMIDI.addTempo(track, time, tempo)
for i, pitch in enumerate(degrees):
MyMIDI.addNote(track, channel, pitch, time + i, duration, volume)
with open("major-scale.mid", "wb") as output_file:
MyMIDI.writeFile(output_file)
- 输出了一系列的 大调音阶
- major-scale
- 打开之后查看到mid状态
- 确实是大调音阶
- 这次从零开始
- 安装了midi软件
- 使用python制作了mid文件
- 不过
- 究竟什么是mid呢?🤔
- 我们下次再说!👋