com.groovemanager.sampled.waveform
Class AbstractWaveForm

java.lang.Object
  extended by com.groovemanager.sampled.waveform.AbstractWaveForm
All Implemented Interfaces:
WaveForm
Direct Known Subclasses:
AudioFileWaveForm, ByteArrayWaveForm, ConcatWaveForm, FillUpWaveForm, PeakWaveForm, UpdatingWaveForm, WaveFormPart, ZoomedWaveForm

public abstract class AbstractWaveForm
extends java.lang.Object
implements WaveForm

An abstract superclass for implementation of IWaveForm

Author:
Manu Robledo

Field Summary
protected  int channels
          Total displayable width of this WaveForm
protected  int displayWidth
          Total displayable width of this WaveForm
protected  int intervallSize
          The intervall size.
protected static WaveForm nullWave
          An empty WaveForm to be reused when needed
protected  int position
          Total displayable width of this WaveForm
protected  int realLength
          Total displayable width of this WaveForm
 
Constructor Summary
AbstractWaveForm()
           
 
Method Summary
 boolean canProvide(int begin, int length, int width)
          Tells if this WaveForm sees itself capable of providing a SubWaveForm with the given parameters
protected  java.lang.String getAdditionalToString()
          Get an additional String describing this WaveForm.
 int getChannels()
          Get the number of channels in this WaveForm
 byte[] getData()
          Get the whole Peak data as array.
 int getDisplayableLength()
          Get the total displayable length of this WaveForm.
 int getIntervallSize()
          Get the number of samples of the original Sample which are represented by one step of this WaveForm.
 int getPosition()
          Get the read position of this WaveForm
 int getRealLength()
          Get the Length of the original sample which this WaveForm represents
 int getRealPosition()
          Get the position inside the sample represented by this WaveForm corresponding to the actual read position of this WaveForm.
 double getZoomFactor()
          Get the ratio between the length of the represented Sample and and the displayable length of this WaveForm.
 boolean next()
          Tells the WaveForm to increase its position by one
 void rewind()
          Sets the current read position to the beginning of this WaveForm
 void setPosition(int pos)
          Set the read position of this WaveForm
 void setRealPosition(int pos)
          Set the read position of this WaveForm to the value corresponding to the given real position of the represented sample.
 WaveForm subWaveForm(int begin, int length, int width)
          Get a WaveForm Object that represents the part of this WaveForm specified by begin and length and displays this part in the specified width
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.groovemanager.sampled.waveform.WaveForm
getMax, getMin
 

Field Detail

channels

protected int channels
Total displayable width of this WaveForm


displayWidth

protected int displayWidth
Total displayable width of this WaveForm


intervallSize

protected int intervallSize
The intervall size. May be -1 to indicate that the intervall size should be calculated out of getRealLength() and getDisplayableLength().


nullWave

protected static WaveForm nullWave
An empty WaveForm to be reused when needed


position

protected int position
Total displayable width of this WaveForm


realLength

protected int realLength
Total displayable width of this WaveForm

Constructor Detail

AbstractWaveForm

public AbstractWaveForm()
Method Detail

canProvide

public boolean canProvide(int begin,
                          int length,
                          int width)
Description copied from interface: WaveForm
Tells if this WaveForm sees itself capable of providing a SubWaveForm with the given parameters

Specified by:
canProvide in interface WaveForm
Parameters:
begin - The offset to the beginning of this WaveForm. May also be negative.
length - The length in steps of this WaveForm that should be represented by the returned WaveForm.
width - The new width in which the part should be displayed.
Returns:
true if this WaveForm can provide the wanted subWaveForm, false otherwise
See Also:
WaveForm.canProvide(int, int, int)

getAdditionalToString

protected java.lang.String getAdditionalToString()
Get an additional String describing this WaveForm. Will be used in toString()

Returns:
An optional String describing special characteristics of this WaveForm

getChannels

public int getChannels()
Description copied from interface: WaveForm
Get the number of channels in this WaveForm

Specified by:
getChannels in interface WaveForm
Returns:
The number of channels (1 or bigger)
See Also:
WaveForm.getChannels()

getData

