Is there a way for a toggle to always be read without having its signal be updated?

Nick Penrod's icon

Currently, using an HI device, I have a set-up where holding a button causing a toggle to switch on, and letting go causes it to switch off, and different buttons control different toggles controlling various sounds and whatnot.

Right now, all my toggles are going towards one general destination, so only one toggle's sound can be active at the same time. So, if I am holding one button, activating another will have the newest updated toggle be read, even if the last one is still active/on.

The problem I'm having is that, if holding down multiple buttons and thereby having multiple toggles on, I want it to be the case that letting go of toggles results in the toggles still being held to be read or activated. In essence, as an analogy to a real instrument, I want to do something akin to a "pull-off" on a guitar. I want to do something analogous to holding multiple frets on one string, where letting go of the highest fret causes the lower fret on the same string to sound.

However, Max MSP seems to not read toggles, buttons, etc unless they've had an update or bang signal sent to them, so a toggle turning off sends a signal, but not a toggle staying on, which is what I want to be read. In other terms, In a row of toggles, I want the right-most toggle that's turned on to always be read, regardless of order of toggle activation. How can I achieve this? Trying to have a button feed back into the button inputs to send a bang to update reading the messages causes a stack overflow error, so that doesn't work.

Sebastian Adams's icon

If you have individual physical (or virtual) buttons it would probably be better to separate the on/off signal another way (e.g. separate the input signal with sel object) and then send a 0 or 1 to toggle only when the state changes, rather than going straight to a toggle from your button.

If using keyboard keys you could use key in combination with keyup
The ubutton object sends a separate click and off message

If any of those routes work for you I think it will be very simple to put together.

another route I used for something that sounds similar before was using the matrixctrl object

By doing some messing around you can make it "remember" the previous setting and only register changes

really by re-inputting the previous setting rather than it remembering:
It reads the whole range of possible buttons (in this case, keypresses) and then if it doesn't get a change of state for any buttons it uses the previous value.

you could also do something similar with toggles and set messages but it seems like more work to me.

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

(this patch was used to play chords of overtones from a single fundamental in an intuitive way)

Roman Thilenius's icon


i was about to recommend [grab] - but interestingly it doesnt work with GUI externals.

Sebastian Adams's icon

Would this do what you want, Nick?

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

Source Audio's icon

priority switching could be done in that Hi device in first place, if it is programmable.

Or here a simple priority switcher with unlimited switch numbers, currently 10 added

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

Nick Penrod's icon

Would this do what you want, Nick?

Or here a simple priority switcher with unlimited switch numbers, currently 10 added

Both of these patches do exactly what I want thanks for the help!