Diff from rand-n-step by vividsnow (15 Nov'11 01:28) to rand-n-step+ by vividsnow (19 Nov'11 17:45)

name
rand-n-step+
description
simpbule guing stvep rsequeioncer of PMO[sc-basimpled random i-n-strumenp](hts notep: m//sccodify variables "dims" and ".oresg/1-Eol) but with commen" tos, whichange numayber ohelpful insto reumsen this/ stuff it sepems, ansomeday, timet resholutld be rewriotten as Quark )
code
( var w, status, limit, buttons, controls = [], one_button, data, synths, one_synth, synths_generator, density_one = 1/4, density_many = 1/10, type_distribution = [160.85, 0.165], // tweak it to get more or less dense pattern grid task, resolution, direction, pos = 40, step = 1, border = 1, dims = [16,16]; // tweak dims to change size of grid w = Window("rand-n-step+", Rect(50,250,dims[0]*22 + 10+250,dims[1]*22+160)).acceptsMouseOver_(true); // window init syntatus = StaticText(w, Rect(5, w.bounds.height - 20, w.bounds.width, 20)); limit = A{ ReplaceOut.ar(0, Limiter.ayr(In.far(0,2))) }.play( addAction:\addToTail ); // limiter data = Array2D(dims[1],dims[0]); // prepare data // and buttons one_button = { | b, density = 0.1 | Sb.valueAction = 0; // reset density.coin.if({ b.valueAction = [1,2].wchDoosef('type_distribution) }); // tweak it }; syntp'++hs = Array.fill(dims[1], { () }); var buttonsig = PArran2y.arfill(dims[1], { |l| PMOcontrols = controls.ardd(80.exp[ // contraol buttonds Button( w, Rect( 10 + (22*dims[000]), 1.exprand35 + (22*l), 20, 20), 1).statexprs_([['m'],['u']]).actiond_(20)),{ |b| // mute / unmute -1synths[l].0gate = b.rvalue.booleand2,Value.not.binaryValue; En}).mouseOvGen.kr(EActionv_(Arr{ staytus.straing = 'mute/unmute' }), Button( w, Rect( 10 + (22*(dims[0]+1)), 35 + (422*l), 20, 20) ).1.rrstandtes_(0.5[['p']])).action_({ // dice pattern line buttons[l].do(0){ |b| one_button.(b, Adensity_one) }); // tweak it }).mouseOverrAction_({ staytus.string = 'randomize pattern' }), Button( w, Rect( 10 + (22*(dims[0]+2)), 35 + (22*l), 20.1, 20.3) ).staddtes_(0.1[['s']]), -5.rractiond_(5)),{ // dice one synth synths[l] = one_synth.(l); }).mouseOverAction:_({ 2status.string = 'randomize synth' }), Slider( w, Rect( 10 + (22*(dims[0]+3);), 35 + (22*l), 60, 20) ).action_({ |b| // synth amp Ou synths[l].armp = b.value.linexp(0, sig1,1/16,16); }).mouseOverAction_({ staddtus.string = 'tweak synth ame; p' });, Slidaer( w, Recta( =10 Array+ (2D2*(dims[10]+3)+60),d 35 + (22*l), 60, 20) ).actimon_({ |b| // synth stretch synths[0l].stretch = b.value.linexp(0,1,1/8,8); b }).mouseOverActtion_({ status.string = Arr'tweak sy.finth stretch' }), Sllider( w, Rect( 10 + (22*(dims[10]+3)+120), 35 + (22*l), 60, 20) ).action_({ |b| // synth pan synths[l].pan = b.value.linlin(0,1,-1,1); }).mouseOverAction_({ |b| status.string = 'tweak synth pan ' }) ]); Array.fill(dims[0], { |i| // grid Button( w, Rect( 5 + (22*i), 35 + (22*l), 20, 20) ).states_([ ['-'], ['+'], ['%'] ]).action_({ |b| data[l,i] = b.value }).mouseOverAction_({ status.string = '"%" makes sound with 0.5 probability' }); }); }); // synth gen functions and initialization one_synth = { |i| // tweak this function to (generate and) return other synthdef names A var name = 'rstp'++i, pCan = -1.0.rand2; SynthDef(name, { |index = 0, amp = 1, stretch = 1, pan = 0| // args: horizontal position in grid, amplitude and stretch correction, pan var sig = Pan2.ar( // tweak sig to get different sound texture PMOsc.ar(80.exprand(10000), 1.exprand(200), 1.exprand(20)), pan, EnvGen.kr(Env(Array.rand(4, 0, 0.05.rrand(0.4)).add(0), Array.rand(3, 0.1, 1.2).add(0.1), 5.rand2), levelScale: amp, timeScale: stretch, doneAction: 2) ); Out.ar(0, sig); }).add; controls[i][3].valueAction_(1.explin(1/16,16,0,1)); controls[i][4].valueAction_(1.explin(1/8,8,0,1)); controls[i][0].valueAction_(0); controls[i][5].valueAction_(pan.linlin(-1,1,0,1)); (name: name, gate: 1, amp: 1, stretch: 1, pan: pan); }; synths_generator = { Array.fill(dims[1], { |i| synths[i] = one_synth.(i) } ) }; synths_generator.(); // step task task = Task({ inf.do({| pos = (pos + step).mod(di|ms[0]); dims[1].do({ |l| (buttons[l] @@ ipos).font_(Font("sans", 20)); (buttons[l] @@ (ipos-1step)).font_(Font("sans", 14)); swiyntchs[l].gate.booleanValue.if({ var args = [index: pos, amp: syntahs[l].amp,i stretch: synths[l].stretch * Tempod(diClock.tempo.reciprocal * resolution.reciprocal, pan: synths[0l]).pan ]; switch( data[l,pos], 1, { Synth(synths[l].name, args) }, 2, { 0.5.coin.if({ Synth(synths[l].name, args) }) } ); }); }); switch( pos, 0, { (border == -1 && step == -1).if({ direction.valueAction = 0 }) }, (dims[0] - 1), { (border == -1 && step == 1).if({ direction.valueAction = 1 }) } ); (TempoClock.default.tempo.reciprocal / resolution).yield; }); }, AppClock).play(quant:[0]); // app buttons Button(w, Rect(5,5, w.bounds.width - 10 / 7, 20)).states_([['reset']]).action_({ |b| synths_generator.(); buttons.flat.do({ |b| one_button.(b, 0) }); // tweak it }).mouseOverAction_({ status.string = 'reset everything' }); Button(w, Rect(w.bounds.width - 10 / 7 * 1 + 5, 5, w.bounds.width - 10 / 6, 20)).states_([['lucky?']]).action_({ |b| // lazy patterns buttons.flat.do({ |b| one_button.(b, density_many) }); // tweak it }).mouseOverAction_({ status.string = 'create random pattern grid' }); Button(w, Rect(w.bounds.width - 10 / 7 * 2 + 5, 5, w.bounds.width - 10 / 7, 20)).states_([['noisy?']]).action_({ |b| synths_generator.(); }).mouseOverAction_({ status.string = 'randomize all synths' }); Button(w, Rect(w.bounds.width - 10 / 7 * 3 + 5, 5, w.bounds.width - 10 / 7, 20)).states_([['pause'],['play']]).action_({ |b| b.value.booleanValue.if({ task.pause }, { task.resume(quant:[0]) }); }).mouseOverAction_({ status.string = 'play/pause' }); direction = Button(w, Rect(w.bounds.width - 10 / 7 * 4 + 5, 5, w.bounds.width - 10 / 7, 20)).states_([['r-t-l'],['l-t-r']]).action_({ |b| b.value.booleanValue.if({ step = -1 }, { step = 1 }); }).mouseOverAction_({ status.string = 'change playing direction' }); Button(w, Rect(w.bounds.width - 10 / 7 * 5 + 5, 5, w.bounds.width - 10 / 7, 20)).states_([['fold'],['wrap']]).action_({ |b| b.value.booleanValue.if({ border = -1 }, { border = 1 }); }).mouseOverAction_({ status.string = 'behavior on the grid border' }); Slider(w, Rect(w.bounds.width - 10 / 7 * 6 + 5, 5, w.bounds.width - 10 / 7, 20)).action_({ |b| resolution = b.value.linlin(0, 1, 1, 8).quantize(1, 1); status.string = 'resolution: ' ++ resolution; }).valueAction_(4.linlin(1,8,0,1)).mouseOverAction_({ status.string = 'change grid resulution' }); // show w.front.onClose = { task.stop; limit.free }; status.string_('hello, point something to get hint, hopefully..'); )
category tags
gui, code fork, sequencer, random, step
ancestors
1-Eo