Python Forum

Full Version: MIDI FILES TEMPO - MIDO
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, i try to code a simple midi file looper with mido library on raspberry pi.

Here the simple code that play the loop 4 times

outport = mido.open_output('MIDISPORT 2x2 Anniv:MIDISPORT 2x2 Anniv MIDI 1 24:0')
mid = mido.MidiFile('/home/pi/Documents/it.mid')
i = 0
while i < 4:
    for msg in mid.play():
        outport.send(msg)
        i = i +1
My problem is :
How can I change tempo real time while playing the file ?
I can't find any help on this

thx a lot
This blog shows how to create an event: https://openbookproject.net/thinkcs/pyth...vents.html
you could do this to bring up a routine to modify tempo while music continues playing:
this blog on midi with python and mido: https://www.twilio.com/blog/working-with...using-mido

The idea is to bring up a window without interrupting the music playback, and that's where 'events' come in.

Not specifically for PI, but with a bit om modification should work, if not exactly 'right out of the box'.
Ok but what's the command to change tempo , i d'ont find it in the mido doc. they speak of a set_tempo but its a meta message in the begining of the midi files, this will not change the speed in real time during playing
That command can be embedded at any point in the midi file - edit the file with a midi file editor and you can put the command in.

However, I suspect you want to change the tempo "on the fly", so you want to send a tempo change to the player while playing, not do pre-programmed. Correct?
looks like: mido.set_tempo(tempo=468750 time=0)
or something close to that
(Sep-05-2020, 03:22 PM)jefsummers Wrote: [ -> ]I suspect you want to change the tempo "on the fly", so you want to send a tempo change to the player while playing, not do pre-programmed. Correct?

Yes that's exact, I'd like to change tempo on the fly (so not in the midi file) ...
mido.set_tempo(tempo=250000 time=0
send an invalid syntax
you're missing a closing parenthesis
I also stated 'or something close to that'
please read the docs
(Sep-06-2020, 03:45 PM)Larz60+ Wrote: [ -> ]you're missing a closing parenthesis
I also stated 'or something close to that'
please read the docs

Thx, the missing parenthesis change nothing to this ... (this parenthesis was in my code when i launch it). I already read the doc many times ... If I found the answer in it , I would not ask here ...
Quote: I already read the doc many times ... If I found the answer in it , I would not ask here ...
Sorry, had to ask, many don't read the documentation, so it becomes standard procedure to ask
The challenge, as I see it, is the target. Most info in a midi file is note information - note on, note off, etc. The tempo command is not sent out over midi, rather it is an instruction to the player. I see that rtMidi is the back end for Mido, but looking there I don't see an easy tempo change either. So, how do you change the tempo in the player that is playing the midi file? Sorry, don't have an answer at this point, but I think this rephrases the question and maybe someone better than me can figure it out.