{
   "ancestor_list" : [],
   "description" : "Example of the Graphical Tracker Functions usage ( https://sccode.org/1-5cA ). Both files should be saved inside the same folder. See internal documentation for more details.",
   "author" : "Dindoléon",
   "name" : "Graphical Tracker Functions Example",
   "is_private" : null,
   "id" : "1-5cB",
   "code" : "(\r\n\r\nvar synth; // This variable wil hold the synth definition which will produce sound\r\nvar folder_path = thisProcess.nowExecutingPath.dirname ++ \"/\"; // Get the actual folder name to load the tracker module\r\n\r\n// The tracker will work modifying an array of note playing probabilities (i.e. 1 = 100% chance, 0.5 = 50% chance, etc). The size of the array will define the beat number. Here, we'll have three examples, one for the binary tracker, one for the brobabilist tracker, and one for the duo tracker, which is a combination of these two.\r\n\r\nvar rythm = [ 1, 0, 0, 1, 0, 0, 1, 0 ];\r\nvar rythm2 = [ 1, 0.28571428571429, 0, 0.57142857142857, 0.28571428571429, 0.57142857142857 ];\r\nvar rythm3 = [ 1, 0, 0.28571428571429, 0.57142857142857, 0, 0.57142857142857, 1, 0.28571428571429, 0, 1 ];\r\n\r\nvar binary_tracker_text, probabilist_tracker_text, duo_tracker_text;\r\n\r\nvar win = Window.new( \"Tracker Example\", Rect( 100, 100, 500, 300 ) ); // Obviously, the purpose of these trackers is to be displayed somewhere.\r\n\r\nt = TempoClock.new(); // Let's define a TempoClock to drive the routines.\r\nt.tempo = 4;\r\n\r\nsynth = SynthDef( \\test_synth, { | freq = 220 | // A really simple synth for example purposes\r\n\r\n\tvar env = Env.perc( 0.05, 1, 1 );\r\n\tvar envgen = EnvGen.kr( env, doneAction: Done.freeSelf );\r\n\tvar snd = SinOsc.ar( freq, mul: envgen * 0.25 );\r\n\r\n\tOut.ar( 0, [ snd, snd ] );\r\n\r\n}).add();\r\n\r\n\r\nRoutine { // Routine associated to the first tracker.\r\n\r\n\tvar count = 0; // This will store the current beat\r\n\r\n\tloop {\r\n\t\tif( rythm[count].coin, {\tSynth( \\test_synth, [\\freq, 440] ) } ); // Coin function used against the note playing probability at the current rythm index.\r\n\t\tcount = count + 1; // Current beat moving on...\r\n\t\tif( count == rythm.size, { count = 0 } ); // ...getting back to 0 if it passed the rythm length.\r\n\t\t1.wait; // Wait for the next beat, please.\r\n\t};\r\n}.play( t ); // Our TempoClock will drive the routine.\r\n\r\nRoutine { // Rythm #2\r\n\tvar count = 0;\r\n\tloop {\r\n\t\tif( rythm2[count].coin, { Synth( \\test_synth, [\\freq, 440 * 3/2] ) } );\r\n\t\tcount = count + 1;\r\n\t\tif( count == rythm2.size, { count = 0 } );\r\n\t\t1.wait;\r\n\t};\r\n}.play( t );\r\n\r\nRoutine { // Rythm #3\r\n\tvar count = 0;\r\n\tloop {\r\n\t\tif( rythm3[count].coin, { Synth( \\test_synth, [\\freq, 440 * 5/4] ) } );\r\n\t\tcount = count + 1;\r\n\t\tif( count == rythm3.size, { count = 0 } );\r\n\t\t1.wait;\r\n\t};\r\n}.play( t );\r\n\r\nthis.executeFile( ( folder_path ++ \"tracker.scd\" ).standardizePath ); // Now load the tracker functions, which will be stored on global variables.\r\n\r\n// Now add the three tracker types. See tracker.scd for a description of the algorithms.\r\n\r\nbinary_tracker_text = StaticText.new( win, Rect( 0, 0, win.bounds.width, 30 ) );\r\nbinary_tracker_text.align = \\center;\r\nbinary_tracker_text.string = \"Binary Tracker :\";\r\n\r\n~add_binary_tracker.value( rythm, win, Rect( 0, 30, win.bounds.width, win.bounds.height / 3 - 30 ), 1, Color( 1, 0.5, 0 ) );\r\n\r\nprobabilist_tracker_text = StaticText.new( win, Rect( 0, win.bounds.height * 0.333, win.bounds.width, 30 ) );\r\nprobabilist_tracker_text.align = \\center;\r\nprobabilist_tracker_text.string = \"Probabilist Tracker :\";\r\n\r\n~add_probabilist_tracker.value( rythm2, win, Rect( 0, win.bounds.height * 0.333 + 30, win.bounds.width, win.bounds.height / 3 - 30 ), 1, [ 0, 0.5, 1 ], 0, 1, 8 );\r\n\r\nduo_tracker_text = StaticText.new( win, Rect( 0, win.bounds.height * 0.666, win.bounds.width, 30 ) );\r\nduo_tracker_text.align = \\center;\r\nduo_tracker_text.string = \"Duo Tracker :\";\r\n\r\n~add_duo_tracker.value( rythm3, win, Rect( 0, win.bounds.height * 0.666 + 30, win.bounds.width, win.bounds.height / 3 - 30 ), 1, [ 0, 1, 0.5 ], 0, 1, 8 );\r\n\r\n// Finally, bring the window to the front.\r\nwin.front;\r\nCmdPeriod.doOnce({Window.closeAll}); // Kill GUI and server sounds on < Ctrl + ^ + . > .\r\nwin.onClose = {\r\n\ts.freeAll;\r\n\tWindow.closeAll;\r\n};\r\n\r\n)",
   "labels" : [
      "gui",
      "tracker",
      "api"
   ]
}
