Pattern share and flip pattern?

I tried pattern share program.
But dose not work.

1
just copy pattern , but pattern A and B different.

//same ~pA
~pB = ~pA.collect{ arg value; value; } ;

2
if i could copy A pattern to B , next i want to flip A pattern in B.
Is there mistake?

//flip ~pA
~pB = ~pA.collect{ arg value; if( value.isRest ){ value=1; }{ value=Rest(value) } } ;

//setting
(
//kick1
(
SynthDef(\tes, {
    arg freq=400;
    var snd , env;

	env = EnvGen.ar(  Env([ 1, 0], [ 1/4 ]) , doneAction:2);
	snd = SinOsc.ar( freq  );

	snd = Pan2.ar(snd, 0, 0.5);
    Out.ar(0,  snd);
}).add;
);

//Synth(  \tes , [freq:400]  );
//Synth(  \tes , [freq:4400]  );

////////////////////////

~pA = Pxrand( [  1,1, Rest(1) , 1   ]  ,inf    );

//same ~pA
//~pB = ~pA.collect{ arg value;  value; } ;
//flip ~pA
~pB = ~pA.collect{ arg value;  if( value.isRest ){ value=1; }{ value=Rest(value)  }  } ;

(
Pbindef(\pdef_A,
	     \instrument, "tes",
	     \freq, 440 ,
	     \dur,  ~pA,
	      \check , Pfunc(  {arg e; [ "\n A" , e.dur].postln;   }  );
);
);

(
Pbindef(\pdef_B,
	     \instrument, "tes",
	     \freq, 4400 ,
	     \dur,  ~pB,
	     \check , Pfunc(  {arg e; [ "B" , e.dur].postln;   }  );
);
);
)


//play
(
Pdef(\pdef_A).play.quant_([0,0]);
Pdef(\pdef_B).play.quant_([0,0]);
)

//stop
(
Pdef(\pdef_A).stop;
Pdef(\pdef_B).stop;
)

In general, when troubleshooting, “doesn’t work” is short for “I expected it to do one thing, and it did something else instead.”

So, what is interesting for troubleshooting isn’t the fact that it didn’t work – the interesting things are a/ what did you expect to do? and b/ what did it do?

Could you clarify those?

I guess it’s that pA and pB are returning a different series of events. This is inherent to the way patterns work. A pattern isn’t a stream of values. It’s a template for producing a stream of values.

So, the pattern doesn’t produce the values. A Stream object, made from the pattern, produces them. http://doc.sccode.org/Tutorials/A-Practical-Guide/PG_01_Introduction.html#Patterns%20versus%20Streams

One pattern can be the source for multiple streams, and all of those streams evaluate independently.

So pA and pB are both based on the same Pxrand object, but they produce separate streams, and the two streams produce different random sequences.

See http://doc.sccode.org/Tutorials/A-Practical-Guide/PG_06g_Data_Sharing.html for more ideas about how to handle this case.

hjh

Oh, and there’s also Pseed, which will make a random pattern produce the same values for every stream.

hjh

Oh , sorry short trouble shooting explanation.

1st step.
I tried make pattern A and copy A pattern to B.
But pattern A and B were different.

And now i got how pattern makes stream , good reference.

Below 2pattern be same value.

~pA = Pseed( 1,  Pxrand( [  1,1, Rest(1) , 1   ]  ,inf    ) );

//same ~pA
~pB=~pA;

2nd step
I tried make pattern B flip pattern A.
( When pattern A ringing ,pattern B rest and oposite )

~pA = Pseed( 1,  Pxrand( [  1/2,  1/4, Rest(1/2) , Rest(1/4)   ]  ,inf    ) );

//flip ~pA
~pB = ~pA.collect{ arg value;  if( value.isRest ){  value.value ; }{ Rest(value)  }  } ;