Add processed flag for batch processing of new recordings
This commit is contained in:
@@ -32,6 +32,7 @@ import javax.xml.transform.Transformer;
|
|||||||
import javax.xml.transform.TransformerFactory;
|
import javax.xml.transform.TransformerFactory;
|
||||||
import javax.xml.transform.dom.DOMSource;
|
import javax.xml.transform.dom.DOMSource;
|
||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import javax.xml.transform.OutputKeys;
|
||||||
import org.w3c.dom.Attr;
|
import org.w3c.dom.Attr;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
@@ -949,6 +950,8 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
// write the content into xml file
|
// write the content into xml file
|
||||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
Transformer transformer = transformerFactory.newTransformer();
|
Transformer transformer = transformerFactory.newTransformer();
|
||||||
|
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||||
|
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
|
||||||
DOMSource source = new DOMSource(doc);
|
DOMSource source = new DOMSource(doc);
|
||||||
StreamResult result = new StreamResult(xml);
|
StreamResult result = new StreamResult(xml);
|
||||||
transformer.transform(source, result);
|
transformer.transform(source, result);
|
||||||
@@ -1298,6 +1301,34 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
JMenuObject peaknew = new JMenuObject("Auto-trim new (Peak)", c, new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
|
Chapter chap = (Chapter)o.getObject();
|
||||||
|
|
||||||
|
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName());
|
||||||
|
|
||||||
|
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.Peak, AutoTrimThread.NewOnly);
|
||||||
|
Thread nt = new Thread(t);
|
||||||
|
nt.start();
|
||||||
|
ed.setVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JMenuObject fftnew = new JMenuObject("Auto-trim new (FFT)", c, new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
|
Chapter chap = (Chapter)o.getObject();
|
||||||
|
|
||||||
|
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName());
|
||||||
|
|
||||||
|
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.FFT, AutoTrimThread.NewOnly);
|
||||||
|
Thread nt = new Thread(t);
|
||||||
|
nt.start();
|
||||||
|
ed.setVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
JMenuObject peak = new JMenuObject("Auto-trim all (Peak)", c, new ActionListener() {
|
JMenuObject peak = new JMenuObject("Auto-trim all (Peak)", c, new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
@@ -1305,7 +1336,7 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
|
|
||||||
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName());
|
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName());
|
||||||
|
|
||||||
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.Peak);
|
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.Peak, AutoTrimThread.All);
|
||||||
Thread nt = new Thread(t);
|
Thread nt = new Thread(t);
|
||||||
nt.start();
|
nt.start();
|
||||||
ed.setVisible(true);
|
ed.setVisible(true);
|
||||||
@@ -1319,7 +1350,7 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
|
|
||||||
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName());
|
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName());
|
||||||
|
|
||||||
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.FFT);
|
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.FFT, AutoTrimThread.All);
|
||||||
Thread nt = new Thread(t);
|
Thread nt = new Thread(t);
|
||||||
nt.start();
|
nt.start();
|
||||||
ed.setVisible(true);
|
ed.setVisible(true);
|
||||||
@@ -1512,6 +1543,8 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
menu.add(mergeWith);
|
menu.add(mergeWith);
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
menu.add(peaknew);
|
||||||
|
menu.add(fftnew);
|
||||||
menu.add(peak);
|
menu.add(peak);
|
||||||
menu.add(fft);
|
menu.add(fft);
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
@@ -1934,6 +1967,8 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
// write the content into xml file
|
// write the content into xml file
|
||||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
Transformer transformer = transformerFactory.newTransformer();
|
Transformer transformer = transformerFactory.newTransformer();
|
||||||
|
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||||
|
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
|
||||||
DOMSource source = new DOMSource(doc);
|
DOMSource source = new DOMSource(doc);
|
||||||
StreamResult result = new StreamResult(xml);
|
StreamResult result = new StreamResult(xml);
|
||||||
transformer.transform(source, result);
|
transformer.transform(source, result);
|
||||||
@@ -2478,15 +2513,19 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
ProgressDialog dialog;
|
ProgressDialog dialog;
|
||||||
Chapter chapter;
|
Chapter chapter;
|
||||||
int type;
|
int type;
|
||||||
|
int scope;
|
||||||
|
|
||||||
public final static int FFT = 0;
|
public final static int FFT = 0;
|
||||||
public final static int Peak = 1;
|
public final static int Peak = 1;
|
||||||
|
public final static int NewOnly = 0;
|
||||||
|
public final static int All = 1;
|
||||||
|
|
||||||
public AutoTrimThread(Chapter c, ProgressDialog e, int t) {
|
public AutoTrimThread(Chapter c, ProgressDialog e, int t, int sc) {
|
||||||
super();
|
super();
|
||||||
dialog = e;
|
dialog = e;
|
||||||
chapter = c;
|
chapter = c;
|
||||||
type = t;
|
type = t;
|
||||||
|
scope = sc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -2498,6 +2537,9 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
kidCount++;
|
kidCount++;
|
||||||
dialog.setProgress(kidCount * 2000 / numKids);
|
dialog.setProgress(kidCount * 2000 / numKids);
|
||||||
Sentence snt = (Sentence)s.nextElement();
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
|
if (scope == NewOnly) {
|
||||||
|
if (snt.isProcessed()) continue;
|
||||||
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case FFT:
|
case FFT:
|
||||||
snt.autoTrimSampleFFT();
|
snt.autoTrimSampleFFT();
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
|||||||
ret.setText(s.getOverrideText());
|
ret.setText(s.getOverrideText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!s.isProcessed()) {
|
||||||
|
ret.setForeground(new Color(0x88, 0x88, 0x88));
|
||||||
|
}
|
||||||
|
|
||||||
if (s.getAttentionFlag()) {
|
if (s.getAttentionFlag()) {
|
||||||
ret.setForeground(new Color(0xFF, 0xFF, 0x00));
|
ret.setForeground(new Color(0xFF, 0xFF, 0x00));
|
||||||
icn.add(Overlays.attention, OverlayIcon.TOP_LEFT);
|
icn.add(Overlays.attention, OverlayIcon.TOP_LEFT);
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
boolean inSample;
|
boolean inSample;
|
||||||
boolean attention = false;
|
boolean attention = false;
|
||||||
|
boolean processed = false;
|
||||||
|
|
||||||
String effectChain = null;
|
String effectChain = null;
|
||||||
|
|
||||||
@@ -86,20 +87,26 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
boolean effectEthereal = false;
|
boolean effectEthereal = false;
|
||||||
|
|
||||||
|
public void setSampleSize(int s) {
|
||||||
|
sampleSize = s;
|
||||||
|
}
|
||||||
|
|
||||||
static class RecordingThread implements Runnable {
|
static class RecordingThread implements Runnable {
|
||||||
|
|
||||||
boolean running = false;
|
boolean running = false;
|
||||||
boolean recording = false;
|
boolean recording = false;
|
||||||
|
Sentence sent = null;
|
||||||
|
|
||||||
File tempFile;
|
File tempFile;
|
||||||
File wavFile;
|
File wavFile;
|
||||||
|
|
||||||
AudioFormat format;
|
AudioFormat format;
|
||||||
|
|
||||||
public RecordingThread(File tf, File wf, AudioFormat af) {
|
public RecordingThread(File tf, File wf, AudioFormat af, Sentence s) {
|
||||||
tempFile = tf;
|
tempFile = tf;
|
||||||
wavFile = wf;
|
wavFile = wf;
|
||||||
format = af;
|
format = af;
|
||||||
|
sent = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -121,6 +128,8 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
fos.write(buf, 0, nr);
|
fos.write(buf, 0, nr);
|
||||||
fos.close();
|
fos.close();
|
||||||
|
|
||||||
|
sent.setSampleSize(len / format.getFrameSize());
|
||||||
|
|
||||||
FileInputStream fis = new FileInputStream(tempFile);
|
FileInputStream fis = new FileInputStream(tempFile);
|
||||||
AudioInputStream ais = new AudioInputStream(fis, format, len / format.getFrameSize());
|
AudioInputStream ais = new AudioInputStream(fis, format, len / format.getFrameSize());
|
||||||
fos = new FileOutputStream(wavFile);
|
fos = new FileOutputStream(wavFile);
|
||||||
@@ -180,6 +189,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
setEffectChain(Book.getTextNode(root, "effect"));
|
setEffectChain(Book.getTextNode(root, "effect"));
|
||||||
setPostGapType(Book.getTextNode(root, "gaptype"));
|
setPostGapType(Book.getTextNode(root, "gaptype"));
|
||||||
sampleSize = Utils.s2i(Book.getTextNode(root, "samples"));
|
sampleSize = Utils.s2i(Book.getTextNode(root, "samples"));
|
||||||
|
processed = Utils.s2b(Book.getTextNode(root, "processed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startRecording() {
|
public boolean startRecording() {
|
||||||
@@ -190,7 +200,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
CacheManager.removeFromCache(this);
|
CacheManager.removeFromCache(this);
|
||||||
|
|
||||||
recordingThread = new RecordingThread(getTempFile(), getFile(), Options.getAudioFormat());
|
recordingThread = new RecordingThread(getTempFile(), getFile(), Options.getAudioFormat(), this);
|
||||||
|
|
||||||
Thread rc = new Thread(recordingThread);
|
Thread rc = new Thread(recordingThread);
|
||||||
rc.setDaemon(true);
|
rc.setDaemon(true);
|
||||||
@@ -230,6 +240,12 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
autoTrimSamplePeak(useRaw);
|
autoTrimSamplePeak(useRaw);
|
||||||
} else if (tm.equals("fft")) {
|
} else if (tm.equals("fft")) {
|
||||||
autoTrimSampleFFT(useRaw);
|
autoTrimSampleFFT(useRaw);
|
||||||
|
} else {
|
||||||
|
startOffset = 0;
|
||||||
|
crossStartOffset = 0;
|
||||||
|
endOffset = sampleSize - 1;
|
||||||
|
crossEndOffset = sampleSize - 1;
|
||||||
|
processed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,6 +347,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
updateCrossings(useRaw);
|
updateCrossings(useRaw);
|
||||||
intens = null;
|
intens = null;
|
||||||
samples = null;
|
samples = null;
|
||||||
|
processed = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,6 +404,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
if (startOffset < 0) startOffset = 0;
|
if (startOffset < 0) startOffset = 0;
|
||||||
if (endOffset >= samples.length) endOffset = samples.length-1;
|
if (endOffset >= samples.length) endOffset = samples.length-1;
|
||||||
updateCrossings(useRaw);
|
updateCrossings(useRaw);
|
||||||
|
processed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
@@ -1391,7 +1409,17 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
sentenceNode.appendChild(Book.makeTextNode(doc, "effect", getEffectChain()));
|
sentenceNode.appendChild(Book.makeTextNode(doc, "effect", getEffectChain()));
|
||||||
sentenceNode.appendChild(Book.makeTextNode(doc, "gaptype", getPostGapType()));
|
sentenceNode.appendChild(Book.makeTextNode(doc, "gaptype", getPostGapType()));
|
||||||
sentenceNode.appendChild(Book.makeTextNode(doc, "samples", getSampleSize()));
|
sentenceNode.appendChild(Book.makeTextNode(doc, "samples", getSampleSize()));
|
||||||
|
sentenceNode.appendChild(Book.makeTextNode(doc, "processed", isProcessed()));
|
||||||
return sentenceNode;
|
return sentenceNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isProcessed() {
|
||||||
|
return processed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProcessed(boolean p) {
|
||||||
|
processed = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user