Skip to content

Instantly share code, notes, and snippets.

@tastycode
Created December 4, 2021 09:00
Show Gist options
  • Save tastycode/a51dcb3b2dbe52455e421be16f7f711d to your computer and use it in GitHub Desktop.
Save tastycode/a51dcb3b2dbe52455e421be16f7f711d to your computer and use it in GitHub Desktop.
Max 4 Live Patches
autowatch = 1
inlets = 1
var toggles = jsarguments[1]
outlets = toggles
var defaultMessage = typeof(jsarguments[2]) == "undefined" ? "hidden" : jsarguments[2]
var lastvalue
/**
This device takes an int, and sends either "hidden 1" or "hidden 0"
to a dynamic number of outlets. Each outlet can be connected to a UI element
and will conditionally hide and show depending on the outlet it is connected to
jsarguments:
1: The number of controls to toggle visibility for
* Control multiple controls with `t s s`
2: The message to send, default is "hidden". You could use this to toggle different boolean things like disabled and what not..
*/
function log(message) {
  post(JSON.stringify({message: message}, null, 4));
  post("\n");
}
function anything() {
msg_int(lastvalue)
}
function msg_int(selected) {
lastvalue = selected
for (var i = 0; i < toggles; i++) {
outlet(i, arrayfromargs(defaultMessage, [i === selected ? 0 : 1]))
}
}
function set(val) {
msg_int(lastvalue)
}
function save() {
embedmessage("set", lastvalue)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment