Environment, Event & syntax


I’m trying to write something like swingify for Rests ie:

So at the end of the Prout I’ve got:

if( thisShouldRest,
	{ ev.amp = Rest() }
ev = ev.yield;

Firstly, if I just left it like this would the original amp persist?
If not would any of the following be correct / necessary in order to yield the original amp:

if( thisShouldRest,
	{ ev.amp = Rest() },
	{ ev.amp = ev.use{ev.amp} }


if( thisShouldRest,
	{ ev.amp = Rest() },
	{ ev.amp = ev.use{~amp.value} }

or even

if( thisShouldRest,
	{ ev.amp = Rest() },
	{ ev.amp }


You didn’t change anything about ev, so of course \amp does not change - both of the cases where you reset \amp are redundant, there’s no need to do this. FWIW, you only need use if you want to refer to keys in ev using the ~environmentVariable syntax, or if for some reason a function in your ev expects it to be the current environment. The latter is often the case, so it’s sort of safer to do this but not required.

Thanks for clarifying.
Sometimes when a project grows my head gets tied in knots.

I’m getting closer, but it only seems to work when I trace the pattern?
May as well post the full Prout, it’s part of a larger chain…
Any glaring errors here:

Prout({ |ev|
	var now, nextTime=0, range,
	thisShouldRest, cycleTime, restProb;
	while { ev.notNil } {
		now = nextTime;
		nextTime = now + ev.delta;
		range = 4;
		cycleTime = Array.fill(16, { |i| 1/4*i });
		restProb = (q.arraySize16)[ cycleTime.indexIn(now%range) ].value;
				restProb.coin.not || ev.isRest ||
				( ev.freq < q.nodeProxy1.bus.getSynchronous ) ||
				( ev.freq > q.nodeProxy2.bus.getSynchronous ) ||
				( ev.amp < q.nodeProxy3.bus.getSynchronous ) ||
				( ev.amp > q.nodeProxy4.bus.getSynchronous ) ||
				( ev.sustain < q.nodeProxy5.bus.getSynchronous ) ||
				( ev.sustain > q.nodeProxy6.bus.getSynchronous ) ||
				( q.nodeProxy7.bus.getSynchronous ).clip(0,1).coin
			{ thisShouldRest = true },
			{ thisShouldRest = false }
		if( thisShouldRest,
			{ ev.amp = Rest() },
			{ ev.amp = ev.use{~amp.value} }
		ev = ev.yield;

Something to do with using q and ev together?
I thought q was a dictionary, but just checked & it’s an event.
(I vaguely remember a thread on the list about this years ago)

I’m missing some context here (e.g. I don’t see where q[\arraySize16] gets set), but at a glance I don’t see anything wrong with it. A few observations:

  1. You almost for sure don’t need to do ev.amp = ev.use{~amp.value} - depending on how you’re using this Prout, it can even break certain usages.
  2. Event is a Dictionary, or a subclass of it. The functional difference is that (a) it’s generally intended to use \symbols as keys, and (b) it has a lot of extra functionality to allow it to be used for musical events (e.g. default values and behaviors).

What do you mean when you say it “only seems to work when you trace”?

This is just part of a larger pattern - too big to show it all,
so thought I would just try to give some extra context.

If I uncomment .trace at the end of the Prout it works fine
(I’m doing .trace(\amp) now to reduce the volume of data in the post window,
so I can live with it…),
but if it is commented out the Prout has no effect?
Something similar happened once before in a different project -
so thought it might be something I was doing wrong / bug,
the use of q ( ie. q=q?() ) in a pattern was just a guess.

Can’t find a simplest case to demonstrate but wondered if it might be
something people had seen before…

Suppose the question is whether .trace returns something other than just the event when it posts?

It’s of course possible that there’s a bug in here. But, .trace just wraps the pattern in a Ptrace, which only prints out values but does not change the pattern or the returned events at all - so this should have no effect on the behavior of the pattern (other than the printing).

I don’t know what this means – “has no effect”?

There’s not really a way to investigate further because the code example can’t be run: if I do q = (); p = Prout { ... your code ... }; z = p.asStream and then z.next(Event.new), it produces an error binary operator '+' failed. (.trace does not improve that situation.)


I don’t know what this means – “has no effect”?

It’s as if the code isn’t there, the pattern still plays but the nodeProxies
(with simple synthDefs as source & controlled by sliders)
have no effect on the output.

Now I think on, the previous time I was thinking of
was actually needing to .poll the \freq argument
in the BlitB3 Ugens - so may / may not be related…

I can’t work a simple example to recreate the problem
(I just put a snippet of my code up to see if there were any glaring errors)…

Apologies I can’t be more specific, but thanks for having a look
and clarifying a few things along the way.
There seem to be endless possibilities modifying ~swingify…
If I run into it again I’ll post it.