1 package tim.prune.undo;
\r
3 import tim.prune.I18nManager;
\r
4 import tim.prune.data.AudioClip;
\r
5 import tim.prune.data.DataPoint;
\r
6 import tim.prune.data.TrackInfo;
\r
9 * Operation to undo an auto-correlation of audios with points
\r
10 * (very similar to UndoCorrelatePhotos)
\r
12 public class UndoCorrelateAudios implements UndoOperation
\r
14 private DataPoint[] _contents = null;
\r
15 private DataPoint[] _audioPoints = null;
\r
16 private int _numCorrelated = -1;
\r
21 * @param inTrackInfo track information
\r
23 public UndoCorrelateAudios(TrackInfo inTrackInfo)
\r
25 // Copy track contents
\r
26 _contents = inTrackInfo.getTrack().cloneContents();
\r
27 // Copy points associated with audios before correlation
\r
28 int numAudios = inTrackInfo.getAudioList().getNumAudios();
\r
29 _audioPoints = new DataPoint[numAudios];
\r
30 for (int i=0; i<numAudios; i++) {
\r
31 _audioPoints[i] = inTrackInfo.getAudioList().getAudio(i).getDataPoint();
\r
36 * @param inNumCorrelated number of audios correlated
\r
38 public void setNumAudiosCorrelated(int inNumCorrelated)
\r
40 _numCorrelated = inNumCorrelated;
\r
44 * @return description of operation including parameters
\r
46 public String getDescription()
\r
48 return I18nManager.getText("undo.correlateaudios") + " (" + _numCorrelated + ")";
\r
53 * Perform the undo operation on the given Track
\r
54 * @param inTrackInfo TrackInfo object on which to perform the operation
\r
56 public void performUndo(TrackInfo inTrackInfo) throws UndoException
\r
58 // restore track to previous values
\r
59 inTrackInfo.getTrack().replaceContents(_contents);
\r
60 // restore audio association
\r
61 for (int i=0; i<_audioPoints.length; i++)
\r
63 AudioClip audio = inTrackInfo.getAudioList().getAudio(i);
\r
64 // Only need to look at connected ones, since correlation wouldn't disconnect
\r
65 if (audio.getCurrentStatus() == AudioClip.Status.CONNECTED)
\r
67 DataPoint prevPoint = _audioPoints[i];
\r
68 DataPoint currPoint = audio.getDataPoint();
\r
69 audio.setDataPoint(prevPoint);
\r
70 if (currPoint != null) {
\r
71 currPoint.setAudio(null); // disconnect
\r
73 if (prevPoint != null) {
\r
74 prevPoint.setAudio(audio); // reconnect to prev point
\r
79 inTrackInfo.getSelection().clearAll();
\r