com.groovemanager.app.sse
Class WaveTab

java.lang.Object
  extended by com.groovemanager.app.sse.WaveTab
All Implemented Interfaces:
AudioPlayerProvider, ModificationListener, WaveFormProvider

public class WaveTab
extends java.lang.Object
implements AudioPlayerProvider, ModificationListener, WaveFormProvider

A WaveTab represents one open file inside a SampleEditor. It has a TabItem and a source file assigned to it. The WaveTab will handle all things like providing audio data, handling applied effects or edit actions by managing a CutList.

Author:
Manu Robledo

Nested Class Summary
(package private)  class WaveTab.Analyzer
          This class is used for analyzing the WaveTab´s audio data if needed before applying an effect
 class WaveTab.DifferentChannelException
          This Exception is to be used when sources with different channel count should be merged.
 
Field Summary
private  AudioFileSource afSource
          The source of this WaveTab
private  AudioFileWaveForm afWF
          The AudioFileWaveForm corresponding to the source file
private  boolean canRec
          Indicates whether this WaveTab is able to record or not
private  int channels
          Number of channels of this WaveTab
private  CutListSource copySource
          The CutListSource that was the actual one, when the last copy operation was performed
protected  CutList cutList
          The CutList containing all modifications made to this WaveTab
private  SimpleSampleEditor editor
          The SampleEditor to which this WaveTab belongs
protected  javax.sound.sampled.AudioFileFormat fileFormat
          The AudioFileFormat of the current source file
protected  javax.sound.sampled.AudioFormat format
          The current AudioFormat of the audio data
protected  boolean isNew
          Indicates whether this WaveTab contains a new file that has still not been saved
protected  int lastStart
          Last start position used when providing audio data
protected  WaveForm lastWaveForm
          The last WaveForm used for providing WaveForm data to the main WaveFormDisplay
protected  int lastWaveFormPos
          Position in sample frames of the lastWaveForm´s position
protected  WaveForm lastZoomWaveForm
          The last WaveForm used for providing WaveForm data to the main WaveFormDisplay
protected  int lastZoomWaveFormPos
          Position in sample frames of the lastWaveForm´s position
protected  boolean modified
          Indicates whether this WaveTab has been modified since the last new, open or save operation
protected  java.io.OutputStream out
          OutputStream used for recording
protected  int recCount
          Counter for redrawing the WaveFormDisplay in constant intervals during recording
protected  boolean recording
          Indicates whether this Wavetab is currently involved in a recording operation
protected  java.util.ArrayList redoElements
          CutListElements corresponding to the redoOperations
protected  java.util.ArrayList redoOperations
          List of redo operations that can be performed
protected  java.lang.Runnable redrawWave
          Runnable for thread-safe redrawing of the WaveForm
protected  java.io.File source
          The source file
protected  org.eclipse.swt.widgets.TabItem tabItem
          The TabItem assigned to this Wavetab
protected  java.util.ArrayList undoOperations
          List of undo operations that can be performed
protected  WaveFormDisplay waveDisplay
          The WaveFormDisplay for displaying the WaveForm data
 
Constructor Summary
WaveTab(SimpleSampleEditor editor, org.eclipse.swt.widgets.TabFolder parent, int style, int waveStyle, java.io.File f, AudioFileWaveForm wf, javax.sound.sampled.AudioFormat format, boolean rec)
          Create a new WaveTab
 
Method Summary
 void applyEffect(Effect effect)
          Apply the given effect to this WaveTab´s audio data
 boolean canLoop()
          Ask this provider, if he can provide audio data in a loop.
 boolean canProvide()
          Ask this provider, if he is ready for providing playback audio data
 boolean canRec()
          Ask this provider, if he can process recorded audio data in any way.
 boolean canRedo()
          Indicates whether this WaveTab can redo the last undone operation
 boolean canSave()
          Indicates whether this WaveTab can allows performing a Save-operation at the moment (not Save as...) or not.
 boolean canUndo()
          Indicates whether this WaveTab can undo the last operation
