Skip to content

Conversation

@steve-mackinnon
Copy link

@steve-mackinnon steve-mackinnon commented Jan 14, 2026

This adds a new CurrentTime struct containing the time in samples, beats, bpm, and time signature. The change is purely additive and does not update existing nodes leverage this time data yet. The wasm implementation has been updated to expose setters for bpm, time in beats, and time signature. It updates the beat time in each process() call.

Native clients could leverage this to pass down timing information from a host DAW/application to drive the graph.

Copy link
Contributor

@nick-thompson nick-thompson left a comment

Choose a reason for hiding this comment

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

Excellent thank you! One thought inline

wasm/Main.cpp Outdated
}
}

auto const beatTime = sampleTimeToBeatTime(sampleTime, bpm, sampleRate);
Copy link
Contributor

Choose a reason for hiding this comment

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

My only thought is here: should we hold separate state for beatTime and sampleTime? My thought is that if bpm is strictly constant, then this mapping from sampleTime<>beatTime holds as expected. But if the tempo ever changes, this calculation will cause a (potentially large) jump in beat time that isn't quite accurate– like a tempo change at the start of bar 5 should still report the beatTime as start of bar 5 right?

So maybe at the bottom of this process call we have like

sampleTime += numSamples;
beatTime += sampleTimeToBeatTime(numSamples, bpm, sampleRate);

Then the question becomes, what do we do in setCurrentTime in the ms or beattime case.... I guess at that point its' probably fine to just snap both values according to the current bpm.

Copy link
Author

Choose a reason for hiding this comment

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

@nick-thompson yes you're right! I just pushed this change.

For reference, Ableton Live maintains beat position, but snaps the sample position according to the new BPM when tempo changes. I think it seems intuitive to use that behavior here as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect! Thank you, let's roll

@nick-thompson nick-thompson merged commit 2c6e643 into elemaudio:develop Jan 16, 2026
4 checks passed
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