File size: 610 Bytes
9804e6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import mido
from io import BytesIO

def process_midi(midi_bytes: bytes) -> BytesIO:
    """处理MIDI文件:将所有音符提高一个半音"""
    with BytesIO(midi_bytes) as input_buffer:
        mid = mido.MidiFile(file=input_buffer)
        
        for track in mid.tracks:
            for msg in track:
                if msg.type in ['note_on', 'note_off']:
                    if msg.note < 127:
                        msg.note += 1
        
        output_buffer = BytesIO()
        mid.save(file=output_buffer)
        output_buffer.seek(0)
        
        return output_buffer