{
   "name" : "Bjorklund Toy",
   "author" : "rinalka1227",
   "description" : "Toy built to facilitate experimenting with Bjourklund to step through two different 'chords'.\r\nThe \"onChord\" is used in some way for each Bjorklund hit, and the \"offChord\" for all other times.\r\nThe chords can be played as a chord or sequenced in some way.\r\nChords can be generated with white notes only or all notes.\r\nIn addition, there are controls to play with various related patterns\r\nAll of the sounds are generated with the Pluck ugen, played through JPverb",
   "ancestor_list" : [],
   "labels" : [
      "pluck",
      "bjorklund"
   ],
   "id" : "1-5eQ",
   "is_private" : null,
   "code" : "//Bjorklund Pluck Toy\r\n\r\n\r\n//Step1:\r\n(\r\ns.options.memSize_(65536 * 4);\r\ns.reboot;\r\ns.freeAll;\r\nPdef.removeAll;\r\n)\r\n\r\n\r\n//Step2:\r\n(\r\n~bpm = 110;\r\nt = ~bpm/60;\r\nt = TempoClock.new(~bpm/60).permanent_(false);\r\n\r\n~whiteNotes = [//  white notes index 0 to 28\r\n\t36,38,40,41,43,45,47,\r\n\t48,50,52,53,55,57,59,\r\n\t60,62,64,65,67,69,71,\r\n\t72,74,76,77,79,81,83,\r\n\t84];\r\n\r\n~revBus = Bus.audio(s,2);\r\n~makeSynths.value;\r\n\r\n~onChordType = 2;\r\n~onChordStartIndex = 14;\r\n~onChordNumNotes = 4;\r\n~onChord = ~newChordByType.value(~onChordType,~onChordStartIndex,~onChordNumNotes);\r\n~onPattern = 0;  //a chord\r\n~switchPattern.value(\"on\");\r\n\r\n~offChordType = 3;\r\n~offChordStartIndex = 6;\r\n~offChordNumNotes = 4;\r\n~offChord = ~newChordByType.value(~offChordType,~offChordStartIndex,~offChordNumNotes);\r\n~offPattern = 1; //seq up\r\n~switchPattern.value(\"off\");\r\n\r\n~makePBjorklundControlPanel.value; //and wait till the button gets pressed\r\n\r\n\r\n// functions\r\n~makeSynths = {\r\n\tSynthDef(\"plucking\", {\r\n\t\targ outbus = 0, amp = 0.2, sAmp=0.5,\r\n\t\tfreq = 440, pluckDecay = 5, coef = 0.1, pan = 0,\r\n\t\tatk = 0.01, sus = 0.05, rel = 0.5,\r\n\t\ttrigger = 0, dynamic = 0.5;\r\n\t\tvar env = EnvGen.kr(Env.linen(atk,sus,rel,level:1, curve:1),doneAction:2);\r\n\t\tvar snd = Pluck.ar(\r\n\t\t\tin: BrownNoise.ar(amp),\r\n\t\t\ttrig: Impulse.kr(trigger),\r\n\t\t\tmaxdelaytime: 0.005,\r\n\t\t\tdelaytime: freq.reciprocal,\r\n\t\t\tdecaytime: pluckDecay,\r\n\t\t\tcoef: coef\r\n\t\t);\r\n\t\tsnd = LeakDC.ar(snd).clip2;\r\n\t\tsnd = Pan2.ar (snd, pan);\r\n\t\tOut.ar(0, snd * env * sAmp);\r\n\t\tOut.ar(outbus, snd * env * dynamic);\r\n\t}).add;\r\n\r\n\tSynthDef(\\aJPverb, {\r\n\t\targ inBus=0, outBus = 0,\r\n\t\ttailTime = 1, damp = 0.25, pan=0,\r\n\t\tsize = 1.0, eDiff= 0.707, mDepth= 0.1, mFreq= 2.0,\r\n\t\tlow= 1.0, mid= 1.0, high= 1.0, lowcut= 500.0, highcut= 2000.0,\r\n\t\t//jpVol = 0.5,\r\n\t\tstraightOutVol = 0.75;\r\n\t\tvar sig, rev;\r\n\t\tsig = In.ar(~revBus,2);\r\n\t\trev = JPverb.ar(\r\n\t\t\tsig,\r\n\t\t\tt60: tailTime,\r\n\t\t\tdamp: damp,\r\n\t\t\tsize: size,\r\n\t\t\tearlyDiff: eDiff,\r\n\t\t\tmodDepth: mDepth,\r\n\t\t\tmodFreq: mFreq,\r\n\t\t\tlow: low,\r\n\t\t\tmid: mid,\r\n\t\t\thigh: high,\r\n\t\t\tlowcut: lowcut,\r\n\t\t\thighcut: highcut,\r\n\t\t);\r\n\t\tOut.ar(outBus, rev * straightOutVol);\r\n\t}).add;\r\n\r\n\r\n\t//Pdefn's for riff1\r\n\tPdefn(\\hits, 5);\r\n\tPdefn(\\beats, 8);\r\n\tPdefn(\\onPattern,~onPattern);\r\n\tPdefn(\\offPattern,~offPattern);\r\n\tPLbindef(\\riff1,\r\n\t\t\\instrument, \\plucking,\r\n\t\t\\outbus, ~revBus,\r\n\t\t\\trigger, 0,\r\n\t\t\\midinote, Pbjorklund(\r\n\t\t\tPdefn(\\hits),Pdefn(\\beats)).linlin(0, 1, Pdefn(\\offPattern), Pdefn(\\onPattern)),\r\n\t\t\\dur, 0.5,\r\n\t\t\\coef, 0.75,\r\n\t\t\\pluckDecay, 5,\r\n\t\t\\atk, 0.01,\r\n\t\t\\amp, 1,\r\n\t\t\\sAmp, 0.5,\r\n\t\t\\pan, Pbjorklund(Pdefn(\\hits), Pdefn(\\beats)).linlin(0, 1, -1,1),\r\n\t\t\\dynamic, 0.25,\r\n\t\t\\addAction, 0,\r\n\t);\r\n};\r\n\r\n\r\n//~makePBjorklundControlPanel.value\r\n~makePBjorklundControlPanel = {\r\n\tvar\r\n\thits=5, hitsNumBox = hits, beats=8, beatsNumBox = beats,\r\n\tnumNotesInOnChord=4,numNotesInOnChordBox=4,\r\n\tnumNotesInOffChord=4,numNotesInOffChordBox=4,\r\n\tbpmNumBox,\r\n\tstartOnI=14, startOffI=14,endOnI=28, endOffI=28,\r\n\triffTone=0.1, panLeft= -1, panRight=1,\r\n\r\n\tblank, // a blank line used for spacing\r\n\tlabel, knob, button, numBox,popUpMenu,slider,rangeSlider, //standard gui objects\r\n\r\n\tstartOnIBox,endOnIBox,startOffIBox,endOffIBox, //gui objects that get written to\r\n\tstartOnNBox,endOnNBox,startOffNBox,endOffNBox,\r\n\tstartOnN, startOffN,endOnN, endOffN;\r\n\r\n\t//window\r\n\tw = Window(\"Control Panel\", Rect.new(470,300,502,235),resizable:true, border:true)\r\n\t.background_(Color.grey(0.05)).front\r\n\t.alwaysOnTop = true;\r\n\tw.view.decorator_(FlowLayout(w.bounds,4@4, 4@4));\r\n\r\n\t~topPanel = UserView(w, 494@45).background_(Color.rand(0.7,0.9));\r\n\t~topPanel.decorator_(FlowLayout(~topPanel.bounds, 4@4, 4@4));\r\n\t~subPanel= Array.fill(4, {\r\n\t\targ view;\r\n\t\tview = UserView(w, 120@180).background_(Color.rand(0.7,0.9));\r\n\t\tview.decorator_(FlowLayout(view.bounds, 4@4, 4@4));\r\n\t});\r\n\r\n\r\n\t//Start Stop Button\r\n\tbutton = Button(~topPanel, Rect(0,0, 100, 38))\r\n\t.font_(Font(\"Monaco\", 16))\r\n\t.states_([\r\n\t\t[\"Press to Stop\",    Color.black, Color.green],\r\n\t\t[\"Press to Run\",   Color.black, Color.red]])\r\n\t.value_(1)\r\n\t.action_({\r\n\t\targ bu;\r\n\t\tif ( bu.value == 1,\r\n\t\t\t{~riff1.stop;\r\n\t\t\t\t~jpRev.free;\r\n\t\t\t},\r\n\t\t\t{~riff1.play(t).quant_(1.ceil);\r\n\t\t\t\t~jpRev = Synth (\\aJPverb,[\\inbus, ~revBus, \\outbus, 0,\r\n\t\t\t\t\t\\damp, 0.05, \\tailTime, 3,\\straightOutVol, 0.75]).run;\r\n\t\t\t}\r\n\t\t);\r\n\t});\r\n\tblank = StaticText(~topPanel, Rect(0,0,20,5)).string_(\" \");\r\n\r\n\t//Hits Beats and BPM knobs\r\n\tknob = Knob.new(~topPanel, Rect(0, 0, 30, 30))\r\n\t.value_(hits.linlin(1,20,0,1))\r\n\t.color_([Color(0.8,0.4,0.4),Color(0.1,0.1,0.1),Color(1,1,1),Color(0,0,0)])\r\n\t.action_({\r\n\t\targ val;\r\n\t\thitsNumBox.value_(val.value.linlin(0,1,1,32).asInteger);\r\n\t})\r\n\t.mouseUpAction_({\r\n\t\targ val;\r\n\t\thits = val.value.linlin(0,1,1,32).asInteger;\r\n\t\tif (hits > beats, {hits = beats;\r\n\t\t\t(\"can't have more hits than beats! Hits and Beats now \"\r\n\t\t\t\t+ hits + \" \" +beats).postln;\r\n\t\t});\r\n\t\tPdefn(\\hits, hits);\r\n\t});\r\n\tlabel = StaticText(~topPanel, Rect(0,0,25,25))\r\n\t.string_(\"Hits\")\r\n\t.font_(Font(\"Monaco\", 14));\r\n\thitsNumBox = NumberBox(~topPanel, Rect(0,0,25,25))\r\n\t.value_(hits)\r\n\t.font_(Font(\"Monaco\", 14));\r\n\tblank = StaticText(~topPanel, Rect(0,0,20,5)).string_(\" \");\r\n\r\n\tknob = Knob.new(~topPanel, Rect(0, 0, 30, 30))\r\n\t.value_(beats.linlin(1,20,0,1))\r\n\t.color_([Color(0.8,0.4,0.4),Color(0.1,0.1,0.1),Color(1,1,1),Color(0,0,0)])\r\n\t.action_({\r\n\t\targ val;\r\n\t\tbeatsNumBox.value_(val.value.linlin(0,1,2,32).asInteger)\r\n\t})\r\n\t.mouseUpAction_({\r\n\t\targ val;\r\n\t\tbeats = val.value.linlin(0,1,2,32).asInteger;\r\n\t\tPdefn(\\beats, beats);\r\n\t});\r\n\tlabel = StaticText(~topPanel, Rect(0,0,35,25))\r\n\t.string_(\"Beats\")\r\n\t.font_(Font(\"Monaco\", 14));\r\n\tbeatsNumBox = NumberBox(~topPanel, Rect(0,0,25,25))\r\n\t.value_(beats)\r\n\t.font_(Font(\"Monaco\", 14));\r\n\tblank = StaticText(~topPanel, Rect(0,0,20,5)).string_(\" \");\r\n\r\n\t//BPM knob\r\n\tknob = Knob.new(~topPanel, Rect(0, 0, 30, 30))\r\n\t.value_(~bpm.linlin(30,140,0,1))\r\n\t.color_([Color(0.8,0.4,0.4),Color(0.1,0.1,0.1),Color(1,1,1),Color(0,0,0)])\r\n\t.action_({arg val;\r\n\t\t~bpm = val.value.linlin(0,1,30,140).asInteger;\r\n\t\tbpmNumBox.value_(~bpm);})\r\n\t.mouseUpAction_({\r\n\t\targ val;\r\n\t\t~bpm = val.value.linlin(0,1,30,140).asInteger;\r\n\t\tbpmNumBox.value_(~bpm);\r\n\t\tt.tempo = (~bpm/60);\r\n\t});\r\n\tlabel = StaticText(~topPanel, Rect(0,0,30,25))\r\n\t.string_(\"BPM\")\r\n\t.font_(Font(\"Monaco\", 14));\r\n\t//beats per minute numberbox\r\n\tbpmNumBox = NumberBox(~topPanel, Rect(0,0,30,25))\r\n\t.value_(~bpm)\r\n\t.font_(Font(\"Monaco\", 14))\r\n\t.decimals_(0);\r\n\r\n\r\n\t//On Pattern Type Selection\r\n\tblank = StaticText(~subPanel[0], Rect(0,0,200,3)).string_(\" \");\r\n\tlabel = StaticText(~subPanel[0], Rect(0,0,245,14))\r\n\t.string_(\"On Pattern\").align_(\\left)\r\n\t.font_(Font(\"Monaco\", 12));\r\n\tpopUpMenu= PopUpMenu (~subPanel[0], Rect(0,0,112,20))\r\n\t.allowsReselection_(true)\r\n\t.items_([\"play chord hit\", \"seq forward\", \"seq back\", \"random\", \"rest\"])\r\n\t.background_(Color.rand(0.6,0.9))\r\n\t.value_(0)\r\n\t.action_({\r\n\t\targ obj;\r\n\t\t~onPattern = obj.value;\r\n\t\t~switchPattern.value(\"on\");\r\n\t});\r\n\t//type of   chord\r\n\tblank = StaticText(~subPanel[0], Rect(0,0,200,2)).string_(\" \");\r\n\tlabel = StaticText(~subPanel[0], Rect(0,0,245,14))\r\n\t.string_(\"Type of Chord\").align_(\\left)\r\n\t.font_(Font(\"Monaco\", 12));\r\n\tpopUpMenu= PopUpMenu (~subPanel[0], Rect(0,0,112,20))\r\n\t.allowsReselection_(true)\r\n\t.items_([\"random white notes\", \"step white notes\", \"every 2nd white note\",\r\n\t\t\"every 3rd white note\",\t\"random chromatic\", \"chromatic\",\r\n\t\t\"major seconds\", \"minor thirds\"])\r\n\t.font_(Font(\"Monaco\", 10))\r\n\t.background_(Color.rand(0.6,0.9))\r\n\t.value_(2)\r\n\t.action_({\r\n\t\targ obj;\r\n\t\t~onChordType = obj.value;\r\n\t\t~onChord = ~newChordByType.value(~onChordType,~onChordStartIndex,~onChordNumNotes );\r\n\t\t~switchPattern.value(\"on\");\r\n\t});\r\n\r\n\t// number of notes in the chord\r\n\tknob = Knob.new(~subPanel[0], Rect(0, 0, 25, 25))\r\n\t.value_(numNotesInOnChord.linlin(1,8,0,1))\r\n\t.color_([Color(0.8,0.4,0.4),Color(0.1,0.1,0.1),Color(1,1,1),Color(0,0,0)])\r\n\t.action_({\r\n\t\targ val;\r\n\t\tnumNotesInOnChordBox.value_(val.value.linlin(0,1,1,8).asInteger);\r\n\t})\r\n\t.mouseUpAction_({\r\n\t\targ val;\r\n\t\t~onChordNumNotes = val.value.linlin(0,1,1,8).asInteger;\r\n\t\t~onChord = ~newChordByType.value(~onChordType,~onChordStartIndex ,~onChordNumNotes);\r\n\t\t~switchPattern.value(\"on\");\r\n\t});\r\n\tlabel = StaticText(~subPanel[0], Rect(0,0,25,25))\r\n\t.string_(\"# notes in chord\").align_(\\topLeft)\r\n\t.font_(Font(\"Monaco\", 10));\r\n\tnumNotesInOnChordBox = NumberBox(~subPanel[0], Rect(0,0,20,20))\r\n\t.value_(numNotesInOnChord)\r\n\t.font_(Font(\"Monaco\", 14));\r\n\tblank = StaticText(~subPanel[0], Rect(0,0,2,30)).string_(\" \");\r\n\r\n\t//start index for the notes in the chord\r\n\tknob = Knob.new(~subPanel[0], Rect(0, 0, 25, 25))\r\n\t.value_(startOnI.linlin(0,28,0,1))\r\n\t.color_([Color(0.8,0.4,0.4),Color(0.1,0.1,0.1),Color(1,1,1),Color(0,0,0)])\r\n\t.action_({\r\n\t\targ val;\r\n\t\tstartOnIBox.value_(val.value.linlin(0,1,0,28).asInteger);\r\n\t\tstartOnNBox.string_(~whiteNotes[val.value.linlin(0,1,0,28).asInteger].midiname())\r\n\t})\r\n\t.mouseUpAction_({\r\n\t\targ val;\r\n\t\t~onChordStartIndex = val.value.linlin(0,1,0,28).asInteger;\r\n\t\t~onChord = ~newChordByType.value(~onChordType,~onChordStartIndex ,~onChordNumNotes);\r\n\t\t~switchPattern.value(\"on\");\r\n\t});\r\n\tlabel = StaticText(~subPanel[0], Rect(0,0,25,25))\r\n\t.string_(\"start note\").align_(\\topLeft)\r\n\t.font_(Font(\"Monaco\", 10));\r\n\tstartOnIBox = NumberBox(~subPanel[0], Rect(0,0,20,20))\r\n\t.value_(startOnI)\r\n\t.font_(Font(\"Monaco\", 14));\r\n\tstartOnNBox = StaticText(~subPanel[0], Rect(0,0,25,25))\r\n\t.string_(~whiteNotes[startOnI].midiname())\r\n\t.font_(Font(\"Monaco\", 14));\r\n\r\n\r\n\t//Off Pattern Type Selection\r\n\tblank = StaticText(~subPanel[1], Rect(0,0,200,3)).string_(\" \");\r\n\tlabel = StaticText(~subPanel[1], Rect(0,0,245,14))\r\n\t.string_(\"Off Pattern\").align_(\\left)\r\n\t.font_(Font(\"Monaco\", 12));\r\n\tpopUpMenu= PopUpMenu (~subPanel[1], Rect(0,0,112,20))\r\n\t.allowsReselection_(true)\r\n\t.items_([\"play chord hit\", \"seq forward\", \"seq back\", \"random\", \"rest\"])\r\n\t.background_(Color.rand(0.6,0.9))\r\n\t.value_(1)\r\n\t.action_({\r\n\t\targ obj;\r\n\t\t~offPattern = obj.value;\r\n\t\t~switchPattern.value(\"off\");\r\n\t});\r\n\t//type of   chord\r\n\tblank = StaticText(~subPanel[1], Rect(0,0,200,2)).string_(\" \");\r\n\tlabel = StaticText(~subPanel[1], Rect(0,0,245,14))\r\n\t.string_(\"Type of Chord\").align_(\\left)\r\n\t.font_(Font(\"Monaco\", 12));\r\n\tpopUpMenu= PopUpMenu (~subPanel[1], Rect(0,0,112,20))\r\n\t.allowsReselection_(true)\r\n\t.items_([\"random white notes\", \"step white notes\", \"every 2nd white note\",\r\n\t\t\"every 3rd white note\",\t\"random chromatic\", \"chromatic\",\r\n\t\t\"major seconds\", \"minor thirds\"])\r\n\t.font_(Font(\"Monaco\", 10))\r\n\t.background_(Color.rand(0.6,0.9))\r\n\t.value_(2)\r\n\t.action_({\r\n\t\targ obj;\r\n\t\t~offChordType = obj.value;\r\n\t\t~offChord = ~newChordByType.value(~offChordType,~offChordStartIndex,~offChordNumNotes );\r\n\t\t~switchPattern.value(\"off\");\r\n\t});\r\n\r\n\t// number of notes in the off chord\r\n\tknob = Knob.new(~subPanel[1], Rect(0, 0, 25, 25))\r\n\t.value_(numNotesInOffChord.linlin(1,8,0,1))\r\n\t.color_([Color(0.8,0.4,0.4),Color(0.1,0.1,0.1),Color(1,1,1),Color(0,0,0)])\r\n\t.action_({\r\n\t\targ val;\r\n\t\tnumNotesInOffChordBox.value_(val.value.linlin(0,1,1,8).asInteger);\r\n\t})\r\n\t.mouseUpAction_({\r\n\t\targ val;\r\n\t\t~offChordNumNotes = val.value.linlin(0,1,1,8).asInteger;\r\n\t\t~offChord = ~newChordByType.value(~offChordType,~offChordStartIndex ,~offChordNumNotes);\r\n\t\t~switchPattern.value(\"off\");\r\n\t});\r\n\tlabel = StaticText(~subPanel[1], Rect(0,0,25,25))\r\n\t.string_(\"# notes in chord\").align_(\\topLeft)\r\n\t.font_(Font(\"Monaco\", 10));\r\n\tnumNotesInOffChordBox = NumberBox(~subPanel[1], Rect(0,0,20,20))\r\n\t.value_(numNotesInOnChord)\r\n\t.font_(Font(\"Monaco\", 14));\r\n\tblank = StaticText(~subPanel[1], Rect(0,0,2,30)).string_(\" \");\r\n\r\n\t//start index for the notes in the off chord\r\n\tknob = Knob.new(~subPanel[1], Rect(0, 0, 25, 25))\r\n\t.value_(startOnI.linlin(0,28,0,1))\r\n\t.color_([Color(0.8,0.4,0.4),Color(0.1,0.1,0.1),Color(1,1,1),Color(0,0,0)])\r\n\t.action_({\r\n\t\targ val;\r\n\t\tstartOffIBox.value_(val.value.linlin(0,1,0,28).asInteger);\r\n\t\tstartOffNBox.string_(~whiteNotes[val.value.linlin(0,1,0,28).asInteger].midiname())\r\n\t})\r\n\t.mouseUpAction_({\r\n\t\targ val;\r\n\t\t~offChordStartIndex = val.value.linlin(0,1,0,28).asInteger;\r\n\t\t~offChord = ~newChordByType.value(~offChordType,~offChordStartIndex ,~offChordNumNotes);\r\n\t\t~switchPattern.value(\"off\");\r\n\t});\r\n\tlabel = StaticText(~subPanel[1], Rect(0,0,25,25))\r\n\t.string_(\"start note\").align_(\\topLeft)\r\n\t.font_(Font(\"Monaco\", 10));\r\n\tstartOffIBox = NumberBox(~subPanel[1], Rect(0,0,20,20))\r\n\t.value_(startOnI)\r\n\t.font_(Font(\"Monaco\", 14));\r\n\tstartOffNBox = StaticText(~subPanel[1], Rect(0,0,25,25))\r\n\t.string_(~whiteNotes[startOnI].midiname())\r\n\t.font_(Font(\"Monaco\", 14));\r\n\r\n\r\n\t//Dynamics\r\n\tlabel = StaticText(~subPanel[2], Rect(0,0,120,12))\r\n\t.string_(\"Dynamics\").align_(\\left)\r\n\t.font_(Font(\"Arial\",12));\r\n\tpopUpMenu= PopUpMenu (~subPanel[2], Rect(0,0,112,20))\r\n\t.allowsReselection_(true)\r\n\t.items_([\"loud, soft\", \"loud soft soft\", \"loud soft*3\", \"bjork(loud,soft)\", \"flat 0.5\",\" random\"])\r\n\t.background_(Color.rand(0.6,0.9))\r\n\t.value_(4)\r\n\t.action_({\r\n\t\targ obj;\r\n\t\tswitch (obj.value,\r\n\t\t\t0, {~riff1.dynamic = Pseq([0.65,0.45], inf)},\r\n\t\t\t1, {~riff1.dynamic = Pseq([0.65,Pseq([0.45],2)], inf)},\r\n\t\t\t2, {~riff1.dynamic = Pseq([0.65,Pseq([0.45],3)], inf)},\r\n\t\t\t3, {~riff1.dynamic = Pbjorklund(hits,beats).linlin(0, 1, 0.65, 0.45)},\r\n\t\t\t4, {~riff1.dynamic = 0.4},\r\n\t\t\t5, {~riff1.dynamic = Prand([0.75,0.65,0.55,0.45,0.35],inf)},\r\n\t\t);\r\n\t});\r\n\r\n\t// Tone\r\n\tblank = StaticText(~subPanel[2], Rect(0,0,200,5)).string_(\" \");\r\n\tlabel = StaticText(~subPanel[2], Rect(0,0,120,12))\r\n\t.string_(\"Tone pattern\").align_(\\left)\r\n\t.font_(Font(\"Arial\",12));\r\n\tpopUpMenu= PopUpMenu (~subPanel[2], Rect(0,0,112,20))\r\n\t.items_([\"hard + knob\", \"soft + knob\", \"rand + knob\", \"just knob\"])\r\n\t.background_(Color.rand(0.6,0.9))\r\n\t.value_(3)\r\n\t.action_({\r\n\t\targ obj;\r\n\t\tswitch (obj.value,\r\n\t\t\t0, {~riff1.coef = Prand([0, 0.05, 0.1, 0.15, 0.2], inf) +(riffTone/2) },\r\n\t\t\t1, {~riff1.coef = Prand([0.35, 0.4, 0.45, 0.5], inf) +(riffTone/2)},\r\n\t\t\t2, {~riff1.coef = Prand([0.5,0.4,0.3,0.1,0], inf)+(riffTone/2)},\r\n\t\t\t3, {~riff1.coef = Pseq([riffTone],inf)}\r\n\t\t);\r\n\t});\r\n\tknob = Knob.new(~subPanel[2], Rect(0, 0, 25, 25))\r\n\t.color_([Color(0.8,0.4,0.4),Color(0.1,0.1,0.1),Color(1,1,1),Color(0,0,0)])\r\n\t.value_(0.75)\r\n\t.action_({\r\n\t\targ val;\r\n\t\triffTone = val.value;\r\n\t\t~riff1.coef = val.value.linlin(0,1,0.01,0.99);\r\n\t});\r\n\tlabel = StaticText(~subPanel[2], Rect(0,0,70,25))\r\n\t.string_(\"Tone\")\r\n\t.font_(Font(\"Monaco\", 10));\r\n\r\n\t//Duration\r\n\tblank = StaticText(~subPanel[2], Rect(0,0,200,5)).string_(\" \");\r\n\tlabel = StaticText(~subPanel[2], Rect(0,0,120,12))\r\n\t.string_(\"Duration pattern\").align_(\\left)\r\n\t.font_(Font(\"Arial\",12));\r\n\tpopUpMenu= PopUpMenu (~subPanel[2], Rect(0,0,112,20))\r\n\t.allowsReselection_(true)\r\n\t.items_([\"8th 16th 16th\", \"8th 16th 16th 16th\", \"bjork(8th,quarter)\", \"bjork(16th,8th)\",\r\n\t\t\"8th\", \"quarter\", \"quarter triplets\", \"triplets\"])\r\n\t.background_(Color.rand(0.6,0.9))\r\n\t.value_(4)\r\n\t.action_({\r\n\t\targ obj;\r\n\t\tswitch (obj.value,\r\n\t\t\t0, {~riff1.dur = Pseq([0.5,0.25,0.25], inf)},\r\n\t\t\t1, {~riff1.dur = Pseq([0.5,Pseq([0.25],3)], inf)},\r\n\t\t\t2, {~riff1.dur = Pbjorklund(hits,beats).linlin(0, 1, 0.5, 1)},\r\n\t\t\t3, {~riff1.dur = Pbjorklund(hits,beats).linlin(0, 1, 0.25, 0.5)},\r\n\t\t\t4, {~riff1.dur = 0.5},\r\n\t\t\t5, {~riff1.dur = 1},\r\n\t\t\t6, {~riff1.dur = Pseq([2/3],inf)},\r\n\t\t\t7, {~riff1.dur = Pseq([1/3],inf)},\r\n\t\t);\r\n\t});\r\n\r\n\t//Pan\r\n\tblank = StaticText(~subPanel[3], Rect(0,0,112,2)).string_(\" \");\r\n\tlabel = StaticText(~subPanel[3], Rect(0,0,112,12))\r\n\t.string_(\"Pan pattern\").align_(\\left)\r\n\t.font_(Font(\"Arial\",12));\r\n\tpopUpMenu = PopUpMenu (~subPanel[3], Rect(0,0,112,20))\r\n\t.allowsReselection_(true)\r\n\t.items_([\"fixed\", \"bounce\", \"random\", \"bjork bounce\"])\r\n\t.background_(Color.rand(0.6,0.9))\r\n\t.value_(3)\r\n\t.action_({\r\n\t\targ obj;\r\n\t\t~panPattern = obj.value;\r\n\t\tswitch (~panPattern,\r\n\t\t\t0, {~riff1.pan =     Pseq([(panLeft+panRight)/2],inf);},\r\n\t\t\t1, {~riff1.pan =     Pseq([panLeft,panRight],inf);},\r\n\t\t\t2, {~riff1.pan =     Prand([panLeft,(panLeft+panRight)/2,panRight],inf);},\r\n\t\t\t3, {~riff1.pan =     Pbjorklund(Pdefn(\\hits), Pdefn(\\beats)).linlin(0, 1, panLeft,panRight);}\r\n\t\t);\r\n\t});\r\n\trangeSlider = RangeSlider(~subPanel[3], Rect(0, 0, 112, 14))\r\n\t.lo_(0)\r\n\t.hi_(1)\r\n\t.activeLo_(0.25)\r\n\t.activeHi_(0.75)\r\n\t.action_({ arg slider;\r\n\t\tpanLeft  = slider.lo.linlin(0,1,-1,1);\r\n\t\tpanRight = slider.hi.linlin(0,1,-1,1);\r\n\t\tswitch (~panPattern,\r\n\t\t\t0, {~riff1.pan =     Pseq([(panLeft+panRight)/2],inf);},\r\n\t\t\t1, {~riff1.pan =     Pseq([panLeft,panRight],inf);},\r\n\t\t\t2, {~riff1.pan =     Prand([panLeft,(panLeft+panRight)/2,panRight],inf);},\r\n\t\t\t3, {~riff1.pan =     Pbjorklund(Pdefn(\\hits), Pdefn(\\beats)).linlin(0, 1, panLeft,panRight);}\r\n\t\t);\r\n\t});\r\n\r\n\t// jp reverb\r\n\tblank = StaticText(~subPanel[3], Rect(0,0,200,5)).string_(\" \");\r\n\tlabel = StaticText(~subPanel[3], Rect(0,0,120,12))\r\n\t.string_(\"JPVerb\")\r\n\t.font_(Font(\"Arial\",12))\r\n\t.align_(\\left);\r\n\r\n\tlabel= StaticText(~subPanel[3], Rect(0,0,40,10))\r\n\t.string_(\"Damp\")\r\n\t.font_(Font(\"Arial\",10))\r\n\t.align_(\\left);\r\n\tslider = Slider(~subPanel[3], Rect.new(0,20,60,14))\r\n\t.background_(Color.rand(0.7,0.8))\r\n\t.valueAction_(0.25)\r\n\t.action_({\r\n\t\targ obj;\r\n\t\t~jpRev.set(\\damp, obj.value.linlin(0,1, 0.000,0.99));\r\n\t});\r\n\r\n\tlabel = StaticText(~subPanel[3], Rect(0,0,40,10))\r\n\t.string_(\"Tail Time\")\r\n\t.font_(Font(\"Arial\",10))\r\n\t.align_(\\left);\r\n\tslider = Slider(~subPanel[3], Rect.new(0,20,60,14))\r\n\t.background_(Color.rand(0.7,0.8))\r\n\t.value_(0.25)\r\n\t.valueAction_(0.25)\r\n\t.action_({\r\n\t\targ obj;\r\n\t\t~jpRev.set(\\tailTime, obj.value.linlin(0,1, 0.1,20));\r\n\t});\r\n\r\n\r\n\r\n\t//volume\r\n\tlabel = StaticText(~subPanel[3], Rect(0,0,120,12))\r\n\t.string_(\"Volumes\").align_(\\left)\r\n\t.font_(Font(\"Arial\",12))\r\n\t.align_(\\left);\r\n\r\n\tslider = Slider(~subPanel[3], Rect.new(0,20,40,14))\r\n\t.background_(Color.rand(0.7,0.8))\r\n\t.valueAction_(0.5)\r\n\t.action_({\r\n\t\targ obj;\r\n\t\tobj.value;\r\n\t\t~riff1.sAmp = obj.value.linlin(0,1, 0,1 );\r\n\t});\r\n\tlabel = StaticText(~subPanel[3], Rect(0,0,50,10))\r\n\t.string_(\"Riff Straight\" )\r\n\t.font_(Font(\"Arial\",10))\r\n\t.align_(\\left);\r\n\r\n\tslider = Slider(~subPanel[3], Rect.new(0,20,40,14))\r\n\t.background_(Color.rand(0.7,0.8))\r\n\t.valueAction_(0.85)\r\n\t.action_({\r\n\t\targ obj;\r\n\t\t~jpRev.set(\\straightOutVol, obj.value.linlin(0,1, 0,1 ));\r\n\t});\r\n\tlabel = StaticText(~subPanel[3], Rect(0,0,50,10))\r\n\t.string_(\"jpVerb riff\")\r\n\t.font_(Font(\"Arial\",10))\r\n\t.align_(\\left);\r\n};\r\n\r\n\r\n\r\n~newChordByType = {\r\n\targ type, startIndex,numberOfNotes;\r\n\tvar tempIndex,check,chord;\r\n\tchord = Array.fill(numberOfNotes, { Rest() });\r\n\tnumberOfNotes.do {arg index = 0;\r\n\t\tswitch (type,\r\n\t\t\t0, {tempIndex = rrand(startIndex,28); check=0},     //white note random\r\n\t\t\t1, {tempIndex = startIndex + index; check=0},             //white note mode\r\n\t\t\t2, {tempIndex = startIndex + (index*2); check=0},         //white note chord\r\n\t\t\t3, {tempIndex = startIndex +( index*3); check=0},         //white note wide chord\r\n\t\t\t4, {tempIndex = rrand(startIndex+36,48); check=1},     //chromatic random\r\n\t\t\t5, {tempIndex = startIndex+36 + index; check=1},             //chromatic scale\r\n\t\t\t6, {tempIndex = startIndex+36 + (index*2); check=1},         //chromatic whole note check\r\n\t\t\t7, {tempIndex = startIndex+36 +( index*3); check=1},         //chromatic minor thirds scale\r\n\t\t);\r\n\t\tif (check == 0,\r\n\t\t\t{if (tempIndex > 28, {tempIndex = 28; \"WARNING INDEX TOO BIG\".postln;});\r\n\t\t\t\tchord[index] = ~whiteNotes[tempIndex];\r\n\t\t\t},\r\n\t\t\t{if (tempIndex > 84, {tempIndex = 28; \"WARNING INDEX TOO BIG\".postln;});\r\n\t\t\t\tchord[index] = tempIndex;\r\n\t\t});\r\n\t};\r\n\t(\"new chord is \" + chord).postln;\r\n\tchord;\r\n};\r\n\r\n\r\n~switchPattern = {arg onOrOff;\r\n\tif (onOrOff == \"on\",\r\n\t\t{switch (~onPattern,\r\n\t\t\t0, {Pdefn(\\onPattern,   ~onChord)},\r\n\t\t\t1, {Pdefn(\\onPattern,   Pseq(~onChord,inf))},\r\n\t\t\t2, {Pdefn(\\onPattern,   Pseq(~onChord.reverse,inf))},\r\n\t\t\t3, {Pdefn(\\onPattern,   Prand(~onChord,inf))},\r\n\t\t\t4, {Pdefn(\\onPattern,   Pseq([Rest()],inf))},\r\n\t\t)},\r\n\t\t{switch (~offPattern,\r\n\t\t\t0, {Pdefn(\\offPattern,   ~offChord)},\r\n\t\t\t1, {Pdefn(\\offPattern,   Pseq(~offChord,inf))},\r\n\t\t\t2, {Pdefn(\\offPattern,   Pseq(~offChord.reverse,inf))},\r\n\t\t\t3, {Pdefn(\\offPattern,   Prand(~offChord,inf))},\r\n\t\t\t4, {Pdefn(\\offPattern,   Pseq([Rest()],inf))},\r\n\t\t)}\r\n\t)\r\n};\r\n\r\n)"
}
