summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--live_sampler.ck141
1 files changed, 93 insertions, 48 deletions
diff --git a/live_sampler.ck b/live_sampler.ck
index 114f7e8..765ff66 100644
--- a/live_sampler.ck
+++ b/live_sampler.ck
@@ -2,86 +2,131 @@
* Live (and stock) sampler based on LiSaX (LiSa)
* in-port: Bus.channels[0]
*/
+class Bank extends Chubgraph {
+ /*
+ * NOTE: for multichannel LiSa it's more efficient to only chuck
+ * channel 0: LiSaX lisa.chan(0) => PitShift pitch
+ */
+ inlet => LiSaX lisa => PitShift pitch => outlet;
+
+ /* default buffer size, if no stock sample is read in */
+ 30::second => lisa.duration;
+ /* loop start, end and recording end are initialized after allocation! */
-/* default buffer size (for banks without stock sample) */
-30::second => dur default_size;
+ /* setting this to 1 if we only need one voice improves performance */
+ 1 => lisa.maxVoices;
-LiSaX lisa[7];
-Gain amp => Bus.out_left;
-amp => Bus.out_right;
+ .8 => pitch.mix;
+ 1 => pitch.shift;
-fun void
-read(int i, string file)
-{
- chout <= "Loading \"" <= file <= "\" into sample bank " <= i <= "... ";
- chout.flush();
- file => lisa[i].read;
- chout <= "Done!" <= IO.newline();
+ lisa.rate() => float lisaRate;
+ 0::samp => dur lisaLoopEnd; /* empty bank */
+
+ fun void
+ load(int i, string file)
+ {
+ chout <= "Loading \"" <= file <= "\" into sample bank " <= i <= "... ";
+ chout.flush();
+
+ file => lisa.read;
+ lisa.loopEnd() => lisaLoopEnd;
+
+ chout <= "Done!" <= IO.newline();
+ }
}
+/* patch */
+Bank banks[7];
+Gain amp => Bus.out_left; amp => Bus.out_right;
+
+for (0 => int i; i < banks.cap(); i++)
+ Bus.channels[0] => banks[i] => amp;
+
/* stock samples */
-read(0, "samples/stier_loop_stereo.wav");
-
-for (0 => int i; i < lisa.cap(); i++) {
- if (lisa[i].duration() == 0::samp) {
- /* empty sample bank */
- default_size => lisa[i].duration;
- /* loop start, end and recording end are initialized! */
- 0::samp => lisa[i].loopEnd;
- }
+banks[0].load(0, "samples/stier_loop_stereo.wav");
- /* setting this to 1 if we only need one voice improves performance */
- 1 => lisa[i].maxVoices;
+banks[0] @=> Bank @currentBank;
- /* patch */
- /*
- * NOTE: for multichannel LiSa it's more efficient to only chuck
- * channel 0: lisa[i].chan(0) => amp;
- */
- Bus.channels[0] => lisa[i] => amp;
-}
+/*
+ * Sampler configuration: Gamepad
+ */
+fun void
+rumble_loop()
+{
+ RumbleEvent rumblev;
+
+ false => int rep;
+ 500::ms => dur maxLoopDur => dur loopDur;
-lisa[0] @=> LiSaX @currentSample;
+ while (rumblev => now) {
+ if ("axisButtonLeft" => rumblev.isControl) {
+ rumblev.getDur(maxLoopDur, ms) => loopDur;
+ } else if ("joystickRightX" => rumblev.isControl) {
+ rumblev.getFloat(-1, 1) + currentBank.lisaRate =>
+ currentBank.lisa.rate;
+ } else if ("joystickRightY" => rumblev.isControl) {
+ rumblev.getFloat(2, 0) => currentBank.pitch.shift;
+ } else if ("buttonLeft" => rumblev.isControl) {
+ if (rumblev.getBool() => rep) {
+ currentBank.lisa.playPos() => currentBank.lisa.loopEnd;
+ } else {
+ 0::samp => currentBank.lisa.loopStart;
+ currentBank.lisaLoopEnd => currentBank.lisa.loopEnd;
+ }
+ }
+
+ if (rep)
+ currentBank.lisa.loopEnd() - loopDur => currentBank.lisa.loopStart;
+ }
+ /* not reached */
+}
+spork ~ rumble_loop();
/*
- * Sampler configuration
+ * Sampler configuration: MIDI
*/
"primary" => NanoEvent.init @=> NanoEvent @nanoev;
while (nanoev => now) {
if ("recordToggle" => nanoev.isControl) {
- if (currentSample.loop()) {
+ if (currentBank.lisa.loop()) {
/* loop recording */
- nanoev.getBool() => currentSample.loopRec;
- if (currentSample.loopEnd() == 0::samp &&
+ nanoev.getBool() => currentBank.lisa.loopRec;
+ if (currentBank.lisaLoopEnd == 0::samp &&
!nanoev.getBool())
- currentSample.recPos() => currentSample.loopEndRec
- => currentSample.loopEnd;
- } else if (!(nanoev.getBool() => currentSample.record)) {
+ currentBank.lisa.recPos() => currentBank.lisaLoopEnd
+ => currentBank.lisa.loopEndRec
+ => currentBank.lisa.loopEnd;
+ } else if (!(nanoev.getBool() => currentBank.lisa.record)) {
/* normal recording (overwrite buffer) */
- currentSample.recPos() => currentSample.loopEnd
- => currentSample.loopEndRec;
+ currentBank.lisa.recPos() => currentBank.lisaLoopEnd
+ => currentBank.lisa.loopEnd
+ => currentBank.lisa.loopEndRec;
}
if (nanoev.getBool())
- 0::samp => currentSample.recPos;
+ 0::samp => currentBank.lisa.recPos;
} else if ("playButton" => nanoev.isControl) {
if (nanoev.getBool()) {
- 0::samp => currentSample.playPos;
- true => currentSample.play;
+ 0::samp => currentBank.lisa.playPos;
+ true => currentBank.lisa.play;
}
} else if ("stopButton" => nanoev.isControl) {
if (nanoev.getBool())
- false => currentSample.play;
+ false => currentBank.lisa.play;
} else if ("loopToggle" => nanoev.isControl) {
/* toggles loop playing AND loop recording */
- nanoev.getBool() => currentSample.loop;
+ nanoev.getBool() => currentBank.lisa.loop;
} else if ("samplerVolumeKnob" => nanoev.isControl) {
- nanoev.getFloat(10) => currentSample.gain;
+ nanoev.getFloat(1) => currentBank.gain;
} else if ("samplerPitchSlider" => nanoev.isControl) {
- nanoev.getFloat(-2, 2) => currentSample.rate;
+ nanoev.getFloat(-2, 2) => currentBank.lisaRate
+ => currentBank.lisa.rate;
} else if (nanoev.CCId >= 23 && nanoev.CCId <= 29) {
/* chooseSampleButton#CCId pressed */
- lisa[nanoev.CCId - 23] @=> currentSample;
+ nanoev.CCId - 23 => int id;
+ banks[id] @=> currentBank;
+
+ chout <= "Sample bank #" <= id <= " selected." <= IO.newline();
}
}