(
~samplerFactory = {
+ var maxDur = 10.0;
var sampler = Environment[
\version -> "33.7.2.3",
- \buf -> Buffer.alloc(s, s.sampleRate * 10.0, 1),
+ \maxDur -> maxDur,
+ \buf -> Buffer.alloc(s, s.sampleRate * maxDur, 1),
\recsynthdef -> SynthDef(\samplerRecord, { |input, buf|
var sig;
sig = In.ar(input, 1);
}).add,
\playsynthdef -> SynthDef(\samplerPlay, { |out = 0, buf = 0, startPos = 0, duration = 0.01|
var sig, env;
- sig = PlayBuf.ar(1, buf, BufRateScale.ir(buf), startPos: startPos, doneAction: 2);
+ sig = PlayBuf.ar(1, buf, BufRateScale.ir(buf), startPos: startPos*BufSampleRate.ir(buf), doneAction: 2);
env = Env.new([0, 1, 1, 0], [0.01, duration-0.02, 0.01]);
sig = sig * EnvGen.ar(env, 1, doneAction: 2);
Out.ar(out, sig!2);
}).add,
\startRec -> { |zi|
+ zi.startPos = 0.0;
zi.recSynth = Synth(\samplerRecord, [\input, s.inputBus, \buf, zi.buf], addAction: \addToTail);
zi.endPos = s.sampleRate * 10;
zi.startTime = thisThread.seconds;
playSynth = Synth(\samplerPlay,
[\out, 0, \buf, zi.buf, \startPos, zi.startPos, \duration, zi.duration],
addAction: \addToHead);
+ },
+ \makeSynthEvent -> { |zi|
+ (
+ instrument: \samplerPlay,
+ buf: zi.buf,
+ startPos: zi.startPos,
+ duration: zi.duration,
+ )
+ },
+ \shiftPos -> { |zi, delta|
+ var endPos = zi.startPos + zi.duration;
+ zi.startPos = (zi.startPos + delta).clip(0, endPos);
+ zi.duration = endPos - zi.startPos;
}
];
-
sampler.know = true;
+
sampler;
};
)
+(
+~push = ~pushFactory.value;
+~se = ~samplerFactory.value;
+)
+
+~se.makeSynthEvent
+
+(
+~push.recDown = { |zi|
+ ~se.startRec();
+};
+~push.recUp = { |zi|
+ ~se.stopRec();
+};
+~push.playDown = { |zi|
+ ~se.playSample();
+};
+~push.hcPushTurnL = { |zi, delta|
+ var mul = 0.01;
+ ~se.shiftPos(delta * mul);
+ ~se.startPos.postln;
+ ~se.duration.postln;
+};
+)
+
+//=============================================================================
+
+// sampler test
+
~se = ~samplerFactory.value;
~se.startRec();
}.fork();
)
-~push.pushOut
+~push.pushOut.sysex(Int8Array[0xF0, 0x00, 0x21, 0x1D, 0x01, 0x01, 0x08, 0x00, 0x00, 0xF7]);
m = MIDIClockOut("Ableton Push", "Ableton Push MIDI 2");
m.port