Created
November 27, 2018 01:11
-
-
Save caseyanderson/e02c844ec3a7390ccb8143c413a5491d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // setup buffer and busses | |
| ( | |
| var thePath, bufList; | |
| thePath = "/Users/cta/Desktop/haiti_baptism.wav"; | |
| ~buffer = Buffer.readChannel(s, thePath, channels: 0 ); // this is a hack to eliminate accidental stereo buffers | |
| ~vol = Bus.control(s, 1).set(0.0); | |
| ~dur = Bus.control(s, 1).set(1); | |
| ) | |
| // the SynthDef // | |
| ( | |
| SynthDef(\play, { | amp = 0.0, buf, len, start = 0, trig = 1 | | |
| var env, sig; | |
| env = EnvGen.kr( Env.linen( 0.0, len, 0.01), trig, doneAction: 2 ); | |
| sig = PlayBuf.ar(1, buf, BufRateScale.kr( buf ), startPos: (Rand(0.0, 1.0) * BufFrames.kr(buf)), loop: 1) * env; | |
| Out.ar(0, sig * amp); | |
| }).add; | |
| ) | |
| // the GUI // | |
| ( | |
| var pad = 10; | |
| w = Window.new("chop!", Rect(130, 130, 220, 300)); | |
| a = Button(w, Rect(pad, pad, 100, 100)) | |
| .states_([ | |
| ["",Color.black, Color.gray], | |
| ]) | |
| .action_({arg butt; | |
| "fire".postln; | |
| Synth( \play, [ \amp, ~vol.asMap, \trig, 1, \buf, ~buffer, \len, ~dur.asMap ]); | |
| }); | |
| // volume | |
| b = Slider(w, Rect( 100 + pad, pad, 50, 150 )) | |
| .action_({ | |
| c.value_(b.value); | |
| ~vol.set(b.value); | |
| }); | |
| c = NumberBox(w, Rect(100 + pad, 150 + pad, 50, 25)); | |
| // playback dur | |
| d = Slider(w, Rect( 150 + pad, pad, 50, 150 )) | |
| .action_({ | |
| var val = d.value.linlin(0.0, 1.0, 0.025, 10.0); | |
| e.value_(val); | |
| ~dur.set(val); | |
| }); | |
| e = NumberBox(w, Rect(150 + pad, 150 + pad, 50, 25)); | |
| w.front; | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment