com.softsynth.jsyn.util
Class VoiceAllocator

java.lang.Object
  extended by com.softsynth.jsyn.util.VoiceAllocator
Direct Known Subclasses:
BussedVoiceAllocator

public abstract class VoiceAllocator
extends java.lang.Object

Voice Allocator for managing the allocation and reuse of voices. Uses an abstract method makeVoice() which the user must define in a subclass. BussedVoiceAllocator is typically used instead of VoiceAllocator. To allocate a voice if freely available, use allocate().
To allocate a free voice, or steal the oldest voice use steal(). Steal is the preferred method for getting a voice because it is usually more important to start the new voice then to continue the old one.

Author:
(C) 1997 Phil Burk, SoftSynth.com, All Rights Reserved
See Also:
com.softsynth.jsyn.examples.TJ_PlayKeys1, BussedVoiceAllocator

Constructor Summary
VoiceAllocator(int maxVoices)
           
VoiceAllocator(SynthContext synthContext, int maxVoices)
          Specify the maximum number of voices that can be allocated at a time.
 
Method Summary
 SynthCircuit allocate()
           
 SynthCircuit allocate(int startTime)
          Allocate a voice to use with an unknown stopTime.
 SynthCircuit allocate(int startTime, int stopTime)
          Allocate a voice using a default priority of zero.
 SynthCircuit allocate(int startTime, int stopTime, int priority)
          Allocate a voice for use at startTime, lasting until stopTime.
 void clear()
          Delete all of the allocated voices and clear records of the allocations.
 void delete()
          Calls clear().
 void free(int stopTime, SynthCircuit circuit)
          Free a voice for others to use.
 void free(SynthCircuit circuit)
           
 int getMaxVoices()
           
 SynthCircuit getNthVoice(int index)
           
 int getNumVoices()
           
abstract  SynthCircuit makeVoice()
          Create a new voice.
 SynthCircuit steal()
           
 SynthCircuit steal(int startTime)
          Steal a voice with an unknown stopTime.
 SynthCircuit steal(int startTime, int stopTime)
          Steal a voice using a default priority of zero.
 SynthCircuit steal(int startTime, int stopTime, int priority)
          Allocate a voice at startTime, lasting until stopTime.
 void stop()
           
 void stop(int time)
          Stop all of the allocated voices.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VoiceAllocator

public VoiceAllocator(SynthContext synthContext,
                      int maxVoices)
Specify the maximum number of voices that can be allocated at a time. If an attempt is made to allocate more, then voices that are in use may be stolen.


VoiceAllocator

public VoiceAllocator(int maxVoices)
Method Detail

getMaxVoices

public int getMaxVoices()
Returns:
Maximum number of voices that will be allocated.

getNumVoices

public int getNumVoices()
Returns:
Current number of voices allocated.

getNthVoice

public SynthCircuit getNthVoice(int index)
Returns:
Nth voice or null.

makeVoice

public abstract SynthCircuit makeVoice()
                                throws SynthException
Create a new voice. This method must be defined in your classes.

Throws:
SynthException

allocate

public SynthCircuit allocate(int startTime,
                             int stopTime,
                             int priority)
                      throws SynthException
Allocate a voice for use at startTime, lasting until stopTime.

Returns:
a voice or null if maximum number of voices are already allocated.
Throws:
SynthException

allocate

public SynthCircuit allocate(int startTime,
                             int stopTime)
                      throws SynthException
Allocate a voice using a default priority of zero.

Throws:
SynthException

allocate

public SynthCircuit allocate(int startTime)
                      throws SynthException
Allocate a voice to use with an unknown stopTime.

Throws:
SynthException

allocate

public SynthCircuit allocate()
                      throws SynthException
Throws:
SynthException

steal

public SynthCircuit steal(int startTime,
                          int stopTime,
                          int priority)
                   throws SynthException
Allocate a voice at startTime, lasting until stopTime. Try to allocate a voice then steal the voice whose stopTime is earliest if none other available.

Throws:
SynthException

steal

public SynthCircuit steal(int startTime,
                          int stopTime)
                   throws SynthException
Steal a voice using a default priority of zero.

Throws:
SynthException

steal

public SynthCircuit steal(int startTime)
                   throws SynthException
Steal a voice with an unknown stopTime.

Throws:
SynthException

steal

public SynthCircuit steal()
                   throws SynthException
Throws:
SynthException

free

public void free(int stopTime,
                 SynthCircuit circuit)
Free a voice for others to use.


free

public void free(SynthCircuit circuit)
          throws SynthException
Throws:
SynthException

stop

public void stop(int time)
Stop all of the allocated voices.


stop

public void stop()

delete

public void delete()
Calls clear().


clear

public void clear()
Delete all of the allocated voices and clear records of the allocations.