Conditional Boolean = False when Routine Ends

Hi,

When a Routine has finished I would like it to send a false message. I want to control the flow of a composition. When a Routine ends a new one begins.

Maybe I am approaching this from the wrong angle? Advice welcome

`

if(~oldRoutine = false, ~newRoutine.play)

`

Maybe it would be easier to wrap your routines in another routine?

Yeah, after thinking on it… I could just add a ~newRoutine.play at the end of the ~oldRoutine.

The related class Task can do this another way (using changed / update notifications).

(
~r1 = Task {
	10.do {
		"abcde".scramble.postln;
		0.5.wait;
	};
};

~r2 = Task {
	10.do {
		"vwxyz".scramble.postln;
		0.5.wait;
	};
};

~watcher = SimpleController(~r1)
.put(\stopped, { |... args|
	~watcher.remove;
	args.debug("got stopped notification");
	~r2.play;
});

~r1.play;
)

(Routine doesn’t support this directly, though.)

This is useful, for instance, if you have a user interface displaying the status of running tasks/routines. If the task runs out of things to do and stops on its own, this is a way for the task to communicate to any interested objects that it has stopped.

(
~r1 = Task {
	10.do {
		"abcde".scramble.postln;
		0.5.wait;
	};
};

~watcher = SimpleController(~r1)
.put(\playing, { |... args|
	defer { ~status.value = 1 };
})
.put(\stopped, { |... args|
	defer { ~status.value = 0 };
});

~status = Button(nil, Rect(800, 200, 100, 30))
.states_([["off"], ["ON", Color.black, Color(0.7, 1, 0.7)]])
.onClose_({ ~watcher.remove })  // important! clean up garbage
.front;

~r1.play;
)

~r1.reset.play;

~watcher.remove;  // remember to do this later

hjh

2 Likes

Thank you, that ~watcher code looks like a great tool for helping me build and explore structure