PsymNilSafe Psym variant that avoids hangs if all referenced patterns return nil


Part of: miSCellaneous


Inherits from: Psym


This adapts an idea of James Harkins' PnNilSafe (ddwPatterns quark) for Psym. If all patterns in the Dictinonary return nil, then Psym's embedInStream can produce an infinite loop, as it never yields. PnNilSafe can't be wrapped around Psym, but the check with logical time can be built into Psym itself. The wrapping into PsymNilSafe can shortly be written by applying 'symplay' instead of 'play'.


See also: Psym, PLx and live coding with Strings



Creation / Class Methods


*new (pattern, dict, maxNull)

Creates a new PsymNilSafe object. pattern expects a pattern of Symbols, dict the lookup dictionary and defaults to the current Environment. maxNull is the number of events with delta = 0 after which PsymNilSafe's method 'embedInStream' yields and thus stops a potentially endless loop. maxNull defaults to 128.


Instance Method for Class Pattern

 

aPattern.symplay(dict, clock, protoEvent, quant, maxNull = 128)

Play a pattern wrapped into a PsymNilSafe. Arguments clock, protoEvent and quant work as with playing a Pattern, arguments dict and maxNull work as with PsymNilSafe.new.

Example


(

s = Server.local;

Server.default = s;

s.boot;

)


(

x = Pbind(\midinote, Pseries(60, 1, 10), \dur, 0.5).asStream;

y = Pbind(\midinote, Pseries(90, -1, 10), \dur, 0.5).asStream;


z = Pseq([2, 3, 1, 2], 1).asStream;


~a = Pfuncn({ x.next(()) }, { z.next });

~b = Pfuncn({ y.next(()) }, { z.next });


PsymNilSafe(Pseq("ab", inf)).trace.play;


// shorter with method 'symplay':

// trace indicates all events with delta = 0 (maxNull = 128) in the post window

// Pseq("ab", inf).trace.symplay



// ATTENTION: with Psym the example leads to a SC hang !

// Psym(Pseq("ab", inf), currentEnvironment).trace.play

)