gen patcher writing data on buffer inconsistency

Davide Ghelli's icon

Hi everybody,

I have a patch with a gen patcher inside that writes random gates (0 or 1) into a buffer of 8 samples. Inside gen I am using peek and poke to access the buffer; the problem I am experiencing is that whenever I try to "lock" the writing process and just read the buffer, I notice this inconsistency where the first sample always gets to 0, no matter what the previous recorded pattern was. I attach here the patcher, if someone can have a look (the two gen patchers are identical).

Best,

Davide

repetition and difference.maxpat
Max Patch

Graham Wakefield's icon

It was hard to figure out what I was supposed to do in the patch to get it to do what you say, but I figured it out eventually. (Next time it would be great if you could send a patch that has comments saying "do this, then this, then look here" etc., with everything else unrelated removed from the patch :-))

The reason it always writes 0 to the first sample is because poke is always writing. In gen~, objects are doing their thing on every sample. It's as if every cable is sending a message on every sample.

In your patch, when you turn lock on, it sets both of the signals going to poke to 0. That literally means "write the value 0 to the buffer at position 0", so it writes a value of 0 to the sample position 0, and keeps doing that on every sample.

The usual trick here to selectively stop poke from writing is to tell it to write to a position that doesn't exist (e.g. -1). That is, send the value -1 to the 2nd inlet. It will notice that this position doesn't exist, and won't write. You can use a switch -1 object to do this: route the "lock" parameter to switch -1's 1st inlet (the condition), and the normal write position to the 2nd inlet of the switch -1 (which it will pass when lock is not enabled).

PS. D&R has some profound ideas but I found it one of his hardest books to read. "What is Philosophy" was easier for me to parse. Also along those lines I recommend Manuel Delanda's Intensive Science & Virtual Philosophy