});
});
)
+*/
+
+// TODO: try sysex again
+/*
+
+~push.midiout.sysex(Int8Array[0xF0, 0x00, 0x21, 0x1D, 0x01, 0x01, 0x08, 0x00, 0x00, 0xF7]);
+
*/
\ No newline at end of file
bend = 0;
notes = Array.newClear(128);
group = group ?? {madeNewGroup = true; Group.new()};
- params = nil ? ();
+ params = params ? ();
midihandler.key_{|d, v, n|
var panParam=#[];
if (panAcross) {
panParam = [\pan, n.bilin(63, 0, 127, 0, -0.7, 0.7)];
};
- notes[n] = Synth(synthName, params.asPairs++[
+ notes[n] = Synth(synthName, params.value.asPairs++[
\gate, 1,
\freq, n.midicps,
\amp, amp * v,
if (madeNewGroup) {
group.free;
};
+ midihandler.key = nil;
+ midihandler.bend = nil;
}
}
~m.free
+*/
+
+//=============================================================================
+// connect synth to pads
+PadSynth {
+ var <midihandler, <>synthName, <>bendRadius, <>panAcross, <>params, <>amp, <>group;
+ var <bend, <notes, <amps, madeNewGroup;
+
+ *new {|midihandler, synthName=\default, bendRadius=1, panAcross=false, params=nil, amp=1.0, group=nil|
+ ^super.newCopyArgs(midihandler, synthName, bendRadius, panAcross, params, amp, group).allInit;
+ }
+
+ allInit {
+ bend = 0;
+ notes = Array.newClear(128);
+ amps = Array.fill(128, 0);
+ group = group ?? {madeNewGroup = true; Group.new()};
+ params = params ? ();
+
+ midihandler.pad_{|d, v, col, row|
+ var freq, midinote;
+ var panParam=#[];
+ freq = Scale.major.degreeToFreq(col, 0.midicps, row+1);
+ midinote = freq.cpsmidi.asInteger;
+ if (d) {
+ if (panAcross) {
+ panParam = [\pan, midinote.bilin(63, 0, 127, 0, -0.7, 0.7)];
+ };
+ midihandler.ledPad(row, col, 2, 1, 1);
+ notes[midinote] = Synth(synthName, params.value.asPairs++[
+ \gate, 1,
+ \freq, freq,
+ \amp, amp * v,
+ ]++panParam, group);
+ amps[midinote] = amp * v;
+ } {
+ midihandler.ledPad(row, col, 0, 1, 1);
+ //~notes[midinote].set(\gate, 0);
+ //~notes[midinote] = nil;
+ amps[midinote] = 0;
+ }
+ };
+
+ midihandler.press_{|v, col, row|
+ var freq, vel, midinote;
+ freq = Scale.major.degreeToFreq(col, 0.midicps, row+1);
+ midinote = freq.cpsmidi.asInteger;
+ vel = v * amp;
+ if (vel > amps[midinote], {
+ notes[freq.cpsmidi.asInteger].get(\amp, { |curAmp|
+ var maxRatio = 1.5;
+ if ((vel/curAmp) > maxRatio, { vel = curAmp * maxRatio; });
+ notes[midinote].set(\amp, vel);
+ });
+ });
+ };
+
+
+
+ midihandler.bend_{|v|
+ bend = v * bendRadius;
+ notes.do{|item, i|
+ item.set(\freq, (i+bend).midicps);
+ };
+ };
+ }
+
+ free {
+ notes.do{|item|
+ item.free;
+ };
+ if (madeNewGroup) {
+ group.free;
+ };
+ midihandler.key = nil;
+ midihandler.bend = nil;
+ }
+}
+
+// example
+/*
+
+~kedi = MidiRemote25SL();
+~m = KeySynth(~kedi, \dyti, amp: 0.2, panAcross: true);
+(
+~m.params[\modAmp] = 0.0;
+~kedi.press_{|v|
+ ~m.group.set(\modAmp, v);
+ ~m.params[\modAmp] = v;
+};
+)
+
+~m.free
+
+*/
+
+//=============================================================================
+
+// connect sampler to pedals + push
+MidiSampler {
+ var <push, <pedals, <sampler, <>tuneSound;
+
+ *new {|push, pedals, sampler, tuneSound=true|
+ ^super.newCopyArgs(push, pedals, sampler, tuneSound).allInit;
+ }
+
+ allInit {
+ pedals.sustain_{|d|
+ if (d) {
+ sampler.startRec(tuneSound);
+ } {
+ sampler.stopRec;
+ };
+ };
+
+ push.but.play = {|d|
+ if (d) {
+ sampler.playSample;
+ } {
+ sampler.stopPlay;
+ };
+ };
+
+ push.rotRight_{|d|
+ var mul = 0.01;
+ sampler.shiftPos(d * mul);
+ };
+ }
+
+ free {
+ pedals.sustain = nil;
+ push.but.play = nil;
+ push.rotRight = nil;
+ }
+}
+
+// Examples
+
+/*
+(
+~same = Sampler();
+~kedi = MidiRemote25SL();
+~push = MidiPush();
+~peda = MidiPedals();
+~samtrig = MidiSampler(~push, ~peda, ~same, false);
+~keys = KeySynth(~kedi, ~same.synthdefName, 1, true, {~same.makeSynthArgs});
+~pads = PadSynth(~push, ~same.synthdefName, 1, true, {~same.makeSynthArgs});
+)
*/
\ No newline at end of file
+++ /dev/null
-(
-Pdef(\daki, ~se.makeSynthBind <> Pbind(
- \dur, Pwrand([
- Pseq(1!4, 1),
- Pseq(2!2, 1),
- Pseq((4/3)!3, 1),
- ], [5, 2, 1].normalizeSum, inf),
- \octave, [4, 5],
- \note, Pxrand([0, 4, 9, 7, 2.5], inf),
- \db, -5,
-)).quant_(4).stop;
-)
-
-(
-Pdef(\niru, ~se.makeSynthBind <> Pbind(
- \dur, 1/2 * Pwrand([
- Pseq(1!4, 1),
- Pseq(2!2, 1),
- Pseq((4/3)!3, 1),
- ], [5, 2, 1].normalizeSum, inf),
- \octave, [2, 3],
- \note, Pxrand([0, 4, 9, 7], inf),
- \db, -10,
-)).quant_(4).stop;
-)
-
-(
-Pdef(\bagi, Pbind(
- \instrument, \dire,
- \dur, 1/4 * Pwrand([
- Pseq(1!4, 1),
- Pseq(2!2, 1),
- Pseq((4/3)!3, 1),
- ], [5, 2, 1].normalizeSum, inf),
- \octave, [2, 3],
- \note, Pxrand([0, 4, 9, 7], inf),
- \db, -20,
- \legato, 2,
-)).quant_(4).stop;
-)
-
-TempoClock.tempo = 140 / 60;
-
-(
-SynthDef(\dire, { |amp=1, out=0, freq=440, gate=1|
- var sig, modFreq, env;
- modFreq = SinOsc.ar(3000, mul: freq/4, add: freq);
- sig = Pulse.ar(modFreq);
- env = EnvGen.ar(Env.adsr(), gate, doneAction: 2);
- sig = sig * env;
- sig = Pan2.ar(sig, Rand(-0.5, 0.5));
- Out.ar(out, sig * amp);
-}).add;
-)
\ No newline at end of file
(
~kedi = MidiRemote25SL();
~push = MidiPush();
+~peda = MidiPedals();
)
(
//=============================================================================
-
-(
-~push = ~pushFactory.value;
-~se = Sampler(\qaxi);
-~pe = ~pedalFactory.value;
-)
-
-~se.avgSize = 1;
-~se.sampDiv = 50;
-
-~se.plotter.domainSpecs_([0, 1, \lin, 0, 0, "se"].asSpec;).refresh;
-a = ~se.plotter.value;
-b = a[..a.size-5].collect {|item, index|
- item+a[index+1]+a[index+6];
-};
-~se.plotter.value=b;
-a = a.resamp1(500);
-
-(
-~se.buf.loadToFloatArray(action: { |array|
- {
- ~data = array;
- "loading done".postln;
- }.defer;
- ~se.window.front;
-});
-)
-
-~se.plotter.specs = \bipolar.asSpec;
-
-~se.soundView.setData(~data, 1024, samplerate: ~se.buf.sampleRate);
-~se.soundView.data.
-
-(\freq: 220).play;
-
-~se.makeSynthEvent
-~se.makeSynthArgs
-
-
-(
-~notes = Array.newClear(128);
-~amps = Array.newClear(128);
-~pe.suDown = { |zi|
- ~se.startRec(false);
-};
-~pe.suUp = { |zi|
- ~se.stopRec;
-};
-~push.playDown = { |zi|
- ~se.playSample;
-};
-~push.playUp = { |zi|
- ~se.stopPlay;
-};
-~push.hcPushTurnL = { |zi, delta|
- var mul = 0.01;
- ~se.shiftPos(delta * mul);
- ~se.startPos.postln;
- ~se.duration.postln;
-};
-~push.padDown = { |zi, row, col, vel|
- var freq;
- vel = vel * 5;
- ~push.padLight(row, col, 2, 1, false, 0);
- freq = Scale.major.degreeToFreq(col, 0.midicps, row+1);
- ~notes[freq.cpsmidi.asInteger] = Synth(~se.synthdefName, ~se.makeSynthArgs++[\freq, freq, \amp, vel]);
- ~amps[freq.cpsmidi.asInteger] = vel;
- ("down "++vel).postln;
-};
-~push.padUp = { |zi, row, col, vel|
- var freq;
- ~push.padLight(row, col, 0, 0, false, 1);
- freq = Scale.major.degreeToFreq(col, 0.midicps, row+1);
- //~notes[freq.cpsmidi.asInteger].set(\gate, 0);
- ~amps[freq.cpsmidi.asInteger] = 0;
-};
-~push.padPressure = { |zi, row, col, vel|
- var freq;
- vel = vel * 5;
- //~push.padLight(row, col, 0, 0, false, 1);
- freq = Scale.major.degreeToFreq(col, 0.midicps, row+1);
- if (vel > ~amps[freq.cpsmidi.asInteger], {
- ~notes[freq.cpsmidi.asInteger].get(\amp, { |amp|
- var maxRatio = 1.5;
- ("initial "++vel).postln;
- if ((vel/amp) > maxRatio, { vel = amp * maxRatio; });
- ~notes[freq.cpsmidi.asInteger].set(\amp, vel*5);
- ("new "++vel).postln;
- });
- });
- ("pres "++vel).postln;
-};
-)
-
-//=============================================================================
-
-// sampler test
-
-~se = ~samplerFactory.value;
-
-~se.startRec();
-~se.stopRec();
-
-~se.buf.plot;
-~se.buf.getToFloatArray(wait:0.01, action: {arg array; a = array; { a[0..100].plot }.defer; "done".postln });
-
-~se.playSample();
-~se.duration = 2.5;
-
-(
-SynthDef(\test, { |amp = 1.0|
- Out.ar(0, SoundIn.ar(1!2, amp.lag(0.01)));
-}).add;
-)
-
-a = Synth(\test);
-a.free;
-
-(
-MIDIdef.cc(\pollcc, { |...args|
- //"cc".postln;
- //args.postln;
-});
-
-MIDIdef.noteOn(\pollnoteon, { |...args|
- "noteon".postln;
- args.postln;
-});
-)
-
-(
-MIDIdef.cc(\tafe, { |...args|
- var amp = args[0].linlin(0, 127, 0.1, 20);
- a.set(\amp, amp);
- amp.postln;
-}, 1);
-)
-
-/// push test
-
-~push = ~pushFactory.value;
-
-(
-~color = 64;
-8.do({|i|
- 8.do({|j|
- ~push.pushOut.noteOn(0, 36+(i*8)+j, ~color);
- ~color = ~color + 1;
- });
-});
-)
-
-~push.hcPushKeyPressure.valueArray([1, 2, 3, 4]);
-~push.hcPushKeyOn.valueArray([1, 2, 3, 4]);
-
-(
-MIDIdef.cc(\testcc, {|...args|
- (["cc"] ++ args).postln;
-});
-MIDIdef.noteOn(\testnoteon, {|...args|
- (["note on"] ++ args).postln;
-});
-MIDIdef.noteOff(\testnoteoff, {|...args|
- (["note off"] ++ args).postln;
-});
-MIDIdef.touch(\testtouch, {|...args|
- (["touch"] ++ args).postln;
-});
-MIDIdef.polytouch(\testpolytouch, {|...args|
- (["polytouch"] ++ args).postln;
-});
-MIDIdef.bend(\testbend, {|...args|
- (["bend"] ++ args).postln;
-});
-MIDIdef.sysex(\testsysex, {|...args|
- (["sysex"] ++ args).postln;
-});
-)
-
-MIDIdef.freeAll;
-
-(
-(0..127).do({|i|
- ~push.pushOut.noteOn(15, i, 4);
- //~push.pushOut.control(12, i, 3.choose);
-});
-)
-
-(
-~col = 38;
-(0..127).do({|i|
- ~push.pushOut.noteOn(0, i, ~col);
- ~push.pushOut.control(0, i, ~col);
-});
-)
-
-~push = ~pushFactory.value;
-~col = 0;
-
-(
-~push.hcPushTurnS = { |zi, delta|
- ~col = (~col + delta).clip(0, 127);
- ~col.postln;
- (0..127).do({|i|
- ~push.pushOut.noteOn(13, i, ~col);
- ~push.pushOut.control(0, i, ~col);
- });
-};
-)
-
(
-{
- ~tempo = 40;
- ~push.pushOut.start;
- 5.do({
- 24.do({
- ~push.pushOut.midiClock;
- (60/~tempo/24).wait;
- });
- });
- ~push.pushOut.stop;
-}.fork();
-)
-
-~push.pushOut.sysex(Int8Array[0xF0, 0x00, 0x21, 0x1D, 0x01, 0x01, 0x08, 0x00, 0x00, 0xF7]);
-
-m = MIDIClockOut("Ableton Push", "Ableton Push MIDI 2");
-m.port
-Tempo.bpm = 300;
-
-m.stop
-
-Tempo.default.bpm = 1;
-
-~pushOut = nil;
-
-(
-try {
- ~pushOut = MIDIOut.newByName("Ableton Push", "Ableton Push MIDI 2").latency_(0);
-} {
- ~pushOut = MIDIOut.newByName("Ableton Push", "User Port").latency_(0);
-};
-)
-
-// test exception problem
-
-(
-~factory = {
- var ret;
-try { Exception.new().throw; ret = 1; } { ret = 2 };
- ret;
-};
-)
-
-~test = ~factory.value;
-
-~push.setTempo(1);
-
-(
-~caller = Environment[
- \func -> { "test".postln; }
-];
-~caller.know = true;
+~same = Sampler();
+~kedi = MidiRemote25SL();
+~push = MidiPush();
+~peda = MidiPedals();
+~samtrig = MidiSampler(~push, ~peda, ~same, false);
+~keys = KeySynth(~kedi, ~same.synthdefName, 1, true, {~same.makeSynthArgs});
+~pads = PadSynth(~push, ~same.synthdefName, 1, true, {~same.makeSynthArgs});
)
-~caller.func
-
-~se.maxDur
+~keys.amp = 3;
//=========================== scale experiments