generalize sample synthdef creation
authorEugene Petkevich <nasedil.genio.code@gmail.com>
Sat, 30 Dec 2023 17:11:28 +0000 (18:11 +0100)
committerEugene Petkevich <nasedil.genio.code@gmail.com>
Sat, 30 Dec 2023 17:11:28 +0000 (18:11 +0100)
library/samplers.scd [new file with mode: 0644]
startup.scd
Ка/Камыр-Хыпёдё/Хыпёдё-песня.scd

diff --git a/library/samplers.scd b/library/samplers.scd
new file mode 100644 (file)
index 0000000..8356299
--- /dev/null
@@ -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
index ada1443..76d6880 100644 (file)
@@ -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;
index d368727..f32bc57 100644 (file)
@@ -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