Fix tree collapse on recording finish
This commit is contained in:
@@ -1684,10 +1684,11 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
Sentence snt = (Sentence)s.nextElement();
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
if (!snt.isLocked()) {
|
if (!snt.isLocked()) {
|
||||||
if (!snt.beenDetected()) {
|
if (!snt.beenDetected()) {
|
||||||
Debug.d("Queueing recognition of", snt.getId());
|
queueJob(new SentenceJob(snt) {
|
||||||
Runnable r = snt.getRecognitionRunnable();
|
public void run() {
|
||||||
snt.setQueued();
|
sentence.doRecognition();
|
||||||
queueJob(r);
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2096,7 +2097,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
if (recording == null) return;
|
if (recording == null) return;
|
||||||
recording.stopRecording();
|
recording.stopRecording();
|
||||||
|
|
||||||
book.reloadTree();
|
// book.reloadTree();
|
||||||
|
|
||||||
bookTree.expandPath(new TreePath(((DefaultMutableTreeNode)recording.getParent()).getPath()));
|
bookTree.expandPath(new TreePath(((DefaultMutableTreeNode)recording.getParent()).getPath()));
|
||||||
bookTree.setSelectionPath(new TreePath(recording.getPath()));
|
bookTree.setSelectionPath(new TreePath(recording.getPath()));
|
||||||
|
|||||||
@@ -450,6 +450,7 @@ public class Book extends BookTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void reloadTree() {
|
public void reloadTree() {
|
||||||
|
Debug.trace();
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(Book.this);
|
AudiobookRecorder.window.bookTreeModel.reload(Book.this);
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
if (text.equals("")) text = id;
|
if (text.equals("")) text = id;
|
||||||
|
|
||||||
if ((crossStartOffset == -1) || (crossEndOffset == -1)) {
|
if ((crossStartOffset == -1) || (crossEndOffset == -1)) {
|
||||||
updateCrossings(true);
|
updateCrossings();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runtime <= 0.01d) getLength();
|
if (runtime <= 0.01d) getLength();
|
||||||
@@ -260,26 +260,40 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
CacheManager.removeFromCache(this);
|
CacheManager.removeFromCache(this);
|
||||||
|
|
||||||
if (!id.equals("room-noise")) {
|
if (!id.equals("room-noise")) {
|
||||||
autoTrimSample(true);
|
autoTrimSample();
|
||||||
if (Options.getBoolean("process.sphinx")) {
|
if (Options.getBoolean("process.sphinx")) {
|
||||||
recognise();
|
AudiobookRecorder.window.queueJob(new SentenceJob(this) {
|
||||||
|
public void run() {
|
||||||
|
sentence.doRecognition();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void autoTrimSample(boolean ignored) {
|
||||||
|
Debug.trace();
|
||||||
|
autoTrimSample();
|
||||||
|
}
|
||||||
|
|
||||||
public void autoTrimSample() {
|
public void autoTrimSample() {
|
||||||
Debug.trace();
|
|
||||||
autoTrimSample(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void autoTrimSample(boolean useRaw) {
|
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
String tm = Options.get("audio.recording.trim");
|
String tm = Options.get("audio.recording.trim");
|
||||||
if (tm.equals("peak")) {
|
if (tm.equals("peak")) {
|
||||||
autoTrimSamplePeak(useRaw);
|
AudiobookRecorder.window.queueJob(new SentenceJob(this) {
|
||||||
|
public void run() {
|
||||||
|
sentence.autoTrimSamplePeak();
|
||||||
|
AudiobookRecorder.window.updateWaveformMarkers();
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if (tm.equals("fft")) {
|
} else if (tm.equals("fft")) {
|
||||||
autoTrimSampleFFT(useRaw);
|
AudiobookRecorder.window.queueJob(new SentenceJob(this) {
|
||||||
|
public void run() {
|
||||||
|
sentence.autoTrimSampleFFT();
|
||||||
|
AudiobookRecorder.window.updateWaveformMarkers();
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
startOffset = 0;
|
startOffset = 0;
|
||||||
crossStartOffset = 0;
|
crossStartOffset = 0;
|
||||||
@@ -288,13 +302,13 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
processed = false;
|
processed = false;
|
||||||
// peak = -1d;
|
// peak = -1d;
|
||||||
}
|
}
|
||||||
|
AudiobookRecorder.window.updateWaveform(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int FFTBuckets = 1024;
|
public static final int FFTBuckets = 1024;
|
||||||
|
|
||||||
public void autoTrimSampleFFT() {
|
public void autoTrimSampleFFT(boolean ignored) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
autoTrimSampleFFT(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double bucketDifference(double[] a, double[] b) {
|
public double bucketDifference(double[] a, double[] b) {
|
||||||
@@ -308,16 +322,12 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
return diff;
|
return diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void autoTrimSampleFFT(boolean useRaw) {
|
public void autoTrimSampleFFT() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
crossStartOffset = -1;
|
crossStartOffset = -1;
|
||||||
crossEndOffset = -1;
|
crossEndOffset = -1;
|
||||||
double[][] samples;
|
double[][] samples;
|
||||||
if (useRaw) {
|
|
||||||
samples = getRawAudioData();
|
|
||||||
} else {
|
|
||||||
samples = getProcessedAudioData();
|
samples = getProcessedAudioData();
|
||||||
}
|
|
||||||
if (samples == null) {
|
if (samples == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -389,7 +399,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
if (endOffset <= startOffset) endOffset = startOffset + fftSize;
|
if (endOffset <= startOffset) endOffset = startOffset + fftSize;
|
||||||
if (endOffset < 0) endOffset = 0;
|
if (endOffset < 0) endOffset = 0;
|
||||||
if (endOffset >= samples[LEFT].length) endOffset = samples[LEFT].length;
|
if (endOffset >= samples[LEFT].length) endOffset = samples[LEFT].length;
|
||||||
updateCrossings(useRaw);
|
updateCrossings();
|
||||||
intens = null;
|
intens = null;
|
||||||
samples = null;
|
samples = null;
|
||||||
processed = true;
|
processed = true;
|
||||||
@@ -440,21 +450,17 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void autoTrimSamplePeak() {
|
public void autoTrimSamplePeak(boolean ignored) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
autoTrimSamplePeak(false);
|
autoTrimSamplePeak();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void autoTrimSamplePeak(boolean useRaw) {
|
public void autoTrimSamplePeak() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
crossStartOffset = -1;
|
crossStartOffset = -1;
|
||||||
crossEndOffset = -1;
|
crossEndOffset = -1;
|
||||||
double[][] samples;
|
double[][] samples;
|
||||||
if (useRaw) {
|
|
||||||
samples = getRawAudioData();
|
|
||||||
} else {
|
|
||||||
samples = getProcessedAudioData();
|
samples = getProcessedAudioData();
|
||||||
}
|
|
||||||
if (samples == null) return;
|
if (samples == null) return;
|
||||||
double noiseFloor = AudiobookRecorder.window.getNoiseFloor();
|
double noiseFloor = AudiobookRecorder.window.getNoiseFloor();
|
||||||
noiseFloor *= 1.1;
|
noiseFloor *= 1.1;
|
||||||
@@ -494,7 +500,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
|
|
||||||
if (startOffset < 0) startOffset = 0;
|
if (startOffset < 0) startOffset = 0;
|
||||||
if (endOffset >= samples[LEFT].length) endOffset = samples[LEFT].length-1;
|
if (endOffset >= samples[LEFT].length) endOffset = samples[LEFT].length-1;
|
||||||
updateCrossings(useRaw);
|
updateCrossings();
|
||||||
processed = true;
|
processed = true;
|
||||||
reloadTree();
|
reloadTree();
|
||||||
}
|
}
|
||||||
@@ -601,38 +607,23 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public void updateCrossings() {
|
public void updateCrossings() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
updateCrossings(false);
|
updateStartCrossing();
|
||||||
}
|
updateEndCrossing();
|
||||||
|
|
||||||
public void updateCrossings(boolean useRaw) {
|
|
||||||
Debug.trace();
|
|
||||||
updateStartCrossing(useRaw);
|
|
||||||
updateEndCrossing(useRaw);
|
|
||||||
runtime = -1d;
|
runtime = -1d;
|
||||||
getLength();
|
getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateStartCrossing() {
|
public void updateStartCrossing() {
|
||||||
Debug.trace();
|
|
||||||
updateStartCrossing(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateStartCrossing(boolean useRaw) {
|
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (crossStartOffset == -1) {
|
if (crossStartOffset == -1) {
|
||||||
crossStartOffset = findNearestZeroCrossing(useRaw, startOffset, 4096);
|
crossStartOffset = findNearestZeroCrossing(startOffset, 4096);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateEndCrossing() {
|
public void updateEndCrossing() {
|
||||||
Debug.trace();
|
|
||||||
updateEndCrossing(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateEndCrossing(boolean useRaw) {
|
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (crossEndOffset == -1) {
|
if (crossEndOffset == -1) {
|
||||||
crossEndOffset = findNearestZeroCrossing(useRaw, endOffset, 4096);
|
crossEndOffset = findNearestZeroCrossing(endOffset, 4096);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -698,16 +689,6 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Runnable getRecognitionRunnable() {
|
|
||||||
Runnable r = new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
Debug.d("Starting recognition of", getId());
|
|
||||||
doRecognition();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doRecognition() {
|
public void doRecognition() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
try {
|
try {
|
||||||
@@ -735,12 +716,6 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recognise() {
|
|
||||||
Debug.trace();
|
|
||||||
Thread t = new Thread(getRecognitionRunnable());
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocked(boolean l) {
|
public void setLocked(boolean l) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (locked == l) return;
|
if (locked == l) return;
|
||||||
@@ -776,18 +751,9 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int findNearestZeroCrossing(int pos, int range) {
|
public int findNearestZeroCrossing(int pos, int range) {
|
||||||
Debug.trace();
|
|
||||||
return findNearestZeroCrossing(false, pos, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int findNearestZeroCrossing(boolean useRaw, int pos, int range) {
|
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
double[][] data = null;
|
double[][] data = null;
|
||||||
if (useRaw) {
|
|
||||||
data = getRawAudioData();
|
|
||||||
} else {
|
|
||||||
data = getProcessedAudioData();
|
data = getProcessedAudioData();
|
||||||
}
|
|
||||||
if (data == null) return 0;
|
if (data == null) return 0;
|
||||||
if (data[LEFT].length == 0) return 0;
|
if (data[LEFT].length == 0) return 0;
|
||||||
|
|
||||||
@@ -855,7 +821,6 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
File to = sentence.getFile();
|
File to = sentence.getFile();
|
||||||
Files.copy(from.toPath(), to.toPath());
|
Files.copy(from.toPath(), to.toPath());
|
||||||
|
|
||||||
// sentence.updateCrossings();
|
|
||||||
return sentence;
|
return sentence;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -873,24 +838,15 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public double getPeakValue() {
|
public double getPeakValue() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
return getPeakValue(false, true);
|
return getPeakValue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPeakValue(boolean useRaw) {
|
public double getPeakValue(boolean applyGain) {
|
||||||
Debug.trace();
|
|
||||||
return getPeakValue(useRaw, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getPeakValue(boolean useRaw, boolean applyGain) {
|
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
double oldGain = gain;
|
double oldGain = gain;
|
||||||
gain = 1.0d;
|
gain = 1.0d;
|
||||||
double[][] samples = null;
|
double[][] samples = null;
|
||||||
if (useRaw) {
|
|
||||||
samples = getRawAudioData();
|
|
||||||
} else {
|
|
||||||
samples = getProcessedAudioData(true, applyGain);
|
samples = getProcessedAudioData(true, applyGain);
|
||||||
}
|
|
||||||
gain = oldGain;
|
gain = oldGain;
|
||||||
if (samples == null) {
|
if (samples == null) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -937,7 +893,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
public double normalize(double low, double high) {
|
public double normalize(double low, double high) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (locked) return gain;
|
if (locked) return gain;
|
||||||
double max = getPeakValue(true, false);
|
double max = getPeakValue(false);
|
||||||
double d = 0.708 / max;
|
double d = 0.708 / max;
|
||||||
if (d > 1d) d = 1d;
|
if (d > 1d) d = 1d;
|
||||||
if (d < low) d = low;
|
if (d < low) d = low;
|
||||||
@@ -952,7 +908,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
public double normalize() {
|
public double normalize() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (locked) return gain;
|
if (locked) return gain;
|
||||||
double max = getPeakValue(true, false);
|
double max = getPeakValue(false);
|
||||||
double d = 0.708 / max;
|
double d = 0.708 / max;
|
||||||
if (d > 1d) d = 1d;
|
if (d > 1d) d = 1d;
|
||||||
setGain(d);
|
setGain(d);
|
||||||
@@ -1427,6 +1383,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
|
|
||||||
|
|
||||||
String def = AudiobookRecorder.window.getDefaultEffectsChain();
|
String def = AudiobookRecorder.window.getDefaultEffectsChain();
|
||||||
|
if ((def != null) && (AudiobookRecorder.window.effects != null)) {
|
||||||
Effect eff = AudiobookRecorder.window.effects.get(def);
|
Effect eff = AudiobookRecorder.window.effects.get(def);
|
||||||
|
|
||||||
if (effectsEnabled) {
|
if (effectsEnabled) {
|
||||||
@@ -1446,6 +1403,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (applyGain) {
|
if (applyGain) {
|
||||||
// Add final master gain stage
|
// Add final master gain stage
|
||||||
|
|||||||
Reference in New Issue
Block a user