-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exported midi tempo #40
Comments
Great point @correa-coder ! This is now on our backlog - but in the meantime if anyone wants to try this we're happy to take a PR for this. |
Hello, I made a workaround using Mido to change the MIDI tempo without affecting the note duration/speed. import math
import os
import mido
MIDI_DIR = "C:\\Users\\UserName\\Desktop"
MIDI_INPUT_NAME = "piano_basic_pitch.mid"
MIDI_OUTPUT_NAME = f"{MIDI_INPUT_NAME.replace('.mid', '')}_with_tempo.mid"
TARGET_BPM = 60 # new BPM to use in the exported file
mid = mido.MidiFile(os.path.join(MIDI_DIR, MIDI_INPUT_NAME))
# get original file tempo, defauts to 120 BPM (500000 microseconds per beat)
midi_tempo = mid.tracks[0][0].tempo
# change midi tempo to new BPM
mid.tracks[0][0].tempo = mido.bpm2tempo(TARGET_BPM)
for i, track in enumerate(mid.tracks):
if i == 0:
# skipping first track because it only contains time signature and tempo information
continue
print(f"Track {i} - {track.name}")
for msg in track:
if msg.type == 'note_on' or msg.type == 'note_off':
# convert note lengths to fit new BPM without changing the speed of the song
old_msg_time = msg.time
new_msg_time = old_msg_time * (midi_tempo / mido.bpm2tempo(TARGET_BPM))
msg.time = math.floor(new_msg_time)
mid.save(os.path.join(MIDI_DIR, MIDI_OUTPUT_NAME)) To test I created a .wav file using FL Studio. It plays this chord progression: C G/B Gm/Bb Dm7 G7 C at 60 BPM After running After running the script, it changes the BPM back to 60 and the notes got closer to the original durations |
Hi! Thanks for raising this, we have a PR with the new CLI parameter completed and awaiting testing. I'll let you know once it gets patched in and you can give it a try |
Hello! Thanks for your patience. The midi tempo CLI argument has been added in version 0.2.3 (the latest version). Please feel free to update your package and give it a try. Thanks! |
In the web demo there's a slider that allows you to choose the midi file tempo, however, today I installed the CLI tool with pip and I liked it because it's a lot faster, but I couldn't find a way to change the midi tempo, it would be nice if it had a parameter like
basic-pitch <output> <input> --midi-tempo 75
for instance. Currently, it always exports the file at 120 bpm so I need to manually stretch the notes in the DAW to fit the desired tempo.The text was updated successfully, but these errors were encountered: