// title: KickandBass // author: Scott L Simon // description: // Another small GUI performance module. Builds on a 303 from the helpfiles with a few changes. // code: //evaluate this block first 1. You need to add a path to a kick here... ( ~b=Bus.audio(s,2); ~path=""; ~buff=Buffer.read(s,~path); ) //tests.... ~path.value; ~buff.play; ~buff.plot; ~buff.value; ~buff.numFrames; //evaluate this block 2. Synths.... ( SynthDef(\PlayBufz, {| out = 0, bufnum = 0, amp = 1 | Out.ar(out, PlayBuf.ar(2, ~buff, BufRateScale.kr(1), doneAction: Done.freeSelf)*amp ) }).add; SynthDef(\bass, { |out, freq = 440, gate = 1, amp = 0.4, slideTime = 0.17, ffreq = 1100, width = 0.15, detune = 1.005, preamp = 4, freqHi| var sig, env = Env.adsr(0.01, 0.3, 0.4, 0.1); freq = Lag.kr(freq, slideTime); sig = Mix(VarSaw.ar([freq, freq * detune], 0, width, preamp)).distort * amp * EnvGen.kr(env, gate, doneAction: Done.freeSelf); sig = Resonz.ar(sig, VarLag.kr(ffreq,0.3)); //freqHi = Linlin.ar(ffreq,20,2000,200,20000).poll; Out.ar(out, sig ! 2) }).add; ) //evaluate this block 3. ( ~ffreq= 200; ~amp = 1; x = Pmono(\bass, \midinote, Prand([36, 39, 36, 42], 4), \dur, Pseq([0.75,0.75], 4), \amp, 0.3, \detune, 1.005, \ffreq, Pfunc({~ffreq}) ); t = Pmono(\bass, \midinote, Prand([36, 42, 41, 33], 4), \dur, Pseq([0.25, 0.25, 0.25, 0.75], 4), \amp, 0.3, \detune, 1.003, \ffreq, Pfunc({~ffreq}*1.6) ); z = Pbind( \instrument, \PlayBufz, \dur, Pseq([0.75,0.75], inf), \amp, Pfunc({~amp}) ); TempoClock.default.tempo = 128/60; ) //evaluate this last 4. GUI. ( var bb,cc, dd, text, pt, r, u, mx=0, my=0; ~amp = 1; TempoClock.default.tempo = 128/60; w = Window.new("buttontest",Rect(100,100,450,350)); w.view.background = Color(0.8,0.0,01); u = UserView(w, Rect(300, 200,100, 100)); u.background = Color.black; u.animate = true; pt = Point(); r = Rect(); //w.view.decorator = FlowLayout(w.view.bounds); bb = Button(w, Rect(60, 20, 40, 30)) .states_([ ["on", Color.black, Color.red], ["off", Color.white, Color.black] ]) .action_({ arg zz; zz.value.postln; if(zz.value == 1){c = Ppar([z,Prand([t,x],inf)],inf).play;}; if(zz.value == 0){c.stop}; }); g=EZSlider(w,Rect(10,80,390,20),"Freq",ControlSpec(20,2000,\exp,0.001,200),{|ez| ~ffreq = ez.value;ez.value.postln},numberWidth: 60); text = StaticText.new(w,Rect(100,200,200,200)).string_("kick on / off = kik\ncutoff = freq\nspeed = norm"); text.font = Font("Monaco", 13); cc = Button(w, Rect(200, 20, 40, 30)) .states_([ ["kik", Color.green, Color.red], ["off", Color.blue, Color.white] ]) .action_({ arg zz; if(zz.value == 0){~amp = 1}; if(zz.value == 1){~amp = 0}; }); dd = Button(w, Rect(60, 140, 40, 30)) .states_([ ["norm", Color.black, Color.green], ["slo", Color.black, Color.green], ["slo2", Color.black, Color.green] ]) .action_({ arg zz; if(zz.value == 0){TempoClock.default.tempo = 128/60;}; if(zz.value == 1){TempoClock.default.tempo = 110/60;}; if(zz.value == 2){TempoClock.default.tempo = 60/60;}; }); u.drawFunc = { Pen.fillColor = Color.red; Pen.color = Color.white; pt.x=mx; pt.y=my; 100.do{|i| Pen.moveTo(pt); pt.x = sin(u.frame*0.1.neg+i)*(5*i)+mx; //use .frame to drive animation pt.y = cos(u.frame*0.4+i)*(5*i)+my; r.left=pt.x; r.top=pt.y; r.width=sin(u.frame*0.1); r.height=i; Pen.lineTo(pt); Pen.fillStroke; Pen.addOval(r); Pen.fillStroke; }; }; w.front; )