protected  org.eclipse.swt.events.KeyListener createKeyListener()
          Create the KeyListener to be added to the WaveFormDisplay´s composite
 void editAction(int type)
          Perform an EditAction of the given type
 javax.sound.sampled.AudioInputStream getAudioInputStream()
          Get the AudioInputStream for the current selection
 int getChannels()
          Get the channels of the audio data represented by the provider
 CutListSource getCopySource()
          Get the clipbaord source
 javax.sound.sampled.AudioFileFormat getFileFormat()
          Get the audio file format of this WaveTab´s source
 javax.sound.sampled.AudioFormat getFormat()
          Get the format of the audio data contained in this WaveTab
 org.eclipse.swt.widgets.TabItem getItem()
          Get the TabItem associated with this WaveTab
 int getLastStart()
          Get the last start position inside the whole audio source.
 java.lang.String getRedoName()
          Get the name of the next possible operation to redo
 org.eclipse.swt.widgets.Shell getShell()
          Get the Shell of the editor this WaveTab is assigned to
 int[][] getSlices()
          Get the slices contained in this WabeTab
 java.io.File getSource()
          Get this WaveTab´s source file
 int getTotalLength()
          Get the total length of the audio data represented by the provider in sample frames
 java.lang.String getUndoName()
          Get the name of the next possible operation to undo
 WaveFormDisplay getWaveDisplay()
          Get the WaveFormDisplay used for displaying WaveForm data
 WaveForm getWaveForm(AbstractWaveFormDisplay display, int start, int length, int width)
          Get a WaveForm for the specified display
 javax.sound.sampled.AudioInputStream getWholeAudioInputStream()
          Get the whole AudioInputStream from this WaveTab´s audio data independent of its selection
 boolean hasBeenModified()
          Ask this WaveTab, if it has been modified since the last open, new or save operation
 boolean isNew()
          Ask this WaveTab, if it contains a new file that has not been saved yet.
 void performCopy()
          Copy the current selection to the audio editor´s cipboard
 void performCut()
          Copy the current selection to the audio editor´s cipboard and delete it from this WaveTab´s audio data
 void performDelete()
          Delete the current selection
 void performPaste()
          Insert the clipboard content of the editor at the current position
 void performRedo()
          Redo the last undone operation
 void performTrim()
          Trim this WaveTab´s data to the current selection
 void performUndo()
          Undo the last operation
private  void prepareClipboard()
          Create a clone of the current CutList to be used as clipboard source
 int rec(byte[] b, int offset, int length)
          Process a recorded buffer of audio data.
protected  void saveFile(javax.sound.sampled.AudioInputStream in, java.io.File f, AudioFileOutputStream out)
          Save this WaveTab´s audio data to the given file using the given AudioFileOutputStream
protected  boolean savePeak()
          Try to save the peak file
protected  void setInput(java.io.File f, AudioFileWaveForm waveForm)
          Set the source file for this WaveTab
 javax.sound.sampled.AudioFormat startRec()
          Start recording of audio data.
 void stopRec()
          Notification from the AudioPlayer that recording has finished.
 void update(CutListElement element)
          Notification about the change of a CutListElement
 void update(CutListSource source)
          Notification about the change of a CutListSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

afSource

private AudioFileSource afSource
The source of this WaveTab


afWF

private AudioFileWaveForm afWF
The AudioFileWaveForm corresponding to the source file


canRec

private boolean canRec
Indicates whether this WaveTab is able to record or not


channels

private int channels
Number of channels of this WaveTab


copySource

private CutListSource copySource
The CutListSource that was the actual one, when the last copy operation was performed


cutList

protected CutList cutList
The CutList containing all modifications made to this WaveTab


editor

private final SimpleSampleEditor editor
The SampleEditor to which this WaveTab belongs


fileFormat

protected javax.sound.sampled.AudioFileFormat fileFormat
The AudioFileFormat of the current source file


format

protected javax.sound.sampled.AudioFormat format
The current AudioFormat of the audio data


isNew

protected boolean isNew
Indicates whether this WaveTab contains a new file that has still not been saved


lastStart

protected int lastStart
Last start position used when providing audio data


