Posts: 6
Threads: 2
Joined: Sep 2020
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
1 2 3 4 5 6 7 |
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
Posts: 12,026
Threads: 485
Joined: Sep 2016
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'.
Posts: 6
Threads: 2
Joined: Sep 2020
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
Posts: 1,358
Threads: 2
Joined: May 2019
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?
Posts: 12,026
Threads: 485
Joined: Sep 2016
looks like: mido.set_tempo(tempo=468750 time=0)
or something close to that
Posts: 6
Threads: 2
Joined: Sep 2020
(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) ...
1 |
mido.set_tempo(tempo = 250000 time = 0
|
send an invalid syntax
Posts: 12,026
Threads: 485
Joined: Sep 2016
you're missing a closing parenthesis
I also stated 'or something close to that'
please read the docs
Posts: 6
Threads: 2
Joined: Sep 2020
(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 ...
Posts: 12,026
Threads: 485
Joined: Sep 2016
Sep-06-2020, 06:54 PM
(This post was last modified: Sep-07-2020, 12:30 AM by Larz60+.)
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
Posts: 1,358
Threads: 2
Joined: May 2019
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.
|