|
|
import mido
|
|
|
from io import BytesIO
|
|
|
|
|
|
def process_midi(midi_bytes: bytes) -> BytesIO:
|
|
|
"""
|
|
|
Processes a MIDI file by transposing all notes up by one semitone.
|
|
|
|
|
|
Args:
|
|
|
midi_bytes: The raw bytes of the input MIDI file.
|
|
|
|
|
|
Returns:
|
|
|
A BytesIO buffer containing the processed MIDI data.
|
|
|
"""
|
|
|
|
|
|
with BytesIO(midi_bytes) as input_buffer:
|
|
|
mid = mido.MidiFile(file=input_buffer)
|
|
|
|
|
|
|
|
|
for i, track in enumerate(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 |