From 1d013f04af7a4ef26b631b4396dd74793b491c09 Mon Sep 17 00:00:00 2001 From: Eugene Petkevich Date: Wed, 8 Jun 2022 18:35:12 +0300 Subject: [PATCH] Cleanup code / Add connection for midi pads and midi sampler --- extensions/classes/midipush.sc | 7 + extensions/classes/midisynths.sc | 154 +++++++++- ...\201-\320\235\321\215\321\206\321\215.scd" | 54 ---- .../test.scd" | 274 +----------------- 4 files changed, 168 insertions(+), 321 deletions(-) delete mode 100644 "\320\245\321\215\320\267\320\270\321\204\321\203/33.7.3.2-\321\201-\320\235\321\215\321\206\321\215.scd" diff --git a/extensions/classes/midipush.sc b/extensions/classes/midipush.sc index 30f54df..eed33c9 100644 --- a/extensions/classes/midipush.sc +++ b/extensions/classes/midipush.sc @@ -396,4 +396,11 @@ MidiPush : MidiHandler { }); }); ) +*/ + +// TODO: try sysex again +/* + +~push.midiout.sysex(Int8Array[0xF0, 0x00, 0x21, 0x1D, 0x01, 0x01, 0x08, 0x00, 0x00, 0xF7]); + */ \ No newline at end of file diff --git a/extensions/classes/midisynths.sc b/extensions/classes/midisynths.sc index a55fe55..6eff326 100644 --- a/extensions/classes/midisynths.sc +++ b/extensions/classes/midisynths.sc @@ -11,7 +11,7 @@ KeySynth { bend = 0; notes = Array.newClear(128); group = group ?? {madeNewGroup = true; Group.new()}; - params = nil ? (); + params = params ? (); midihandler.key_{|d, v, n| var panParam=#[]; @@ -19,7 +19,7 @@ KeySynth { 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, @@ -45,6 +45,8 @@ KeySynth { if (madeNewGroup) { group.free; }; + midihandler.key = nil; + midihandler.bend = nil; } } @@ -63,4 +65,152 @@ KeySynth { ~m.free +*/ + +//============================================================================= +// connect synth to pads +PadSynth { + var synthName, <>bendRadius, <>panAcross, <>params, <>amp, <>group; + var 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 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 diff --git "a/\320\245\321\215\320\267\320\270\321\204\321\203/33.7.3.2-\321\201-\320\235\321\215\321\206\321\215.scd" "b/\320\245\321\215\320\267\320\270\321\204\321\203/33.7.3.2-\321\201-\320\235\321\215\321\206\321\215.scd" deleted file mode 100644 index 27a82ad..0000000 --- "a/\320\245\321\215\320\267\320\270\321\204\321\203/33.7.3.2-\321\201-\320\235\321\215\321\206\321\215.scd" +++ /dev/null @@ -1,54 +0,0 @@ -( -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 diff --git "a/\320\245\321\215\320\267\320\270\321\204\321\203/test.scd" "b/\320\245\321\215\320\267\320\270\321\204\321\203/test.scd" index 4d42332..4a9ebdd 100644 --- "a/\320\245\321\215\320\267\320\270\321\204\321\203/test.scd" +++ "b/\320\245\321\215\320\267\320\270\321\204\321\203/test.scd" @@ -4,6 +4,7 @@ ( ~kedi = MidiRemote25SL(); ~push = MidiPush(); +~peda = MidiPedals(); ) ( @@ -36,274 +37,17 @@ TempoClock.play({|beats, time, clock| //============================================================================= - -( -~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 -- 2.17.1