multigrain/granulator.scd

99 lines
2.2 KiB
Plaintext

(
~modes = [
[ "saw", \pos_saw ],
[ "reverse", \pos_reverse ],
[ "sine", \pos_sine ],
[ "step", \pos_step ],
];
~outputDir = Platform.recordingsDir +/+ "GrainBuffers";
~grainsb = Bus.audio(s, 2);
~granulators = Array.new(4);
~grainmodes = [ 0, 0, 0, 0 ]; // keep track of mode so don't swap if not needed
~speeds = [ 1, 1, 1, 1 ]; // hacky speed quantisation
~posb = Array.new(4);
~rectriggerb = Array.new(4);
~patterns = [ nil, nil, nil, nil ];
~players = [ nil, nil, nil, nil ];
~loopsynths = [ nil, nil, nil, nil ];
// create the control busses
(0..3).do({
~posb.add(Bus.control(s, 1));
~rectriggerb.add(Bus.control(s, 1));
});
// start the granulators
(0..3).do({ |i|
var pb = ~posb[i], rtb = ~rectriggerb[i];
~granulators.add(Granulator.new(~buflen, ~infxb, ~grainsb, pb, rtb));
});
// set up the Patterns which drive the position synths
// (0..3).do({ |i|
// ~patterns.add(~makePattern.value(i, 0, ~speeds[i]));
// });
//
// (0..3).do({|i|
// ~players.add(~patterns[i].play(~tc, quant: ~beatsperbar))
// });
~setmode = {
arg track, mode;
~grainmodes[track] = mode;
if(~players[track].isNil.not,{
~players[track].stop;
~patterns[track].free;
});
~patterns[track] = ~makePattern.value(track, mode, ~speeds[track]);
~players[track] = ~patterns[track].play(~tc, quant: ~beatsperbar);
};
~setspeed = {
arg track, speed;
if( ~speeds[track] != speed, {
~speeds[track] = speed;
~players[track].stop;
~patterns[track].free;
~patterns[track] = ~makePattern.value(track, ~grainmodes[track], ~speeds[track]);
~players[track] = ~patterns[track].play(~tc, quant: ~beatsperbar);
});
};
~makePattern = {
arg track, mode, speed;
var ptrig, ppos, synth = ~modes[mode][1];
// note: trigger is going off the base tempoclock, not the playback speed - I think this is
// the right thing to do but I'm not sure yet
ptrig = Pbind(
\instrument, \trigger,
\dur, ~beatsperbar,
\out, ~rectriggerb[track]
);
ppos = Pbind(
\instrument, synth,
\dur, ~beatsperbar / speed,
\length, ~buflen / speed,
\out, ~posb[track]
);
Ppar([ptrig, ppos]);
};
~dumpbuffers = { |prefix|
(0..3).do({|i|
var filename = ~outputDir +/+ prefix ++ 'buffer' ++ i.asString ++ '.aiff';
~granulators[i].buffer.write(filename);
});
}
)