AbstractPlayer a playable synthesis process


superclass: AbstractFunction


Players are things that play.  Anything that you want to play, you can stick your concept into a subclass of AbstractPlayer and you will inherit powerful server management and patching abilities.


A Player can be told to play and to stop, and will allocate and load any resources needed.  Many players have subplayers.  PlayerMixer mixes several players together.  Patch can take other players as inputs. PlayerSeqTrack can sequence successions of players.



play(group,atTime,bus)

boots the server, prepares the player for play (loading samples etc.)

and spawns the player

all of these args are optional

group - a Server (will use the root node) 

a Group

nil (default server's root node)

atTime - see atTime (Nil,Float,Integer or Date)

bus - (Bus,Integer,Nil) 

a specific Bus to play on, otherwise will default to the main audio outs


spawn(atTime)

assumes the player has been prepared.  see prepareForPlay

stop(atTime)

stops playing but does not deallocate any resources (buffers etc.)

free 

stops playind and frees all allocated resources (buffers etc.)


release(releaseTime,atTime)

call release on the synth, with the releaseTime

then calls stop on the player, so even if the synthDef does not have a \gate

input, it will function the same as stop after a short delay.


prepareForPlay(group,isPrivate,bus)

group - a Server, a Group or Nil

isPrivate: a public bus is one of the main audio outputs of your soundcard.

a private bus is one that will be patched and mixed further down the line.

When makePatchOut is called on the top player (the one that actually was sent .play)

it plays to a public (main audio output), and any internal children are told to 

allocate and play onto a private bus.

bus -    a specific Bus to play on.  this will cause isPrivate to be ignored


this loads the synthDef to the server for the player and all of its children,

and allocates any resources such as buffers, loading sound files etc.

see also [playerServerSupport]



Common players

Patch 

- specifies a function ( Instr ) and the arguments 

with which to play that function.

SFP 

- plays sound files

StreamKrDur Stream2Trig 

- renders a number stream to a .kr signal

InstrSpawner InstrGateSpawner



Gui

AbstractPlayer also comes with a powerful gui class framework.  Because of this, many people make the mistake of assuming that AbstractPlayer is primarily a way to get pretty windows.  It has nothing to do with that.


But it is very nice  to:

hit the play button and have your sound play.

select a format, choose a path by normal dialog and record your 

sound to disk as a soundfile.

hit the save button and save your object with all its parameters to disk.

change the tempo when you want to.



Methods


path -  if loaded or saved, the player knows its path

name - if loaded or saved, the filename, else the name of the class (eg. "a Patch")




children - for players that hold other players or objects, return those children

player classes should implement where appropriate.

a Patch has its args as children

SFP has its underlying object as child


using this.children.do({arg item; .... })  can save you from having to muck up 

the Player class with extra methods.

allChildren - and all your children's children, and their children...

deepDo(function) - do to allChildren









Subclassing AbstractPlayer


see [playerServerSupport] for a rundown of the complexities involved


After that you would usually write a gui class for it.

Then implement the storeParamsOn method which enables you 

to load and save your object.


AbstractPlayer  is a subclass of AbstractFunction 

therefore you can do math with them:


//right now this works, but only with simple ugenGraphs, no Samples,Envs etc.

(Patch({ Saw.ar(400) }).wrap2( 0.5) ).gui



// not yet

(Patch({ Saw.ar(400) }).wrap2( KrNumberEditor(0.5,[0.0,1.0]) ) ).gui


//(somePatch * EnvPlayer.new(Env.newClear(10)) ).topGui