net.beadsproject.beads.data
Class SampleManager

java.lang.Object
  extended by net.beadsproject.beads.data.SampleManager

public class SampleManager
extends java.lang.Object

SampleManager provides a static repository for Sample data and provides methods to organise samples into groups.


Nested Class Summary
static interface SampleManager.SampleGroupListener
          Interface for notificaiton of changes to a group.
 
Constructor Summary
SampleManager()
           
 
Method Summary
static void addGroupListener(SampleManager.SampleGroupListener l)
           
static void addToGroup(java.lang.String group, java.util.List<Sample> newSamples)
          Add a new list of Samples to the specified group.
static void addToGroup(java.lang.String group, Sample sample)
          Add a new Sample to a group.
static void destroyGroup(java.lang.String groupName)
          Removes the specified group, and removes all of the samples found in the group from the sample repository.
static Sample fromGroup(java.lang.String groupName, int index)
          Gets the Sample at the specified index from the specified group.
static java.util.ArrayList<Sample> getGroup(java.lang.String groupName)
          Gets the specified group in the form ArrayList<Sample>.
static java.lang.String getGroupDir(java.lang.String groupName)
          Gets the directory path of the group.
static java.util.List<java.lang.String> getSampleNameList()
          Returns an ArrayList containing all of the Sample names.
static java.util.List<Sample> group(java.lang.String groupName, Sample[] sampleList)
          Generates a new group with the given group name and list of Samples to be added to the group.
static java.util.List<Sample> group(java.lang.String groupName, java.lang.String folderName)
          Generates a new group with the given group name and a string that specifies where to load samples to be added to the group.
static java.util.List<Sample> group(java.lang.String groupName, java.lang.String[] fileNameList)
          Generates a new group with the given group name and a list of file names to be added to the group.
static java.util.List<Sample> group(java.lang.String groupName, java.lang.String[] fileNameList, int maxItems)
          Generates a new group with the given group name and a list of file names to be added to the group, with number of elements loaded limited to maxItems.
static java.util.List<Sample> group(java.lang.String groupName, java.lang.String folderName, int maxItems)
          Generates a new group with the given group name and a string that specifies where to load samples to be added to the group, and also limits the number of items loaded from the folder to maxItems.
static java.util.Set<java.lang.String> groups()
          Gets the set of group names.
static java.util.List<java.lang.String> groupsAsList()
          List the groups by name as a list of Strings.
static boolean isVerbose()
          Determines if SampleManager is being verbose.
static void logSamplePaths(java.lang.String toFile)
          Creates a text file at the specified path containing a list of all of the file names of Samples loaded so far.
static void printSampleList()
          Prints a list of all Samples to System.out.
static Sample randomFromGroup(java.lang.String groupName)
          Gets a random sample from the specified group.
static void removeGroup(java.lang.String groupName)
          Removes the specified group, without removing the samples.
static void removeGroupListener(SampleManager.SampleGroupListener l)
           
static void removeSample(Sample sample)
          Removes the Sample.
static void removeSample(java.lang.String sampleName)
          Removes the named Sample.
static Sample sample(java.io.InputStream is)
          Returns a new Sample from the given filename.
static Sample sample(java.lang.String fn)
          Returns a new Sample from the given filename.
static Sample sample(java.lang.String ref, java.io.InputStream is)
          Like sample(String) but with the option to specify the name with which this Sample is indexed.
static void sample(java.lang.String name, Sample sample)
          Adds a sample by name to the sample list.
static Sample sample(java.lang.String ref, java.lang.String fn)
          Like sample(String) but with the option to specify the name with which this Sample is indexed.
static void setVerbose(boolean verbose)
          Tells SampleManager to produce verbose output.
static void transferSamples(java.lang.String sourceRootDir, java.lang.String destRootDir, boolean force)
          Takes all of the Samples currently stored and attempts to relocate them so that their position relative to destRootDir duplicates their position relative to sourceRootDir.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SampleManager

public SampleManager()
Method Detail

sample

public static Sample sample(java.lang.String fn)
Returns a new Sample from the given filename. If the Sample has already been loaded, it will not be loaded again, but will simply be retrieved from the static repository.

Parameters:
fn - the file path.
Returns:
the sample.

sample

public static Sample sample(java.io.InputStream is)
Returns a new Sample from the given filename. If the Sample has already been loaded, it will not be loaded again, but will simply be retrieved from the static repository.

Parameters:
is - the InputStream.
Returns:
the sample.

sample

public static void sample(java.lang.String name,
                          Sample sample)
Adds a sample by name to the sample list. This lets you load samples with a different buffering regime.

Parameters:
name -
sample -

sample

public static Sample sample(java.lang.String ref,
                            java.lang.String fn)
Like sample(String) but with the option to specify the name with which this Sample is indexed.

Parameters:
ref - the name with which to index this Sample.
fn - the file path.
Returns:
the sample.

sample

public static Sample sample(java.lang.String ref,
                            java.io.InputStream is)
Like sample(String) but with the option to specify the name with which this Sample is indexed.

Parameters:
ref - the name with which to index this Sample.
is - the InputStream.
Returns:
the sample.

group

