{
   "ancestor_list" : [],
   "description" : "Example on how to interface SuperCollider with Ableton Push via [Modality](http://modalityteam.github.io/) toolkit. (I only have the first version here, send me a second version and I'll make it compatible with that ;) )",
   "name" : "Basic Ableton Push control with Modality",
   "author" : "LFSaw",
   "code" : "// create Mktl for the Push controller, it has two ports, the 2nd one is the \"default\"\r\n// make sure, ableton is not running (it grabs the device)\r\n\r\n\r\n// there is a specified class that simplifies use of LEDs, everything else is the same as in MKtl\r\nk = MPush('push');\r\n\r\n\r\n// standard method\r\nk = MKtl('push', \"ableton-push\", multiIndex: 1);\r\n\r\n\r\n\r\n\r\n\r\nk.trace(true);\r\n// wiggle some pots / buttons\r\n\r\nk.trace(false);\r\n\r\n\r\nk.elAt(\\pad, \\8, \\1); // symbols represent button names (typically starting at 1), integers are indices (starting at 0)\r\n\r\n// set an action to post aftertouch values\r\nk.elAt(\\pad, \\8, \\1).action = {|el|\r\n\tel.value.postln;\r\n}\r\n\r\n// remove action\r\nk.elAt(\\pad, \\8, \\1).action= nil;\r\n\r\n\r\n// on-action:\r\n\r\nk.elAt(\\pad, \\8, \\1, \\on).action = {|el|\r\n\t\"on:\\t%\".format(el.value).postln\r\n}\r\n\r\n// off-action:\r\n\r\nk.elAt(\\pad, \\8, \\1, \\off).action = {|el|\r\n\t\"off:\\t%\".format(el.value).postln\r\n}\r\n\r\n// set lights\r\nk.setPadLight(k.elAt(\\pad, \\8, \\1, \\on), \\green);\r\nk.setBtLight(k.elementAt(\\bt, 0, 0), \\green);\r\nk.setBtLight(k.elementAt(\\bt, 1, 0), \\blue);\r\nk.setCtlLight(k.elementAt(\\btCtl), blink: \\slow);\r\nk.setCtlLight(k.elementAt(\\btCtl), blink: \\steady);\r\n\r\n// turn off all lights\r\nk.lightsOff\r\n\r\n\r\n\r\n\r\n\r\n// use for sounds:\r\ns.boot;\r\ns.latency = nil;\r\nq = (); // a dict;\r\n\r\n// let's use a pad\r\nq.pad  = k.elAt(\\pad, \\8, \\1);\r\n\r\n// this is the pad:\r\nk.setPadLight(q.pad.elAt(\\on), \\red, \\half);\r\n\r\n\r\n(\r\nNdef(\\myGendy).addSpec(\\wiggle, [55, 220,'exp']);\r\nNdef(\\myGendy).addSpec(\\ampScale, [0.01,0.03]);\r\nNdef(\\myGendy).addSpec(\\durScale, [0.01,0.03]);\r\nNdef(\\myGendy).addSpec(\\changespeed, [0.1,100, \\exp]);\r\n\r\nNdef(\\myGendy, {|wiggle = 55, ampScale = 0.03, durScale = 0.1, changespeed = 1|\r\n\t// Pan2.ar(Gendy3.ar(1,2,ad,0.07,wiggle,ampScale,0.1, ), Gendy1.ar(2, minfreq: 0.1, maxfreq: 100))\r\n\tSplay.ar(Gendy3.ar(3,5,1.0,1.0, (\r\n\t\tArray.fill(5,{\r\n\t\t\tLFNoise0.kr(Rand(0, 1.3) * changespeed,1,2)\r\n\t\t}) * wiggle\r\n\t),\r\n\tampscale:\tampScale,\r\n\tdurscale:\tdurScale, \r\n\tinitCPs: 5,\r\n\tmul:0.1\r\n))})\r\n)\r\n\r\n\r\nNdef(\\myGendy).gui\r\n\r\n\r\nq.pad.elAt(\\on).action = {|el|\r\n\tNdef(\\myGendy).vol = el.value;\r\n\tNdef(\\myGendy).setUni(\\durScale, 1-el.value, \\wiggle, el.value);\r\n};\r\nq.pad.elAt(\\off).action = {|el|\r\n\tNdef(\\myGendy).vol = el.value;\r\n};\r\nq.pad.elAt(\\touch).action = {|el|\r\n\tNdef(\\myGendy).setUni(\\durScale, 1-el.value, \\wiggle, el.value);\r\n};\r\n\r\n\r\nk.elAt(\\ribbon, \\bend).action = {|el|\r\n\tNdef(\\myGendy).setUni(\\changespeed, el.value);\r\n};",
   "id" : "1-56m",
   "is_private" : null,
   "labels" : [
      "modality",
      "cookbook",
      "ableton push"
   ]
}
