I have a Routine in which way can I put it in a Function

Dear love Community,
I have multiple Routines with the same name.
I will choose one of them and load that Routine.
New I will call this Routine Multiple Times in a Function.
So I hope I can multiplay this Routine.
Is there any way to do that.

In hope of Answers
ComputerArtists_ThL

Routines should not be played multiple times simultaneously.

If you take one routine and play it multiple times, the multiple plays will not behave independently – rather, they will be interleaved in time order.

r = Routine {
	var i = 0;
	loop {
		[i, thisThread.beats].postln;
		i = i + 1;
		1.0.wait;
	}
};

r.play(quant: 1);  // play once
... snip...
[4, 2103.0]
[5, 2104.0]
[6, 2105.0]
[7, 2106.0]

r.play(quant: [1, 0.25]);
[8, 2107.0]
[9, 2107.25]   -- note: this is NOT index 0!
[10, 2108.0]
[11, 2108.25]
[12, 2109.0]

r.stop;

I’m pretty sure this behavior is not what you want.

You can get independent routines by creating multiple Routine instances.

(
f = {
	var i = 0;
	loop {
		[i, thisThread.beats].postln;
		i = i + 1;
		1.0.wait;
	}
};
)

r = Routine(f).play(quant: 1);  // play once
[0, 2254.0]
[1, 2255.0]
[2, 2256.0]
[3, 2257.0]

t = Routine(f).play(quant: [1, 0.25]);
[0, 2257.25]  -- now they are independent
[4, 2258.0]
[1, 2258.25]
[5, 2259.0]
[2, 2259.25]

r.stop;
t.stop;

My opinion is that Routines are meant to be created when needed, and thrown away easily. Sometimes we’re tempted to try to preserve a routine for reuse, out of some sense that it’s more economical or something. That’s often a mistake. Use the objects according to the desired behavior.

hjh

Yes I understand,
but the Problem is that in my situatin i have written lots of simple Routines to Play musical motives - and now the user schould do it simple to play such motives in parallel - even diferent motives / routines - or the same motive / routine - in parallel gives it there a simpler way then wrap eacxh of this routines in a seperate function

IMO a Routine is too low-level an object for what you’re describing.

You might consider Prout instead – a pattern that is structured like a routine.

In the pattern library, there is a distinction between a pattern object (which defines the behavior that you want, but doesn’t execute it) and a stream object (which executes the behavior). When you play a pattern, it manufactures a stream based on the pattern template. This can be done multiple times, and every stream will be independent from the others, even if generated from the same pattern. (Patterns are “stateless.”)

If I edit my original bad-behavior demo to use Prout instead, then you do get the independent, parallel behavior.

p = Prout {
	var i = 0;
	loop {
		[i, thisThread.beats].postln;
		i = i + 1;
		1.0.wait;
	}
};

x = p.play(quant: 1);  // note: "an EventStreamPlayer"
[0, 618.0]
[1, 619.0]
[2, 620.0]

y = p.play(quant: [1, 0.25]);
[3, 621.0]
[0, 621.25]  -- yes! an independent counter
[4, 622.0]
[1, 622.25]
[5, 623.0]
[2, 623.25]

// note that you stop the *players*, not the pattern
// there are two players, why would `p.stop` single out only one of them?
x.stop; y.stop;

So this way, you could make a library of Prout objects, and every time you play one of them, you would get an independent, parallel player.

Again, Routine itself is the wrong object for what you want to do.

hjh

1 Like