lastWaveForm

protected WaveForm lastWaveForm
The last WaveForm used for providing WaveForm data to the main WaveFormDisplay


lastWaveFormPos

protected int lastWaveFormPos
Position in sample frames of the lastWaveForm´s position


lastZoomWaveForm

protected WaveForm lastZoomWaveForm
The last WaveForm used for providing WaveForm data to the main WaveFormDisplay


lastZoomWaveFormPos

protected int lastZoomWaveFormPos
Position in sample frames of the lastWaveForm´s position


modified

protected boolean modified
Indicates whether this WaveTab has been modified since the last new, open or save operation


out

protected java.io.OutputStream out
OutputStream used for recording


recCount

protected int recCount
Counter for redrawing the WaveFormDisplay in constant intervals during recording


recording

protected boolean recording
Indicates whether this Wavetab is currently involved in a recording operation


redoElements

protected java.util.ArrayList redoElements
CutListElements corresponding to the redoOperations


redoOperations

protected java.util.ArrayList redoOperations
List of redo operations that can be performed


redrawWave

protected java.lang.Runnable redrawWave
Runnable for thread-safe redrawing of the WaveForm


source

protected java.io.File source
The source file


tabItem

protected org.eclipse.swt.widgets.TabItem tabItem
The TabItem assigned to this Wavetab


undoOperations

protected java.util.ArrayList undoOperations
List of undo operations that can be performed


waveDisplay

protected WaveFormDisplay waveDisplay
The WaveFormDisplay for displaying the WaveForm data

Constructor Detail

WaveTab

WaveTab(SimpleSampleEditor editor,
        org.eclipse.swt.widgets.TabFolder parent,
        int style,
        int waveStyle,
        java.io.File f,
        AudioFileWaveForm wf,
        javax.sound.sampled.AudioFormat format,
        boolean rec)
  throws javax.sound.sampled.UnsupportedAudioFileException,
         java.io.IOException
Create a new WaveTab

Parameters:
editor - The SampleEditor to which the WaveTab belongs
parent - The TabFolder to be used as parent for the TabItem that will be created
style - The style to be used for the TabItem
waveStyle - The style to be used for the WaveFormDisplay
f - The source file
wf - The WaveForm corresponding to the file
format - The AudioFormat to be used for recording or null, if not recording
rec - true, if recording should be possible for this WaveTab, false otherwise
Throws:
javax.sound.sampled.UnsupportedAudioFileException - If the AudioFileFormat of the given file can not be detected (only in case of not recording)
java.io.IOException - If an I/O error occured
Method Detail

applyEffect

public void applyEffect(Effect effect)
Apply the given effect to this WaveTab´s audio data

Parameters:
effect - The effect to apply

canLoop

public boolean canLoop()
Description copied from interface: AudioPlayerProvider
Ask this provider, if he can provide audio data in a loop. If so, he will be asked for a new AudioInputStream after each loop end.

Specified by:
canLoop in interface AudioPlayerProvider
Returns:
true, if this provider can provide its audio data in a loop, false otherwise
See Also:
AudioPlayerProvider.canLoop()

canProvide

public boolean canProvide()
Description copied from interface: AudioPlayerProvider
Ask this provider, if he is ready for providing playback audio data

Specified by:
canProvide in interface AudioPlayerProvider
Returns:
true, if audio data can provided, false otherwise
See Also:
AudioPlayerProvider.canProvide()

canRec

public boolean canRec()
Description copied from interface: AudioPlayerProvider
Ask this provider, if he can process recorded audio data in any way.

Specified by:
canRec in interface AudioPlayerProvider
Returns:
true, if this provider can currently process recorded audio data, false otherwise
See Also:
AudioPlayerProvider.canRec()

canRedo

public boolean canRedo()
Indicates whether this WaveTab can redo the last undone operation

Returns:
true, if redo can be applied, false otherwise

canSave

public boolean canSave()
Indicates whether this WaveTab can allows performing a Save-operation at the moment (not Save as...) or not.

Returns:
true, if
- the audio data has been modified and
- the source is not a new created file and
- the source file can be written,
false otherwise

