a simple gate dilemma
Having a little trouble with a gate at the moment.
Let suppose I have a gate with 3 outputs.
I'm sending it an integer in the left inlet, and then either a 1 (on) or a 0 (off) in the right inlet. So basic button states.
I'll then attach a LED to each output of the gate, in order to test my messages are going through the right gate.
I'll press button 1, which sends a 1 to the gate, and a 1 to right inlet. Sure enough, the LED under the first outlet blinks. If I press button one again, I'll send it a 0 through the right inlet, and sure enough, the LED under the first outlet blinks.
This is all as I expected so far.
I press button 2, which should send a 2 to the gate, and a 1 to the right inlet. But here's where things go a little backward. The LED under the first outlet blinks again.
If I press button 2 again, which should send a 2 to the gate, and a 0 to the right outlet, THEN the second outlet blinks. A second press of button 2 will make the second outlet blink again.
Its like every time I change the gate, I need to press the button twice, which doesn't seem right.
Its probably something really obvious I'm guessing? :)
Just made an effort to solve this. Really dunno if this is what you want, but it could be. Patch attached (you'll have to hit the message box '0' for the first outlet, '1' for the 2nd and '2' for the third; things in max usually start counting from 0).
be careful with [gate], it's one of the objects which *doesn't* start counting from 0, at least not the way we might think. Rather, a 0 will close all outlets, regardless of how many you have. 1 will open the first outlet, etc. [switch] operates similarly.
Take a look at [trigger] for this kind of order-of-operations issue. Sounds like messages aren't getting where they need to be in the right order. So to open outlet 2 and then send a 1 through, you'd use
[t 1 2]
the crucial thing to remember is that the 2 comes out first (and goes to the control/left inlet of [gate]), then the 1 comes out and goes through the data/right inlet. This should work. Possibly in your patch you unintentionally have the order reversed, that's what it sounds like (needing to hit it twice, and the first hit sends to the previously-opened outlet). Right-to-left ordering of messages: is your data message to the right of the control message? :) if so, there's your problem.
@seejayjames
By saying that max usually counts from 0, I was referring to the umenu object (which I used to the patch I made, trying to solve toddak's problem).
There is a trigger object there as well.
@alexandros: Thanks for your patch. I had a look at it but it does something similar. I'm thinking the problem arrises when I I'm not sending on/off messages after each other for the same gate.
To try to explain:
On your patch when I press 0, the first led lights.
However, when I hit 1 directly after turning the first led on, nothing happens. The toggle box changes, but nothing lights.
Its the second press of the 1 that makes the second LED light.
However, sending it on then off for 1 works fine, on then off for 2 works fine, and on then off for 3 works fine. Do you see what I mean? Does this mean that there are some conditions where a gate can only deal with consecutive on/off messages? And if so, any ideas as to what object would work better?
@seejayjames: yes, I was thinking along the same lines myself, but couldn't explain as well as you could! The trigger object looks like it might solve a few problems. I thought it was an ordering problem, and thought about using a delay to delay the messages, but trigger looks alot less complicated. Do you often use triggers with gates?
And many thanks to you both! This has been a great help. Shall be back in the studio later today to try to implement a trigger.
In regards to the 0's, I have noticed this to be a challenge. I'm working with a monome as my control surface, and the top row involves alot of 0's as its co-ordinates. I have been putting a '+1' message in a lot of the time to change its data from 0-7 to 1-8 to make things in max alot easier!
does this do what you're looking for?
(if you remove the toggles under the [gate] it will just blink the LEDs once every time you click the buttons)
@laonikoss: yes yes yes!! Many thanks! I can see know that the trigger is very useful when ordering the messages to the gate.
Awesome. Thankyou everyone!!