sequence:setTempo() - no relation to real world bpm and only works with whole numbers

I am working on this project here:
Cat Keys

I wanted to integrate the option to set the tempo and I am realising that - either I am missing something - or the playdate.sound.sequence:setTempo(stepsPerSecond) is not working as intended.

setTempo() can only be whole numbers, which is a problem if I want 80 bpm, in my head that would be 1.3333 stepsPerSecond, but that returns tempo 1, which is not what I want and also sounds nothing like 80 bpm when I run the sequence.

I thought it might just be my terrible coding, so I looked for the file examples and found the drum machine - which looks like this:

function setBPM(bpm)
	local stepsPerBeat = 4
	local beatsPerSecond = bpm / 60
	local stepsPerSecond = stepsPerBeat * beatsPerSecond
	sequence:setTempo(stepsPerSecond)
end

setBPM(120)

This works with ex. 120 bpm (which is the default setting in the example - returns tempo 8) also 60 and 75 bpm works because that returns 4 and 5 as tempo, but ex 80 bpm returns tempo 5, which is actually 75 bpm

On top of that I am also not getting how 120 bpm is 8 steps pr second. In my head that would make a bpm of 480 as in: 8 steps*60 seconds = 480 steps pr minut.

Even besides me not understanding how this steps pr second works I cannot get it to play in 80 bpm in the real world (playing it along my other synths).

What am I missing here?

2 Likes

This is all a result of me implementing sequences for .mid file playback and not thinking about how it would be used outside of that context. :confused: A couple of related issues:

I've got a fix in the queue that changes the tempo to a floating-point number. In the mean time you can increase the tempo resolution by using more steps per beat (.mid files usually have 480 steps per quarter note, e.g.) and scaling up your tempo to match: To get 80 beats per minute at 480 steps per beat (and 1/60 minute per second) you'd use a tempo of 80*480/60 = 640.

2 Likes

Hi Dave!
Thanks for the reply and explaination, that makes sense.
I was actually thinking of fixing it exactly like you suggest - well I guess I just gotta start multiplying :smiley:

Also while I got you on the line, thanks for the awesome job on the playdate - I have been having endless fun with this thing, I never knew coding before I got started with the playdate but I feel like I learned so much, so a mega big thank you from me to all you playdate developers!

1 Like

I finally got a fix in for this, scheduled it for 2.1.0. Sorry for the delay!

1 Like

Hi Dave, that is Awesome!
In the meantime I managed to fix it by multiplication, it took some long evenings to get it working because my setup just wasn't made for it, but eventually I managed. Maybe now I can rewrite it and avoid some of all the strange hoops I had to jump through.

1 Like