Is there a momentary ggate like object?

David Sutherland's icon

I'm a n00b and just starting my first not a tutorial MaxForLive project.

The goal is to have a max midi device that filters a midi data stream and when a specific midi note is found;
1. Send the midi note object to flush and then to the midi output
2. start a counter that is stopped when the midi note off is found
3. Take the counter value and increase it by a value, count down the resulting time and bang flush.

The patch I have so far, uses the switch object to detect the specified midi note and the ggate object to route the midi data stream.

While the ggate object routes the switch sends a bang having detected desired midi note it does not reset for subsequent notes.

What the application needs is a "mgate" object, one that functions as a momentary switch. When a bang is received the value is routed to the alternate output and then returns to the original output.

I have tried to build some logic that would take the bang from the switch and issue a second bang once the selected midi note has been processed but haven't succeeded in figuring that out.

Any suggestions are most welcome. Max is certainly a fun environment, can't think of the last time when I had so much fun failing so miserably :^).

Ds

Source Audio's icon

It is not obvious what You want to achieve with gates, counters, note offs etc.
But it is much simplier to have match, route or select object after midiin to select a specific note
and let it triger whatever action is desired.

Peter Ostry's icon

"Gate On" — "Thru" — "Gate Off" can be done by a [trigger] object that opens the gate, lets an incoming number through (or bangs it) and closes the gate. But gating ist seldom the best way for such actions. Rather think of comparing the input to the desired value, store what you expect as next event, and wait until exactly this comes in. Look into the attached patcher for an example. It finds a certain note-on, runs a counter and stops when the note-off is received.

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

Problem of the patch: If the note-off does not come, the counter runs forever. You may look into [borax] to handle that. If you don't need a counter but only the note duration, take the same patch but use [borax] after the note/velocity input. This works similar and you can a) deal with held notes and b) automatically get the note duration in milliseconds.

David Sutherland's icon

Source Audio and Peter Ostry,

Thank you for responding to my question. Sorry to delay following up, real life intervened for a few week and I just back to this today.

The pasted patch from Peter looks very promising. I had written out what I want to do in pseudo code but couldn't figure out my way to the right objects in the API. I will spend the rest of today understanding the patch.

I really appreciate your attention and helps

Thanks

David