Download midi_utils.py from peter288/mido: direct link, hf CLI and curl.
- Browser
- Download file 677 Bytes
-
https://huggingface.co/spaces/peter288/mido/resolve/main/midi_utils.py
- Command line
-
hf download hf://spaces/peter288/mido/midi_utils.py
-
curl -L -o midi_utils.py https://huggingface.co/spaces/peter288/mido/resolve/main/midi_utils.py
677 Bytes
| 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']: | |
| # 确保音符不会超过MIDI的最大值127 | |
| if msg.note < 127: | |
| msg.note += 1 | |
| output_buffer = BytesIO() | |
| mid.save(file=output_buffer) | |
| output_buffer.seek(0) | |
| return output_buffer |