{
   "author" : "prko",
   "name" : "Equal-Loudness Contour Experience in SC",
   "ancestor_list" : [],
   "description" : "Equal-Loudness Contour Experience in SC\r\n\r\nspecial thanks to James Harkins who resolved my errors in the code via the sc-users list!",
   "labels" : [],
   "is_private" : null,
   "id" : "1-5aj",
   "code" : "(\r\ns.waitForBoot{\r\n\tvar\r\n\tfreqs = [0] ++ Array.geom(19, 30, 1.425),\r\n\tstrps = [$a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $q, $r, $t, $u],\r\n\tnumDB = 34,\r\n\tbuttW = 39,\r\n\tbuttH = 13,\r\n\tstrpH = buttH * numDB,\r\n\tmargL = 0,\r\n\tmargR = 10,\r\n\tmargT = 10,\r\n\tmargB = 10,\r\n\twindW = buttW * strps.size + margL + margR,\r\n\twindH = strpH + margT + margB,\r\n\twinPH = Window.screenBounds.width - windW / 2,\r\n\twinPV = Window.screenBounds.height - windH / 2;\r\n\r\n\tstrps.size.do{\r\n\t\t|i|\r\n\t\t(freqs[i] < 1000).if(\r\n\t\t\t{ freqs[i] = freqs[i].round(5) },\r\n\t\t\t{ freqs[i] = freqs[i].round(500) }\r\n\t\t)\r\n\t};\r\n\r\n\tx = {\r\n\t\t|freq=0, amp=1, trig=0|\r\n\t\tSinOsc.ar(\r\n\t\t\tfreq,\r\n\t\t\t0,\r\n\t\t\tamp*(EnvGen.ar(Env.asr(0.08, 0.2, 0.12, \\welch), trig, doneAction: 0))\r\n\t\t)\r\n\t}.play;\r\n\r\n\tw = Window.new(\"Equal-Loudness Contour Finding Tool\",Rect(winPH, winPV, windW, windH)).front;\r\n\r\n\tstrps.do{\r\n\t\t|name, frqIdx|\r\n\t\tvar frqStrp = VLayoutView(w,Rect(frqIdx*buttW + margL, margT, buttW, strpH)),\r\n\t\tthisFreq = freqs[frqIdx],\r\n\t\tdbLabelW = buttW/2,\r\n\t\tlastClickId= 0;\r\n\r\n\t\t(frqIdx == 0).if(\r\n\t\t\t{\r\n\t\t\t\tStaticText(frqStrp, buttW@buttH)\r\n\t\t\t\t.string_(\"dB\")\r\n\t\t\t\t.align_(\\center)\r\n\t\t\t\t.font_(Font(\"Arial\", 9))\r\n\t\t\t\t.stringColor_(Color.grey);\r\n\r\n\t\t\t\tname = numDB.collect{\r\n\t\t\t\t\t|dbIdx|\r\n\t\t\t\t\tvar db = (1/(2**(dbIdx/2))).ampdb.round;\r\n\t\t\t\t\tStaticText(frqStrp, dbLabelW@buttH)\r\n\t\t\t\t\t.string_(db)\r\n\t\t\t\t\t.align_(\\center)\r\n\t\t\t\t\t.font_(Font(\"Arial\", 9))\r\n\t\t\t\t\t.stringColor_(Color.grey);\r\n\t\t\t\t};\r\n\t\t\t},\r\n\r\n\t\t\t{\r\n\t\t\t\tStaticText(frqStrp, buttW@buttH)\r\n\t\t\t\t.string_((thisFreq<1000).if({ thisFreq+\"Hz\" },{ (thisFreq/1000)+\"kHz\" }))\r\n\t\t\t\t.align_(\\center)\r\n\t\t\t\t.font_(Font(\"Arial\", 9));\r\n\r\n\t\t\t\tname = numDB.collect{\r\n\t\t\t\t\t|dbIdx|\r\n\t\t\t\t\tvar db = (1/(2**(dbIdx/2))).ampdb.round;\r\n\t\t\t\t\tButton(frqStrp, buttW@buttH)\r\n\t\t\t\t\t.states_([\r\n\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\t\"\",\r\n\t\t\t\t\t\t\tColor.grey,\r\n\t\t\t\t\t\t\tColor.green(1, 1-(((dbIdx)*9)/400))\r\n\t\t\t\t\t\t],\r\n\t\t\t\t\t\t[\r\n\t\t\t\t\t\t\tdb,\r\n\t\t\t\t\t\t\tColor.grey,\r\n\t\t\t\t\t\t\tColor.new(0,1,0.7, 1-(((dbIdx)*9)/400))\r\n\t\t\t\t\t\t]\r\n\t\t\t\t\t])\r\n\t\t\t\t\t.mouseDownAction_{\r\n\t\t\t\t\t\tx.set(\r\n\t\t\t\t\t\t\t\\freq, freqs[frqIdx].postln,\r\n\t\t\t\t\t\t\t\\amp, db.dbamp.postln, \\trig, 1\r\n\t\t\t\t\t\t);\r\n\t\t\t\t\t\tname[lastClickId].value = 0;\r\n\t\t\t\t\t}\r\n\t\t\t\t\t.mouseUpAction_{\r\n\t\t\t\t\t\tx.set(\\trig, 0);\r\n\t\t\t\t\t\tlastClickId = dbIdx\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t)\r\n\t}\r\n}\r\n)"
}
