From e300b3842827dfeb46b366120699e76a6341b5e6 Mon Sep 17 00:00:00 2001 From: Eugene Petkevich Date: Sat, 30 Dec 2023 18:11:28 +0100 Subject: [PATCH] generalize sample synthdef creation --- library/samplers.scd | 45 +++++++++++++ startup.scd | 32 +++++++++ ...0\277\320\265\321\201\320\275\321\217.scd" | 67 +------------------ 3 files changed, 78 insertions(+), 66 deletions(-) create mode 100644 library/samplers.scd diff --git a/library/samplers.scd b/library/samplers.scd new file mode 100644 index 0000000..8356299 --- /dev/null +++ b/library/samplers.scd @@ -0,0 +1,45 @@ +// use ~makeSampleSynths from startup.scd + +( +// amplification coefficients for samples +~hahomo = ( + name: "Хахомо", + params: [( + name: \bu, + mul: 0.5, + ), ( + name: \me, + mul: 10, + ), ( + name: \mo, + mul: 6, + ), ( + name: \nu, + mul: 3, + ), ( + name: \da, + mul: 3, + ), ( + name: \do, + mul: 2, + ), ( + name: \tu, + mul: 5, + ), ( + name: \by, + mul: 1, + ), ( + name: \bo, + mul: 1.5, + ), ( + name: \be, + mul: 1.5, + ), ( + name: \ma, + mul: 1, + ), ( + name: \my, + mul: 1, + )]; +); +) \ No newline at end of file diff --git a/startup.scd b/startup.scd index ada1443..76d6880 100644 --- a/startup.scd +++ b/startup.scd @@ -77,6 +77,38 @@ c = ( media: "~/gart/media" ); +// ==== Samplers setup + +~makeSampleSynth = { arg name, sampleArray, sampleIndex, ampMultiplier; + SynthDef(name, {|out=0, rate=1, amp=1, pan=0| + var sig; + var buf = sampleArray[sampleIndex]; + sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf), doneAction: 2); + sig = sig * amp * ampMultiplier; + sig = Balance2.ar(sig[0], sig[1], pan); + Out.ar(out, sig); + }).add; +}; + +~loadSamples = { arg name, parentPath=nil; + var samples = Array(); + var samplesPath = PathName(parentPath?(c.media) +/+ name); + samplesPath.entries.do({ + arg path; + samples = samples.add(Buffer.read(s, path.fullPath)); + }); + samples +}; + +~makeSampleSynths = { arg name, params, parentPath=nil; + var samples = ~loadSamples.(name, parentPath); + params.do{|p, i| + ~makeSampleSynth.(p.name, samples, i, p.mul).value; + }; + + params.collect{|i| i.name}; // return instrument names +}; + // ==== Midi setup ~midiup = { MIDIClient.init; diff --git "a/\320\232\320\260/\320\232\320\260\320\274\321\213\321\200-\320\245\321\213\320\277\321\221\320\264\321\221/\320\245\321\213\320\277\321\221\320\264\321\221-\320\277\320\265\321\201\320\275\321\217.scd" "b/\320\232\320\260/\320\232\320\260\320\274\321\213\321\200-\320\245\321\213\320\277\321\221\320\264\321\221/\320\245\321\213\320\277\321\221\320\264\321\221-\320\277\320\265\321\201\320\275\321\217.scd" index d368727..f32bc57 100644 --- "a/\320\232\320\260/\320\232\320\260\320\274\321\213\321\200-\320\245\321\213\320\277\321\221\320\264\321\221/\320\245\321\213\320\277\321\221\320\264\321\221-\320\277\320\265\321\201\320\275\321\217.scd" +++ "b/\320\232\320\260/\320\232\320\260\320\274\321\213\321\200-\320\245\321\213\320\277\321\221\320\264\321\221/\320\245\321\213\320\277\321\221\320\264\321\221-\320\277\320\265\321\201\320\275\321\217.scd" @@ -2,72 +2,7 @@ // instrument -( -~makeSampleSynth = { arg name, sampleArray, sampleIndex, ampMultiplier; - SynthDef(name, {|out=0, rate=1, amp=1, pan=0| - var sig; - var buf = sampleArray[sampleIndex]; - sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf), doneAction: 2); - sig = sig * amp * ampMultiplier; - sig = Balance2.ar(sig[0], sig[1], pan); - Out.ar(out, sig); - }).add; -}; -) - -( -~hahomoSamples = Array(); -~hahomoPath = PathName(c.media +/+ "Хахомо"); -~hahomoPath.entries.do({ - arg path; - ~hahomoSamples = ~hahomoSamples.add(Buffer.read(s, path.fullPath)); -}); -) -( -// amplification coefficients for samples -~hahomo = [( - name: \bu, - mul: 0.5, -), ( - name: \me, - mul: 10, -), ( - name: \mo, - mul: 6, -), ( - name: \nu, - mul: 3, -), ( - name: \da, - mul: 3, -), ( - name: \do, - mul: 2, -), ( - name: \tu, - mul: 5, -), ( - name: \by, - mul: 1, -), ( - name: \bo, - mul: 1.5, -), ( - name: \be, - mul: 1.5, -), ( - name: \ma, - mul: 1, -), ( - name: \my, - mul: 1, -)]; -~hahomoInstruments = ~hahomo.collect{|i| i.name}; - -~hahomo.do{|p, i| - ~makeSampleSynth.(p.name, ~hahomoSamples, i, p.mul).value; -} -) +~hahomoInstruments = ~makeSampleSynths.(~hahomo.name, ~hahomo.params); // test -- 2.17.1