Mido is a Python library for working with MIDI messages and ports. It’s designed to be as straight forward and Pythonic as possible
Questions tagged [mido]
54 questions
7
votes
1 answer
How to create a nested dictionary from existing dictionary with set and list of tuples
I have parsed a midi file, and I've successfully gotten a dictionary of notes broken up by instrument. An abbreviated example of this is note_dict below, truncated for the purposes of this question.
My end goal is to have a nested dictionary that…

Tim
- 71
- 3
6
votes
1 answer
How can I integrate Python mido and asyncio?
I have a device which does file I/O over MIDI. I have a script using Mido that downloads files but it is a mess of global variables. I want to tidy it up to use asyncio properly but I am not sure how to integrate the mido callback. I think the…

Mark Green
- 1,310
- 12
- 19
4
votes
2 answers
python mido how to get [note, starttime, stoptime, track] in a list?
I need help in the following: I am designing a new music notation. I want to read a midi file and get a list that contains every note/start-stop-time/track. Desired result:
[[60, 0, 0.25, 1], [62, 0.25, 0.50, 1]]# the format is [note, start-time,…

Philip Bergwerf
- 67
- 1
- 5
3
votes
1 answer
Mido - How to get midi data in realtime from different ports
I have created 2 ports as input, to capture data from a keyboard and a midi surface controller (which has a bunch of sliders and knobs). Although I am not sure how to get data from both
for msg1 in input_hw:
if not msg1.type == "clock":
…
user9990443
3
votes
1 answer
How to set ticks_per_beat under MIDO to a new MIDI file?
Reading ticks_per_beat under MIDO can be done via mid.ticks_per_beat. However, if I want to save the value of ticks_per_beat (e.g., 120 or 480) to a new MIDI file, how it can be done? (p.s. I can set "time signature" or "tempo" as follows. But, it…

Frank
- 172
- 2
- 11
3
votes
1 answer
Convert time/tick in Python MIDI MIDO read/save file
The following program uses MIDO to read 'g1.mid' then save it to 'g1_new.mid'. My question is that: in reading the file, 'msg.time' is a float value, but in saving the file, 'time in Message' is an integer in tick. How do we convert 'msg.time' to…

Frank
- 172
- 2
- 11
3
votes
1 answer
Outputting MIDI sound from Python Mido library on Mac
I'm trying to output a note to my computers internal speakers using python with the mido library. I have a mac, and I've learned that by default you need to go through the IAC Driver to output any sound to the speakers. I enable the IAC Driver and…

Eric S
- 1,001
- 10
- 14
3
votes
1 answer
"PortMidi: `Bad pointer'" when closing mido port
My code:
import mido
import time
mido.set_backend('mido.backends.pygame')
output = mido.open_output()
output.send(mido.Message('note_on', note=64, velocity=60))
time.sleep(3)
output.close()
After the last line, the following error is…

Aviv Cohn
- 15,543
- 25
- 68
- 131
2
votes
0 answers
Extracting actual note starting time from midi files
I am trying to make a midi file parser that outputs something of shape [Songs, track_data], where each track_data contains it's song name and track's beats. Each beat contaings it's notes [semitone, octave] and the temporal distance in milliseconds…

Maxim Mashkov
- 61
- 1
- 3
2
votes
1 answer
Problem with MultiPort use in python mido MIDI package
I am working in a program that autosaves MIDI messages as they are played, and everything is working really well when using a single input port.
I want to extend to use 2 or 3 simultaneous ports (the app is aimed at VST piano players, and some use…

autosave midi
- 23
- 2
2
votes
0 answers
Python: How to label .midi file using MIDO library
I have these .midi files and I want to label them with pitch (in MIDI numbers) per 0.032 second. Example of the label I desired can be found here. In this task, I use Python mido library, the docs can be found here.
From what I know now, I need to…

Dionisius Pratama
- 464
- 3
- 13
2
votes
1 answer
Why is ticks per beat a big number and time very small?
My midifile looks like this:
note_on channel=0 note=75 velocity=62 time=0
note_off channel=0 note=75 velocity=0 time=0.20833324999999997
note_on channel=0 note=76 velocity=62 time=0
note_off channel=0 note=76 velocity=0…

Philip Bergwerf
- 67
- 1
- 5
2
votes
1 answer
Music21: get track index of a note
I have a multi-track midi file that I'm reading with music21:
import music21
f = music21.midi.MidiFile()
f.open('1079-02.mid')
f.read()
stream = music21.midi.translate.midiFileToStream(f).flat
note_filter =…

duhaime
- 25,611
- 17
- 169
- 224
2
votes
1 answer
Popping Messages from MIDI Tracks
I have type 0 MIDI file, containing the track with only 269 meta-messages that I'd like to keep the header chunk and the last one for the end of the file.
for i, msg in enumerate(mid.tracks[0]):
if i > 10 or i < len(mid.tracks[0])-1:
if…

chikitin
- 762
- 6
- 28
2
votes
1 answer
Question with python, music and events, is there a more elegant way of programming this?
Goal: To create a program that will be able to turn off and on lights to music based on events that are triggered from midi notes.
Hello all, I am hoping that this isn't too broad of a question to ask. I am working on a project where I get events…

nmendez
- 33
- 4