{
   "labels" : [],
   "code" : "// ===================================\r\n// SynthDefs here\r\n// ===================================\r\n\r\n// Your SynthDefs go here\r\n(\r\n\r\n\r\n\r\n\r\n) // end of SynthDefs\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n// ===================================\r\n// Define a bunch of \"score snippets\"\r\n// ===================================\r\n\r\n(\r\n\r\n~beat = Pbind(\r\n    \\degree, [0, 7],\r\n    \\ctranspose, 24,\r\n    \\dur, 0.2,\r\n    \\legato, 0.1,\r\n    \\amp, Pseq([0.2, 0.12, 0.16, 0.12], inf)\r\n); // forever pattern\r\n\r\n~up = Pbind(\r\n\t\\scale, Scale.major,\r\n    \\degree, Pseq([0, 1, 2, 3, 4, 5, 6, 7], 1), // finite pattern\r\n    \\dur, 0.2\r\n);\r\n\r\n~down = Pbind(\r\n\t\\scale, Scale.minor,\r\n    \\degree, Pseq([7, 6, 5, 4, 3, 2, 1, 0], 1), // finite pattern\r\n    \\dur, 0.1,\r\n);\r\n\r\n~trill = Pbind(\r\n\t\\degree, Pseq([8, 9], 4), // finite Pattern\r\n    \\dur, 0.1\r\n);\r\n\r\n~thick = Pbind(\r\n    \\degree, Pseq([0, 1, 2, 3, 4, 5, 6, 7], 1), // finite Pattern\r\n    \\dur, 0.2,\r\n    \\mtranspose, [0, 2, 4, 6, 8, 10, 12, 14]\r\n);\r\n\r\n) // end of Pbind definitions\r\n\r\n\r\n\r\n\r\n\r\n// ============\r\n// Quick test\r\n// ============\r\n\r\n~beat.play;\r\n~up.play;\r\n~down.play;\r\n~trill.play;\r\n~thick.play;\r\n\r\n\r\n\r\n\r\n\r\n\r\n// =====================\r\n// Sequencing & playing\r\n// using Pspawner\r\n// =====================\r\n\r\n// The advantage is that the spawner *knows* when a pattern has finished.\r\n// (... as opposed to sequencing patterns inside a {}.fork)\r\n\r\n// It's like a fork (things happen in order top to bottom), but\r\n// you always use the spawner argument (in this case, \"maestro\" -- arbitrary name)\r\n// in order to request a new pattern.\r\n\r\n// Notice you should NOT put any .play inside the Pspawner. The only .play is at the very end of the Pspawner.\r\n\r\n// When you write \"maestro.seq(somePattern)\", you are saying:\r\n// \"maestro, please play this pattern and only move on in the sequence AFTER said pattern is finished\".\r\n\r\n// When you write \"maestro.par(somePattern)\", you are saying:\r\n// \"maestro, please start playing this pattern and MOVE ON RIGHT AWAY to the next line.\"\r\n\r\n// Patterns that self-terminate will do so as expected.\r\n// Patterns that do not self-terminate (inf) will keep going forever until told to stop.\r\n\r\n// TIP 1: Notice that if you write maestro.seq(someInfPattern) you are setting yourself up for failture. If you request maestro to play an *infinite* pattern and only move on when it's finished, maestro will never move on.\r\n\r\n// TIP 2: In order to control start and stop of specific patterns, you should declare a new variable to name it (as you learned before). See ~player1 example below.\r\n\r\n\r\n\r\n(\r\nPspawner({ arg maestro;\r\n\r\n\t\"Scales in sequence, one right after the other\".postln;\r\n    maestro.seq(~up);\r\n\t\"Down...\".postln;\r\n    maestro.seq(~down);\r\n\r\n\t\"With a little pause in between\".postln;\r\n    maestro.wait(2.5);\r\n    maestro.seq(~up);\r\n    maestro.wait(1);\r\n    maestro.seq(~down);\r\n    maestro.wait(1);\r\n\r\n\t\"Now two of them in paralell\".postln;\r\n    maestro.seq(Ppar([~up, ~down]));\r\n\r\n\tmaestro.wait(4);\r\n\r\n\t\"Now the never-ending beat\".postln;\r\n    // Saving into a variable so I can stop it later\r\n    ~player1 = maestro.par(~beat);\r\n    maestro.wait(4);\r\n\r\n\t\"Up again...\".postln;\r\n    maestro.seq(~up);\r\n    maestro.wait(1);\r\n\r\n\t\"Stop player1 beta\".postln;\r\n\tmaestro.suspend(~player1); // stop that one\r\n    maestro.wait(1);\r\n\r\n\t\"Play the thick pattern\".postln;\r\n    maestro.seq(~thick);\r\n\r\n\t\"Bye!\".postln;\r\n    maestro.suspendAll;\r\n\r\n}).play\r\n)",
   "id" : "1-554",
   "is_private" : null,
   "author" : "Bruno Ruviaro",
   "name" : "Pspawner demo",
   "description" : "A short classroom demonstration of sequencing patterns with Pspawner",
   "ancestor_list" : []
}
