(// if a usb sensorinterface is connected to this computer:
q = q ?? ();
Routine{
LID.closeAll;
1.0.wait;
LID.buildDeviceTable;
2.0.wait;
LID.closeAll;
NASCens_LID.initNASCens; // initialise the deviceSpec
q.device = LID.deviceTable.detect( {|it,i| it[1].vendor == 0x1043 } );
q.device.at(0).postln;
q.lid = NASCens_LID.new( q.device.at(0) );
q.lid.initActions;
}.play( AppClock );
)
q.lid.dumpCaps
// preparing the server:
s = Server.local.boot;
(
SynthDef( "writememory", { arg in=0, buf=0, amp=1, prevlev=0.5;
RecordBuf.ar( In.ar(in,2), buf, recLevel: amp, preLevel: prevlev, loop: 1 );
}).load(s);
SynthDef( "playmemory", { arg out=0, buf=0, rate=1, amp=0.5, lt = 5, freq=400;
Out.ar(out, Lag.kr(amp,lt)*LPF.ar(PlayBuf.ar( 2, buf,
Lag.kr(-1*rate,lt), loop: 1 ),freq));
}).load(s);
)
// see if it's all working:
q.lid.sensordata
( // prepare groups on server
q.controlgroup = Group.new(s, \addToHead );
q.maingroup = Group.new(s, \addToHead );
q.subgroups = Array.fill(4,0);
q.subgroups.do{|it,i| q.subgroups.put( i, Group.new( q.maingroup ) ) };
q.recgroup = Group.new(s, \addToTail) ;
q.playgroup = Group.new( s, \addToTail );
s.queryAllNodes;
q.membuf = Buffer.alloc(s, 44100*90.0,2);
)
(
q.args = Array.fill( 4, { [\amp,0.25,\out,0] } );
q.durs = Array.fill( 4, { Pseq( [0.25],inf ).asStream } );
q.freqs = Array.fill( 4, { Pseq( [400],inf ).asStream } );
q.streams = Array.fill(4,0);
q.streams.do{ |it,i|
q.streams.put(i, Task({
var dur,freq;
loop {
dur = q.durs.at(i).next;
freq = q.freqs.at(i).next;
x = Synth.new( "lac"++i, q.args.at(i), target:q.subgroups.at(i) );
x.set( \dur, dur );
x.set( \freq, freq );
// x.postln;
dur.next.wait;
}
});
);
};
q.recsynth =
Synth.tail(q.recgroup,"writememory",[\buf,q.membuf.bufnum,\in,0,\amp,0.5,\prevlev,
0.9]);
q.playsynth =
Synth.tail(q.playgroup,"playmemory",[\buf,q.membuf.bufnum,\out,0,\amp,0.4]);
~start = { |id| q.streams.at(id).play; q.lid.setLEDState( id, 1 ); };
~stop = { |id| q.subgroups.at(id).release(5.0); q.streams.at(id).stop;
q.lid.setLEDState( id, 0 ); };
)
(
q.lightcontrol1 = Bus.control( s, 1 );
q.lightcontrol2 = Bus.control( s, 1 );
q.potcontrol = Bus.control( s, 1 );
q.updatecontrols = Routine{
loop {
q.lightcontrol1.set( q.lid.sensordata[0] );
q.lightcontrol2.set( q.lid.sensordata[2] );
q.potcontrol.set( q.lid.sensordata[12] * 800 );
0.005.wait;
}
};
)
(
q.updatepres = [
Routine{
loop {
q.subgroups[0].set(\freqmod, [2.0,0.8].asSpec.map( q.lid.sensordata[3] ) );
0.005.wait;
}
},
Routine{
loop {
q.subgroups[1].set(\freqmod, [2.0,0.8].asSpec.map( q.lid.sensordata[4] ) );
0.005.wait;
}
},
Routine{
loop {
q.subgroups[2].set(\freqmod, [2.0,0.8].asSpec.map( q.lid.sensordata[3] ) );
0.005.wait;
}
},
Routine{
loop {
q.subgroups[3].set(\freqmod, [2.0,0.8].asSpec.map( q.lid.sensordata[4] ) );
0.005.wait;
}
}
];
~startcontrol = { |id| q.updatepres.at(id).play; q.lid.setLEDState(
id+4, 1 ); };
~stopcontrol = { |id| q.updatepres.at(id).stop; q.lid.setLEDState( id+4, 0 ); };
)
// update buses
q.updatecontrols.play
//q.updatelight.stop;
q.playsynth.busMap( \rate, q.lightcontrol1 );
q.playsynth.busMap( \freq, q.potcontrol );
q.recsynth.busMap( \reclevel, q.lightcontrol2 );
s.prepareForRecord;
s.record;
// from here on, the code was changed live:
(
// create a new synthdef:
SynthDef( "lac"++3, { |out=0,dur=0.25,amp=0.25,gate=1,freq=200, freqmod=1.0|
Out.ar( out,
CombL.ar(
Mix.new(
// BPF.ar( WhiteNoise.ar( 1.0 ), freq*freqmod.lag(0.1), 0.2 );
SinOsc.ar( //freq*freqmod.lag(0.05)
Array.geom( 3, freq*freqmod.lag(0.05), 1.5 ), mul: Array.geom( 4,
0.5, 0.9 )
)
)
, 0.2, 0.1, 0.15 )
*
EnvGen.kr( Env.cutoff(1), gate, doneAction:2) *
EnvGen.kr( Env.sine(1.0), levelScale: amp, timeScale:dur, doneAction: 2 ) );
}).send(s);
)
Env.sine( 1 ).plot;
Env.perc(0.05,0.95).plot
q.durs[2] = Pseq([0.25,0.5,0.25,0.125,0.25]*0.1,inf).asStream;
q.freqs[2] = Pseq([400,350,360,370,205],inf).asStream;
q.args[2] = [\amp,0.2,\out,1];
q.args[3] = [\amp,0.2,\out,0];
q.freqs[3] = Pseq(Array.geom( 6, 100, 1.4 ),inf).asStream;
q.durs[3] = Pseq([1.0,0.4],inf).asStream;
~start.value(1);
~stop.value(1);
~startcontrol.value(1);
~stopcontrol.value(1);
//q.subgroups[0].busMap( \freqmod, q.prescontrol1 );
(
q.updatepres.put( 0,
Routine{
loop {
q.subgroups[0].set(\freqmod, [2.0,0.8].asSpec.map( q.lid.sensordata[3] ) );
0.005.wait;
}
}
);
)
s.stopRecording;