public byte[] getData()
Description copied from interface: WaveForm
Get the whole Peak data as array. This method could take very long for WaveForms which don't store their data in such an array. Should be very fast for peak Wave Forms.

Specified by:
getData in interface WaveForm
Returns:
The Peak Data as byte-Array.
See Also:
WaveForm.getData()

getDisplayableLength

public int getDisplayableLength()
Description copied from interface: WaveForm
Get the total displayable length of this WaveForm.

Specified by:
getDisplayableLength in interface WaveForm
Returns:
The length of this WaveForm
See Also:
WaveForm.getDisplayableLength()

getIntervallSize

public int getIntervallSize()
Description copied from interface: WaveForm
Get the number of samples of the original Sample which are represented by one step of this WaveForm. Especially interesting for PeakWaveForms.

Specified by:
getIntervallSize in interface WaveForm
Returns:
The number of samples
See Also:
WaveForm.getIntervallSize()

getPosition

public int getPosition()
Description copied from interface: WaveForm
Get the read position of this WaveForm

Specified by:
getPosition in interface WaveForm
Returns:
The current read position
See Also:
WaveForm.getPosition()

getRealLength

public int getRealLength()
Description copied from interface: WaveForm
Get the Length of the original sample which this WaveForm represents

Specified by:
getRealLength in interface WaveForm
Returns:
The length of the original sample in sample frames.
See Also:
WaveForm.getRealLength()

getRealPosition

public int getRealPosition()
Description copied from interface: WaveForm
Get the position inside the sample represented by this WaveForm corresponding to the actual read position of this WaveForm. For WaveForms with a zoom factor of 1.0 this method should behave exactly like getPosition()

Specified by:
getRealPosition in interface WaveForm
Returns:
The position in the original sample
See Also:
WaveForm.getRealPosition()

getZoomFactor

public double getZoomFactor()
Description copied from interface: WaveForm
Get the ratio between the length of the represented Sample and and the displayable length of this WaveForm.

Specified by:
getZoomFactor in interface WaveForm
Returns:
getRealLength() / (double)getDisplayableLength()
See Also:
WaveForm.getZoomFactor()

next

public boolean next()
Description copied from interface: WaveForm
Tells the WaveForm to increase its position by one

Specified by:
next in interface WaveForm
Returns:
true if the end position was not reached before this method call so that the position could be increased, false otherwise. The return value can be used for iteratin over the whole WaveForm like this:
IWaveForm w = ...;
int channel = ...;
w.rewind();
do{
byte min = w.getMin(channel);
byte max = w.getMax(channel);
// ...(do something with those values)
} while(w.next());
See Also:
WaveForm.next()

rewind

public void rewind()
Description copied from interface: WaveForm
Sets the current read position to the beginning of this WaveForm

Specified by:
rewind in interface WaveForm
See Also:
WaveForm.rewind()

setPosition

public void setPosition(int pos)
Description copied from interface: WaveForm
Set the read position of this WaveForm

Specified by:
setPosition in interface WaveForm
Parameters:
pos - The new read position
See Also:
WaveForm.setPosition(int)

setRealPosition

public void setRealPosition(int pos)
Description copied from interface: WaveForm
Set the read position of this WaveForm to the value corresponding to the given real position of the represented sample. For WaveForms with a zoom factor of 1.0 this method should behave exactly like setPosition(pos)

Specified by:
setRealPosition in interface WaveForm
Parameters:
pos - The new position in the original sample
See Also:
WaveForm.setRealPosition(int)

subWaveForm

public WaveForm subWaveForm(int begin,
                            int length,
                            int width)
Description copied from interface: WaveForm
Get a WaveForm Object that represents the part of this WaveForm specified by begin and length and displays this part in the specified width

Specified by:
subWaveForm in interface WaveForm
Parameters:
begin - The offset to the beginning of this WaveForm. May also be negative.
length - The length in steps of this WaveForm that should be represented by the returned WaveForm.
width - The new width in which the part should be displayed.
Returns:
A WaveForm Object that represents the specified Part of this WaveForm and displays it in the given width. Can also be the same Object with adapted attributes
See Also:
WaveForm.subWaveForm(int, int, int)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()