com.groovemanager.sampled.nondestructive
Class CutList

java.lang.Object
  extended by com.groovemanager.sampled.nondestructive.AbstractSource
      extended by com.groovemanager.sampled.nondestructive.CutList
All Implemented Interfaces:
CutListSource, ModificationListener

public class CutList
extends AbstractSource
implements CutListSource, ModificationListener

A CutList consists of a CutListSource and a stack of CutListElements that acts as a CutListSource itself. When queried for an AudioInputStream or a WaveForm, the CutList will handle over the request to the top CutListElement, which handles it over to the next one and so on. Each CutListElement adds its own modification to the CutList. The result will then be an AudioinputStream or a WaveForm containing all modifications of the CutList.

Author:
Manu Robledo

Field Summary
private  java.util.ArrayList elements
          List of CutListElements contained in this CutList
private  CutListSource lastResult
          The last result of the query through all CutListEleemnts.
private  CutListSource source
          The CutListSource of this CutList
 
Constructor Summary
CutList(CutListSource source)
          Create a new CutList using the given source
 
Method Summary
 void addElement(CutListElement el)
          Add a CutListElement to the top of this CutList
protected  void calcLastResult()
          Calc the resulting CutListSource element by quering through all CutListElements
 CutListSource duplicate()
          Create a new CutListSource that represents the same data, but is independent of changes made to this source
 javax.sound.sampled.AudioInputStream getAudioInputStream(int start, int length)
          Get an AudioInputStream from this source
 CutListElement getLastElement()
          Get the top element of this CutList
 int getLength()
          Get the total length of this source in sample frames
 WaveForm getWaveForm(int start, int length, int width)
          Get a WaveForm from this source
 boolean isReady()
          Ask this source, if it is ready for providing audio data
 void remove(CutListElement el)
          Remove a CutListElement from this CutList
 void removeElement(CutListElement el)
          Remove a CutListElement from this CutList
 void removeLastElement()
          Remove this CutListīs top element
 void replaceFile(java.io.File from, java.io.File to)
          Replace all references to the given source file inside this CutListSource with references to the given target file.
 void setSource(CutListSource source)
          Set this CutListīs source
 void update()
          Notification that a change has been made to this CutList
 void update(CutListElement element)
          Notification about the change of a CutListElement
 void update(CutListSource source)
          Notification about the change of a CutListSource
 boolean usesFile(java.io.File f)
          Ask this CutListSource whether it relies on the contents of the given file.
 
Methods inherited from class com.groovemanager.sampled.nondestructive.AbstractSource
addModificationListener, notifyListeners, removeModificationListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.groovemanager.sampled.nondestructive.CutListSource
addModificationListener, removeModificationListener
 

Field Detail

elements

private java.util.ArrayList elements
List of CutListElements contained in this CutList


lastResult

private CutListSource lastResult
The last result of the query through all CutListEleemnts. As long as no modification happens to any this CutListīs elements or to its source, this result can be used again and again to avoid having to calculate it for each request.


source

private CutListSource source
The CutListSource of this CutList

Constructor Detail

CutList

public CutList(CutListSource source)
Create a new CutList using the given source

Parameters:
source - The CutListSource to get the audio data from
Method Detail

addElement

public void addElement(CutListElement el)
Add a CutListElement to the top of this CutList

Parameters:
el - The CutListEleemnt to add

calcLastResult

protected void calcLastResult()
Calc the resulting CutListSource element by quering through all CutListElements


duplicate

public CutListSource duplicate()
Description copied from interface: CutListSource
Create a new CutListSource that represents the same data, but is independent of changes made to this source

Specified by:
duplicate in interface CutListSource
Returns:
An independent copy of this source
See Also:
CutListSource.duplicate()

getAudioInputStream

public javax.sound.sampled.AudioInputStream getAudioInputStream(int start,
                                                                int length)
                                                         throws NotReadyException
Description copied from interface: CutListSource
Get an AudioInputStream from this source

Specified by:
getAudioInputStream in interface CutListSource
Parameters:
start - The start position of the stream in sample frames
length - The length of the stream in sample frames
Returns:
An AudioInputStream starting at position start of this source with the length of length sample frames.
Throws:
NotReadyException - If the audio data can not be provided
See Also:
CutListSource.getAudioInputStream(int, int)

getLastElement

public CutListElement getLastElement()
Get the top element of this CutList

Returns:
This CutListīs top element or null, if it has no elements

getLength

public int getLength()
Description copied from interface: CutListSource
Get the total length of this source in sample frames

Specified by:
getLength in interface CutListSource
Returns:
The length of this source in sample frames
See Also:
CutListSource.getLength()

getWaveForm

public WaveForm getWaveForm(int start,
                            int length,
                            int width)
Description copied from interface: CutListSource
Get a WaveForm from this source

Specified by:
getWaveForm in interface CutListSource
Parameters:
start - The start position of the WaveForm in sample frames
length - The length of the audio data represented by the WaveForm in sample frames
width - The width in which the WaveForm should be displayed
Returns:
A WaveForm starting at position start of this source representing length sample frames with the width of width.
See Also:
CutListSource.getWaveForm(int, int, int)

isReady

public boolean isReady()
Description copied from interface: CutListSource
Ask this source, if it is ready for providing audio data

Specified by:
isReady in interface CutListSource
Returns:
true, if this source can provide data, false otherwise
See Also:
CutListSource.isReady()

remove

public void remove(CutListElement el)
Remove a CutListElement from this CutList

Parameters:
el - The CutListElement to remove

removeElement

public void removeElement(CutListElement el)
Remove a CutListElement from this CutList

Parameters:
el - The CutListElement to remove

removeLastElement

public void removeLastElement()
Remove this CutListīs top element


replaceFile

public void replaceFile(java.io.File from,
                        java.io.File to)
Description copied from interface: CutListSource
Replace all references to the given source file inside this CutListSource with references to the given target file. This may be because the source file is about to change and to avoid inconsistencies. If the given source file is not used by this CutListSource, the call can be ignored.

Specified by:
replaceFile in interface CutListSource
Parameters:
from - The source file to replace
to - The target file to replace with
See Also:
CutListSource.replaceFile(java.io.File, java.io.File)

setSource

public void setSource(CutListSource source)
Set this CutListīs source

Parameters:
source - The new CutListSource

update

public void update()
Notification that a change has been made to this CutList


update

public void update(CutListElement element)
Description copied from interface: ModificationListener
Notification about the change of a CutListElement

Specified by:
update in interface ModificationListener
Parameters:
element - The modified CutListElement
See Also:
ModificationListener.update(com.groovemanager.sampled.nondestructive.CutListElement)

update

public void update(CutListSource source)
Description copied from interface: ModificationListener
Notification about the change of a CutListSource

Specified by:
update in interface ModificationListener
Parameters:
source - The modified CutListSource
See Also:
ModificationListener.update(com.groovemanager.sampled.nondestructive.CutListSource)

usesFile

public boolean usesFile(java.io.File f)
Description copied from interface: CutListSource
Ask this CutListSource whether it relies on the contents of the given file. This is needed, if a file should be overwritten and it must be checked that this doesnīt cause any inconsistencies

Specified by:
usesFile in interface CutListSource
Parameters:
f - The file to ask for
Returns:
true, if a change to the given fileīs content would also mean a change to this source, false otherwise
See Also:
CutListSource.usesFile(java.io.File)