import mido

# Load MIDI file
midi_file = mido.MidiFile("example.mid")

# Set default tempo and note duration
tempo = 500000
note_duration = 100

# Iterate over all messages in the MIDI file
for message in midi_file.play():

    # Update tempo if tempo change message is found
    if message.type == "set_tempo":
        tempo = message.tempo

    # Play note if note on message is found
    elif message.type == "note_on":
        frequency = int(2 ** ((message.note - 69) / 12) * 440)
        duration = int(note_duration * message.time / tempo * 1000)
        print(f"Playing note {message.note} (frequency={frequency}, duration={duration}ms)")