Last active
April 17, 2017 08:38
-
-
Save scztt/584b0d51263e971bf0a5a62d6caf7282 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
q = QuNeo().connect(); | |
( | |
SynthDef(\buzz, { | |
var sig, env, pressure, freqs, lpfFreq, gate; | |
gate = \gate.kr(1); // wait 2 secs before releasing | |
pressure = \pressure.kr(0.1, 1); | |
pressure = Gate.kr(pressure, gate); | |
freqs = \freq.kr(440) + \bend.kr(0); | |
freqs = freqs * [1, 2, 3]; | |
freqs = freqs.collect { |f| f + (rrand(-3.0, 3.0) * pressure) }; | |
freqs = freqs.flatten; | |
sig = freqs.collect { | |
|f| | |
LFSaw.ar(f, pressure * 1.0.rand) | |
}; | |
sig = Splay.ar(sig); | |
lpfFreq = pressure.linexp(0, 1, 200, 4000); | |
sig = BLowPass4.ar( | |
sig, | |
freq: lpfFreq.lagud(0.1, 3), | |
rq: 1 | |
); | |
sig = SoftClipAmp8.ar(sig, pressure.linlin(0, 1, 1, 14.5)); | |
sig = LPF.ar(sig, 3000); | |
sig = sig * Env.adsr( | |
attackTime:0.5, | |
sustainLevel: 0.9, | |
releaseTime:6).kr(gate:Slew.kr(gate, inf, 2), doneAction:2); // delay gate to delay end of synth | |
sig = sig * pressure.linlin(0, 1, -10.dbamp, 0.dbamp); | |
Out.ar(0, sig * -12.dbamp); | |
}).add; | |
) | |
( | |
// clear any existing connections | |
q.signal(\xypres).releaseDependants; | |
q.signal(\on).releaseDependants; | |
q.signal(\off).releaseDependants; | |
q.signal(\xypres).connectTo({ | |
|q, what, index, pad, x, y, pres| | |
" (pad: %, % % %)".format(index, x, y, pres).postln; | |
pad.events[\note] !? { | |
s.makeBundle(nil, { | |
pad.events[\note].set( | |
\pressure, pres, | |
\bend, (x - pad.events[\startXYP][0]) * 1 | |
); | |
}) | |
} | |
}); | |
q.signal(\on).connectTo({ | |
|q, what, index, pad, x, y, pres| | |
"ON (pad: %, % % %)".format(index, x, y, pres).postln; | |
pad.events[\startXYP] = [x, y, pres]; | |
s.makeBundle(nil, { | |
pad.events[\note] = Synth(\buzz, | |
args: [ | |
freq: Scale.major.degreeToFreq(index, 40, 0), | |
pressure: pres, | |
gate: 1 | |
] | |
); | |
}) | |
}); | |
q.signal(\off).connectTo({ | |
|q, what, index, pad, x, y, pres| | |
"OFF (pad: %, % % %)".format(index, x, y, pres).postln; | |
pad.events[\note] !? { | |
s.makeBundle(nil, { | |
pad.events[\note].set(\gate, 0); | |
}); | |
pad.events[\note] = nil; | |
pad.events[\startXYP] = nil; | |
} | |
}); | |
) | |
// Individual pads can be accessed via: | |
~p = q.padRows[0][0]; | |
// They broadcast signals | |
~c = ~p.signals(\on, \off, \xypres).connectAll({ | |
|...args| | |
args.postln; | |
}); | |
// ~c.disconnect(); | |
// Pads have CV's for x, y, pressure, and on off | |
v = View(bounds:400@200).layout_(VLayout( | |
StaticText().string_("x"), | |
x = NumberBox(), | |
StaticText().string_("y"), | |
y = NumberBox(), | |
StaticText().string_("pressure"), | |
p = NumberBox(), | |
o = Button().states_([["OFF"], ["ON", Color.green]]) | |
)).front; | |
~c = ConnectionList [ | |
~p.xCV.signal(\value) .connectTo(x.valueSlot), | |
~p.yCV.signal(\value) .connectTo(y.valueSlot), | |
~p.presCV.signal(\value) .connectTo(p.valueSlot), | |
~p.noteCV.signal(\value) .connectTo(o.methodSlot("value_(value.ceil)")) | |
]; | |
~c.freeAfter(v); | |
// you can set colors on the pads also: | |
q.pads.do { | |
|pad, j| | |
pad.device.setRed(1.0.rand); | |
pad.device.setGreen(1.0.rand); | |
}; | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment