1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
package tim.prune.undo;
import tim.prune.I18nManager;
import tim.prune.data.AudioClip;
import tim.prune.data.DataPoint;
import tim.prune.data.TrackInfo;
/**
* Operation to undo an auto-correlation of audios with points
* (very similar to UndoCorrelatePhotos)
*/
public class UndoCorrelateAudios implements UndoOperation
{
private DataPoint[] _contents = null;
private DataPoint[] _audioPoints = null;
private int _numCorrelated = -1;
/**
* Constructor
* @param inTrackInfo track information
*/
public UndoCorrelateAudios(TrackInfo inTrackInfo)
{
// Copy track contents
_contents = inTrackInfo.getTrack().cloneContents();
// Copy points associated with audios before correlation
int numAudios = inTrackInfo.getAudioList().getNumAudios();
_audioPoints = new DataPoint[numAudios];
for (int i=0; i<numAudios; i++) {
_audioPoints[i] = inTrackInfo.getAudioList().getAudio(i).getDataPoint();
}
}
/**
* @param inNumCorrelated number of audios correlated
*/
public void setNumAudiosCorrelated(int inNumCorrelated)
{
_numCorrelated = inNumCorrelated;
}
/**
* @return description of operation including parameters
*/
public String getDescription()
{
return I18nManager.getText("undo.correlateaudios") + " (" + _numCorrelated + ")";
}
/**
* Perform the undo operation on the given Track
* @param inTrackInfo TrackInfo object on which to perform the operation
*/
public void performUndo(TrackInfo inTrackInfo) throws UndoException
{
// restore track to previous values
inTrackInfo.getTrack().replaceContents(_contents);
// restore audio association
for (int i=0; i<_audioPoints.length; i++)
{
AudioClip audio = inTrackInfo.getAudioList().getAudio(i);
// Only need to look at connected ones, since correlation wouldn't disconnect
if (audio.getCurrentStatus() == AudioClip.Status.CONNECTED)
{
DataPoint prevPoint = _audioPoints[i];
DataPoint currPoint = audio.getDataPoint();
audio.setDataPoint(prevPoint);
if (currPoint != null) {
currPoint.setAudio(null); // disconnect
}
if (prevPoint != null) {
prevPoint.setAudio(audio); // reconnect to prev point
}
}
}
// clear selection
inTrackInfo.getSelection().clearAll();
}
}
|