canUndo

public boolean canUndo()
Indicates whether this WaveTab can undo the last operation

Returns:
true, if undo can be applied, false otherwise

createKeyListener

protected org.eclipse.swt.events.KeyListener createKeyListener()
Create the KeyListener to be added to the WaveFormDisplay´s composite

Returns:
The KeyListener to be used

editAction

public void editAction(int type)
Perform an EditAction of the given type

Parameters:
type - The type of the EditAction to apply

getAudioInputStream

public javax.sound.sampled.AudioInputStream getAudioInputStream()
                                                         throws NotReadyException
Get the AudioInputStream for the current selection

Specified by:
getAudioInputStream in interface AudioPlayerProvider
Returns:
The AudioInputStream to be played back
Throws:
NotReadyException - If no audio data can be presented at the moment
See Also:
AudioPlayerProvider.getAudioInputStream()

getChannels

public int getChannels()
Description copied from interface: WaveFormProvider
Get the channels of the audio data represented by the provider

Specified by:
getChannels in interface WaveFormProvider
Returns:
The provider´s audio data´s channels
See Also:
WaveFormProvider.getChannels()

getCopySource

public CutListSource getCopySource()
Get the clipbaord source

Returns:
The clipboard source that was last prepared for this WaveTab, if any

getFileFormat

public javax.sound.sampled.AudioFileFormat getFileFormat()
Get the audio file format of this WaveTab´s source

Returns:
The audio file format of this WaveTab´s source

getFormat

public javax.sound.sampled.AudioFormat getFormat()
Get the format of the audio data contained in this WaveTab

Returns:
The format of the audio data contained in this WaveTab

getItem

public org.eclipse.swt.widgets.TabItem getItem()
Get the TabItem associated with this WaveTab

Returns:
The TabItem associated with this WaveTab

getLastStart

public int getLastStart()
Description copied from interface: AudioPlayerProvider
Get the last start position inside the whole audio source. Is needed for correct displaying of The play position and will usually be called shortly after getAudioInputStream()

Specified by:
getLastStart in interface AudioPlayerProvider
Returns:
The frame position inside the audio source represented by this provider, at which the provided AudioInputStream starts.
See Also:
AudioPlayerProvider.getLastStart()

getRedoName

public java.lang.String getRedoName()
Get the name of the next possible operation to redo

Returns:
The name of the next possible operation to redo

getShell

public org.eclipse.swt.widgets.Shell getShell()
Get the Shell of the editor this WaveTab is assigned to

Returns:
The Shell of the editor this WaveTab is assigned to

getSlices

public int[][] getSlices()
Get the slices contained in this WabeTab

Returns:
Array of slices contained in this WaveTab. Each slice is represented by an int-Array of size 2 with the sample position of the slice in sample frames at index [0] and the length of the slice or -1, if the length is not specified at index [1]

getSource

public java.io.File getSource()
Get this WaveTab´s source file

Returns:
This WaveTab´s source file

getTotalLength

public int getTotalLength()
Description copied from interface: WaveFormProvider
Get the total length of the audio data represented by the provider in sample frames

Specified by:
getTotalLength in interface WaveFormProvider
Returns:
The provider´s audio data´s length in sample frames
See Also:
WaveFormProvider.getTotalLength()

getUndoName

public java.lang.String getUndoName()
Get the name of the next possible operation to undo

Returns:
The name of the next possible operation to undo

getWaveDisplay

public WaveFormDisplay getWaveDisplay()
Get the WaveFormDisplay used for displaying WaveForm data

Returns:
The WaveFormDisplay of this WaveTab

getWaveForm

public WaveForm getWaveForm(AbstractWaveFormDisplay display,
                            int start,
                            int length,
                            int width)
Description copied from interface: WaveFormProvider
Get a WaveForm for the specified display

