Is it possible to change envelope segment values on-the-fly?

13 views
Skip to first unread message

Devin Smith

unread,
Jun 18, 2025, 8:10:29 PMJun 18
to beadsproject
I've done a lot of work in processing, but just getting started with Beads.

I'm curious about best-practices for changing envelope segments on-the-fly.
  • Quick clarification Q: In the javadocs, the Envelope class' methods don't seem to have any function for directly setting the Envelope's duration position, am I understanding this correctly?
  • Is there a way to directly alter segment value and duration while (e.g.) a wavePlayer is currently running?
  • Or is the preferred method to use clearSegments() and re-initialize (with the constructor that includes the third "current value" param)?
  • If instead, the clearSegments() function is used, followed by addSegments(), will the envelope's current duration position remain static or reinitialize? E.g., if the envelope started and is at duration "500", then you clear and add other segments, will the envelope continue playing as it was at duration "500" in the new segments?
Thanks!
Devin

Oliver Bown

unread,
Jun 18, 2025, 8:18:24 PMJun 18
to beadsp...@googlegroups.com
Hi Devin,

You might have the wrong mental model of what the Envelope is doing. I’m not sure what you mean by “duration position”. The way Envelope works is, it has a running queue of segments, and a current value. The clear() function clears the queue (leaving the Envelope value to be whatever it is at the exact moment the queue is cleared, even if it is mid-segment). The setValue() function directly sets the value. All successive addSegment() functions add a new segment to the end of the queue. The envelope works through the segments in succession until the queue is cleared. So for example:

e.clear();
e.setValue(0f);
e.addSegment(1f, 100f);
e.addSegment(0.5f, 100f);
e.addSegment(0.5f, 1000f);
e.addSegment(0, 1000f);

This will take 2,200ms to execute. 

Ollie

--
You received this message because you are subscribed to the Google Groups "beadsproject" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beadsproject...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/beadsproject/984cfa5f-4aa2-49fe-a4f8-6016485b94bdn%40googlegroups.com.

Devin Smith

unread,
Jun 18, 2025, 8:32:47 PMJun 18
to beadsp...@googlegroups.com
Thanks for the quick reply!

To be a little more specific in my question, using your example:

e.clear();
e.setValue(0f);
[0] e.addSegment(1f, 100f);
[1] e.addSegment(0.5f, 100f);
[2] e.addSegment(0.5f, 1000f);
[3] e.addSegment(0, 1000f);

Let's say the envelope has started, and we're currently at 150ms duration, in the middle of segment [1], with the value of 0.75f (halfway between 1f and 0.5f).

Now let's say I decide I want the segment [2] to be (0.3f, 800f) instead of (0.5f, 1000f). What is the preferred way to do this?

Should I (e.g.) do some math to figure out which segment I'm currently in, then pop() all subsequent segments and add new ones?

Or should I getCurrentVlaue(), clear all the segments, and do some math to figure out what the remainder of the segment I'm currently in is (in this case, 50ms) and to the empty envelope do:

e.addSegment(getCurrentValue(), 50f)
e.addSegment(0.3f, 800f)
e.addSegment(0, 1000f);

Or is there a way to directly alter segment [2]'s value and duration?

Thanks!
Devin



You received this message because you are subscribed to a topic in the Google Groups "beadsproject" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beadsproject/Z0ZgwWsOrMc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beadsproject...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/beadsproject/23EC564A-E6F2-4D52-8D25-3F092308599E%40icarus.nu.


--

Devin

Oliver Bown

unread,
Jun 18, 2025, 8:39:12 PMJun 18
to beadsp...@googlegroups.com
Yeah, so we’re somewhere on the way through segment [1] and you are about to do something. Segment [1] has yet to finish and there are future segments waiting to execute.

Sure you can go ahead and clear(), then do whatever you need to do to calculate the new segment queue.

Now, it’s been, hmmm, 15 years since I wrote these functions, and I’d like to think I was forward thinking enough to put something in there that lets you grab the queue of segments and do something with them. But TBH I have no memory of this, and I don’t even write code any more, and your guess is as good as mine :-) Check if the API has something like “getSegments()” returning an array list.

Best of luck!

Ollie

Reply all
Reply to author
Forward
0 new messages