Skip to content

Instantly share code, notes, and snippets.

@madskjeldgaard
Created May 15, 2020 21:07
Show Gist options
  • Save madskjeldgaard/939a99beb4f1071d0f0d0087aaa1499d to your computer and use it in GitHub Desktop.
Save madskjeldgaard/939a99beb4f1071d0f0d0087aaa1499d to your computer and use it in GitHub Desktop.
Alternative, more modern and responsive auto gui for NodeProxy in SuperCollider
// Test Ndef
(
Ndef(\yo, {|freq, amp, pan, what|
var sig = SinOsc.ar(freq) * amp;
what;
Pan2.ar(sig, pan)
}).play
)
// Gui function
(
~ndefgui = {|ndef|
var window, sliders, transport, play, clear, name, scope, fade, fadeLabel;
var params = IdentityDictionary.new();
var paramNames = ndef.controlKeys;
// Populate param dict
paramNames.do{|paramname|
var spec = Spec.specs.at(paramname);
spec = if(spec.isNil, { [0.0,1.0].asSpec }, { spec });
params.put(paramname, spec)
};
// GUI
window = Window.new(ndef.key);
sliders = [];
params.keysValuesDo{|pName, spec|
// Slider
var slider = Slider.new()
.orientation_(\horizontal)
.action_({|obj|
var sliderVal = obj.value;
var mappedVal = spec.map(sliderVal);
valueBox.value = mappedVal;
ndef.set(pName, mappedVal);
});
// Label
var label = StaticText.new
.string_(pName);
// Value box
var valueBox = NumberBox.new();
// Slider Layout
var sliderLayout = HLayout([label, s: 1], [slider, s: 4], [valueBox, s:1]);
sliders = sliders.add(sliderLayout);
};
// Transport
name = StaticText.new()
.string_(ndef.key);
play = Button.new()
.states_([
["play"],
["stop"]
])
.action_({|obj|
var val = obj.value;
if(val==1, {
ndef.play;
}, {
ndef.stop
})
});
// Get current play state
ndef.isPlaying.if({
play.value_(1)
}, {
play.value_(0)
});
clear = Button.new()
.states_([
["clear"]
])
.action_({|obj|
ndef.clear
});
scope = Button.new()
.states_([
["scope"]
])
.action_({|obj|
ndef.scope
});
fadeLabel = StaticText.new()
.string_("fade:");
fade = NumberBox.new()
.step_(0.01)
.clipLo_(0.0)
.clipHi_(100.0)
.action_({|obj|
var val = obj.value;
ndef.fadeTime = val;
});
transport = HLayout(
play, clear, scope, fadeLabel, fade
);
window.layout = VLayout([name, s: 1], [transport, s:1], *sliders);
window.front;
};
)
// Make gui
~ndefgui.value(Ndef(\yo));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment