Skip to content

Instantly share code, notes, and snippets.

@dqgorelick
Last active September 14, 2021 23:47
Show Gist options
  • Save dqgorelick/665a6931107af2bb1bdc7d7c2b51f905 to your computer and use it in GitHub Desktop.
Save dqgorelick/665a6931107af2bb1bdc7d7c2b51f905 to your computer and use it in GitHub Desktop.
Dan Gorelick supercollider tidalcycles server
SuperDirt.start // start server
Server.killAll // kill server
Quarks.gui // open samples folder
Platform.userExtensionDir // view extensions folder
Platform.systemExtensionDir // view system extensions folder
~dirt.loadSoundFiles("/Users/dang/Documents/supercollider/samples/*") // load samples
// inputs & outputs
// list all devices:
ServerOptions.devices; //all devices
ServerOptions.inDevices; //input devices
ServerOptions.outDevices; //output devices
// set outputs
ServerOptions.outDevices[2]
Server.default.options.outDevice_(ServerOptions.outDevices[2])
Server.local.options.outDevice_(ServerOptions.outDevices[2])
// set inputs
ServerOptions.inDevices; //input devices
Server.default.options.inDevice(ServerOptions.inDevices[0])
Server.local.options.inDevice_(ServerOptions.inDevices[0])
// Setup MIDI (note – you have to set up a MIDI bus in settings
MIDIClient.init;
MIDIClient.restart;
(
// without ableton
~midiOut = MIDIOut.newByName("OB-6", "OB-6");
~dirt.soundLibrary.addMIDI(\ob6, ~midiOut);
~midiOut.latency = 0;
~midiOut2 = MIDIOut.newByName("Scarlett 18i8 USB", "Scarlett 18i8 USB");
~dirt.soundLibrary.addMIDI(\ms20, ~midiOut2);
~midiOut2.latency = 0;
)
(
~midiOut1 = MIDIOut.newByName("IAC Driver", "ob6");
~midiOut2 = MIDIOut.newByName("IAC Driver", "ms20");
~midiOut3 = MIDIOut.newByName("IAC Driver", "synth");
~midiOut4 = MIDIOut.newByName("IAC Driver", "drums");
~midiOut5 = MIDIOut.newByName("IAC Driver", "drums2");
~dirt.soundLibrary.addMIDI(\ob6, ~midiOut1);
~dirt.soundLibrary.addMIDI(\ms20 , ~midiOut2);
~dirt.soundLibrary.addMIDI(\synth, ~midiOut3);
~dirt.soundLibrary.addMIDI(\drums , ~midiOut4);
~dirt.soundLibrary.addMIDI(\drums2, ~midiOut5);
~midiOut1.latency = 0;
~midiOut2.latency = 0;
~midiOut3.latency = 0;
~midiOut4.latency = 0;
~midiOut5.latency = 0;
)
// sync midi w/ Carabiner
// sock <- carabiner tidal 2 (-0.14)
// mouse to MIDI CC
~midiOutCC = MIDIOut.newByName("IAC Driver", "cc");
~midiOutCC.latency = 0;
(
~lastMouseY = -1;
~lastMouseX = -1;
SynthDef("sendMouseY",{
SendTrig.kr(Impulse.kr(60),0,MouseY.kr(0, 127));
}).add;
SynthDef("sendMouseX",{
SendTrig.kr(Impulse.kr(60),1,MouseX.kr(0, 127));
}).add;
o = OSCFunc({ arg msg;
switch (msg[2])
{0} {
if (~lastMouseY == msg[3].trunc, {}, {
msg[3].trunc.postln;
~midiOutCC.control(0, 7, msg[3].trunc);
~lastMouseY = msg[3].trunc
});
}
{1} {
if (~lastMouseX == msg[3].trunc, {}, {
msg[3].trunc.postln;
~midiOutCC.control(0, 8, msg[3].trunc);
~lastMouseX = msg[3].trunc
});
}
},'/tr', s.addr);
)
Synth("sendMouseY");
Synth("sendMouseX");
// custom synths
(
SynthDef(\mouse, {|out, pan, accelerate, freq, attack=0.01, decay=0.0, sustain=1, release=1.5, res=0.25 |
var sig, env;
env = EnvGen.kr(Env([0,1,1,0],[attack,decay,release],\sine), timeScale:sustain, doneAction: 2);
sig = Saw.ar(freq);
sig = RLPF.ar(sig, MouseY.kr(80, 24000, 1), res);
// Out.ar(out, DirtPan.ar(sig, ~dirt.numChannels, pan, env));
Out.ar(out, DirtPan.ar(sig * 0.7, ~dirt.numChannels, MouseX.kr(-2,2), env))
}).add;
)
(
SynthDef(\synthMouse, {|out, pan, accelerate, freq, attack=0.01, decay=0.8, sustain=1, release=0.1, res=0.2 |
var sig, env;
env = EnvGen.kr(Env([0,1,1,0],[attack,decay,release],\sine), timeScale:sustain, doneAction: 2);
sig = Saw.ar(freq);
sig = RLPF.ar(sig, MouseY.kr(80, 20000, 1), res);
// Out.ar(out, DirtPan.ar(sig, ~dirt.numChannels, pan, env));
Out.ar(out, DirtPan.ar(sig, ~dirt.numChannels, pan, env));
}).add;
)
// samplings stuff
// vox char
(
var functions = (); // make a dictionary of functions
var recSynth, recBufs, counter = 0, recording = false;
var whichOrbit = ~dirt.orbits[0];
var maxTime = 24; // allow a maximum of four seconds, adjust to your needs
var lat = s.latency + 0.02; // finetune
var numBuffers = 8; // number of buffers
var bufnamePrefix = "char"; // soundname prefix
var soundIn = Array.with(0);
~recBufs.do(_.free); // free them if they are left over (this is why we keep it in the environment variable)
~recBufs = recBufs = { Buffer.alloc(~dirt.server, ~dirt.server.sampleRate * maxTime, soundIn.size) } ! numBuffers;
// recorder writes audio from SoundIn to a bufnum
SynthDef(\record, { |bufnum|
var in = SoundIn.ar(soundIn) * EnvGen.ar(Env.linen(0.003, 23, 0.003, 1, \sine), doneAction: 0);
RecordBuf.ar(in, bufnum, loop:0, doneAction:2);
}).add;
// start recording round robin to buffers
functions[\recordLoop] = {
if(recording) { functions[\recordLoopAdd].value };
counter = counter + 1;
"CHAR".postln;
counter.postln;
if(counter > recBufs.lastIndex, {counter = 0});
~server.makeBundle(lat, {
recSynth = Synth(\record, [bufnum: (recBufs @ counter)], ~server);
recording = true;
})
};
// add new buffer and free synth
functions[\recordLoopAdd] = {
var name = bufnamePrefix ++ counter.asString;
if(recording) {
~server.makeBundle(lat, {
~dirt.soundLibrary.addBuffer(name, (recBufs @@ counter), false );
recSynth.free;
recording = false;
})
}
};
// reset all buffers
functions[\recordReset] = {
"reset".postln;
~recBufs.do(_.free);
~recBufs = recBufs = { Buffer.alloc(~dirt.server, ~dirt.server.sampleRate * maxTime, soundIn.size) } ! numBuffers;
for(0,numBuffers-1, { |i| ~dirt.soundLibrary.addBuffer(bufnamePrefix++i, (recBufs @@ i), false )});
counter = 0;
recording = false;
};
// add these functions to the dirt soundLibrary
functions.keysValuesDo{ |key, func| ~dirt.soundLibrary.addSynth( key, (play: func)) };
)
// vox record
(
var functions = (); // make a dictionary of functions
var recSynth, recBufs, counter = 0, recording = false;
var whichOrbit = ~dirt.orbits[0];
var maxTime = 24; // allow a maximum of four seconds, adjust to your needs
var lat = s.latency + 0.02; // finetune
var numBuffers = 8; // number of buffers
var bufnamePrefix = "vox"; // soundname prefix
var soundIn = Array.with(0);
~recBufs.do(_.free); // free them if they are left over (this is why we keep it in the environment variable)
~recBufs = recBufs = { Buffer.alloc(~dirt.server, ~dirt.server.sampleRate * maxTime, soundIn.size) } ! numBuffers;
// recorder writes audio from SoundIn to a bufnum
SynthDef(\record, { |bufnum|
var in = SoundIn.ar(soundIn) * EnvGen.ar(Env.linen(0.003, 23, 0.003, 1, \sine), doneAction: 0);
RecordBuf.ar(in, bufnum, loop:0, doneAction:2);
}).add;
// start recording round robin to buffers
functions[\recordLoop] = {
if(recording) { functions[\recordLoopAdd].value };
counter = counter + 1;
"DAN".postln;
counter.postln;
if(counter > recBufs.lastIndex, {counter = 0});
~server.makeBundle(lat, {
recSynth = Synth(\record, [bufnum: (recBufs @ counter)], ~server);
recording = true;
})
};
// add new buffer and free synth
functions[\recordLoopAdd] = {
var name = bufnamePrefix ++ counter.asString;
if(recording) {
~server.makeBundle(lat, {
~dirt.soundLibrary.addBuffer(name, (recBufs @@ counter), false );
recSynth.free;
recording = false;
})
}
};
// reset all buffers
functions[\recordReset] = {
"reset".postln;
~recBufs.do(_.free);
~recBufs = recBufs = { Buffer.alloc(~dirt.server, ~dirt.server.sampleRate * maxTime, soundIn.size) } ! numBuffers;
for(0,numBuffers-1, { |i| ~dirt.soundLibrary.addBuffer(bufnamePrefix++i, (recBufs @@ i), false )});
counter = 0;
recording = false;
};
// add these functions to the dirt soundLibrary
functions.keysValuesDo{ |key, func| ~dirt.soundLibrary.addSynth( key, (play: func)) };
)
// rhodes
(
var functions = (); // make a dictionary of functions
var recSynth, recBufs, counter = 0, recording = false;
var whichOrbit = ~dirt.orbits[0];
var maxTime = 24; // allow a maximum of four seconds, adjust to your needs
var lat = s.latency + 0.2; // finetune
var numBuffers = 16; // number of buffers
var bufnamePrefix = "rhodes"; // soundname prefix
var soundIn = Array.with(1);
~recBufs.do(_.free); // free them if they are left over (this is why we keep it in the environment variable)
~recBufs = recBufs = { Buffer.alloc(~dirt.server, ~dirt.server.sampleRate * maxTime, soundIn.size) } ! numBuffers;
// recorder writes audio from SoundIn to a bufnum
SynthDef(\record, { |bufnum|
var in = SoundIn.ar(soundIn) * EnvGen.ar(Env.linen(0.003, 23, 0.003, 1, \sine), doneAction: 0);
RecordBuf.ar(in, bufnum, loop:0, doneAction:2);
}).add;
// start recording round robin to buffers
functions[\recordLoop] = {
if(recording) { functions[\recordLoopAdd].value };
counter = counter + 1;
if(counter > recBufs.lastIndex, {counter = 0});
~server.makeBundle(lat, {
recSynth = Synth(\record, [bufnum: (recBufs @ counter)], ~server);
recording = true;
})
};
// add new buffer and free synth
functions[\recordLoopAdd] = {
var name = bufnamePrefix ++ counter.asString;
if(recording) {
~server.makeBundle(lat, {
~dirt.soundLibrary.addBuffer(name, (recBufs @@ counter), false );
recSynth.free;
recording = false;
})
}
};
// reset all buffers
functions[\recordReset] = {
"reset".postln;
~recBufs.do(_.free);
~recBufs = recBufs = { Buffer.alloc(~dirt.server, ~dirt.server.sampleRate * maxTime, soundIn.size) } ! numBuffers;
for(0,numBuffers-1, { |i| ~dirt.soundLibrary.addBuffer(bufnamePrefix++i, (recBufs @@ i), false )});
counter = 0;
recording = false;
};
// add these functions to the dirt soundLibrary
functions.keysValuesDo{ |key, func| ~dirt.soundLibrary.addSynth( key, (play: func)) };
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment