Skip to content

Add synthio.MidiTrack.tempo property #10567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2025
Merged

Conversation

relic-se
Copy link

This update allows the tempo of a synthio.MidiTrack object to be manipulated after it has been constructed.

In my use case, I wanted to gradually increase the speed of a song within a game as it progresses.

Here is a demonstration of this property written for the Fruit Jam:

import audiobusio
import audiomixer
import board
import synthio
import time

import adafruit_tlv320

# configure dac
i2c = board.I2C()
dac = adafruit_tlv320.TLV320DAC3100(i2c)
dac.configure_clocks(sample_rate=44100, bit_depth=16)

# use headphones
dac.headphone_output = True
dac.headphone_volume = -15  # dB

# setup audio output
audio = audiobusio.I2SOut(board.I2S_BCLK, board.I2S_WS, board.I2S_DIN)

# load melody
melody = synthio.MidiTrack(b"\0\x90H\0*\x80H\0\6\x90J\0*\x80J\0\6\x90L\0*\x80L\0\6\x90J\0" +
                           b"*\x80J\0\6\x90H\0*\x80H\0\6\x90J\0*\x80J\0\6\x90L\0T\x80L\0" +
                           b"\x0c\x90H\0T\x80H\0\x0c\x90H\0T\x80H\0",
                           tempo=640, sample_rate=dac.sample_rate)
audio.play(melody, loop=True)

# increase tempo by 2% every second
while True:
    time.sleep(1)
    melody.tempo = int(melody.tempo * 1.02)

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks!

@tannewt tannewt merged commit 712550c into adafruit:main Aug 12, 2025
486 checks passed
@relic-se relic-se deleted the miditrack-tempo branch August 12, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants