Created
October 20, 2021 11:38
-
-
Save julianrubisch/2c54c8254b690c6c552977a21127e05a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BufferSoundFileView : SoundFileView { | |
var buffer; | |
*new { |parent, bounds, buffer| | |
^super.new.init(parent, bounds, buffer); | |
} | |
init { |parent, bounds, buffer| | |
buffer = buffer; | |
buffer.getToFloatArray(timeout: 30, action: { |samples| | |
{ | |
this.setData(samples); | |
this.refresh; | |
}.defer; | |
}); | |
} | |
} | |
Delegator { | |
var wrapped; | |
*new { |wrapped| | |
^super.newCopyArgs(wrapped); | |
} | |
respondsTo { |aSymbol| | |
^(super.respondsTo(aSymbol) || wrapped.respondsTo(aSymbol)); | |
} | |
doesNotUnderstand { |selector ... args| | |
if(wrapped.respondsTo(selector)) { | |
^wrapped.performList(selector, args); | |
}; | |
^this.superPerformList(\doesNotUnderstand, selector, args); | |
} | |
} | |
BufferViewDecorator : Delegator { | |
var view; | |
view { |parent| | |
view = BufferSoundFileView.new(parent, nil, wrapped); | |
^view; | |
} | |
} | |
BufferRecorderDecorator : Delegator { | |
var recSynth, <>recEnd; | |
*registerDefs { |server| | |
SynthDef(\bufferRec, { | |
|in=0, bufnum=0, rec=1| | |
var sig = SoundIn.ar(in), | |
stopTrig = (rec <= 0), | |
phase = Phasor.ar(0, 1, 0, BufFrames.kr(bufnum)); | |
BufWr.ar(sig, bufnum, phase); | |
SendReply.ar(K2A.ar(stopTrig), '/bufferRecEnded', [phase.poll, bufnum]); | |
FreeSelf.kr(stopTrig); | |
}).add; | |
// see https://scsynth.org/t/looper-with-a-variable-length/818/6 | |
OSCdef(\bufferRecEnded, { |msg| | |
// msg is ['/recEnded', nodeID, replyID, value0...] | |
// so the data point is msg[3] | |
var bufnum = msg[4].asInteger; | |
// var pattern_key = ('pattern_' ++ bufnum).asSymbol; | |
// ~rec_end[bufnum] = msg[3]; // save ending frame index | |
// if(Pbindef(pattern_key).isPlaying, { Pbindef(pattern_key, \end, ~rec_end[bufnum]) }) | |
// callback? | |
// server.cachedBufferAt(bufnum).recEnd = msg[3]; | |
}, '/bufferRecEnded', server.addr); | |
} | |
startRec { | |
recSynth = Synth(\bufferRec, [\bufnum, wrapped.bufnum]); | |
} | |
stopRec { | |
recSynth.set(\rec, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment