-
-
Save yratof/604df3d8fcf1971471d8962434949f07 to your computer and use it in GitHub Desktop.
sup
This file contains hidden or 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
( | |
s = Server.default; | |
s.options.memSize_(2.pow(10)); // 512mb of Memory | |
s.options.numAnalogInChannels = 8; | |
s.options.numAnalogOutChannels = 8; | |
s.options.numDigitalChannels = 16; | |
s.options.maxLogins = 16; // set max number of clients | |
s.options.blockSize = 128; // This one is fucking important as f | |
s.options.numInputBusChannels = 2; | |
s.options.numOutputBusChannels = 8; | |
ServerBoot.removeAll; | |
ServerTree.removeAll; | |
ServerQuit.removeAll; | |
// Global ints | |
~out = 0; // Global output starting number | |
// Create path to samples | |
~path = PathName(thisProcess.nowExecutingPath).parentPath++"samples/"; | |
// Create global Dictionary | |
~makeBuffers = { | |
b = Dictionary.new; | |
PathName(~path).entries.do { | |
arg subfolder; | |
b.add( | |
subfolder.folderName.asSymbol -> | |
Array.fill( | |
subfolder.entries.size, | |
{ | |
arg i; | |
Buffer.read(s, subfolder.entries[i].fullPath); | |
} | |
) | |
); | |
}; | |
}; | |
~makeBusses = { | |
~bus = Dictionary.new; | |
~bus.add(\reverb -> Bus.audio(s,2)); | |
}; | |
~cleanup = { | |
s.newBufferAllocators; | |
ServerBoot.removeAll; | |
ServerTree.removeAll; | |
ServerQuit.removeAll; | |
}; | |
// Make the groups of the tree | |
~makeNodes = { | |
~mainGrp = Group.new; | |
~reverbGrp = Group.after(~mainGrp); | |
~reverbSynth = Synth.new( | |
\reverb, | |
[ | |
\amp, 1, | |
\predelay, 0.1, | |
\revtime, 1.8, | |
\lpf, 4500, | |
\mix, 0.35, | |
\in, ~bus[\reverb], | |
\out, ~out, | |
], | |
~reverbGrp | |
); | |
}; | |
~makeEvents = { | |
e = Dictionary.new; | |
e.add(\event1 -> { "Event 1".postln; }); | |
e.add(\event2 -> { "Event 2".postln; }); | |
e.add(\event3 -> { "Event 3".postln; }); | |
e.add(\event4 -> { "Event 4".postln; }); | |
}; | |
// Register real buffer sounds on boot | |
ServerBoot.add(~makeBuffers); | |
ServerBoot.add(~makeBusses); | |
ServerQuit.add(~cleanup); | |
); | |
( | |
s.waitForBoot({ | |
( | |
s.sync; | |
// BLIP! The sound of stars | |
SynthDef.new(\blip, { | |
arg out, freq=440, atk=0.005, rel=0.3, amp=1, pan=0; | |
var trig, sig, env; | |
sig = VarSaw.ar(freq, 0.9, 0.8); | |
trig = Dust.kr(5); | |
env = EnvGen.kr(Env.new([0,1,0], [atk,rel], [1, -1]), doneAction: 2); | |
sig = BPF.ar( | |
sig, | |
{LFNoise1.kr(0.2).exprange(100, 4000)}!8, | |
{LFNoise1.kr(0.1).exprange(0.1, 0.2)}!8 | |
); | |
sig = Pan2.ar(sig, LFNoise1.kr(1)); | |
sig = sig * env * amp; | |
Out.ar(out, sig); | |
}).add; | |
// Buffers/Sound files | |
SynthDef(\bpfbuf, { | |
arg atk=0, sus=0, rel=3, c1=1, c2=(-1), | |
buf=0, rate=1, spos=0, freq=440, rq=1, bpfmix=0, | |
pan=0, amp=1, out=0; | |
var sig, env; | |
env = EnvGen.kr(Env([0,1,1,0], [atk, sus, rel], [c1,0,c2]), doneAction: 2); | |
sig = PlayBuf.ar(1, buf, rate*BufRateScale.ir(buf), startPos:spos); | |
sig = XFade2.ar(sig, BPF.ar(sig, freq, rq, 1/rq.sqrt), bpfmix*2-1); | |
sig = sig * amp; | |
sig = Pan2.ar(sig, pan, amp); | |
Out.ar(out, sig); | |
}).add; | |
// Reverb synthdef to allow reverb on synths | |
SynthDef(\reverb, { | |
arg in, predelay=0.1, revtime=1.8, lpf=4500, mix=0.15, amp=1, out=0; | |
var dry, wet, temp, sig; | |
dry = In.ar(in, 2); | |
temp = In.ar(in, 2); | |
wet = 0; | |
temp = DelayN.ar(temp, 0.2, predelay); | |
16.do{ | |
temp = AllpassN.ar(temp, 0.05, {Rand(0.001, 0.05)}!2, revtime); | |
temp = LPF.ar(temp, lpf); | |
wet = wet + temp; | |
}; | |
sig = XFade2.ar(dry, wet, mix*2-1, amp); | |
Out.ar(out, sig); | |
}).add; | |
// Super SAW sound, detuned | |
SynthDef(\supersaw, { | |
// args allow you to modify with Synth | |
arg atk=2, sus=0, rel=3, c1=1, c2=(-1), | |
freq=500, detune=0.2, pan=0, | |
cfmin=500, cfmax=2000, rqmin=0.1, rqmax=0.2, amp=1, out=0; | |
// signal and envelope | |
var sig, env; | |
// Envelope | |
env = EnvGen.kr(Env([0,1,1,0], [atk, sus, rel], [c1, 0, c2]), doneAction:2); | |
sig = Saw.ar(freq * {LFNoise1.kr(0.5, detune).midiratio}!2); | |
sig = BPF.ar( | |
sig, | |
{LFNoise1.kr(0.2).exprange(cfmin, cfmax)}!2, | |
{LFNoise1.kr(0.1).exprange(rqmin, rqmax)}!2 | |
); | |
sig = sig * env * amp; | |
Out.ar(out, sig); | |
}).add; | |
s.sync; // double check it's all ready | |
ServerTree.add(~makeNodes); | |
ServerTree.add(~makeEvents); | |
s.sync; // double check it's all ready | |
s.freeAll; | |
"Environment is ready for music".postln; | |
s.sync; | |
// This is what sees all the data and sends it over to | |
// /ctrl every 10hz (fuck knows when that is) | |
~ctrl = { | |
var a0 = AnalogIn.ar(0); // Analog pin 0 - Weight 1 | |
var a1 = AnalogIn.ar(1); // Analog pin 1 - Weight 2 | |
var a2 = AnalogIn.ar(2); // Analog pin 2 - Weight 3 | |
var a3 = AnalogIn.ar(3); // Analog pin 3 - Weight 4 | |
var d0 = DigitalIn.ar(0); // Digital pin 0 - Button | |
var d1 = DigitalIn.ar(1); // Digital pin 1 - Button | |
var d2 = DigitalIn.ar(2); // Digital pin 2 - Button | |
var d3 = DigitalIn.ar(3); // Digital pin 3 - Button | |
SendReply.kr(Impulse.kr(1), '/ctrl', [a0, a1, a2, a3, d0, d1, d2, d3]); | |
}.play; | |
s.sync; // double check it's all ready | |
"Sensors are being read".postln; | |
s.sync; | |
OSCdef('listen', { | |
arg msg; | |
~weight1 = msg[3].linexp(0, 200, 0.1, 200 ).asInteger; | |
~weight2 = msg[4].linexp(0, 200, 0.1, 200 ).asInteger; | |
~weight3 = msg[5]; //.linexp(0.001, 1.0, 0.1, 200 ).asInteger; | |
~weight4 = msg[6].linexp(0.001, 1.0, 0.1, 200 ).asInteger; | |
~button1 =msg[7].asInteger; | |
~button2 =msg[8].asInteger; | |
~button3 =msg[9].asInteger; | |
~button4 =msg[10].asInteger; | |
[~weight1, ~weight2, ~weight3, ~weight4, ~button1, ~button2, ~button3, ~button4 ].postln; | |
[~weight3 ].postln; | |
}, '/ctrl'); | |
); | |
}); | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment