«Equal-Loudness Contour Experience in SC» by prko
on 05 Apr'18 11:16 inEqual-Loudness Contour Experience in SC
special thanks to James Harkins who resolved my errors in the code via the sc-users list!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
( s.waitForBoot{ var freqs = [0] ++ Array.geom(19, 30, 1.425), strps = [$a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $q, $r, $t, $u], numDB = 34, buttW = 39, buttH = 13, strpH = buttH * numDB, margL = 0, margR = 10, margT = 10, margB = 10, windW = buttW * strps.size + margL + margR, windH = strpH + margT + margB, winPH = Window.screenBounds.width - windW / 2, winPV = Window.screenBounds.height - windH / 2; strps.size.do{ |i| (freqs[i] < 1000).if( { freqs[i] = freqs[i].round(5) }, { freqs[i] = freqs[i].round(500) } ) }; x = { |freq=0, amp=1, trig=0| SinOsc.ar( freq, 0, amp*(EnvGen.ar(Env.asr(0.08, 0.2, 0.12, \welch), trig, doneAction: 0)) ) }.play; w = Window.new("Equal-Loudness Contour Finding Tool",Rect(winPH, winPV, windW, windH)).front; strps.do{ |name, frqIdx| var frqStrp = VLayoutView(w,Rect(frqIdx*buttW + margL, margT, buttW, strpH)), thisFreq = freqs[frqIdx], dbLabelW = buttW/2, lastClickId= 0; (frqIdx == 0).if( { StaticText(frqStrp, buttW@buttH) .string_("dB") .align_(\center) .font_(Font("Arial", 9)) .stringColor_(Color.grey); name = numDB.collect{ |dbIdx| var db = (1/(2**(dbIdx/2))).ampdb.round; StaticText(frqStrp, dbLabelW@buttH) .string_(db) .align_(\center) .font_(Font("Arial", 9)) .stringColor_(Color.grey); }; }, { StaticText(frqStrp, buttW@buttH) .string_((thisFreq<1000).if({ thisFreq+"Hz" },{ (thisFreq/1000)+"kHz" })) .align_(\center) .font_(Font("Arial", 9)); name = numDB.collect{ |dbIdx| var db = (1/(2**(dbIdx/2))).ampdb.round; Button(frqStrp, buttW@buttH) .states_([ [ "", Color.grey, Color.green(1, 1-(((dbIdx)*9)/400)) ], [ db, Color.grey, Color.new(0,1,0.7, 1-(((dbIdx)*9)/400)) ] ]) .mouseDownAction_{ x.set( \freq, freqs[frqIdx].postln, \amp, db.dbamp.postln, \trig, 1 ); name[lastClickId].value = 0; } .mouseUpAction_{ x.set(\trig, 0); lastClickId = dbIdx } } } ) } } )
reception
cool!