Skip to content

Instantly share code, notes, and snippets.

@scztt
Created March 25, 2026 07:22
Show Gist options
  • Select an option

  • Save scztt/1094b9388b6413fac6886326d69ad2fc to your computer and use it in GitHub Desktop.

Select an option

Save scztt/1094b9388b6413fac6886326d69ad2fc to your computer and use it in GitHub Desktop.
+ControlPanelNotification {
*exposeControlValue {
|category, cv, id|
instances.do { |inst| inst.exposeControlValue(category, cv, id) };
}
displayString {
|value, cv|
var str = cv.value.asString;
if (cv.spec.units.notNil and: { cv.spec.units.notEmpty }) {
str = str ++ " " ++ cv.spec.units;
};
^str;
}
exposeControlValue {
|category, cv, formatFunc|
var path = [category];
path = path.addAll(
(cv.name ?? { cv.hash }).asString.split($_)
);
case
{ cv.isKindOf(OnOffControlValue) } {
var toggleable = cv.md[\toggleable] ?? { false };
formatFunc = formatFunc ?? {{ |cv| cv.displayName }};
ControlPanelNotification.registerActionControl(
path: path,
position: nil,
displayName: cv.displayName,
displayValue: formatFunc.(cv),
normalizedValue: cv.input.asInteger,
toggleable: toggleable,
);
cv.signal(\value).connectToUnique(\ControlPanel) {
ControlPanelNotification.updateValue(
path,
formatFunc.(cv),
cv.input.asInteger,
);
};
ControlPanelChangeProvider.signal(path.join("_").asSymbol).connectTo(cv.inputSlot);
}
{ cv.isKindOf(ArrayControlValue) } {
var items = cv.items.collect { |item, index|
item.asString
};
formatFunc = formatFunc ?? {{ |cv| cv.value.asString }};
ControlPanelNotification.registerPopupControl(
path: path,
position: nil,
displayName: cv.displayName,
items: items,
normalizedValue: cv.value
);
cv.signal(\value).connectToUnique(\ControlPanel) {
ControlPanelNotification.updateValue(
path,
formatFunc.(cv),
formatFunc.(cv),
);
};
ControlPanelChangeProvider.signal(path.join("_").asSymbol).connectTo(cv.inputSlot);
}
{ cv.isKindOf(NumericControlValue) } {
formatFunc = formatFunc ?? {{
|cv|
var str;
var value = cv.value;
var decimals = cv.md[\decimals] ?? { 2 };
value = value.round(10.pow(decimals.neg));
str = value.asString;
if (cv.spec.units.notNil and: { cv.spec.units.notEmpty }) {
str = str ++ " " ++ cv.spec.units;
};
str;
}};
ControlPanelNotification.registerNumericControl(
path: path,
position: nil,
displayName: cv.displayName,
displayValue: formatFunc.(cv),
normalizedValue: cv.input,
);
cv.signal(\value).connectToUnique(\ControlPanel) {
ControlPanelNotification.updateValue(
path,
formatFunc.(cv),
cv.input,
);
};
ControlPanelChangeProvider.signal(path.join("_").asSymbol).connectTo(cv.inputSlot);
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment