{
   "description" : "",
   "ancestor_list" : [],
   "author" : "prko",
   "name" : "A Simple Synthesizer Keyboard 1",
   "code" : "(\r\ns.waitForBoot{\r\n\tvar w, n, b, bs, k, ks, x, lay, ctl, kAct, lastPressed;\r\n\tk = (\\a:0, \\w:1, \\s:2, \\e:3, \\d:4, \\f:5, \\t:6, \\g:7, \\y:8, \\h:9, \\u:10, \\j:11, \\k:12, \\o:13, \\l:14,\r\n\t\t\\p:15, ';':16);\r\n\tn = k.size;\r\n\tx = { |i|\r\n\t\t{ |g = 0|\r\n\t\t\tLFTri.ar((i + 69 + [0, 0.15]).midicps)\r\n\t\t\t* 0.1\r\n\t\t\t* Env.adsr.kr(gate:g);\r\n\t\t}.play\r\n\t}!n;\r\n\tctl = { |i=0, gate=0|\r\n\t\tx[i].set(\\g, gate)\r\n\t};\r\n\tw = Window(\"self ear-training\", Rect(200, 200, 583, 136));\r\n\tw.front;\r\n\tw.onClose_{ { |i| x[i].free }!n };\r\n\tb = { |parent, label|\r\n\t\tButton(parent, 30@30)\r\n\t\t.states_([\r\n\t\t\t[label],\r\n\t\t\t[label, Color.white, Color.grey]\r\n\t\t])\r\n\t\t.mouseDownAction_{\r\n\t\t\tlastPressed = label;\r\n\t\t\tctl.(label, 1);\r\n\t\t\tbs[label].value = 1\r\n\t\t}\r\n\t\t.action_{\r\n\t\t\tctl.(label, 0);\r\n\t\t\tbs[label].value = 0\r\n\t\t}\r\n\t};\r\n\tlay = w.addFlowLayout;\r\n\tbs = { |i| b.(w, i) }!n;\r\n\tlay.nextLine;\r\n\tks = { |i|\r\n\t\tStaticText(w, 30@30)\r\n\t\t.string_(k.findKeyForValue(i))\r\n\t\t.align_(\\center)\r\n\t}!n;\r\n\tkAct = { |c, v|\r\n\t\tc = c.asSymbol;\r\n\t\t(k.includesKey(c) != false).if{\r\n\t\t\tctl.(k[c], v);\r\n\t\t\tbs[k[c]].value = v\r\n\t\t}\r\n\t};\r\n\tStaticText(w, 572@60).string_(\"Press, hold and then release the keys under the numbered buttons using\"\r\n\t\t+ \"your computer keyboard. Alternatively, you might press, hold, and then release each button using\"\r\n\t\t+ \"the left button of the computer mouse. The multi-touch on touchscreen may function, but it\"\r\n\t\t+ \"hasn't been tested.\");\r\n\tw.view\r\n\t.keyDownAction_{ |view, char|\r\n\t\tkAct.(char, 1)\r\n\t}\r\n\t.keyUpAction_{ |view, char, mod, unicode, keycode, key|\r\n\t\tkAct.(char, 0)\r\n\t}\r\n\t.mouseUpAction_{ //|view, x, y, modifiers, buttonNumber|\r\n\t\tvar lastPressedK = k.findKeyForValue(lastPressed);\r\n\t\tkAct.(lastPressedK, 0)\r\n\t}\r\n}\r\n)",
   "is_private" : null,
   "id" : "1-5gp",
   "labels" : [
      "keyboard"
   ]
}
