PseqFunc : Pseq

PseqFunc executes a function on each list item before embedding the item in the stream. This is different from Pattern:collect, which executes the function on the values yielded by the stream.

This is useful for manipulating SequenceNote objects prior to embedding in the stream. SequenceNotes may be compound; thus manipulations after .yield can be incorrect.

*new(list, repeats, offset, func)

The arguments are the same as Pseq, with the addition of func, which is the function to execute.

Example:

// create a sequence with compound notes -- parsing turns 0.03 durations into grace notes

x = MIDIRecBuf(\pseqfunc, [

#[60, 63, 60, 65, 66, 65, 62, 63, 60],

#[0.4, 0.6, 0.4, 0.03, 0.57, 0.4, 0.03, 0.57, 1],

0.5

].asNotes).parse;

// stream the notes out

p = Pseq(x.notes, 1).asStream;

p.nextN(10).do(_.postln);

[ 60, 0.4, 0.4, 0.5 ]

[ 63, 0.6, 0.6, 0.5 ]

[ 60, 0.4, 0.4, 0.5 ]

[ 65, 0.03, 0.03, 0.5 ] // grace notes are preserved

[ 66, 0.57, 0.57, 0.5 ]

[ 65, 0.4, 0.4, 0.5 ]

[ 62, 0.03, 0.03, 0.5 ]

[ 63, 0.57, 0.57, 0.5 ]

[ 60, 1, 1, 0.5 ]

nil

// play it, hear the grace notes

p = Pbind(

\note, Pseq(x.notes, 1),

#[midinote, delta, sustain], Pfunc({ |ev|

#[freq, dur, length].collect({ |key| ev[\note].tryPerform(key) });

}),

\instrument, \default,

\amp, 0.4

).play;

// apply arbitrary duration with Pseq and .collect -- grace note relationships are lost

p = Pseq(x.notes, 1).collect({ |n| n.copy.dur_(rrand(1, 8) * 0.25) }).asStream;

p.nextN(10).do(_.postln);

[ 60, 1, 0.4, 0.5 ]

[ 63, 1, 0.6, 0.5 ]

[ 60, 1.75, 0.4, 0.5 ]

[ 65, 0.75, 0.03, 0.5 ] // grace note durations are destroyed

[ 66, 1.5, 0.57, 0.5 ]

[ 65, 1.5, 0.4, 0.5 ]

[ 62, 1, 0.03, 0.5 ]

[ 63, 2, 0.57, 0.5 ]

[ 60, 1.25, 1, 0.5 ]

nil

p = Pbind(

\note, Pseq(x.notes, 1).collect({ |n| n.copy.dur_(rrand(1, 8) * 0.25) }),

#[midinote, delta, sustain], Pfunc({ |ev|

#[freq, dur, length].collect({ |key| ev[\note].tryPerform(key) });

}),

\instrument, \default,

\amp, 0.4

).play;

// apply arbitrary duration with PseqFunc -- grace note relationships are kept

p = PseqFunc(x.notes, 1, func: { |n| n.copy.dur_(rrand(1, 8) * 0.25) }).asStream;

p.nextN(10).do(_.postln);

[ 60, 1, 0.4, 0.5 ]

[ 63, 0.25, 0.6, 0.5 ]

[ 60, 0.5, 0.4, 0.5 ]

[ 65, 0.025, 0.03, 0.5 ] // grace note is still here

[ 66, 0.475, 0.57, 0.5 ]

[ 65, 0.5, 0.4, 0.5 ]

[ 62, 0.0125, 0.03, 0.5 ]

[ 63, 0.2375, 0.57, 0.5 ]

[ 60, 0.5, 1, 0.5 ]

nil

p = Pbind(

\note, PseqFunc(x.notes, 1, func: { |n| n.copy.dur_(rrand(1, 8) * 0.25) }),

#[midinote, delta, sustain], Pfunc({ |ev|

#[freq, dur, length].collect({ |key| ev[\note].tryPerform(key) });

}),

\instrument, \default,

\amp, 0.4

).play;