public static java.util.List<Sample> group(java.lang.String groupName,
                                           Sample[] sampleList)
Generates a new group with the given group name and list of Samples to be added to the group.

Parameters:
groupName - the group name.
sampleList - the sample list.

group

public static java.util.List<Sample> group(java.lang.String groupName,
                                           java.lang.String folderName)
Generates a new group with the given group name and a string that specifies where to load samples to be added to the group. The string is interpreted firstly as a URL, and if that fails, as a folder path.

Parameters:
groupName - the group name.
folderName - the folder address (URL or file path).

group

public static java.util.List<Sample> group(java.lang.String groupName,
                                           java.lang.String folderName,
                                           int maxItems)
Generates a new group with the given group name and a string that specifies where to load samples to be added to the group, and also limits the number of items loaded from the folder to maxItems. The string is interpreted firstly as a URL, and if that fails, as a folder path.

Parameters:
groupName - the group name.
folderName - the folder address (URL or file path).
maxItems - number of items to limit to.

group

public static java.util.List<Sample> group(java.lang.String groupName,
                                           java.lang.String[] fileNameList)
Generates a new group with the given group name and a list of file names to be added to the group.

Parameters:
groupName - the group name.
fileNameList - the file name list.

group

public static java.util.List<Sample> group(java.lang.String groupName,
                                           java.lang.String[] fileNameList,
                                           int maxItems)
Generates a new group with the given group name and a list of file names to be added to the group, with number of elements loaded limited to maxItems.

Parameters:
groupName - the group name.
fileNameList - the file name list.
maxItems - number of items to limit to.

addToGroup

public static void addToGroup(java.lang.String group,
                              Sample sample)
Add a new Sample to a group. Create the group if it doesn't exist.

Parameters:
group - the group to add to.
sample - the Sample to add.

addToGroup

public static void addToGroup(java.lang.String group,
                              java.util.List<Sample> newSamples)
Add a new list of Samples to the specified group. Create the group if it doesn't exist.

Parameters:
group - the group to add to.
newSamples - the list of Samples to add.

groups

public static java.util.Set<java.lang.String> groups()
Gets the set of group names.

Returns:
Set of Strings representing group names.

groupsAsList

public static java.util.List<java.lang.String> groupsAsList()
List the groups by name as a list of Strings.

Returns:
a List of Strings.

getGroup

public static java.util.ArrayList<Sample> getGroup(java.lang.String groupName)
Gets the specified group in the form ArrayList<Sample>.

Parameters:
groupName - the group name.
Returns:
the group.

getGroupDir

public static java.lang.String getGroupDir(java.lang.String groupName)
Gets the directory path of the group.

Parameters:
groupName -
Returns:
directory path.

randomFromGroup

public static Sample randomFromGroup(java.lang.String groupName)
Gets a random sample from the specified group.

Parameters:
groupName - the group.
Returns:
a random Sample.

fromGroup

public static Sample fromGroup(java.lang.String groupName,
                               int index)
Gets the Sample at the specified index from the specified group. If index is greater than the size of the group then the value index % sizeOfGroup is used.

Parameters:
groupName - the group name.
index - the index.
Returns:
the Sample.

removeSample

public static void removeSample(java.lang.String sampleName)
Removes the named Sample.

Parameters:
sampleName - the sample name.

removeSample

public static void removeSample(Sample sample)
Removes the Sample.

Parameters:
sample - the Sample.

removeGroup

public static void removeGroup(java.lang.String groupName)
Removes the specified group, without removing the samples.

Parameters:
groupName - the group name.

destroyGroup

public static void destroyGroup(java.lang.String groupName)
Removes the specified group, and removes all of the samples found in the group from the sample repository.

Parameters:
groupName - the group name.

addGroupListener

public static void addGroupListener(SampleManager.SampleGroupListener l)

removeGroupListener

public static void removeGroupListener(SampleManager.SampleGroupListener l)

printSampleList

public static void printSampleList()
Prints a list of all Samples to System.out.


getSampleNameList

public static java.util.List<java.lang.String> getSampleNameList()
Returns an ArrayList containing all of the Sample names.

Returns:
ArrayList of Sample names.

isVerbose

public static boolean isVerbose()
Determines if SampleManager is being verbose.

Returns:
true if verbose.

setVerbose

public static void setVerbose(boolean verbose)
Tells SampleManager to produce verbose output.

Parameters:
verbose - true for verbose output.

logSamplePaths

public static void logSamplePaths(java.lang.String toFile)
Creates a text file at the specified path containing a list of all of the file names of Samples loaded so far. Useful if you need to gather all of your sample data into one place using a script. Puts all file names in double quotes.

Parameters:
toFile - destination of the file.

transferSamples

public static void transferSamples(java.lang.String sourceRootDir,
                                   java.lang.String destRootDir,
                                   boolean force)
Takes all of the Samples currently stored and attempts to relocate them so that their position relative to destRootDir duplicates their position relative to sourceRootDir. This only applies to Samples that were loaded from a position below sourceRootDir.

Parameters:
sourceRootDir - root that you want to transfer from
destRootDir - place you want to transfer to
force - set to true to force overwrite existing files - take care!