From: Eugene Petkevich Date: Fri, 13 May 2022 10:22:10 +0000 (+0300) Subject: Show sample in a window X-Git-Url: https://git.zuelum.org/?a=commitdiff_plain;h=16b9861612255036d7d50c46cf0fb2a87013e16d;p=scprojects.git Show sample in a window --- diff --git a/sampler.scd b/sampler.scd index 87dbfe4..ccd5c77 100644 --- a/sampler.scd +++ b/sampler.scd @@ -40,11 +40,14 @@ \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; @@ -75,13 +78,25 @@ }, \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; diff --git a/test.scd b/test.scd index c4fc30b..1ba9b93 100644 --- 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|