Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MIDI FILES TEMPO - MIDO
#1
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
Reply
#2
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'.
Reply
#3
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
Reply
#4
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?
Reply
#5
looks like: mido.set_tempo(tempo=468750 time=0)
or something close to that
Reply
#6
(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
Reply
#7
you're missing a closing parenthesis
I also stated 'or something close to that'
please read the docs
Reply
#8
(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 ...
Reply
#9
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
Reply
#10
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to execute tempo changes in Mido? NickShredScott 0 448 Nov-28-2023, 05:16 AM
Last Post: NickShredScott
  Adding MIDI Channels to each Input zach1234 6 1,194 Apr-20-2023, 11:51 AM
Last Post: jefsummers
  How to bind a midi signal to tkinter? philipbergwerf 1 1,598 Feb-09-2022, 05:17 PM
Last Post: Gribouillis
  mido MIDI-file; how to distinguis tracks? philipbergwerf 2 2,251 Dec-10-2021, 05:06 PM
Last Post: philipbergwerf
  How to open MIDI-file and get events in a list? philipbergwerf 7 4,959 May-29-2021, 08:24 AM
Last Post: j.crater
  Mido and virtual midi ports dore_m 2 4,590 Dec-27-2020, 06:02 AM
Last Post: dore_m
  Real time MIDI with python eythoralex 1 3,447 May-19-2020, 07:17 PM
Last Post: Larz60+
  Please help! Akai APC20 midi controller script versusliveact 0 2,125 Feb-14-2020, 05:37 AM
Last Post: versusliveact
  Using MIDI from Python on Windows 7 PythonAndMIDIUser 3 3,439 Jun-16-2018, 06:20 AM
Last Post: buran
  MIDI Inputs NightPython42 3 44,172 Aug-10-2017, 02:37 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020