Specified by:
getWaveForm in interface WaveFormProvider
Parameters:
display - The WaveFormDisplay that asks for the WaveForm
start - The start position of the WaveForm inside the source data in sample frames
length - The length of the audio data that should be represented by the WaveForm
width - The width of the resulting WaveForm.
Returns:
A WaveForm representing length sample frames of the provider´s audio data beginning at position start to be displayed in the width of width.
See Also:
WaveFormProvider.getWaveForm(com.groovemanager.sampled.waveform.AbstractWaveFormDisplay, int, int, int)

getWholeAudioInputStream

public javax.sound.sampled.AudioInputStream getWholeAudioInputStream()
                                                              throws NotReadyException
Get the whole AudioInputStream from this WaveTab´s audio data independent of its selection

Returns:
The AudioInputStream for all of this WaveTab´s audio data
Throws:
NotReadyException - If no audio data can be provided at the moment

hasBeenModified

public boolean hasBeenModified()
Ask this WaveTab, if it has been modified since the last open, new or save operation

Returns:
true, if this WaveTab has been modified without saving the modification, false otherwise

isNew

public boolean isNew()
Ask this WaveTab, if it contains a new file that has not been saved yet.

Returns:
true, if this WaveTab´s source is a new file that has not been saved yet, false otherwise.

performCopy

public void performCopy()
Copy the current selection to the audio editor´s cipboard


performCut

public void performCut()
Copy the current selection to the audio editor´s cipboard and delete it from this WaveTab´s audio data


performDelete

public void performDelete()
Delete the current selection


performPaste

public void performPaste()
                  throws WaveTab.DifferentChannelException
Insert the clipboard content of the editor at the current position

Throws:
WaveTab.DifferentChannelException

performRedo

public void performRedo()
Redo the last undone operation


performTrim

public void performTrim()
Trim this WaveTab´s data to the current selection


performUndo

public void performUndo()
Undo the last operation


prepareClipboard

private void prepareClipboard()
Create a clone of the current CutList to be used as clipboard source


rec

public int rec(byte[] b,
               int offset,
               int length)
Description copied from interface: AudioPlayerProvider
Process a recorded buffer of audio data. This method will be called continuously between startRec() and stopRec(). The delivered audio data will be in the format returned by startRec().

Specified by:
rec in interface AudioPlayerProvider
Parameters:
b - The Array containing the audio data to process
offset - Offset position inside the Array where the usable audio data begins
length - The length of the usable audio data in bytes
Returns:
The number of bytes processed. If this value is less then length, the AudioPlayer will re-attempt to write the remaining data in the next call.
See Also:
AudioPlayerProvider.rec(byte[], int, int)

saveFile

protected void saveFile(javax.sound.sampled.AudioInputStream in,
                        java.io.File f,
                        AudioFileOutputStream out)
                 throws NotFinishedException,
                        NotReadyException
Save this WaveTab´s audio data to the given file using the given AudioFileOutputStream

Parameters:
f - The file to save to (will be set as new source file)
out - The AudioFileOutputStream to use for writing
Throws:
NotFinishedException - If the save operation could not be completed
NotReadyException - If the audio data could not be provided

savePeak

protected boolean savePeak()
Try to save the peak file

Returns:
true, if the operation succeeded and the file was saved, false otherwise

setInput

protected void setInput(java.io.File f,
                        AudioFileWaveForm waveForm)
Set the source file for this WaveTab

Parameters:
f - The source file to set
waveForm - The WaveForm corresponding to the file

startRec

public javax.sound.sampled.AudioFormat startRec()
                                         throws NotReadyException
Description copied from interface: AudioPlayerProvider
Start recording of audio data. The AudioFormat in which the the data will be processed from this provider is returned to give the AudioPlayer a hint. If the AudioPlayer can not find a way to convert the audio data he gets into this format, recording will not start.

Specified by:
startRec in interface AudioPlayerProvider
Returns:
The AudioFormat in which this provider processes the recorded data.
Throws:
NotReadyException - If recording is not possible at the moment
See Also:
AudioPlayerProvider.startRec()

stopRec

public void stopRec()
Description copied from interface: AudioPlayerProvider
Notification from the AudioPlayer that recording has finished.

Specified by:
stopRec in interface AudioPlayerProvider
See Also:
AudioPlayerProvider.stopRec()

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)