From 46b91da9602d9e918cb1277fa96379e0bed1af9c Mon Sep 17 00:00:00 2001 From: Eugene Petkevich Date: Thu, 12 May 2022 22:43:41 +0300 Subject: [PATCH] Add pedal support / start sampler with pedal / add pitch guide to sampler --- pedal-control.scd | 76 +++++++++++++++++++++++++++++++++++++++++++++++ sampler.scd | 11 ++++++- test.scd | 17 ++++------- 3 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 pedal-control.scd diff --git a/pedal-control.scd b/pedal-control.scd new file mode 100644 index 0000000..1a868f0 --- /dev/null +++ b/pedal-control.scd @@ -0,0 +1,76 @@ +// MIDI pedals handler +// by Eugene Zuelum + +( +~pedalFactory = { + var pedal = Environment[ + \version -> "33.7.3.4" + ]; + + pedal.know = true; + + // Sustain pedal on/off + MIDIdef.cc(\midiPedalSustain, { |...args| + if (args[0] != 0, { + pedal.suDown(*args); + }, { + pedal.suUp(*args); + }); + }, + 65, 3); + // M-Audio Exp-M pedal (values range from 0 to 118 only) + MIDIdef.cc(\midiPedalExpression, { |...args| + var normed; + // m-audio + normed = args[0].linlin(0, 118, 0, 1); + pedal.xePres(normed, *args); + }, + 64, 3); + + pedal.freeDefs = { |zi| + MIDIdef(\midiPedalSustain).free; + MIDIdef(\midiPedalExpression).free; + }; + + "Нычосё и Щюҙуԉы готовы к использованию 😊".postln; + + pedal; +}; +) + +//============================================================================= Testing + +// Test incoming MIDI messages +/* +( +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; +}); +) +*/ + +// Test library +/* +~pe = ~pedalFactory.value; +~pe.suUp = {"up".postln}; +~pe.suDown = {"down".postln}; +~pe.xePres = {|zi, val| val.postln}; +*/ diff --git a/sampler.scd b/sampler.scd index ae5b7d2..c341a08 100644 --- a/sampler.scd +++ b/sampler.scd @@ -23,12 +23,16 @@ sig = sig * amp; Out.ar(out, sig!2); }).add, - \startRec -> { |zi| + \startRec -> { |zi, pleiPich=false| "startRec called".postln; 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; + zi.pleiPich = pleiPich; + if (pleiPich, { + zi.pichSint = Synth(\default, [freq: 220]); + }); }, \startPos -> 0, \duration -> 0, @@ -36,6 +40,9 @@ "stopRec called".postln; zi.duration = thisThread.seconds - zi.startTime; zi.recSynth.free; + if (zi.pleiPich, { + zi.pichSint.set(\gate, 0); + }); }, \playSample -> { |zi| var playSynth; @@ -70,6 +77,8 @@ ]; sampler.know = true; + "Сэмплер готов к использованию 😊".postln; + sampler; }; ) diff --git a/test.scd b/test.scd index 3ed9a42..3a7353c 100644 --- a/test.scd +++ b/test.scd @@ -1,26 +1,19 @@ ( ~push = ~pushFactory.value; ~se = ~samplerFactory.value; +~pe = ~pedalFactory.value; ) (\freq: 220).play; ~se.makeSynthEvent ~se.makeSynthArgs -~recording = false; - ( -~push.recDown = { |zi| - if (~recording, { - ~se.stopRec(); - ~recording = false; - }, { - ~se.startRec(); - ~recording = true; - }); +~pe.suDown = { |zi| + ~se.startRec(true); }; -~push.recUp = { |zi| - //~se.stopRec(); +~pe.suUp = { |zi| + ~se.stopRec(); }; ~push.playDown = { |zi| ~se.playSample(); -- 2.17.1