Skip to content
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

Loop.restart (or is there a way of doing this now?) #1304

Open
adrianhardy opened this issue Jan 5, 2025 · 5 comments
Open

Loop.restart (or is there a way of doing this now?) #1304

adrianhardy opened this issue Jan 5, 2025 · 5 comments

Comments

@adrianhardy
Copy link

I can't decide if this would be a new feature, or I just haven't found the right combination of tools.

The feature you'd like

Loop.restart

I have very specific use case. getTransport.start() triggers a Player with audio that loops. The BPM at this stage is unknown and, even when we do know it, it shouldn't be used to control the looping of the audio. The player starts and it uses the built-in loop: true. The player loops every "audio duration" - this is fine.

I'd like to audition a Loop (which will have a BPM) with that sample, so when the sample starts playing at position zero, the Loop should start. However, the when the sample ends (or as it starts) the Loop should restart - clear and reschedule all events, regardless of where it's up to in progress.

Any alternatives you've considered
Unfortunately, it doesn't seem like calling loop.stop() and then loop.start(); works. Even if you try to force a clearing of the future events (using cancel and -Infinity), then the start doesn't seem to reschedule the events from Transport Time Zero. I have thought that this is because of the fact that stop schedules the status to become stopped and at the point start(); is called, the status isn't (yet) stopped.... but at this point I got in knots trying to understand transport time and events.

Let me know if that's the correct path to go down. Or, if the answer is to make my own Loop class, that's fine, but I didn't want to do that if there's a better solution.

I hope this makes sense.

@dirkk0
Copy link

dirkk0 commented Jan 5, 2025

It's totally possible that I completely misunderstood what you are trying to acchieve. If so, I am sorry!
But - if you take this example:
https://codepen.io/dirkk0/pen/NWNBPBB
and change the BPM in line 27 to something else as 120, you can hear the overall sequence is looping, but each sample is playing independently. Meaning, if you choose a BPM greater than 120, the samples overlap, and beyond that there will be gaps. This way, the sequence is looping and triggering the samples.

@adrianhardy
Copy link
Author

adrianhardy commented Jan 5, 2025

Hi.

There might be something in your suggestion - I may need to think about the approach. However, just in case it helps - I have a screenshot:

image

This is an example of a sample where the shaded region represents where it will loop. The thin black line is the playhead (where we are now in the sample). Rather than me trying to find the BPM and loop based on that, it's more about the sample length. Once I've got a sample that loops perfectly, I then want to try and audition a simple beat based on the BPM information I've extracted.

I don't know if you're familiar, but the workflow is like a cross between an MPC and TrackLib's website. I've never found a sampling workflow where I've been able to feel like I'm working quickly, so as soon as I found tone.js I decided to give it a go.

So, the workflow would be:

  • Find a portion of a song
  • Find a decent set of loop points
  • Tweak those loop points
  • See what works (i.e. loop 1, loop 3, loop 1, loop 4)
  • Audition a beat underneath.

I'm at the final step and, because the number of beats/bars is unknown, the beat (Loop instance) would need to be cut short and restarted as the "playhead" of the sample comes to the end.

If the beat were a sample, this would be simple and it might be the direction I go in for now. But I really like the idea of the Beat being a proper sequenced instrument that I can tweak and then either "bookmark" the idea or throw it away.

@padesso
Copy link

padesso commented Jan 5, 2025

I'm new to tone.js so I may be off course. Have you tried creating a second transport for your extracted loop (possibly syncing it to the default transport) and looping the newly created transport?

@adrianhardy
Copy link
Author

I'm new to tone.js so I may be off course. Have you tried creating a second transport for your extracted loop (possibly syncing it to the default transport) and looping the newly created transport?

Assuming there's no architectural reason, then yes, two transports would work. One would be "BPM-less" and the transport would be simply about starting the main sample loop, but the other could have a BPM and that would be adjusted by the user.

@dirkk0
Copy link

dirkk0 commented Jan 5, 2025

If you have a portion of the sample then you would know the start (0) and the end (L) either in seconds or in samples. From that you would be able to calculate the resulting BPM. If the dark region happens to be 0.5s then the BPM would be 120. If the sample length is L in seconds then the BPM = 60/L. (again: I might be totally off)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants