Show sample in a window
authorEugene Petkevich <nasedil.genio.code@gmail.com>
Fri, 13 May 2022 10:22:10 +0000 (13:22 +0300)
committerEugene Petkevich <nasedil.genio.code@gmail.com>
Fri, 13 May 2022 10:22:10 +0000 (13:22 +0300)
sampler.scd
test.scd

index 87dbfe4..ccd5c77 100644 (file)
     \duration -> 0,
     \stopRec -> { |zi|
       "stopRec called".postln;
-      zi.duration = thisThread.seconds - zi.startTime;
+      zi.duration = min(thisThread.seconds - zi.startTime, 10);
       zi.recSynth.free;
       if (zi.pleiPich, {
         zi.pichSint.set(\gate, 0);
       });
+      zi.buf.loadToFloatArray(zi.startPos*zi.buf.sampleRate, zi.duration*zi.buf.sampleRate, action: { |array|
+        { zi.plotter.value = array; }.defer;
+      });
     },
     \playSample -> { |zi|
       "playSample called".postln;
     },
     \shiftPos -> { |zi, delta|
       var endPos = zi.startPos + zi.duration;
-      "shiftPos called".postln;
+      ("shiftPos called"++[delta, endPos, zi.startPos, zi.duration]).postln;
       zi.startPos = (zi.startPos + delta).clip(0, endPos);
       zi.duration = endPos - zi.startPos;
-    }
+      zi.buf.loadToFloatArray(zi.startPos*zi.buf.sampleRate, zi.duration*zi.buf.sampleRate, action: { |array|
+        if (array.size == 0, {array = [0]});
+        { zi.plotter.value = array; }.defer;
+      });
+    },
+    \window -> Window.new(
+      "Sampler",
+      Rect(Window.screenBounds.width-600,Window.screenBounds.height-180,500,100)
+    )
   ];
   sampler.know = true;
 
+  sampler.plotter = Plotter.new("sampler", Rect(0, 0, sampler.window.bounds.width, sampler.window.bounds.height), sampler.window);
+
+  sampler.window.front;
+
   "Сэмплер готов к использованию 😊".postln;
 
   sampler;
index c4fc30b..1ba9b93 100644 (file)
--- a/test.scd
+++ b/test.scd
@@ -3,6 +3,21 @@
 ~se = ~samplerFactory.value;
 ~pe = ~pedalFactory.value;
 )
+~se.window.front
+
+(
+~se.buf.loadToFloatArray(action: { |array|
+  {
+    ~data = array;
+    "loading done".postln;
+  }.defer;
+  ~se.window.front;
+});
+)
+
+~se.soundView.setData(~data, 1024, samplerate: ~se.buf.sampleRate);
+
+~se.soundView.data
 
 (\freq: 220).play;
 
@@ -12,7 +27,7 @@
 ~notes = Array.newClear(128);
 ~amps = Array.newClear(128);
 ~pe.suDown = { |zi|
-  ~se.startRec(true);
+  ~se.startRec(false);
 };
 ~pe.suUp = { |zi|
   ~se.stopRec();
@@ -41,7 +56,7 @@
   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);
+  //~notes[freq.cpsmidi.asInteger].set(\gate, 0);
   ~amps[freq.cpsmidi.asInteger] = 0;
 };
 ~push.padPressure = { |zi, row, col, vel|