translate msp [line~] into gen~ [counter]

brendan mccloskey's icon

Hi

I am trying to get the same functionality from [line~] inside gen~. I would like to send [counter] instructions as follows:

go to 1. in X ms;

go to 0. immediately;

stay at 0. for Y ms.

X and Y will be variable.

Max Patch
Copy patch and select New From Clipboard in Max.

The main challenge is working out how to tell [counter] to wait. I'm fairly sure there isn't a direct equivalent to [line~] in the gen world. The MaxMSP version is below fwiw:

Thanks for looking
Brendan

vichug's icon

to tell a gen~ operator output to "wait", the basic trick is to use a [?] or [sah] operator. What do you mean by [counter] btw ? the actual Max object ? because there is none in your patch, and there is no [counter] operator in gen afaik... there's [accum] though
I'll try and see what i can do...

Gregory Taylor's icon

There most certainly is a counter operator in gen~, although it was not among the early basic list of operators. It counts samples, of course. About the only differences you'll notice is that you'll have to add the "reset on next" count stuff yourself, and the additions of modes of counting [up/down/updown] are left as an "exercise to the genner."

In connection to a little piece of gen~ mischief I was putting together, I realized that it would be very useful to have something in the toolbox that would smooth an input over N samples - which I think is basically what you have in mind. Implementing it proved a more challenging task than I initially assumed. While I languished in the Slough of Despond, I mentioned my suffering to Emmanuel Jourdan [who is owed a drink by quite a number of you by now, and many more by me personally], who kindly suggested that I consider something like this (which you should paste into an empty gen~ object):

Max Patch
Copy patch and select New From Clipboard in Max.

Perhaps it may prove to be as instructive to you as it was to me.

Rock on, B.

brendan mccloskey's icon

Hi vichug
[counter] in gen~ works like [accum] and [+=]. Did you find it?

Recently, I have seen related solutions using [accum] and I am now trying (for reasons of skills development and patch v. CPU optimization) to roll my own. I could be wrong but I believe that using [accum] in a polyphonic context can make excessive demands on memory and/or CPU.

Max Patch
Copy patch and select New From Clipboard in Max.

This solution from Peter McCullough and leafcutter. TBH I can't recall why this one didn't turn out to be perfect, maybe it's just the polyphonic load on my machine?

Brendan

brendan mccloskey's icon

Gregory

[latch]

vichug

[?]

I will have a hacky Sunday, thank you gents

Brendan

vichug's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Hah... by the time i refreshed the page, i just finished finding what seems like a solution... probably useless by now, but here it is anyway :

even more useless, as i don't use the most recent version of Max (6.O.8) that's certainley why i see no [counter] :) and i indeed do use accum, but to achieve this you'll have to somehow count somehting ? so using accum or count is maybe unavoidable ? not sure but....

Emmanuel Jourdan's icon

@noob_meister: latch is a easier solution to do sample & hold (new in Max 6.1.x).

brendan mccloskey's icon

@vichug

Ah, no [counter] in gen~ for you at the moment. I think the reason I want to avoid using [accum] or [+=] with no upper limit is to test a solution where the [accum], [counter] or whatever is constrained between 0. and 1. to see if I get a noticeable improvement in CPU usage. Apologies for the "duplication of effort"; your solution is a useful addition/alternative to leafcutter's.

@Emmanuel

yes, I think I see where the clues left by yourself and Gregory are leading. Using the objects' reference as, erm, reference is the difference that latch truly samples or holds, where sah is either on or off? I could use latch to do the "waiting" part of my MSP solution?

Thank you again
Brendan

Gregory Taylor's icon

You betcha, Brendan. Good call!

brendan mccloskey's icon

Almost there gents; driving [latch] with a DIY rectangle wave for "off" and "on".

Some confusion remains in syncing the control signal ("wait") to the central phasor.

Max Patch
Copy patch and select New From Clipboard in Max.

Maybe I need to spend time with that good old Zen and the Silent Patch tutorial ;¬)

brendan mccloskey's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Even closer:

Brendan

rbrt's icon
Max Patch
Copy patch and select New From Clipboard in Max.

...how about this one?
its just like line~ but its a bit loong

rbrt's icon

heeey yours is much more elegant i feel like an elephant...
--but when you turn on cpu-metering,its a bit more heavy than mine..
one way to improve this was to add a "fixdenorm" after the "history"..
(i need this for some simple parameter smoothing,but inside a poly~ with
64 voices,thats why efficiency is BIG)

brendan mccloskey's icon

Good morning people

Max Patch
Copy patch and select New From Clipboard in Max.

Here's a small patch with a solution offered by either leafcutter john or Andrzej Kopec (I think the former):

My own compromise algo is there to. [latch] is the key object, from this thread. I was originally looking for a mutable 0. - 1. phasor, whose ramptime doesn't vary during muting.

Brendan

Claudio Marcozzi's icon

What about this?

Max Patch
Copy patch and select New From Clipboard in Max.

Claudio Marcozzi's icon

The same thing with Latch operator (not sah), little less expensive

Max Patch
Copy patch and select New From Clipboard in Max.

Dave Mollen's icon

Thanks for this patch Raja! I'm a bit late to this party, but it has been very useful to me. I made a small adaptation I wanted to share. This patch also works when you change the destination mid-ramp.

Max Patch
Copy patch and select New From Clipboard in Max.

Dave Mollen's icon

I'm glad to help you remember your own work. I hope it's useful to you too! :)

Dave Mollen's icon

And here's a codebox version, which uses less processing when the destination has been reached.

Max Patch
Copy patch and select New From Clipboard in Max.

R_Gol's icon

Hi @GREGORYTAYLOR,
Regarding the very first patch you share in this topic. I am trying to figure out how to create a 'bang' each time the operation is finished (similar to the right outlet of the line~ object )
Could you please help with that ?

Thank!

Ernest's icon

It's funny, that's almost how much work I did myself on the same thing before finding the slide~ example in Max 8. The example provides different up and down rates, but if you don't need that, it's incredibly simple:

slide(in1, incr){
// incr = fraction to slide each clock, e.g, .001 slides over 100 clocks.
History prev;
prev = prev + incr * (in1 -prev);
return prev;
}

Clever isn't it? lol.