Created
July 9, 2023 10:27
-
-
Save agoramachina/92a702a9e13b9fbb3aa3862e5bac1291 to your computer and use it in GitHub Desktop.
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
// | |
// eeg2osc Debug | |
// SERVER | |
s.boot; | |
s.stop; | |
// Testing incoming traffic | |
OSCFunc.trace(true); | |
OSCFunc.trace(false); | |
// Receive OSC | |
NetAddr.langPort; | |
NetAddr.localAddr; | |
thisProcess.openPorts; | |
// MIDI Settings | |
MIDIClient.init; | |
MIDIClient.sources; | |
MIDIIn.findPort; | |
// Midi Connections | |
MIDIIn.connect(3,MidiClient.sources[9]); | |
MIDIIn.connect(9,MidiClient.sources[17]); | |
MIDIIn.connect(0,MIDIClient.sources[0]) //first number is port number, second is device from sources list | |
// Initialize MIDI Socket | |
( k = BasicMIDISocket( | |
[\all, \omni], | |
{ |note, vel| [note, vel].debug("Note on") }, | |
{ |note, vel| [note, vel].debug("\tNote off") } | |
); ) | |
// cleanup | |
( | |
MIDIIn.removeFuncFrom(\noteOn, ~noteOnFunc); | |
MIDIIn.removeFuncFrom(\noteOff, ~noteOffFunc); | |
) | |
// Quarks Settings | |
Quarks.gui; | |
Quarks.openFolder; | |
Quarks.save("~/Music/sc/quarks.txt"); | |
Quarks.clear; | |
// Load Synths | |
SCLOrkSynths.gui | |
SCLOrkSynths.directory | |
SCLOrkSynths.load | |
SCLOrkSynths.synthDictionary | |
SynthDefPool.gui | |
SInstruments.openHelpFile | |
Quarks.install("OpenBCI-SuperCollider") | |
Synth(\midisynth1) | |
// Define Datapoints // | |
( o = { |msg| | |
//if(msg[0] != '/status.reply' | |
// && msg[0] !='n_go' | |
//) { | |
if(msg[0] == '/eeg') { | |
"%\n".postf(msg); | |
~time = msg[1]; | |
~signal = msg[2]; | |
~atn = msg[3]; | |
~med = msg[4]; | |
~delta = msg[5]; | |
~theta = msg[6]; | |
~l_alpha = msg[7]; | |
~h_alpha = msg[8]; | |
~l_beta = msg[9]; | |
~h_beta = msg[10]; | |
~l_gamma = msg[11]; | |
~m_gamma = msg[12]; | |
}}; | |
) | |
thisProcess.addOSCRecvFunc(o); | |
thisProcess.removeOSCRecvFunc(o); | |
// Print Datapoints // | |
(~data = { | |
~time.postln; | |
~atn.postln; | |
~med.postln; | |
~delta.postln; | |
~theta.postln; | |
~l_alpha.postln; | |
~h_alpha.postln; | |
~l_beta.postln; | |
~h_beta.postln; | |
~l_gamma.postln; | |
~m_gamma.postln; | |
};) | |
~data.value() | |
// Print Labeled Data // | |
(~printData = { | |
postln(""); | |
postln("Time \t\t" + ~time); | |
postln("Atn \t\t" + ~atn); | |
postln("Med \t\t" + ~med); | |
postln("Delta \t\t" + ~delta); | |
postln("Theta \t\t" + ~theta); | |
postln("L_Alpha \t" + ~l_alpha); | |
postln("H_Alpha \t" + ~h_alpha); | |
postln("L_Beta \t" + ~l_beta); | |
postln("H_Beta \t" + ~h_beta); | |
postln("L_Gamma \t" + ~l_gamma); | |
postln("M_Gamma \t" + ~m_gamma); | |
postln(""); | |
};) | |
~printData.value() | |
// SynthDefs | |
(( | |
SynthDef("umbSinewave",{ | |
arg freq=440, gate=1, amp=1, pan=0; | |
var x; | |
x = SinOsc.ar(freq, 0, amp); | |
x = EnvGen.kr(Env.adsr(0.01,0.3,0.5,1,0.6,-4),gate,doneAction: 2) * x; | |
Out.ar(0, Pan2.ar(x,pan)); | |
})); | |
( SynthDef(\midisynth1, {arg freq=440, amp=0.1; | |
var signal, env; | |
signal = VarSaw.ar([freq, freq+2], 0, XLine.ar(0.7, 0.9, 0.13)); | |
env = EnvGen.ar(Env.perc(0.001), doneAction:2); // this envelope will die out | |
Out.ar(0, signal*env*amp); | |
})); | |
( SynthDef(\sound,{arg freq=440, amp=0.1; | |
var saw, filter, env; | |
saw= Saw.ar(freq); | |
filter= Resonz.ar(saw,1000,0.1)*amp; | |
env= EnvGen.ar(Env([0,1,0],[0.01,0.1]),doneAction:2); | |
Out.ar(0,(filter*env).dup(2)) | |
})); | |
) | |
// Define Arrays // | |
~atnmed = Array.with(~atn, ~med).postln; | |
~pows = Array.with(~delta, ~theta, ~l_alpha, ~h_alpha, ~l_beta, ~h_beta, ~l_gamma, ~mid_gamma).postln; | |
~mini = ~pows.minItem(); | |
postln(~mini); | |
~pows.normalize[5]; | |
normalize([1,2,3]); | |
([1,2,3]).normalize; | |
minItem([1,2,3]); | |
([1,2,3]).minItem; | |
maxItem([1,2,3]); | |
([1,2,3]).maxItem; |
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.boot; | |
s.stop; | |
Quarks.gui; | |
Quarks.save("~/Music/sc/quarks.txt"); | |
Quarks.clear; | |
{RLPF.ar(Dust.ar([12, 15]), LFNoise1.ar([0.3, 0.2]).range(100, 3000), 0.02)}.play; | |
thisProcess.openUDPPort(4560); // open the UDP port | |
n = NetAddr.("192.168.1.100", 4560); // create the NetAddr | |
n.free; | |
// create the OSC listener | |
(o = OSCdef( \eeg, | |
{ |msg, time, source| | |
var data = msg.copyToEnd(1); | |
~time = data[0]; | |
~signal = data[1]; | |
~atn = data[2]; | |
~med = data[3]; | |
~delta = data[4]; | |
~theta = data[5]; | |
~l_alpha = data[6]; | |
~h_alpha = data[7]; | |
~l_beta = data[8]; | |
~h_beta = data[9]; | |
~l_gamma = data[10]; | |
~m_gamma = data[11]; | |
msg.postln; | |
}, | |
'/eeg' ); | |
) | |
o.free; | |
"attention: " + ~atn.postlnw | |
"meditation: " + ~med.postln; | |
Ndef( \sines, { SinOsc.ar( \freq.kr( 300, 0.1 ), 0, \amp.kr(0.1, 0.1) ) } ); | |
Ndef( \sines ).play; | |
f = { SinOsc.ar(440 + 200.rand, 0, 0.2) }; | |
x = f.play; | |
x.free; | |
SCLOrkSynths.gui; | |
SCLOrkSynths.directory | |
SCLOrkSynths.load | |
SCLOrkSynths.synthDictionary | |
SynthDefPool.gui; | |
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
// eeg2osc-init | |
// Test incoming traffic | |
OSCFunc.trace(true); | |
OSCFunc.trace(false); | |
// Load Synths | |
SCLOrkSynths.load | |
// MIDI Settings | |
MIDIClient.init; | |
// MIDI Connections | |
MIDIIn.connectAll; | |
MIDIIn.disconnectAll; | |
MIDIIn.control = { arg src, chan, num, val; [chan,num,val/127].postln; }; //control change messages have a 7 bit value | |
MIDIIn.bend = { arg src, chan, bend; [chan,bend/8192].postln; }; //pitch bend has a 14 bit range and is a bipolar signal (so bend/8192 will remap the range to -1.0 to 1.0) | |
// Print Datapoints | |
~data.value() | |
~printData.value() | |
~atnmed.postln; | |
~pows.postln; | |
// Define Arrays // | |
~atnmed = Array.with(~atn, ~med); | |
~pows = Array.with(~delta, ~theta, ~l_alpha, ~h_alpha, ~l_beta, ~h_beta, ~l_gamma, ~mid_gamma); | |
// Define Datapoints // | |
( o = { |msg| | |
if(msg[0] == '/eeg') { | |
"%\n".postf(msg); | |
~time = msg[1]; | |
~signal = msg[2]; | |
~atn = msg[3]; | |
~med = msg[4]; | |
~delta = msg[5]; | |
~theta = msg[6]; | |
~l_alpha = msg[7]; | |
~h_alpha = msg[8]; | |
~l_beta = msg[9]; | |
~h_beta = msg[10]; | |
~l_gamma = msg[11]; | |
~m_gamma = msg[12]; | |
}}; | |
) | |
thisProcess.addOSCRecvFunc(o); | |
thisProcess.removeOSCRecvFunc(o); | |
// Cleanup // | |
( k.free; | |
thisProcess.removeOSCRecvFunc(o); | |
) |
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
Ndef( \sines, { SinOsc.ar( \freq.kr( 300, 0.1 ), 0, \amp.kr(0.1, 0.1) ) } ); | |
Ndef( \sines ).play; | |
f = { SinOsc.ar(440 + 200.rand, 0, 0.2) }; | |
x = f.play; | |
x.free; | |
/* | |
( | |
Pdef(\moogBass, | |
Pmono( | |
"moogBass", | |
\amp, 0.9, | |
\midinote, Pseq([24, 36, 48, 36, 35, 36, 43, 48], 3), | |
\dur, 0.2, | |
\gain, Pseries(2, 0.1, inf), | |
\cutoff, Pseries(4000, 400, inf), | |
\chorus, Pwhite(0.7, 0.9) | |
) | |
).play; | |
); | |
*/ | |
// APad HH | |
( | |
Pbindef( \apadMH, | |
\instrument, "apadMH", | |
\dur, 4, | |
\tremoloRate, Pwhite(4.0, 6.0, inf), | |
\ctranspose, -5, | |
\strum, Pseq([0.05, -0.05, 0.05, 0.05, -0.05]), | |
\note, Pseq([ | |
[3, 5, 10, 12, 17, 19], | |
[2, 6, 9, 13, 16, 20], | |
[4, 11, 18], | |
[2, 6, 9, 13, 16, 20], | |
[0, 7, 14, 21] | |
]), | |
\amp, 1.0 | |
).play; | |
); | |
// Kick 1 | |
( | |
Pbindef(\kick1, | |
\instrument, "kick1", | |
\dur, Pseq([ | |
3/4, 1/4, | |
1/2, 1/2, | |
Rest(1/2), 1/2, | |
Rest(1/4), 3/4 | |
], 3) * 0.5, | |
\amp, 0.9, | |
\rel, Pseq([0.9, Pn(0.15, 6), 0.6], inf), | |
\glissf, Pseq([Pn(0.9, 7), 0.5], inf) | |
).play; | |
); | |
// SOS Tom | |
( | |
Pbindef( \sosTom, | |
\instrument, "sosTom", | |
\dur, Pseq([1, 2, 1, 2, 1, 2, 1, 2, 2, 2]) / 7, | |
\pan, Pseries(0.75, -0.15, 10), | |
\freq, Pstutter(2, Pseq([250, 200, 150, 100, 50])), | |
).play; | |
); | |
// Snare Stein | |
( | |
Pbindef( \snareStein, | |
\instrument, "snareStein", | |
\dur, 1/8, | |
\amp, Pseq([ | |
1, 0.5, 0.7, 0.5, 0.5, 0.7, 0.5, | |
1, 0.5, 0.7, 0.5, 0.5, 0.7, 0.5, | |
1, 0.5, 0.7, 0.5, 0.7, 0.5, 0.5, | |
1, 0.6, 1]), | |
\toneAmp, Pkey(\amp) * 0.25, | |
\curve, Pseq([ | |
1, 2, 1, 2, 2, 1, 2, | |
1, 2, 1, 2, 2, 1, 2, | |
1, 2, 1, 2, 1, 2, 1, | |
1, 2, 1]) * -4, | |
\noiserel, Pseq([ | |
1, 3, 1, 3, 3, 1, 3, | |
1, 3, 1, 3, 3, 1, 3, | |
1, 3, 1, 3, 1, 3, 1, | |
1, 3, 1]) / 6, | |
).play; | |
); | |
// SOS Hats | |
( | |
Pbindef( \sosHats, | |
\instrument, "sosHats", | |
\initRel, Pwhite(0.05, 0.15), | |
\bodyRel, Pwhite(0.05, 0.15), | |
\dur, Pn(1/8, 16), | |
\amp, 0.5 | |
).play; | |
); | |
// Harsher Symbal | |
( | |
Pbindef( \hashercymbal, | |
\instrument, "hashercymbal", | |
\dur, 1/8, | |
\rel, 0.15, | |
\amp, Pseq([Pseq([0.1, 0.05, 0.05, 0.1, 0.05, 0.05, 0.1, 0.05], 4), 0.1]), | |
\timbre, Pwhite(-100, 100), | |
\looprate, Pwhite(10, 10000), | |
\samplerate, Pwhite(200, 22500), | |
).play; | |
); | |
// Snare 909 | |
( | |
Pbindef( \snare909, | |
\instrument, "snare909", | |
\nyquist, Pgeom(200, 1.5), | |
\dur, Pseq([Pseq([1, 2, 1], 3), 2, 2, 1]) / 4, | |
\amp, 1 | |
).play; | |
); | |
var recvPort = 6000; | |
o = OSCFunc({ arg msg, time, addr, recvPort; [msg, time, addr, recvPort].postln; }, '/goodbye'); // create the OSCFunc | |
o.free; | |
// Make an OSCdef to listen to this kind of message: | |
(OSCFunc.trace(false); | |
OSCdef(\test, { |msg, time, sender, recvport| | |
[msg, sender, recvport].postln }, | |
'/test', recvPort:6000); | |
) | |
List[\null, 1,2, 3, 4].minItem(); | |
minItem([1,2,3]); | |
postln(MinItem(~pows)) | |
[1,2,3].normalize(); | |
o = OSCFunc({ arg msg, time, addr, recvPort; [msg, time, addr, recvPort].postln; }, '/goodbye', n); | |
o.free; | |
// WTF | |
(play{SinOsc.ar(OnePole.ar(Mix( | |
LFSaw.ar([1,0.99],[0,0.6],2000,2000).trunc([400,600])*[1,-1] | |
),0.98)).dup*0.1} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment