Compare commits

...

10 Commits

42 changed files with 1205 additions and 570 deletions

BIN
deps/commons-lang3.jar LFS vendored Normal file

Binary file not shown.

BIN
deps/commons-text.jar LFS vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1 +1 @@
version=0.3.5 version=0.3.7

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -10,6 +10,7 @@ public class AGC implements Effect {
double attack; double attack;
public AGC(double c, double a, double d, double l) { public AGC(double c, double a, double d, double l) {
Debug.trace();
ceiling = c; ceiling = c;
attack = a; attack = a;
decay = d; decay = d;
@@ -18,14 +19,17 @@ public class AGC implements Effect {
} }
public String getName() { public String getName() {
Debug.trace();
return "AGC (Ceiling = " + ceiling + " attack = " + attack + " decay = " + decay + " limit = " + limit; return "AGC (Ceiling = " + ceiling + " attack = " + attack + " decay = " + decay + " limit = " + limit;
} }
public String toString() { public String toString() {
Debug.trace();
return getName(); return getName();
} }
public void process(double[][] samples) { public void process(double[][] samples) {
Debug.trace();
gain = 1d; gain = 1d;
for (int i = 0; i < samples[Sentence.LEFT].length; i++) { for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
double absSampleLeft = Math.abs(samples[Sentence.LEFT][i]) * gain; double absSampleLeft = Math.abs(samples[Sentence.LEFT][i]) * gain;
@@ -55,14 +59,17 @@ public class AGC implements Effect {
} }
public void init(double sr) { public void init(double sr) {
Debug.trace();
gain = 1d; gain = 1d;
} }
public void dump() { public void dump() {
Debug.trace();
System.out.println(toString()); System.out.println(toString());
} }
public ArrayList<Effect> getChildEffects() { public ArrayList<Effect> getChildEffects() {
Debug.trace();
return null; return null;
} }
} }

View File

@@ -1,11 +1,16 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import java.awt.BorderLayout;
import java.awt.*; import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class AboutPanel extends JPanel { public class AboutPanel extends JPanel {
public AboutPanel() { public AboutPanel() {
Debug.trace();
setLayout(new BorderLayout()); setLayout(new BorderLayout());
JLabel icon = new JLabel(Icons.appIcon); JLabel icon = new JLabel(Icons.appIcon);
add(icon, BorderLayout.WEST); add(icon, BorderLayout.WEST);
@@ -17,7 +22,7 @@ public class AboutPanel extends JPanel {
JLabel l1 = new JLabel("AudiobookRecorder"); JLabel l1 = new JLabel("AudiobookRecorder");
JLabel l2 = new JLabel("Version " + AudiobookRecorder.config.getProperty("version")); JLabel l2 = new JLabel("Version " + AudiobookRecorder.config.getProperty("version"));
JLabel l3 = new JLabel("(c) 2018 Majenko Technologies"); JLabel l3 = new JLabel("(c) 2020 Majenko Technologies");
l1.setAlignmentX(JComponent.CENTER_ALIGNMENT); l1.setAlignmentX(JComponent.CENTER_ALIGNMENT);
l2.setAlignmentX(JComponent.CENTER_ALIGNMENT); l2.setAlignmentX(JComponent.CENTER_ALIGNMENT);

View File

@@ -5,21 +5,26 @@ import java.util.ArrayList;
public class Amplifier implements Effect { public class Amplifier implements Effect {
double gain; double gain;
public Amplifier() { public Amplifier() {
Debug.trace();
gain = 1.0d; gain = 1.0d;
} }
public Amplifier(double g) { public Amplifier(double g) {
Debug.trace();
gain = g; gain = g;
} }
public String getName() { public String getName() {
Debug.trace();
return "Amplifier (" + gain + ")"; return "Amplifier (" + gain + ")";
} }
public ArrayList<Effect> getChildEffects() { public ArrayList<Effect> getChildEffects() {
Debug.trace();
return null; return null;
} }
public void process(double[][] samples) { public void process(double[][] samples) {
Debug.trace();
for (int i = 0; i < samples[Sentence.LEFT].length; i++) { for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
samples[Sentence.LEFT][i] *= gain; samples[Sentence.LEFT][i] *= gain;
samples[Sentence.RIGHT][i] *= gain; samples[Sentence.RIGHT][i] *= gain;
@@ -27,21 +32,26 @@ public class Amplifier implements Effect {
} }
public double getGain() { public double getGain() {
Debug.trace();
return gain; return gain;
} }
public void setGain(double g) { public void setGain(double g) {
Debug.trace();
gain = g; gain = g;
} }
public String toString() { public String toString() {
Debug.trace();
return getName(); return getName();
} }
public void dump() { public void dump() {
Debug.trace();
System.out.println(toString()); System.out.println(toString());
} }
public void init(double sf) { public void init(double sf) {
Debug.trace();
} }
} }

View File

@@ -1,32 +1,83 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.sound.sampled.*; import java.io.File;
import javax.swing.*; import java.io.FileInputStream;
import javax.swing.event.*; import java.io.FileOutputStream;
import javax.swing.text.*; import java.io.IOException;
import java.awt.*;
import java.awt.event.*;
import java.nio.file.*;
import javax.swing.tree.*;
import java.lang.reflect.*;
import java.util.*;
import java.util.prefs.*;
import java.io.*;
import it.sauronsoftware.jave.*;
import com.mpatric.mp3agic.*;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.zip.*; import java.util.ArrayList;
import javax.swing.filechooser.*; import java.util.ArrayDeque;
import javax.imageio.*; import java.util.Enumeration;
import org.w3c.dom.*; import java.util.Properties;
import javax.xml.parsers.*; import java.util.Queue;
import java.io.*; import java.util.Random;
import edu.cmu.sphinx.api.*; import java.util.Timer;
import edu.cmu.sphinx.decoder.adaptation.*; import java.util.TimerTask;
import edu.cmu.sphinx.result.*; import java.util.TreeMap;
import org.w3c.dom.Node; import java.util.UUID;
import java.util.concurrent.*; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import java.lang.reflect.Method;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Image;
import java.awt.event.AdjustmentListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.InputMap;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.SwingUtilities;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.Transformer; import javax.xml.transform.Transformer;
@@ -34,10 +85,17 @@ 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 javax.xml.transform.OutputKeys;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
import javax.sound.sampled.AudioInputStream;
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;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
@@ -45,8 +103,6 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
// Settings - tweakable // Settings - tweakable
public static final String SPHINX_MODEL = "resource:/edu/cmu/sphinx/models/en-us/en-us";
static Properties config = new Properties(); static Properties config = new Properties();
TreeMap<String, EffectGroup> effects; TreeMap<String, EffectGroup> effects;
@@ -123,6 +179,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
JSpinner postSentenceGap; JSpinner postSentenceGap;
JSpinner gainPercent; JSpinner gainPercent;
Timer waveformUpdater = new Timer();
JCheckBox locked; JCheckBox locked;
JCheckBox attention; JCheckBox attention;
JCheckBox rawAudio; JCheckBox rawAudio;
@@ -147,25 +204,10 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
public TargetDataLine microphone = null; public TargetDataLine microphone = null;
public AudioInputStream microphoneStream = null; public AudioInputStream microphoneStream = null;
public Configuration sphinxConfig;
public StreamSpeechRecognizer recognizer;
public static AudiobookRecorder window; public static AudiobookRecorder window;
void initSphinx() { public Queue<Runnable>processQueue = null;
Debug.trace(); public QueueMonitor queueMonitor = null;
sphinxConfig = new Configuration();
sphinxConfig.setAcousticModelPath(AudiobookRecorder.SPHINX_MODEL);
sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
try {
recognizer = new StreamSpeechRecognizer(sphinxConfig);
} catch (Exception e) {
e.printStackTrace();
}
}
void buildToolbar(Container ob) { void buildToolbar(Container ob) {
Debug.trace(); Debug.trace();
@@ -381,6 +423,8 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
Debug.debugEnabled = CLI.isSet("debug"); Debug.debugEnabled = CLI.isSet("debug");
Debug.traceEnabled = CLI.isSet("trace"); Debug.traceEnabled = CLI.isSet("trace");
processQueue = new ArrayDeque<Runnable>();
try { try {
String clsname = "com.jtattoo.plaf.hifi.HiFiLookAndFeel"; String clsname = "com.jtattoo.plaf.hifi.HiFiLookAndFeel";
@@ -404,6 +448,15 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
Options.loadPreferences(); Options.loadPreferences();
queueMonitor = new QueueMonitor(processQueue);
for (int i = 0; i < Options.getInteger("process.threads"); i++) {
WorkerThread worker = new WorkerThread(processQueue, queueMonitor);
queueMonitor.addThread(worker);
worker.start();
}
execScript(Options.get("scripts.startup")); execScript(Options.get("scripts.startup"));
CacheManager.setCacheSize(Options.getInteger("cache.size")); CacheManager.setCacheSize(Options.getInteger("cache.size"));
@@ -483,11 +536,12 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Debug.trace(); Debug.trace();
if (selectedSentence != null) { if (selectedSentence != null) {
selectedSentence.autoTrimSampleFFT(); queueJob(new SentenceJob(selectedSentence) {
sampleWaveform.setMarkers(selectedSentence.getStartOffset(), selectedSentence.getEndOffset()); public void run() {
sampleWaveform.setAltMarkers(selectedSentence.getStartCrossing(), selectedSentence.getEndCrossing()); sentence.autoTrimSampleFFT();
postSentenceGap.setValue(selectedSentence.getPostGap()); updateWaveformMarkers();
gainPercent.setValue((int)(selectedSentence.getGain() * 100d)); }
});
} }
} }
}); });
@@ -496,11 +550,12 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Debug.trace(); Debug.trace();
if (selectedSentence != null) { if (selectedSentence != null) {
selectedSentence.autoTrimSamplePeak(); queueJob(new SentenceJob(selectedSentence) {
sampleWaveform.setMarkers(selectedSentence.getStartOffset(), selectedSentence.getEndOffset()); public void run() {
sampleWaveform.setAltMarkers(selectedSentence.getStartCrossing(), selectedSentence.getEndCrossing()); sentence.autoTrimSamplePeak();
postSentenceGap.setValue(selectedSentence.getPostGap()); updateWaveformMarkers();
gainPercent.setValue((int)(selectedSentence.getGain() * 100d)); }
});
} }
} }
}); });
@@ -608,8 +663,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
doCutSplit.setEnabled(false); doCutSplit.setEnabled(false);
selectCutMode.setSelected(false); selectCutMode.setSelected(false);
selectSplitMode.setSelected(false); selectSplitMode.setSelected(false);
selectedSentence.reloadTree();
bookTreeModel.reload(selectedSentence);
} }
}); });
controlsTop.add(locked); controlsTop.add(locked);
@@ -630,7 +684,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
selectedSentence.setAttentionFlag(false); selectedSentence.setAttentionFlag(false);
} }
} }
bookTreeModel.reload(selectedSentence); selectedSentence.reloadTree();
} }
}); });
@@ -698,10 +752,12 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
centralPanel.add(sampleControl, BorderLayout.SOUTH); centralPanel.add(sampleControl, BorderLayout.SOUTH);
statusBar = new JPanel(); statusBar = new JPanel();
statusBar.setLayout(new FlowLayout(FlowLayout.CENTER));
add(statusBar, BorderLayout.SOUTH); add(statusBar, BorderLayout.SOUTH);
statusLabel = new JLabel("Noise floor: " + getNoiseFloorDB() + "dB"); statusLabel = new JLabel("Noise floor: " + getNoiseFloorDB() + "dB");
statusBar.add(statusLabel); statusBar.add(statusLabel);
statusBar.add(queueMonitor);
buildToolbar(centralPanel); buildToolbar(centralPanel);
@@ -885,12 +941,8 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
Debug.trace(); Debug.trace();
if (ev.getPropertyName().equals("dividerLocation")) { if (ev.getPropertyName().equals("dividerLocation")) {
if ((bookTreeModel != null) && (book != null)) { if ((bookTreeModel != null) && (book != null)) {
SwingUtilities.invokeLater(new Runnable() { Debug.trace();
public void run() { book.reloadTree();
Debug.trace();
bookTreeModel.reload(book);
}
});
} }
} }
} }
@@ -993,6 +1045,8 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
public static void main(String args[]) { public static void main(String args[]) {
Debug.trace(); Debug.trace();
Properties props = System.getProperties();
props.setProperty("sun.java2d.opengl", "true");
try { try {
config.load(AudiobookRecorder.class.getResourceAsStream("config.txt")); config.load(AudiobookRecorder.class.getResourceAsStream("config.txt"));
} catch (Exception e) { } catch (Exception e) {
@@ -1025,16 +1079,17 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
newbook.setComment(info.getComment().trim()); newbook.setComment(info.getComment().trim());
newbook.setACX(info.getACX().trim()); newbook.setACX(info.getACX().trim());
Chapter caud = new Chapter("audition", "Audition"); Chapter caud = new Chapter(UUID.randomUUID().toString(), "Audition");
Chapter copen = new Chapter("open", "Opening Credits"); Chapter copen = new Chapter(UUID.randomUUID().toString(), "Opening Credits");
Chapter cone = new Chapter("0001", "Chapter 1"); Chapter cclose = new Chapter(UUID.randomUUID().toString(), "Closing Credits");
Chapter cclose = new Chapter("close", "Closing Credits"); Chapter cone = new Chapter(UUID.randomUUID().toString(), "Chapter 1");
newbook.add(caud); newbook.add(caud);
newbook.add(copen); newbook.add(copen);
newbook.add(cone);
newbook.add(cclose); newbook.add(cclose);
newbook.add(cone);
File bookRoot = new File(Options.get("path.storage"), newbook.getName()); File bookRoot = new File(Options.get("path.storage"), newbook.getName());
if (!bookRoot.exists()) { if (!bookRoot.exists()) {
bookRoot.mkdirs(); bookRoot.mkdirs();
@@ -1043,6 +1098,10 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
File xml = new File(bookRoot, "audiobook.abx"); File xml = new File(bookRoot, "audiobook.abx");
Document doc = newbook.buildDocument(); Document doc = newbook.buildDocument();
File backup = new File(bookRoot, "audiobook.bak");
if (xml.exists()) {
xml.renameTo(backup);
}
// write the content into xml file // write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance(); TransformerFactory transformerFactory = TransformerFactory.newInstance();
@@ -1136,24 +1195,15 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
public void run() { public void run() {
Debug.trace(); Debug.trace();
try { try {
Configuration sphinxConfig = new Configuration();
sphinxConfig.setAcousticModelPath(AudiobookRecorder.SPHINX_MODEL);
sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
sphinxConfig.setSampleRate((int)(book.getAudioFormat().getSampleRate() / 4f));
StreamSpeechRecognizer recognizer;
recognizer = new StreamSpeechRecognizer(sphinxConfig);
for (Enumeration s = chapter.children(); s.hasMoreElements();) { for (Enumeration s = chapter.children(); s.hasMoreElements();) {
Sentence snt = (Sentence)s.nextElement(); Sentence snt = (Sentence)s.nextElement();
if (!snt.isLocked()) { if (!snt.isLocked()) {
if (snt.getId().equals(snt.getText())) { if (snt.getId().equals(snt.getText())) {
snt.doRecognition(recognizer); queueJob(new SentenceJob(snt) {
public void run() {
sentence.doRecognition();
}
});
} }
} }
} }
@@ -1186,7 +1236,11 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
JMenuObject o = (JMenuObject)e.getSource(); JMenuObject o = (JMenuObject)e.getSource();
Sentence s = (Sentence)o.getObject(); Sentence s = (Sentence)o.getObject();
if (!s.isLocked()) { if (!s.isLocked()) {
s.recognise(); queueJob(new SentenceJob(s) {
public void run() {
sentence.doRecognition();
}
});
} }
} }
}); });
@@ -1263,7 +1317,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
String type = (String)o.getObject2(); String type = (String)o.getObject2();
sent.setPostGapType(type); sent.setPostGapType(type);
sent.setPostGap(Options.getInteger("catenation.post-sentence")); sent.setPostGap(Options.getInteger("catenation.post-sentence"));
bookTreeModel.reload(sent); sent.reloadTree();
} }
}); });
setGapType.add(gapTypeSentence); setGapType.add(gapTypeSentence);
@@ -1276,7 +1330,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
String type = (String)o.getObject2(); String type = (String)o.getObject2();
sent.setPostGapType(type); sent.setPostGapType(type);
sent.setPostGap(Options.getInteger("catenation.short-sentence")); sent.setPostGap(Options.getInteger("catenation.short-sentence"));
bookTreeModel.reload(sent); sent.reloadTree();
} }
}); });
setGapType.add(gapTypeContinuation); setGapType.add(gapTypeContinuation);
@@ -1289,7 +1343,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
String type = (String)o.getObject2(); String type = (String)o.getObject2();
sent.setPostGapType(type); sent.setPostGapType(type);
sent.setPostGap(Options.getInteger("catenation.post-paragraph")); sent.setPostGap(Options.getInteger("catenation.post-paragraph"));
bookTreeModel.reload(sent); sent.reloadTree();
} }
}); });
setGapType.add(gapTypeParagraph); setGapType.add(gapTypeParagraph);
@@ -1302,7 +1356,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
String type = (String)o.getObject2(); String type = (String)o.getObject2();
sent.setPostGapType(type); sent.setPostGapType(type);
sent.setPostGap(Options.getInteger("catenation.post-section")); sent.setPostGap(Options.getInteger("catenation.post-section"));
bookTreeModel.reload(sent); sent.reloadTree();
} }
}); });
setGapType.add(gapTypeSection); setGapType.add(gapTypeSection);
@@ -1431,14 +1485,19 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Debug.trace(); Debug.trace();
JMenuObject o = (JMenuObject)e.getSource(); JMenuObject o = (JMenuObject)e.getSource();
Chapter chap = (Chapter)o.getObject(); Chapter c = (Chapter)o.getObject();
for (Enumeration s = c.children(); s.hasMoreElements();) {
Sentence snt = (Sentence)s.nextElement();
if (!snt.isProcessed()) {
queueJob(new SentenceJob(snt) {
public void run() {
sentence.autoTrimSampleFFT();
updateWaveformMarkers();
}
});
}
}
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);
} }
}); });
@@ -1446,14 +1505,18 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Debug.trace(); Debug.trace();
JMenuObject o = (JMenuObject)e.getSource(); JMenuObject o = (JMenuObject)e.getSource();
Chapter chap = (Chapter)o.getObject(); Chapter c = (Chapter)o.getObject();
for (Enumeration s = c.children(); s.hasMoreElements();) {
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName()); Sentence snt = (Sentence)s.nextElement();
if (!snt.isProcessed()) {
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.FFT, AutoTrimThread.NewOnly); queueJob(new SentenceJob(snt) {
Thread nt = new Thread(t); public void run() {
nt.start(); sentence.autoTrimSampleFFT();
ed.setVisible(true); updateWaveformMarkers();
}
});
}
}
} }
}); });
@@ -1461,14 +1524,16 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Debug.trace(); Debug.trace();
JMenuObject o = (JMenuObject)e.getSource(); JMenuObject o = (JMenuObject)e.getSource();
Chapter chap = (Chapter)o.getObject(); Chapter c = (Chapter)o.getObject();
for (Enumeration s = c.children(); s.hasMoreElements();) {
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName()); Sentence snt = (Sentence)s.nextElement();
queueJob(new SentenceJob(snt) {
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.Peak, AutoTrimThread.All); public void run() {
Thread nt = new Thread(t); sentence.autoTrimSamplePeak();
nt.start(); updateWaveformMarkers();
ed.setVisible(true); }
});
}
} }
}); });
@@ -1476,14 +1541,16 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Debug.trace(); Debug.trace();
JMenuObject o = (JMenuObject)e.getSource(); JMenuObject o = (JMenuObject)e.getSource();
Chapter chap = (Chapter)o.getObject(); Chapter c = (Chapter)o.getObject();
for (Enumeration s = c.children(); s.hasMoreElements();) {
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName()); Sentence snt = (Sentence)s.nextElement();
queueJob(new SentenceJob(snt) {
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.FFT, AutoTrimThread.All); public void run() {
Thread nt = new Thread(t); sentence.autoTrimSampleFFT();
nt.start(); updateWaveformMarkers();
ed.setVisible(true); }
});
}
} }
}); });
@@ -1503,20 +1570,11 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
Chapter chap = (Chapter)o.getObject(); Chapter chap = (Chapter)o.getObject();
int pos = bookTreeModel.getIndexOfChild(book, chap); int pos = bookTreeModel.getIndexOfChild(book, chap);
if (pos > 0) pos--; if (pos > 0) pos--;
Chapter prevChap = (Chapter)bookTreeModel.getChild(book, pos);
int id = Utils.s2i(chap.getId()); bookTreeModel.removeNodeFromParent(chap);
if (id > 0) { bookTreeModel.insertNodeInto(chap, book, pos);
Chapter prevChap = (Chapter)bookTreeModel.getChild(book, pos);
id = Utils.s2i(prevChap.getId());
if (id > 0) {
bookTreeModel.removeNodeFromParent(chap);
bookTreeModel.insertNodeInto(chap, book, pos);
}
}
book.renumberChapters();
} }
}); });
moveUp.setEnabled(idNumber > 0);
JMenuObject moveDown = new JMenuObject("Move Down", c, new ActionListener() { JMenuObject moveDown = new JMenuObject("Move Down", c, new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@@ -1525,21 +1583,13 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
Chapter chap = (Chapter)o.getObject(); Chapter chap = (Chapter)o.getObject();
int pos = bookTreeModel.getIndexOfChild(book, chap); int pos = bookTreeModel.getIndexOfChild(book, chap);
pos++; pos++;
int id = Utils.s2i(chap.getId()); Chapter nextChap = (Chapter)bookTreeModel.getChild(book, pos);
if (id > 0) { if (nextChap != null) {
Chapter nextChap = (Chapter)bookTreeModel.getChild(book, pos); bookTreeModel.removeNodeFromParent(chap);
if (nextChap != null) { bookTreeModel.insertNodeInto(chap, book, pos);
id = Utils.s2i(nextChap.getId());
if (id > 0) {
bookTreeModel.removeNodeFromParent(chap);
bookTreeModel.insertNodeInto(chap, book, pos);
}
}
} }
book.renumberChapters();
} }
}); });
moveDown.setEnabled(idNumber > 0);
JMenu mergeWith = new JMenu("Merge chapter with"); JMenu mergeWith = new JMenu("Merge chapter with");
for (Enumeration bc = book.children(); bc.hasMoreElements();) { for (Enumeration bc = book.children(); bc.hasMoreElements();) {
@@ -1573,7 +1623,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
for (Enumeration s = c.children(); s.hasMoreElements();) { for (Enumeration s = c.children(); s.hasMoreElements();) {
Sentence snt = (Sentence)s.nextElement(); Sentence snt = (Sentence)s.nextElement();
snt.setLocked(true); snt.setLocked(true);
bookTreeModel.reload(snt); snt.reloadTree();
} }
} }
}); });
@@ -1586,7 +1636,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
for (Enumeration s = c.children(); s.hasMoreElements();) { for (Enumeration s = c.children(); s.hasMoreElements();) {
Sentence snt = (Sentence)s.nextElement(); Sentence snt = (Sentence)s.nextElement();
snt.setLocked(false); snt.setLocked(false);
bookTreeModel.reload(snt); snt.reloadTree();
} }
} }
}); });
@@ -1629,9 +1679,18 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
Debug.trace(); Debug.trace();
JMenuObject o = (JMenuObject)e.getSource(); JMenuObject o = (JMenuObject)e.getSource();
Chapter c = (Chapter)o.getObject(); Chapter c = (Chapter)o.getObject();
BatchConversionThread r = new BatchConversionThread(c);
Thread t = new Thread(r); for (Enumeration s = c.children(); s.hasMoreElements();) {
t.start(); Sentence snt = (Sentence)s.nextElement();
if (!snt.isLocked()) {
if (!snt.beenDetected()) {
Debug.d("Queueing recognition of", snt.getId());
Runnable r = snt.getRecognitionRunnable();
snt.setQueued();
queueJob(r);
}
}
}
} }
}); });
@@ -2037,7 +2096,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
if (recording == null) return; if (recording == null) return;
recording.stopRecording(); recording.stopRecording();
bookTreeModel.reload(book); 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()));
@@ -2152,8 +2211,12 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
bookTree.setEditable(true); bookTree.setEditable(true);
bookTree.setUI(new CustomTreeUI(mainScroll)); bookTree.setUI(new CustomTreeUI(mainScroll));
bookTree.setCellRenderer(new BookTreeRenderer()); try {
bookTree.setCellRenderer(new BookTreeRenderer());
} catch (Exception ex) {
ex.printStackTrace();
bookTree.setCellRenderer(new BookTreeRenderer());
}
InputMap im = bookTree.getInputMap(JComponent.WHEN_FOCUSED); InputMap im = bookTree.getInputMap(JComponent.WHEN_FOCUSED);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "startStopPlayback"); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "startStopPlayback");
@@ -2244,17 +2307,20 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
ImageIcon i = new ImageIcon(cf.getAbsolutePath()); ImageIcon i = new ImageIcon(cf.getAbsolutePath());
Image ri = Utils.getScaledImage(i.getImage(), 22, 22); Image ri = Utils.getScaledImage(i.getImage(), 22, 22);
book.setIcon(new ImageIcon(ri)); book.setIcon(new ImageIcon(ri));
bookTreeModel.reload(book); } else {
book.setIcon(Icons.book);
} }
book.reloadTree();
bookTree.expandPath(new TreePath(book.getPath())); bookTree.expandPath(new TreePath(book.getPath()));
statusLabel.setText("Noise floor: " + getNoiseFloorDB() + "dB"); statusLabel.setText("Noise floor: " + getNoiseFloorDB() + "dB");
book.setIcon(Icons.book);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
gatherOrphans();
} }
public void loadBookStructure(File f) { public void loadBookStructure(File f) {
@@ -2280,7 +2346,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
ImageIcon i = new ImageIcon(cf.getAbsolutePath()); ImageIcon i = new ImageIcon(cf.getAbsolutePath());
Image ri = Utils.getScaledImage(i.getImage(), 22, 22); Image ri = Utils.getScaledImage(i.getImage(), 22, 22);
book.setIcon(new ImageIcon(ri)); book.setIcon(new ImageIcon(ri));
bookTreeModel.reload(book); book.reloadTree();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -2680,55 +2746,6 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
} }
} }
class AutoTrimThread implements Runnable {
ProgressDialog dialog;
Chapter chapter;
int type;
int scope;
public final static int FFT = 0;
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, int sc) {
super();
Debug.trace();
dialog = e;
chapter = c;
type = t;
scope = sc;
}
@SuppressWarnings("unchecked")
public void run() {
Debug.trace();
int numKids = chapter.getChildCount();
int kidCount = 0;
for (Enumeration s = chapter.children(); s.hasMoreElements();) {
kidCount++;
dialog.setProgress(kidCount * 2000 / numKids);
Sentence snt = (Sentence)s.nextElement();
if (scope == NewOnly) {
if (snt.isProcessed()) continue;
}
switch (type) {
case FFT:
snt.autoTrimSampleFFT();
break;
case Peak:
snt.autoTrimSamplePeak();
break;
}
}
dialog.closeDialog();
}
}
class ExportThread implements Runnable { class ExportThread implements Runnable {
ProgressDialog exportDialog; ProgressDialog exportDialog;
Chapter chapter; Chapter chapter;
@@ -3464,7 +3481,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
ImageIcon i = new ImageIcon(dest.getAbsolutePath()); ImageIcon i = new ImageIcon(dest.getAbsolutePath());
Image ri = Utils.getScaledImage(i.getImage(), 22, 22); Image ri = Utils.getScaledImage(i.getImage(), 22, 22);
book.setIcon(new ImageIcon(ri)); book.setIcon(new ImageIcon(ri));
bookTreeModel.reload(book); book.reloadTree();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -3477,16 +3494,42 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
updateWaveform(false); updateWaveform(false);
} }
public void updateWaveform(boolean force) { TimerTask waveformUpdaterTask = null;
synchronized public void updateWaveform(boolean force) {
Debug.trace(); Debug.trace();
if (selectedSentence != null) { if (selectedSentence != null) {
if ((!force) && (sampleWaveform.getId() != null) && (sampleWaveform.getId().equals(selectedSentence.getId()))) return; if ((!force) && (sampleWaveform.getId() != null) && (sampleWaveform.getId().equals(selectedSentence.getId()))) return;
sampleWaveform.setId(selectedSentence.getId());
if (rawAudio.isSelected()) { synchronized (waveformUpdater) {
sampleWaveform.setData(selectedSentence.getRawAudioData()); try {
} else { if (waveformUpdaterTask != null) {
sampleWaveform.setData(selectedSentence.getDoubleAudioData(effectsEnabled)); waveformUpdaterTask.cancel();
}
} catch (Exception ex) {
}
waveformUpdaterTask = new TimerTask() {
public void run() {
sampleWaveform.setId(selectedSentence.getId());
if (rawAudio.isSelected()) {
sampleWaveform.setData(selectedSentence.getRawAudioData());
} else {
sampleWaveform.setData(selectedSentence.getDoubleAudioData(effectsEnabled));
}
}
};
waveformUpdater.schedule(waveformUpdaterTask, 20);
} }
}
}
synchronized public void updateWaveformMarkers() {
if (selectedSentence != null) {
sampleWaveform.setMarkers(selectedSentence.getStartOffset(), selectedSentence.getEndOffset());
sampleWaveform.setAltMarkers(selectedSentence.getStartCrossing(), selectedSentence.getEndCrossing());
} }
} }
@@ -4103,4 +4146,57 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
// DocumentListener *// // DocumentListener *//
public boolean sentenceIdExists(String id) {
for (Enumeration c = book.children(); c.hasMoreElements();) {
Chapter chp = (Chapter)c.nextElement();
for (Enumeration s = chp.children(); s.hasMoreElements();) {
Sentence snt = (Sentence)s.nextElement();
if (snt.getId().equals(id)) return true;
}
}
return false;
}
public void gatherOrphans() {
Chapter orphans = getChapterById("orphans");
if (orphans == null) {
orphans = new Chapter("orphans", "Orphan Files");
bookTreeModel.insertNodeInto(orphans, book, book.getChildCount());
}
File bookRoot = new File(Options.get("path.storage"), book.getName());
File[] files = new File(bookRoot, "files").listFiles();
for (File f : files) {
String filename = f.getName();
if (filename.startsWith(".")) continue;
if (filename.startsWith("backup")) continue;
if (filename.equals("room-noise.wav")) continue;
if (filename.endsWith(".wav")) {
String id = filename.substring(0, filename.length() - 4);
Debug.d("Testing orphanicity of", id);
if (!sentenceIdExists(id)) {
Sentence newSentence = new Sentence(id, id);
bookTreeModel.insertNodeInto(newSentence, orphans, orphans.getChildCount());
}
}
}
}
public Chapter getChapterById(String id) {
for (Enumeration c = book.children(); c.hasMoreElements();) {
Chapter chp = (Chapter)c.nextElement();
if (chp.getId().equals(id)) return chp;
}
return null;
}
public void queueJob(Runnable r) {
synchronized(processQueue) {
processQueue.add(r);
if (r instanceof SentenceJob) {
SentenceJob sj = (SentenceJob)r;
sj.setQueued();
}
processQueue.notify();
}
}
} }

View File

@@ -37,6 +37,7 @@ public class Biquad implements Effect {
double sampleFrequency; double sampleFrequency;
public Biquad() { public Biquad() {
Debug.trace();
type = Lowpass; type = Lowpass;
a0 = 1.0d; a0 = 1.0d;
a1 = 0.0d; a1 = 0.0d;
@@ -54,6 +55,7 @@ public class Biquad implements Effect {
} }
public Biquad(int type, double Fc, double Q, double peakGainDB) { public Biquad(int type, double Fc, double Q, double peakGainDB) {
Debug.trace();
setBiquad(type, Fc, Q, peakGainDB); setBiquad(type, Fc, Q, peakGainDB);
lz1 = 0.0; lz1 = 0.0;
lz2 = 0.0; lz2 = 0.0;
@@ -63,26 +65,31 @@ public class Biquad implements Effect {
} }
public void setType(int typei) { public void setType(int typei) {
Debug.trace();
type = typei; type = typei;
calcBiquad(); calcBiquad();
} }
public void setQ(double Qi) { public void setQ(double Qi) {
Debug.trace();
Q = Qi; Q = Qi;
calcBiquad(); calcBiquad();
} }
public void setFc(double Fci) { public void setFc(double Fci) {
Debug.trace();
Fc = Fci; Fc = Fci;
calcBiquad(); calcBiquad();
} }
public void setPeakGain(double peakGainDB) { public void setPeakGain(double peakGainDB) {
Debug.trace();
peakGain = peakGainDB; peakGain = peakGainDB;
calcBiquad(); calcBiquad();
} }
public void setBiquad(int typei, double Fci, double Qi, double peakGainDB) { public void setBiquad(int typei, double Fci, double Qi, double peakGainDB) {
Debug.trace();
type = typei; type = typei;
Q = Qi; Q = Qi;
Fc = Fci; Fc = Fci;
@@ -90,6 +97,7 @@ public class Biquad implements Effect {
} }
public void process(double[][] samples) { public void process(double[][] samples) {
Debug.trace();
lz1 = 0d; lz1 = 0d;
lz2 = 0d; lz2 = 0d;
rz1 = 0d; rz1 = 0d;
@@ -111,6 +119,7 @@ public class Biquad implements Effect {
} }
public void init(double sf) { public void init(double sf) {
Debug.trace();
sampleFrequency = sf; sampleFrequency = sf;
lz1 = 0d; lz1 = 0d;
lz2 = 0d; lz2 = 0d;
@@ -120,6 +129,7 @@ public class Biquad implements Effect {
} }
void calcBiquad() { void calcBiquad() {
Debug.trace();
double norm; double norm;
double V = Math.pow(10, Math.abs(peakGain) / 20.0); double V = Math.pow(10, Math.abs(peakGain) / 20.0);
@@ -221,6 +231,7 @@ public class Biquad implements Effect {
} }
public String getName() { public String getName() {
Debug.trace();
String n = "Biquad Filter ("; String n = "Biquad Filter (";
switch (type) { switch (type) {
case Lowpass: n += "Lowpass"; break; case Lowpass: n += "Lowpass"; break;
@@ -242,14 +253,17 @@ public class Biquad implements Effect {
} }
public ArrayList<Effect> getChildEffects() { public ArrayList<Effect> getChildEffects() {
Debug.trace();
return null; return null;
} }
public String toString() { public String toString() {
Debug.trace();
return getName(); return getName();
} }
public void dump() { public void dump() {
Debug.trace();
System.out.println(toString()); System.out.println(toString());
} }
} }

View File

@@ -1,15 +1,16 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import java.io.File;
import javax.swing.event.*; import java.nio.file.Files;
import java.awt.*; import java.util.ArrayList;
import java.awt.event.*; import java.util.Enumeration;
import java.util.*; import java.util.UUID;
import java.io.*; import java.util.Properties;
import java.nio.file.*; import javax.sound.sampled.AudioFormat;
import javax.swing.tree.*; import javax.swing.JOptionPane;
import javax.sound.sampled.*; import javax.swing.SwingUtilities;
import javax.swing.ImageIcon;
import javax.swing.tree.DefaultTreeModel;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
@@ -24,7 +25,7 @@ import org.w3c.dom.NodeList;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Text; import org.w3c.dom.Text;
public class Book extends DefaultMutableTreeNode { public class Book extends BookTreeNode {
String name; String name;
String author; String author;
@@ -39,13 +40,17 @@ public class Book extends DefaultMutableTreeNode {
int channels; int channels;
int resolution; int resolution;
String notes = null;
ImageIcon icon; ImageIcon icon;
Properties prefs; Properties prefs;
File location;
public Book(Properties p, String bookname) { public Book(Properties p, String bookname) {
super(bookname); super(bookname);
Debug.trace();
prefs = p; prefs = p;
name = bookname; name = bookname;
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!! AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!!
@@ -53,12 +58,13 @@ public class Book extends DefaultMutableTreeNode {
public Book(Element root) { public Book(Element root) {
super(getTextNode(root, "title")); super(getTextNode(root, "title"));
Debug.trace();
name = getTextNode(root, "title"); name = getTextNode(root, "title");
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!! AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!!
} }
public void loadBookXML(Element root, DefaultTreeModel model) { public void loadBookXML(Element root, DefaultTreeModel model) {
Debug.trace();
name = getTextNode(root, "title"); name = getTextNode(root, "title");
author = getTextNode(root, "author"); author = getTextNode(root, "author");
genre = getTextNode(root, "genre"); genre = getTextNode(root, "genre");
@@ -67,6 +73,7 @@ public class Book extends DefaultMutableTreeNode {
manuscript = getTextNode(root, "manuscript"); manuscript = getTextNode(root, "manuscript");
AudiobookRecorder.window.setBookNotes(getTextNode(root, "notes")); AudiobookRecorder.window.setBookNotes(getTextNode(root, "notes"));
notes = getTextNode(root, "notes");
Element settings = getNode(root, "settings"); Element settings = getNode(root, "settings");
Element audioSettings = getNode(settings, "audio"); Element audioSettings = getNode(settings, "audio");
@@ -92,6 +99,7 @@ public class Book extends DefaultMutableTreeNode {
} }
public static Element getNode(Element r, String n) { public static Element getNode(Element r, String n) {
Debug.trace();
NodeList nl = r.getElementsByTagName(n); NodeList nl = r.getElementsByTagName(n);
if (nl == null) return null; if (nl == null) return null;
if (nl.getLength() == 0) return null; if (nl.getLength() == 0) return null;
@@ -99,35 +107,40 @@ public class Book extends DefaultMutableTreeNode {
} }
public static String getTextNode(Element r, String n) { public static String getTextNode(Element r, String n) {
Debug.trace();
return getTextNode(r, n, ""); return getTextNode(r, n, "");
} }
public static String getTextNode(Element r, String n, String d) { public static String getTextNode(Element r, String n, String d) {
Debug.trace();
Element node = getNode(r, n); Element node = getNode(r, n);
if (node == null) return d; if (node == null) return d;
return node.getTextContent(); return node.getTextContent();
} }
public void setAuthor(String a) { author = a; } public void setAuthor(String a) { Debug.trace(); author = a; }
public void setGenre(String g) { genre = g; } public void setGenre(String g) { Debug.trace(); genre = g; }
public void setComment(String c) { comment = c; } public void setComment(String c) { Debug.trace(); comment = c; }
public void setACX(String c) { ACX = c; } public void setACX(String c) { Debug.trace(); ACX = c; }
public String getAuthor() { return author; } public String getAuthor() { Debug.trace(); return author; }
public String getGenre() { return genre; } public String getGenre() { Debug.trace(); return genre; }
public String getComment() { return comment; } public String getComment() { Debug.trace(); return comment; }
public String getACX() { if (ACX == null) return ""; return ACX; } public String getACX() { Debug.trace(); if (ACX == null) return ""; return ACX; }
public Chapter getClosingCredits() { public Chapter getClosingCredits() {
Debug.trace();
return getChapterById("close"); return getChapterById("close");
} }
public Chapter getOpeningCredits() { public Chapter getOpeningCredits() {
Debug.trace();
return getChapterById("open"); return getChapterById("open");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Chapter getChapterById(String id) { public Chapter getChapterById(String id) {
Debug.trace();
for (Enumeration o = children(); o.hasMoreElements();) { for (Enumeration o = children(); o.hasMoreElements();) {
Object ob = (Object)o.nextElement(); Object ob = (Object)o.nextElement();
if (ob instanceof Chapter) { if (ob instanceof Chapter) {
@@ -141,6 +154,7 @@ public class Book extends DefaultMutableTreeNode {
} }
public Chapter getLastChapter() { public Chapter getLastChapter() {
Debug.trace();
Chapter cc = getClosingCredits(); Chapter cc = getClosingCredits();
if (cc == null) return null; if (cc == null) return null;
Chapter c = (Chapter)getChildBefore(cc); Chapter c = (Chapter)getChildBefore(cc);
@@ -150,38 +164,34 @@ public class Book extends DefaultMutableTreeNode {
} }
public Chapter getChapter(int n) { public Chapter getChapter(int n) {
Debug.trace();
if (n == 0) return null; if (n == 0) return null;
return (Chapter)getChildAt(n); return (Chapter)getChildAt(n);
} }
public Chapter addChapter() { public Chapter addChapter() {
Chapter lc = getLastChapter(); Debug.trace();
if (lc == null) return new Chapter("1", "Chapter 1"); String uuid = UUID.randomUUID().toString();
try { return new Chapter(uuid, uuid);
int lcid = Integer.parseInt(lc.getId());
lcid++;
Chapter nc = new Chapter(String.format("%04d", lcid), "Chapter " + lcid);
return nc;
} catch (Exception e) {
e.printStackTrace();
}
return null;
} }
public String getName() { public String getName() {
Debug.trace();
return name; return name;
} }
public ImageIcon getIcon() { public ImageIcon getIcon() {
Debug.trace();
return icon; return icon;
} }
public void setIcon(ImageIcon i) { public void setIcon(ImageIcon i) {
Debug.trace();
icon = i; icon = i;
} }
public void setUserObject(Object o) { public void setUserObject(Object o) {
Debug.trace();
if (o instanceof String) { if (o instanceof String) {
String newName = (String)o; String newName = (String)o;
if (newName.equals(name)) return; if (newName.equals(name)) return;
@@ -190,10 +200,12 @@ public class Book extends DefaultMutableTreeNode {
} }
public File getBookPath() { public File getBookPath() {
Debug.trace();
return new File(Options.get("path.storage"), name); return new File(Options.get("path.storage"), name);
} }
public void renameBook(String newName) { public void renameBook(String newName) {
Debug.trace();
File oldDir = getBookPath(); File oldDir = getBookPath();
File newDir = new File(Options.get("path.storage"), newName); File newDir = new File(Options.get("path.storage"), newName);
@@ -206,7 +218,7 @@ public class Book extends DefaultMutableTreeNode {
oldDir.renameTo(newDir); oldDir.renameTo(newDir);
name = newName; name = newName;
AudiobookRecorder.window.saveBookStructure(); AudiobookRecorder.window.saveBookStructure();
AudiobookRecorder.window.bookTreeModel.reload(this); reloadTree();
Options.set("path.last-book", name); Options.set("path.last-book", name);
Options.savePreferences(); Options.savePreferences();
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
@@ -214,11 +226,13 @@ public class Book extends DefaultMutableTreeNode {
} }
public String toString() { public String toString() {
Debug.trace();
return name; return name;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void renumberChapters() { public void renumberChapters() {
Debug.trace();
int id = 1; int id = 1;
for (Enumeration c = children(); c.hasMoreElements();) { for (Enumeration c = children(); c.hasMoreElements();) {
@@ -230,41 +244,48 @@ public class Book extends DefaultMutableTreeNode {
} }
} }
public int getSampleRate() { return sampleRate; } public int getSampleRate() { Debug.trace(); return sampleRate; }
public void setSampleRate(int sr) { sampleRate = sr; } public void setSampleRate(int sr) { Debug.trace(); sampleRate = sr; }
public int getChannels() { return channels; } public int getChannels() { Debug.trace(); return channels; }
public void setChannels(int c) { channels = c; } public void setChannels(int c) { Debug.trace(); channels = c; }
public int getResolution() { return resolution; } public int getResolution() { Debug.trace(); return resolution; }
public void setResolution(int r) { resolution = r; } public void setResolution(int r) { Debug.trace(); resolution = r; }
public AudioFormat getAudioFormat() { public AudioFormat getAudioFormat() {
Debug.trace();
return new AudioFormat(getSampleRate(), getResolution(), getChannels(), true, false); return new AudioFormat(getSampleRate(), getResolution(), getChannels(), true, false);
} }
public String get(String key) { public String get(String key) {
Debug.trace();
if (prefs.getProperty(key) == null) { return Options.get(key); } if (prefs.getProperty(key) == null) { return Options.get(key); }
return prefs.getProperty(key); return prefs.getProperty(key);
} }
public Integer getInteger(String key) { public Integer getInteger(String key) {
Debug.trace();
if (prefs.getProperty(key) == null) { return Options.getInteger(key); } if (prefs.getProperty(key) == null) { return Options.getInteger(key); }
return Utils.s2i(prefs.getProperty(key)); return Utils.s2i(prefs.getProperty(key));
} }
public void set(String key, String value) { public void set(String key, String value) {
Debug.trace();
prefs.setProperty(key, value); prefs.setProperty(key, value);
} }
public void set(String key, Integer value) { public void set(String key, Integer value) {
Debug.trace();
prefs.setProperty(key, "" + value); prefs.setProperty(key, "" + value);
} }
public File getBookFolder() { public File getBookFolder() {
Debug.trace();
File dir = new File(Options.get("path.storage"), name); File dir = new File(Options.get("path.storage"), name);
return dir; return dir;
} }
public ArrayList<String> getUsedEffects() { public ArrayList<String> getUsedEffects() {
Debug.trace();
ArrayList<String> out = new ArrayList<String>(); ArrayList<String> out = new ArrayList<String>();
@@ -285,6 +306,7 @@ public class Book extends DefaultMutableTreeNode {
} }
public void purgeBackups() { public void purgeBackups() {
Debug.trace();
for (Enumeration o = children(); o.hasMoreElements();) { for (Enumeration o = children(); o.hasMoreElements();) {
Object ob = (Object)o.nextElement(); Object ob = (Object)o.nextElement();
if (ob instanceof Chapter) { if (ob instanceof Chapter) {
@@ -295,6 +317,7 @@ public class Book extends DefaultMutableTreeNode {
} }
public Document buildDocument() throws ParserConfigurationException { public Document buildDocument() throws ParserConfigurationException {
Debug.trace();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance(); DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
@@ -343,6 +366,7 @@ public class Book extends DefaultMutableTreeNode {
} }
public static Element makeTextNode(Document doc, String name, String text) { public static Element makeTextNode(Document doc, String name, String text) {
Debug.trace();
Element node = doc.createElement(name); Element node = doc.createElement(name);
Text tnode = doc.createTextNode(text == null ? "" : text); Text tnode = doc.createTextNode(text == null ? "" : text);
node.appendChild(tnode); node.appendChild(tnode);
@@ -350,6 +374,7 @@ public class Book extends DefaultMutableTreeNode {
} }
public static Element makeTextNode(Document doc, String name, Integer text) { public static Element makeTextNode(Document doc, String name, Integer text) {
Debug.trace();
Element node = doc.createElement(name); Element node = doc.createElement(name);
Text tnode = doc.createTextNode(Integer.toString(text)); Text tnode = doc.createTextNode(Integer.toString(text));
node.appendChild(tnode); node.appendChild(tnode);
@@ -357,6 +382,7 @@ public class Book extends DefaultMutableTreeNode {
} }
public static Element makeTextNode(Document doc, String name, Double text) { public static Element makeTextNode(Document doc, String name, Double text) {
Debug.trace();
Element node = doc.createElement(name); Element node = doc.createElement(name);
Text tnode = doc.createTextNode(String.format("%.8f", text)); Text tnode = doc.createTextNode(String.format("%.8f", text));
node.appendChild(tnode); node.appendChild(tnode);
@@ -364,6 +390,7 @@ public class Book extends DefaultMutableTreeNode {
} }
public static Element makeTextNode(Document doc, String name, Boolean text) { public static Element makeTextNode(Document doc, String name, Boolean text) {
Debug.trace();
Element node = doc.createElement(name); Element node = doc.createElement(name);
Text tnode = doc.createTextNode(text ? "true" : "false"); Text tnode = doc.createTextNode(text ? "true" : "false");
node.appendChild(tnode); node.appendChild(tnode);
@@ -371,14 +398,17 @@ public class Book extends DefaultMutableTreeNode {
} }
public String getDefaultEffect() { public String getDefaultEffect() {
Debug.trace();
return defaultEffect; return defaultEffect;
} }
public void setDefaultEffect(String eff) { public void setDefaultEffect(String eff) {
Debug.trace();
defaultEffect = eff; defaultEffect = eff;
} }
public void setManuscript(File f) { public void setManuscript(File f) {
Debug.trace();
manuscript = f.getName(); manuscript = f.getName();
File dst = new File(getBookPath(), manuscript); File dst = new File(getBookPath(), manuscript);
@@ -390,6 +420,7 @@ public class Book extends DefaultMutableTreeNode {
} }
public File getManuscript() { public File getManuscript() {
Debug.trace();
if (manuscript == null) return null; if (manuscript == null) return null;
if (manuscript.equals("")) return null; if (manuscript.equals("")) return null;
File f = new File(getBookPath(), manuscript); File f = new File(getBookPath(), manuscript);
@@ -398,4 +429,31 @@ public class Book extends DefaultMutableTreeNode {
} }
return null; return null;
} }
public void onSelect() {
}
public String getNotes() {
return notes;
}
public void setNotes(String n) {
notes = n;
}
public File getLocation() {
return location;
}
public void setLocation(File l) {
location = l;
}
public void reloadTree() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
AudiobookRecorder.window.bookTreeModel.reload(Book.this);
}
});
}
} }

View File

@@ -1,10 +1,13 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import java.util.regex.Matcher;
import javax.swing.event.*; import java.util.regex.Pattern;
import java.awt.*; import java.awt.Dimension;
import java.awt.event.*; import java.awt.GridBagLayout;
import java.util.regex.*; import java.awt.GridBagConstraints;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPanel;
public class BookInfoPanel extends JPanel { public class BookInfoPanel extends JPanel {
@@ -16,6 +19,7 @@ public class BookInfoPanel extends JPanel {
public BookInfoPanel(String t, String a, String g, String c, String x) { public BookInfoPanel(String t, String a, String g, String c, String x) {
super(); super();
Debug.trace();
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
GridBagConstraints con = new GridBagConstraints(); GridBagConstraints con = new GridBagConstraints();
@@ -69,12 +73,13 @@ public class BookInfoPanel extends JPanel {
} }
public String getTitle() { return title.getText(); } public String getTitle() { Debug.trace(); return title.getText(); }
public String getAuthor() { return author.getText(); } public String getAuthor() { Debug.trace(); return author.getText(); }
public String getGenre() { return genre.getText(); } public String getGenre() { Debug.trace(); return genre.getText(); }
public String getComment() { return comment.getText(); } public String getComment() { Debug.trace(); return comment.getText(); }
public String getACX() { public String getACX() {
Debug.trace();
Pattern p = Pattern.compile("\\/titleview\\/([A-Z0-9]{14})"); Pattern p = Pattern.compile("\\/titleview\\/([A-Z0-9]{14})");
Matcher m = p.matcher(acx.getText()); Matcher m = p.matcher(acx.getText());
if (m.find()) { if (m.find()) {
@@ -84,10 +89,10 @@ public class BookInfoPanel extends JPanel {
return acx.getText(); return acx.getText();
} }
public void setTitle(String t) { title.setText(t); } public void setTitle(String t) { Debug.trace(); title.setText(t); }
public void setAuthor(String a) { author.setText(a); } public void setAuthor(String a) { Debug.trace(); author.setText(a); }
public void setGenre(String g) { genre.setText(g); } public void setGenre(String g) { Debug.trace(); genre.setText(g); }
public void setComment(String c) { comment.setText(c); } public void setComment(String c) { Debug.trace(); comment.setText(c); }
public void setACX(String a) { acx.setText(a); } public void setACX(String a) { Debug.trace(); acx.setText(a); }
} }

View File

@@ -1,14 +1,17 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import java.io.File;
import javax.swing.event.*; import java.io.FileInputStream;
import java.awt.*; import java.util.Properties;
import java.awt.event.*; import java.awt.BorderLayout;
import java.awt.image.*; import java.awt.Color;
import javax.swing.border.*; import java.awt.Dimension;
import java.util.*; import java.awt.Image;
import java.io.*; import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.ImageIcon;
import javax.swing.border.EmptyBorder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;

View File

@@ -1,9 +1,18 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import java.awt.Component;
import javax.swing.tree.*; import java.awt.Color;
import java.awt.*; import java.awt.Dimension;
import javax.swing.border.*; import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.SwingConstants;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.border.EmptyBorder;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultMutableTreeNode;
public class BookTreeRenderer extends DefaultTreeCellRenderer { public class BookTreeRenderer extends DefaultTreeCellRenderer {
@@ -77,43 +86,54 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
} }
JLabel time = new JLabel(Utils.secToTime(s.getLength(), "mm:ss.SSS") + " "); JLabel time = new JLabelFixedWidth(75, " " + Utils.secToTime(s.getLength(), "ss.SSS") + " ");
time.setHorizontalAlignment(SwingConstants.RIGHT);
ctx.gridx = 0; ctx.gridx = 0;
ctx.gridy = 0; ctx.gridy = 0;
ctx.weightx = 1.0d;
ctx.fill = GridBagConstraints.HORIZONTAL; ctx.fill = GridBagConstraints.HORIZONTAL;
ctx.anchor = GridBagConstraints.LINE_START; ctx.anchor = GridBagConstraints.LINE_START;
p.add(ret, ctx);
String effectChain = s.getEffectChain(); if (s.isProcessing()) {
if ((effectChain == null) || (effectChain.equals("none"))) { JLabel eff = new JLabel();
ctx.weightx = 1.0d; eff.setIcon(Icons.processing);
ctx.gridwidth = 2; ctx.weightx = 0.0d;
p.add(ret, ctx); ctx.gridx = 1;
} else { p.add(eff);
ctx.weightx = 1.0d; } else if (s.isQueued()) {
ctx.gridwidth = 1; JLabel eff = new JLabel();
p.add(ret, ctx); eff.setIcon(Icons.queued);
Effect e = AudiobookRecorder.window.effects.get(effectChain);
JLabel eff = new JLabel(e.toString() + " ");
ctx.weightx = 0.0d; ctx.weightx = 0.0d;
ctx.gridwidth = 1;
ctx.gridx = 1; ctx.gridx = 1;
p.add(eff); p.add(eff);
} }
ctx.gridwidth = 1; String effectChain = s.getEffectChain();
if ((effectChain != null) && (!effectChain.equals("none"))) {
Effect e = AudiobookRecorder.window.effects.get(effectChain);
if (e != null) {
JLabel eff = new JLabel(e.toString() + " ");
ctx.weightx = 0.0d;
ctx.gridx = 2;
p.add(eff);
}
}
ctx.weightx = 0.0d; ctx.weightx = 0.0d;
ctx.gridx = 2; ctx.gridx = 3;
ctx.anchor = GridBagConstraints.LINE_END; ctx.anchor = GridBagConstraints.LINE_END;
int peak = s.getPeakDB(); int peak = s.getPeakDB();
JLabel peakLabel = new JLabel(peak + "dB "); JLabel peakLabel = new JLabelFixedWidth(50, peak + "dB ");
peakLabel.setHorizontalAlignment(SwingConstants.RIGHT);
if (peak > 0) { if (peak > 0) {
peakLabel.setForeground(new Color(0xCC, 0x00, 0x00)); peakLabel.setForeground(new Color(0xCC, 0x00, 0x00));
} }
p.add(peakLabel, ctx); p.add(peakLabel, ctx);
ctx.weightx = 0.0d; ctx.weightx = 0.0d;
ctx.gridx = 3; ctx.gridx = 4;
ctx.anchor = GridBagConstraints.LINE_END; ctx.anchor = GridBagConstraints.LINE_END;
p.add(time, ctx); p.add(time, ctx);
@@ -145,7 +165,33 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
p.setOpaque(false); p.setOpaque(false);
return p; return p;
} else if (value instanceof Book) { } else if (value instanceof Book) {
ret.setIcon(((Book)value).getIcon()); Book b = (Book)value;
JPanel p = new JPanel();
p.setLayout(new GridBagLayout());
GridBagConstraints ctx = new GridBagConstraints();
ctx.gridx = 0;
ctx.gridy = 0;
ctx.fill = GridBagConstraints.HORIZONTAL;
ctx.anchor = GridBagConstraints.LINE_START;
ctx.weightx = 1.0d;
ret.setIcon(b.getIcon());
p.add(ret, ctx);
JLabel author = new JLabel(b.getAuthor());
ctx.gridy++;
author.setBorder(new EmptyBorder(0, 27, 0, 0));
Font f = author.getFont();
Font nf = f.deriveFont(Font.ITALIC, (int)(f.getSize() * 0.75));
author.setFont(nf);
author.setForeground(author.getForeground().darker());
p.add(author, ctx);
p.setOpaque(false);
return p;
} }
return ret; return ret;
} }

View File

@@ -1,6 +1,6 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import java.util.*; import java.util.ArrayList;
public class CacheManager { public class CacheManager {
static ArrayList<Cacheable> cache = new ArrayList<Cacheable>(); static ArrayList<Cacheable> cache = new ArrayList<Cacheable>();

View File

@@ -1,16 +1,33 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import java.io.File;
import javax.swing.event.*; import java.io.FileInputStream;
import java.awt.*; import java.io.FileOutputStream;
import java.awt.event.*; import java.io.FileNotFoundException;
import java.util.*; import java.io.IOException;
import java.io.*; import java.util.ArrayList;
import java.nio.file.*; import java.util.Enumeration;
import javax.swing.tree.*; import javax.swing.tree.DefaultTreeModel;
import it.sauronsoftware.jave.*; import javax.swing.tree.DefaultMutableTreeNode;
import com.mpatric.mp3agic.*;
import javax.sound.sampled.*; import it.sauronsoftware.jave.FFMPEGLocator;
import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.EncodingAttributes;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.InputFormatException;
import com.mpatric.mp3agic.Mp3File;
import com.mpatric.mp3agic.ID3v2;
import com.mpatric.mp3agic.ID3v24Tag;
import com.mpatric.mp3agic.InvalidDataException;
import com.mpatric.mp3agic.NotSupportedException;
import com.mpatric.mp3agic.UnsupportedTagException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.AudioInputStream;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
@@ -38,7 +55,7 @@ public class Chapter extends BookTreeNode {
public Chapter(String i, String chaptername) { public Chapter(String i, String chaptername) {
super(chaptername); super(chaptername);
Debug.trace();
id = i; id = i;
name = chaptername; name = chaptername;
preGap = Options.getInteger("catenation.pre-chapter"); preGap = Options.getInteger("catenation.pre-chapter");
@@ -46,7 +63,7 @@ public class Chapter extends BookTreeNode {
} }
public Chapter(Element root, DefaultTreeModel model) { public Chapter(Element root, DefaultTreeModel model) {
Debug.trace();
name = Book.getTextNode(root, "name"); name = Book.getTextNode(root, "name");
id = root.getAttribute("id"); id = root.getAttribute("id");
preGap = Utils.s2i(Book.getTextNode(root, "pre-gap")); preGap = Utils.s2i(Book.getTextNode(root, "pre-gap"));
@@ -65,24 +82,29 @@ public class Chapter extends BookTreeNode {
} }
public String getId() { public String getId() {
Debug.trace();
return id; return id;
} }
public void setId(String i) { public void setId(String i) {
Debug.trace();
id = i; id = i;
} }
public Sentence getLastSentence() { public Sentence getLastSentence() {
Debug.trace();
DefaultMutableTreeNode ls = getLastLeaf(); DefaultMutableTreeNode ls = getLastLeaf();
if (ls instanceof Sentence) return (Sentence)ls; if (ls instanceof Sentence) return (Sentence)ls;
return null; return null;
} }
public String toString() { public String toString() {
Debug.trace();
return name; return name;
} }
public void setUserObject(Object o) { public void setUserObject(Object o) {
Debug.trace();
if (o instanceof String) { if (o instanceof String) {
String so = (String)o; String so = (String)o;
name = so; name = so;
@@ -90,26 +112,32 @@ public class Chapter extends BookTreeNode {
} }
public String getName() { public String getName() {
Debug.trace();
return name; return name;
} }
public void setName(String n) { public void setName(String n) {
Debug.trace();
name = n; name = n;
} }
public void setPreGap(int g) { public void setPreGap(int g) {
Debug.trace();
preGap = g; preGap = g;
} }
public int getPreGap() { public int getPreGap() {
Debug.trace();
return preGap; return preGap;
} }
public void setPostGap(int g) { public void setPostGap(int g) {
Debug.trace();
postGap = g; postGap = g;
} }
public int getPostGap() { public int getPostGap() {
Debug.trace();
return postGap; return postGap;
} }
@@ -117,6 +145,7 @@ public class Chapter extends BookTreeNode {
public void exportChapter(ProgressDialog exportDialog) throws public void exportChapter(ProgressDialog exportDialog) throws
FileNotFoundException, IOException, InputFormatException, NotSupportedException, FileNotFoundException, IOException, InputFormatException, NotSupportedException,
EncoderException, UnsupportedTagException, InvalidDataException { EncoderException, UnsupportedTagException, InvalidDataException {
Debug.trace();
if (getChildCount() == 0) return; if (getChildCount() == 0) return;
@@ -235,6 +264,7 @@ public class Chapter extends BookTreeNode {
} }
public double getChapterLength() { public double getChapterLength() {
Debug.trace();
double totalTime = Options.getInteger("audio.recording.pre-chapter") / 1000d; double totalTime = Options.getInteger("audio.recording.pre-chapter") / 1000d;
for (Enumeration s = children(); s.hasMoreElements();) { for (Enumeration s = children(); s.hasMoreElements();) {
Sentence sentence = (Sentence)s.nextElement(); Sentence sentence = (Sentence)s.nextElement();
@@ -249,6 +279,7 @@ public class Chapter extends BookTreeNode {
} }
public ArrayList<String> getUsedEffects() { public ArrayList<String> getUsedEffects() {
Debug.trace();
ArrayList<String> out = new ArrayList<String>(); ArrayList<String> out = new ArrayList<String>();
@@ -266,6 +297,7 @@ public class Chapter extends BookTreeNode {
} }
public void resetPostGaps() { public void resetPostGaps() {
Debug.trace();
for (Enumeration s = children(); s.hasMoreElements();) { for (Enumeration s = children(); s.hasMoreElements();) {
Sentence snt = (Sentence)s.nextElement(); Sentence snt = (Sentence)s.nextElement();
snt.resetPostGap(); snt.resetPostGap();
@@ -273,6 +305,7 @@ public class Chapter extends BookTreeNode {
} }
public void purgeBackups() { public void purgeBackups() {
Debug.trace();
for (Enumeration o = children(); o.hasMoreElements();) { for (Enumeration o = children(); o.hasMoreElements();) {
Object ob = (Object)o.nextElement(); Object ob = (Object)o.nextElement();
if (ob instanceof Sentence) { if (ob instanceof Sentence) {
@@ -283,6 +316,7 @@ public class Chapter extends BookTreeNode {
} }
public Element getChapterXML(Document doc) { public Element getChapterXML(Document doc) {
Debug.trace();
Element chapterNode = doc.createElement("chapter"); Element chapterNode = doc.createElement("chapter");
chapterNode.setAttribute("id", id); chapterNode.setAttribute("id", id);
chapterNode.appendChild(Book.makeTextNode(doc, "name", name)); chapterNode.appendChild(Book.makeTextNode(doc, "name", name));
@@ -305,18 +339,22 @@ public class Chapter extends BookTreeNode {
} }
public String getNotes() { public String getNotes() {
Debug.trace();
return notes; return notes;
} }
public void setNotes(String t) { public void setNotes(String t) {
Debug.trace();
notes = t; notes = t;
} }
public void onSelect() { public void onSelect() {
Debug.trace();
AudiobookRecorder.window.setChapterNotes(notes); AudiobookRecorder.window.setChapterNotes(notes);
} }
public double getLength() { public double getLength() {
Debug.trace();
double len = 0; double len = 0;
for (Enumeration o = children(); o.hasMoreElements();) { for (Enumeration o = children(); o.hasMoreElements();) {
Object ob = (Object)o.nextElement(); Object ob = (Object)o.nextElement();

View File

@@ -1,10 +1,13 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import javax.swing.JComponent;
import javax.swing.tree.*; import javax.swing.JScrollPane;
import javax.swing.plaf.*; import javax.swing.tree.AbstractLayoutCache;
import javax.swing.plaf.basic.*; import javax.swing.tree.TreePath;
import java.awt.*; import javax.swing.plaf.basic.BasicTreeUI;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Graphics;
public class CustomTreeUI extends BasicTreeUI { public class CustomTreeUI extends BasicTreeUI {

View File

@@ -1,10 +1,13 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import javax.swing.JButton;
import java.awt.*; import javax.swing.JPanel;
import java.awt.event.*; import javax.swing.JLabel;
import javax.swing.border.*; import javax.swing.JTextArea;
import java.net.*; import javax.swing.border.EmptyBorder;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DonationPanel extends JPanel { public class DonationPanel extends JPanel {
public DonationPanel() { public DonationPanel() {

View File

@@ -1,19 +1,24 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import java.util.TimerTask;
import java.awt.*; import java.util.Timer;
import java.util.*; import javax.swing.JPanel;
import javax.swing.JComponent;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Dimension;
public class FlashPanel extends JPanel { public class FlashPanel extends JPanel {
boolean flash = false; boolean flash = false;
boolean col = false; boolean col = false;
java.util.Timer ticker; Timer ticker;
public FlashPanel() { public FlashPanel() {
super(); super();
ticker = new java.util.Timer(true); ticker = new Timer(true);
ticker.scheduleAtFixedRate(new TimerTask() { ticker.scheduleAtFixedRate(new TimerTask() {
public void run() { public void run() {
if (flash) { if (flash) {

View File

@@ -1,6 +1,6 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import javax.swing.ImageIcon;
public class Icons { public class Icons {
static public final ImageIcon book = new ImageIcon(Icons.class.getResource("icons/book.png")); static public final ImageIcon book = new ImageIcon(Icons.class.getResource("icons/book.png"));
@@ -39,4 +39,7 @@ public class Icons {
static public final ImageIcon playto = new ImageIcon(Icons.class.getResource("icons/play-to.png")); static public final ImageIcon playto = new ImageIcon(Icons.class.getResource("icons/play-to.png"));
static public final ImageIcon disable = new ImageIcon(Icons.class.getResource("icons/disable-effects.png")); static public final ImageIcon disable = new ImageIcon(Icons.class.getResource("icons/disable-effects.png"));
static public final ImageIcon manuscript = new ImageIcon(Icons.class.getResource("icons/manuscript.png")); static public final ImageIcon manuscript = new ImageIcon(Icons.class.getResource("icons/manuscript.png"));
static public final ImageIcon tooltip = new ImageIcon(Icons.class.getResource("icons/tooltip.png"));
static public final ImageIcon queued = new ImageIcon(Icons.class.getResource("icons/queued.png"));
static public final ImageIcon processing = new ImageIcon(Icons.class.getResource("icons/processing.png"));
} }

View File

@@ -1,9 +1,11 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import javax.swing.JButton;
import javax.swing.event.*; import javax.swing.ImageIcon;
import java.awt.*; import javax.swing.JComponent;
import java.awt.event.*; import javax.swing.KeyStroke;
import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
public class JButtonSpacePlay extends JButton { public class JButtonSpacePlay extends JButton {
public JButtonSpacePlay(ImageIcon i, String tt, ActionListener al) { public JButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {

View File

@@ -0,0 +1,38 @@
package uk.co.majenko.audiobookrecorder;
import javax.swing.JLabel;
import java.awt.Dimension;
public class JLabelFixedWidth extends JLabel {
int width = 0;
int height = 0;
Dimension size;
public JLabelFixedWidth(int w, String txt) {
super(txt);
JLabel t = new JLabel(txt);
size = t.getPreferredSize();
size.width = w;
}
public JLabelFixedWidth(int w) {
super();
JLabel t = new JLabel("nothing");
size = t.getPreferredSize();
size.width = w;
}
@Override
public Dimension getPreferredSize() {
return size;
}
@Override
public Dimension getMaximumSize() {
return size;
}
@Override
public Dimension getMinimumSize() {
return size;
}
}

View File

@@ -1,6 +1,6 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import javax.swing.JSlider;
public class JSliderOb extends JSlider { public class JSliderOb extends JSlider {
Object object; Object object;

View File

@@ -1,5 +1,6 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*;
import javax.swing.JTextField;
public class JTextFieldOb extends JTextField { public class JTextFieldOb extends JTextField {
Object object; Object object;

View File

@@ -1,9 +1,11 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import java.awt.event.ActionListener;
import javax.swing.event.*; import java.awt.event.KeyEvent;
import java.awt.*; import javax.swing.JToggleButton;
import java.awt.event.*; import javax.swing.JComponent;
import javax.swing.KeyStroke;
import javax.swing.ImageIcon;
public class JToggleButtonSpacePlay extends JToggleButton { public class JToggleButtonSpacePlay extends JToggleButton {
public JToggleButtonSpacePlay(ImageIcon i, String tt, ActionListener al) { public JToggleButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {

View File

@@ -1,9 +1,12 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import java.awt.event.ActionEvent;
import javax.swing.event.*; import java.awt.event.ActionListener;
import java.awt.*; import java.awt.Color;
import java.awt.event.*; import javax.swing.JToggleButton;
import javax.swing.JComboBox;
import javax.swing.JToolBar;
import javax.swing.JLabel;
public class MainToolBar extends JToolBar { public class MainToolBar extends JToolBar {

View File

@@ -1,7 +1,5 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import java.awt.event.*;
public class MarkerDragEvent { public class MarkerDragEvent {
Object src; Object src;

View File

@@ -1,12 +1,18 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import javax.swing.JPanel;
import javax.swing.table.*; import javax.swing.table.TableCellRenderer;
import javax.swing.event.*; import javax.swing.JTable;
import java.awt.*; import javax.swing.table.AbstractTableModel;
import java.awt.event.*; import java.util.ArrayList;
import java.io.*; import javax.swing.JScrollPane;
import java.util.*; import java.io.File;
import java.awt.BorderLayout;
import java.awt.Component;
import javax.swing.ListSelectionModel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JOptionPane;
public class OpenBookPanel extends JPanel { public class OpenBookPanel extends JPanel {

View File

@@ -1,14 +1,42 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.sound.sampled.*; import java.io.File;
import javax.swing.*; import java.util.TreeSet;
import javax.swing.event.*; import java.util.ArrayList;
import java.awt.*; import java.util.HashMap;
import java.awt.event.*; import java.util.prefs.Preferences;
import java.util.*; import java.awt.GridBagConstraints;
import java.util.prefs.*; import java.awt.GridBagLayout;
import java.io.*; import java.awt.BorderLayout;
import javax.swing.tree.*; import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Font;
import java.awt.Dialog;
import java.awt.event.WindowEvent;
import javax.swing.border.EmptyBorder;
import javax.swing.JDialog;
import javax.swing.JTabbedPane;
import javax.swing.JComboBox;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.Mixer;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import javax.swing.JScrollPane;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.TargetDataLine;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.SourceDataLine;
public class Options extends JDialog { public class Options extends JDialog {
@@ -16,8 +44,6 @@ public class Options extends JDialog {
GridBagConstraints constraint; GridBagConstraints constraint;
public static ArrayList<EffectGroup> effectChains;
JComboBox<KVPair> mixerList; JComboBox<KVPair> mixerList;
JComboBox<KVPair> playbackList; JComboBox<KVPair> playbackList;
JComboBox<KVPair> channelList; JComboBox<KVPair> channelList;
@@ -50,6 +76,9 @@ public class Options extends JDialog {
JTextField externalEditor; JTextField externalEditor;
JTextField speechCommand;
JSpinner workerThreads;
JTextArea startupScript; JTextArea startupScript;
ArrayList<JTextField[]> processorList; ArrayList<JTextField[]> processorList;
@@ -69,7 +98,7 @@ public class Options extends JDialog {
} }
} }
JComboBox<KVPair> addDropdown(JPanel panel, String label, KVPair[] options, String def) { JComboBox<KVPair> addDropdown(JPanel panel, String label, KVPair[] options, String def, String tip) {
JLabel l = new JLabel(label); JLabel l = new JLabel(label);
constraint.gridx = 0; constraint.gridx = 0;
constraint.gridwidth = 1; constraint.gridwidth = 1;
@@ -80,6 +109,9 @@ public class Options extends JDialog {
JComboBox<KVPair> o = new JComboBox<KVPair>(options); JComboBox<KVPair> o = new JComboBox<KVPair>(options);
constraint.gridx = 1; constraint.gridx = 1;
panel.add(o, constraint); panel.add(o, constraint);
Tip t = new Tip(tip);
constraint.gridx = 2;
panel.add(t, constraint);
for (KVPair p : options) { for (KVPair p : options) {
if (p.key.equals(def)) { if (p.key.equals(def)) {
@@ -110,7 +142,7 @@ public class Options extends JDialog {
constraint.gridy++; constraint.gridy++;
} }
JTextField addTextField(JPanel panel, String label, String def) { JTextField addTextField(JPanel panel, String label, String def, String tip) {
JLabel l = new JLabel(label); JLabel l = new JLabel(label);
constraint.gridx = 0; constraint.gridx = 0;
constraint.gridwidth = 1; constraint.gridwidth = 1;
@@ -124,13 +156,18 @@ public class Options extends JDialog {
constraint.fill = GridBagConstraints.HORIZONTAL; constraint.fill = GridBagConstraints.HORIZONTAL;
panel.add(a, constraint); panel.add(a, constraint);
Tip t = new Tip(tip);
constraint.gridx = 2;
panel.add(t, constraint);
constraint.fill = GridBagConstraints.NONE; constraint.fill = GridBagConstraints.NONE;
constraint.gridy++; constraint.gridy++;
return a; return a;
} }
JTextField[] addTwoField(JPanel panel, String def1, String def2) { JTextField[] addTwoField(JPanel panel, String def1, String def2, String tip) {
JTextField a = new JTextField(def1); JTextField a = new JTextField(def1);
constraint.gridx = 0; constraint.gridx = 0;
constraint.fill = GridBagConstraints.HORIZONTAL; constraint.fill = GridBagConstraints.HORIZONTAL;
@@ -141,13 +178,18 @@ public class Options extends JDialog {
panel.add(b, constraint); panel.add(b, constraint);
constraint.fill = GridBagConstraints.NONE; constraint.fill = GridBagConstraints.NONE;
Tip t = new Tip(tip);
constraint.gridx = 2;
panel.add(t, constraint);
constraint.gridy++; constraint.gridy++;
return new JTextField[] { a, b }; return new JTextField[] { a, b };
} }
JTextField addFilePath(JPanel panel, String label, String path, boolean dironly) { JTextField addFilePath(JPanel panel, String label, String path, boolean dironly, String tip) {
JLabel l = new JLabel(label); JLabel l = new JLabel(label);
constraint.gridx = 0; constraint.gridx = 0;
constraint.gridwidth = 1; constraint.gridwidth = 1;
@@ -209,6 +251,10 @@ public class Options extends JDialog {
constraint.fill = GridBagConstraints.HORIZONTAL; constraint.fill = GridBagConstraints.HORIZONTAL;
panel.add(p, constraint); panel.add(p, constraint);
Tip t = new Tip(tip);
constraint.gridx = 2;
panel.add(t, constraint);
constraint.fill = GridBagConstraints.NONE; constraint.fill = GridBagConstraints.NONE;
constraint.gridy++; constraint.gridy++;
@@ -235,7 +281,7 @@ public class Options extends JDialog {
constraint.gridy++; constraint.gridy++;
} }
JSpinner addSpinner(JPanel panel, String label, int min, int max, int step, int value, String suffix) { JSpinner addSpinner(JPanel panel, String label, int min, int max, int step, int value, String suffix, String tip) {
JLabel l = new JLabel(label); JLabel l = new JLabel(label);
constraint.gridx = 0; constraint.gridx = 0;
constraint.gridwidth = 1; constraint.gridwidth = 1;
@@ -255,6 +301,10 @@ public class Options extends JDialog {
constraint.fill = GridBagConstraints.HORIZONTAL; constraint.fill = GridBagConstraints.HORIZONTAL;
panel.add(p, constraint); panel.add(p, constraint);
Tip t = new Tip(tip);
constraint.gridx = 2;
panel.add(t, constraint);
constraint.fill = GridBagConstraints.NONE; constraint.fill = GridBagConstraints.NONE;
@@ -263,11 +313,16 @@ public class Options extends JDialog {
} }
JCheckBox addCheckBox(JPanel panel, String label, boolean state) { JCheckBox addCheckBox(JPanel panel, String label, boolean state, String tip) {
constraint.gridx = 1; constraint.gridx = 1;
JCheckBox cb = new JCheckBox(label); JCheckBox cb = new JCheckBox(label);
cb.setSelected(state); cb.setSelected(state);
panel.add(cb, constraint); panel.add(cb, constraint);
Tip t = new Tip(tip);
constraint.gridx = 2;
panel.add(t, constraint);
constraint.gridy++; constraint.gridy++;
return cb; return cb;
} }
@@ -295,93 +350,71 @@ public class Options extends JDialog {
addSeparator(optionsPanel); addSeparator(optionsPanel);
mixerList = addDropdown(optionsPanel, "Recording device:", getRecordingMixerList(), get("audio.recording.device")); mixerList = addDropdown(optionsPanel, "Recording device:", getRecordingMixerList(), get("audio.recording.device"), "This is the system device to record through");
channelList = addDropdown(optionsPanel, "Channels:", getChannelCountList(), get("audio.recording.channels")); channelList = addDropdown(optionsPanel, "Channels:", getChannelCountList(), get("audio.recording.channels"), "How many channels do you want to record - stereo or mono?");
rateList = addDropdown(optionsPanel, "Sample rate:", getSampleRateList(), get("audio.recording.samplerate")); rateList = addDropdown(optionsPanel, "Sample rate:", getSampleRateList(), get("audio.recording.samplerate"), "The higher the sample rate the better the quality, but the bigger the files.");
bitDepth = addDropdown(optionsPanel, "Sample resolution:", getResolutionList(), get("audio.recording.resolution")); bitDepth = addDropdown(optionsPanel, "Sample resolution:", getResolutionList(), get("audio.recording.resolution"), "The higher the resolution the better the quality, but the bigger the files.");
trimMethod = addDropdown(optionsPanel, "Auto-trim method:", getTrimMethods(), get("audio.recording.trim")); trimMethod = addDropdown(optionsPanel, "Auto-trim method:", getTrimMethods(), get("audio.recording.trim"), "None: don't auto-trim. FFT: Compare the FFT profile of blocks to the room noise profile and trim silent blocks, Peak: Look for the start and end rise and fall points");
fftThreshold = addSpinner(optionsPanel, "FFT threshold:", 0, 100, 1, getInteger("audio.recording.trim.fft"), ""); fftThreshold = addSpinner(optionsPanel, "FFT threshold:", 0, 100, 1, getInteger("audio.recording.trim.fft"), "", "This specifies the difference (in hundredths) between the power of FFT buckets in a sample block compared to the overall power of the same FFT bucket in the room noise. Raising this number makes the FFT trimming less sensitive.");
fftBlockSize = addDropdown(optionsPanel, "FFT Block size:", getFFTBlockSizes(), get("audio.recording.trim.blocksize")); fftBlockSize = addDropdown(optionsPanel, "FFT Block size:", getFFTBlockSizes(), get("audio.recording.trim.blocksize"), "How large an FFT block should be when processing. Larger values increase sensitivity but at the epxense of resolution.");
maxGainVariance = addSpinner(optionsPanel, "Maximum gain variance:", 0, 100, 1, getInteger("audio.recording.variance"), ""); maxGainVariance = addSpinner(optionsPanel, "Maximum gain variance:", 0, 100, 1, getInteger("audio.recording.variance"), "", "This is how much the gain is allowed to vary by from phrase to phrase when normalizing an entire chapter.");
addSeparator(optionsPanel); addSeparator(optionsPanel);
playbackList = addDropdown(optionsPanel, "Playback device:", getPlaybackMixerList(), get("audio.playback.device")); playbackList = addDropdown(optionsPanel, "Playback device:", getPlaybackMixerList(), get("audio.playback.device"), "Which device to play back through");
playbackBlockSize = addDropdown(optionsPanel, "Playback Block size:", getPlaybackBlockSizes(), get("audio.playback.blocksize")); playbackBlockSize = addDropdown(optionsPanel, "Playback Block size:", getPlaybackBlockSizes(), get("audio.playback.blocksize"), "How big the playback buffer should be. Larger is smoother playback but the playback marker in the waveform becomes more out of sync");
addSeparator(optionsPanel); addSeparator(optionsPanel);
storageFolder = addFilePath(optionsPanel, "Storage folder:", get("path.storage"), true); storageFolder = addFilePath(optionsPanel, "Storage folder:", get("path.storage"), true, "This is where all your working audiobooks are stored.");
archiveFolder = addFilePath(optionsPanel, "Archive folder:", get("path.archive"), true); archiveFolder = addFilePath(optionsPanel, "Archive folder:", get("path.archive"), true, "This is where audiobooks are archived to.");
addSeparator(optionsPanel); addSeparator(optionsPanel);
preChapterGap = addSpinner(optionsPanel, "Default pre-chapter gap:", 0, 5000, 100, getInteger("catenation.pre-chapter"), "ms"); preChapterGap = addSpinner(optionsPanel, "Default pre-chapter gap:", 0, 5000, 100, getInteger("catenation.pre-chapter"), "ms", "How much room noise to add at the beginning of a chapter.");
postChapterGap = addSpinner(optionsPanel, "Default post-chapter gap:", 0, 5000, 100, getInteger("catenation.post-chapter"), "ms"); postChapterGap = addSpinner(optionsPanel, "Default post-chapter gap:", 0, 5000, 100, getInteger("catenation.post-chapter"), "ms", "How much room noise to add to the end of a chapter.");
postSentenceGap = addSpinner(optionsPanel, "Default post-sentence gap:", 0, 5000, 100, getInteger("catenation.post-sentence"), "ms"); postSentenceGap = addSpinner(optionsPanel, "Default post-sentence gap:", 0, 5000, 100, getInteger("catenation.post-sentence"), "ms", "How much room noise to add between normal sentences.");
shortSentenceGap = addSpinner(optionsPanel, "Short post-sentence gap:", 0, 5000, 100, getInteger("catenation.short-sentence"), "ms"); shortSentenceGap = addSpinner(optionsPanel, "Short post-sentence gap:", 0, 5000, 100, getInteger("catenation.short-sentence"), "ms", "How much room noise to add between 'continuations'.");
postParagraphGap = addSpinner(optionsPanel, "Default post-paragraph gap:", 0, 5000, 100, getInteger("catenation.post-paragraph"), "ms"); postParagraphGap = addSpinner(optionsPanel, "Default post-paragraph gap:", 0, 5000, 100, getInteger("catenation.post-paragraph"), "ms", "How much room noise to add between paragraphs.");
postSectionGap = addSpinner(optionsPanel, "Default post-section gap:", 0, 5000, 100, getInteger("catenation.post-section"), "ms"); postSectionGap = addSpinner(optionsPanel, "Default post-section gap:", 0, 5000, 100, getInteger("catenation.post-section"), "ms", "How much room noise to add between sections.");
addSeparator(optionsPanel); addSeparator(optionsPanel);
ffmpegLocation = addFilePath(optionsPanel, "FFMPEG location:", get("path.ffmpeg"), false); ffmpegLocation = addFilePath(optionsPanel, "FFMPEG location:", get("path.ffmpeg"), false, "Path to your ffmpeg executable.");
bitRate = addDropdown(optionsPanel, "Export bitrate:", getBitrates(), get("audio.export.bitrate")); bitRate = addDropdown(optionsPanel, "Export bitrate:", getBitrates(), get("audio.export.bitrate"), "The MP3 bitrate to produce");
channels = addDropdown(optionsPanel, "Export channels:", getChannelCountList(), get("audio.export.channels")); channels = addDropdown(optionsPanel, "Export channels:", getChannelCountList(), get("audio.export.channels"), "Mono or stereo MP3 production");
exportRate = addDropdown(optionsPanel, "Export sample rate:", getSampleRateList(), get("audio.export.samplerate")); exportRate = addDropdown(optionsPanel, "Export sample rate:", getSampleRateList(), get("audio.export.samplerate"), "Sample frequency of the produced MP3");
addSeparator(optionsPanel); addSeparator(optionsPanel);
enableParsing = addCheckBox(optionsPanel, "Enable automatic sphinx speech-to-text (**SLOW**)", getBoolean("process.sphinx")); enableParsing = addCheckBox(optionsPanel, "Enable automatic speech-to-text (**SLOW**)", getBoolean("process.sphinx"), "This will automatically start recognising the speech in every sentence you record. This can really slow down recording though so it's recommended to leave it turned off and do your recognition afterwards as a batch operation.");
speechCommand = addTextField(optionsPanel, "Speech to text command (must take 1 filename parameter):", get("process.command"), "This specifies what command to run to recognize the speech. This command must take only one parameter, which is the full path of the WAV file. It should return (on standard output) the recognised speech.");
workerThreads = addSpinner(optionsPanel, "Worker threads:", 1, 100, 1, getInteger("process.threads"), "", "How many concurrent threads to run when processing speech. This should ideally be no more than the number of CPU cores you have in your computer.");
addSeparator(optionsPanel); addSeparator(optionsPanel);
externalEditor = addTextField(optionsPanel, "External Editor Command", get("editor.external")); externalEditor = addTextField(optionsPanel, "External Editor Command", get("editor.external"), "The program to run when you select 'Open in external editor'.");
addSeparator(optionsPanel); addSeparator(optionsPanel);
cacheSize = addSpinner(optionsPanel, "Cache size:", 2, 100, 1, getInteger("cache.size"), ""); cacheSize = addSpinner(optionsPanel, "Cache size:", 2, 100, 1, getInteger("cache.size"), "", "How many phrases to keep cached in memory at once. More gives a smoother editing experience, but you can easily run out of memory if you are not careful.");
addSeparator(optionsPanel); addSeparator(optionsPanel);
tabs.add("Options", new JScrollPane(optionsPanel)); tabs.add("Options", new JScrollPane(optionsPanel));
JPanel effectChains = new JPanel();
effectChains.setLayout(new BorderLayout());
JPanel effectDetails = new JPanel() {
public Dimension getPreferredSize() {
return new Dimension(200, 400);
}
};
DefaultTreeModel m = new DefaultTreeModel(new DefaultMutableTreeNode("Effect Chains"));
JTree effectChainTree = new JTree(m);
effectChains.add(effectChainTree, BorderLayout.CENTER);
effectChains.add(effectDetails, BorderLayout.EAST);
tabs.add("Effects Chains", new JScrollPane(effectChains));
JPanel startScript = new JPanel(); JPanel startScript = new JPanel();
startScript.setLayout(new BorderLayout()); startScript.setLayout(new BorderLayout());
startScript.setBorder(new EmptyBorder(15, 15, 15, 15));
startupScript = new JTextArea(get("scripts.startup")); startupScript = new JTextArea(get("scripts.startup"));
startupScript.setBorder(new EmptyBorder(5, 5, 5, 5));
startupScript.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
startScript.add(startupScript, BorderLayout.CENTER); startScript.add(startupScript, BorderLayout.CENTER);
tabs.add("Startup Script", startScript); tabs.add("Startup Script", startScript);
JPanel effects = new JPanel();
effects.setLayout(new GridBagLayout());
constraint.gridx = 0;
constraint.gridy = 0;
constraint.gridwidth = 1;
constraint.gridheight = 1;
etherealOffset = addSpinner(effects, "Ethereal Voice Offset", 0, 2000, 10, getInteger("effects.ethereal.offset"), "ms");
etherealIterations = addSpinner(effects, "Ethereal Voice Iterations", 1, 10, 1, getInteger("effects.ethereal.iterations"), "");
etherealAttenuation = addSpinner(effects, "Ethereal Voice Attenuation", 0, 100, 1, getInteger("effects.ethereal.attenuation"), "%");
tabs.add("Effects", effects);
JPanel processors = new JPanel(); JPanel processors = new JPanel();
processors.setLayout(new BorderLayout()); processors.setLayout(new BorderLayout());
@@ -406,19 +439,16 @@ public class Options extends JDialog {
String command = get("editor.processor." + i + ".command"); String command = get("editor.processor." + i + ".command");
if (name == null || command == null) break; if (name == null || command == null) break;
if (name.equals("") || command.equals("")) break; if (name.equals("") || command.equals("")) break;
JTextField[] f = addTwoField(processorListPanel, name, command); JTextField[] f = addTwoField(processorListPanel, name, command, "Specify the name of the operation (which will appear in context menus) and the command to run for that operation. The command should have parameters separated with :: and %f for the input filename and %o for the output filename.");
processorList.add(f); processorList.add(f);
} }
JTextField[] f = addTwoField(processorListPanel, "", ""); JTextField[] f = addTwoField(processorListPanel, "", "", "Specify the name of the operation (which will appear in context menus) and the command to run for that operation. The command should have parameters separated with :: and %f for the input filename and %o for the output filename.");
processorList.add(f); processorList.add(f);
tabs.add("Processors", processors); tabs.add("Processors", processors);
add(tabs, BorderLayout.CENTER); add(tabs, BorderLayout.CENTER);
setTitle("Options"); setTitle("Options");
@@ -594,6 +624,8 @@ public class Options extends JDialog {
defaultPrefs.put("audio.export.channels", "2"); defaultPrefs.put("audio.export.channels", "2");
defaultPrefs.put("audio.export.samplerate", "44100"); defaultPrefs.put("audio.export.samplerate", "44100");
defaultPrefs.put("process.sphinx", "false"); defaultPrefs.put("process.sphinx", "false");
defaultPrefs.put("process.command", "speech-to-text \"%f\"");
defaultPrefs.put("process.threads", "10");
defaultPrefs.put("editor.external", ""); defaultPrefs.put("editor.external", "");
@@ -601,10 +633,6 @@ public class Options extends JDialog {
defaultPrefs.put("scripts.startup", ""); defaultPrefs.put("scripts.startup", "");
defaultPrefs.put("effects.ethereal.offset", "50");
defaultPrefs.put("effects.ethereal.iterations", "3");
defaultPrefs.put("effects.ethereal.attenuation", "50");
if (prefs == null) { if (prefs == null) {
prefs = Preferences.userNodeForPackage(AudiobookRecorder.class); prefs = Preferences.userNodeForPackage(AudiobookRecorder.class);
} }
@@ -718,6 +746,8 @@ public class Options extends JDialog {
set("audio.export.channels", ((KVPair)channels.getSelectedItem()).key); set("audio.export.channels", ((KVPair)channels.getSelectedItem()).key);
set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key); set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
set("process.sphinx", enableParsing.isSelected()); set("process.sphinx", enableParsing.isSelected());
set("process.command", speechCommand.getText());
set("process.threads", workerThreads.getValue());
set("editor.external", externalEditor.getText()); set("editor.external", externalEditor.getText());
set("cache.size", cacheSize.getValue()); set("cache.size", cacheSize.getValue());
set("audio.recording.trim.fft", fftThreshold.getValue()); set("audio.recording.trim.fft", fftThreshold.getValue());
@@ -725,10 +755,6 @@ public class Options extends JDialog {
set("audio.recording.trim.blocksize", ((KVPair)fftBlockSize.getSelectedItem()).key); set("audio.recording.trim.blocksize", ((KVPair)fftBlockSize.getSelectedItem()).key);
set("audio.playback.blocksize", ((KVPair)playbackBlockSize.getSelectedItem()).key); set("audio.playback.blocksize", ((KVPair)playbackBlockSize.getSelectedItem()).key);
set("effects.ethereal.offset", etherealOffset.getValue());
set("effects.ethereal.iterations", etherealIterations.getValue());
set("effects.ethereal.attenuation", etherealAttenuation.getValue());
set("scripts.startup", startupScript.getText()); set("scripts.startup", startupScript.getText());
int procNo = 0; int procNo = 0;
@@ -823,51 +849,4 @@ public class Options extends JDialog {
pairs[7] = new KVPair<String, String>("131072", "131072"); pairs[7] = new KVPair<String, String>("131072", "131072");
return pairs; return pairs;
} }
public static void createEffectChains() {
effectChains = new ArrayList<EffectGroup>();
for (int i = 0; i < 999999; i++) {
if (get("effects." + i + ".name") == null) {
EffectGroup e = new EffectGroup(get("effects." + i + ".name"));
for (int j = 0; i < 999999; j++) {
String type = get("effects." + i + ".children." + j + ".type");
if (type == null) break;
if (type.equals("biquad")) {
int bqt = getInteger("effects." + i + ".children." + j + ".filtertype");
double fc = getDouble("effects." + i + ".children." + j + ".fc");
double q = getDouble("effects." + i + ".children." + j + ".q");
double gain = getDouble("effects." + i + ".children." + j + ".gain");
Biquad b = new Biquad(bqt, fc, q, gain);
e.addEffect(b);
continue;
}
if (type.equals("amplifier")) {
double gain = getDouble("effects." + i + ".children." + j + ".gain");
Amplifier a = new Amplifier(gain);
e.addEffect(a);
continue;
}
if (type.equals("delayline")) {
DelayLine l = new DelayLine();
for (int c = 0; c < 999999; c++) {
if (get("effects." + i + ".children." + j + ".lines." + c + ".samples") == null) break;
int samples = getInteger("effects." + i + ".children." + j + ".lines." + c + ".samples");
double gain = getDouble("effects." + i + ".children." + j + ".lines." + c + ".gain");
l.addDelayLine(samples, gain);
}
e.addEffect(l);
continue;
}
}
effectChains.add(e);
break;
}
}
}
} }

View File

@@ -1,6 +1,6 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import javax.swing.ImageIcon;
public class Overlays { public class Overlays {
static public final ImageIcon locked = new ImageIcon(Overlays.class.getResource("overlays/locked.png")); static public final ImageIcon locked = new ImageIcon(Overlays.class.getResource("overlays/locked.png"));

View File

@@ -1,12 +1,15 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import javax.swing.JDialog;
import javax.swing.event.*; import javax.swing.JLabel;
import javax.swing.border.*; import javax.swing.JProgressBar;
import java.awt.*; import java.awt.BorderLayout;
import java.awt.event.*; import it.sauronsoftware.jave.MultimediaInfo;
import java.util.*; import it.sauronsoftware.jave.EncoderProgressListener;
import it.sauronsoftware.jave.*; import java.awt.Dialog;
import javax.swing.border.EmptyBorder;
import java.awt.Dimension;
import java.awt.event.WindowEvent;
public class ProgressDialog extends JDialog implements EncoderProgressListener { public class ProgressDialog extends JDialog implements EncoderProgressListener {
JLabel message; JLabel message;

View File

@@ -0,0 +1,71 @@
package uk.co.majenko.audiobookrecorder;
import javax.swing.JPanel;
import java.util.ArrayList;
import java.util.Queue;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Dimension;
import java.awt.Color;
public class QueueMonitor extends JPanel {
ArrayList<WorkerThread> threadList = new ArrayList<WorkerThread>();
Queue queue;
public QueueMonitor(Queue q) {
super();
queue = q;
}
public void addThread(WorkerThread t) {
threadList.add(t);
}
public void purgeQueue() {
synchronized (queue) {
queue.clear();
repaint();
}
}
@Override
public Dimension getPreferredSize() {
return new Dimension(100 + (24 * threadList.size()), 24);
}
@Override
public Dimension getMinimumSize() {
return getPreferredSize();
}
@Override
public Dimension getMaximumSize() {
return getPreferredSize();
}
@Override
public void paintComponent(Graphics g) {
Rectangle size = g.getClipBounds();
g.setColor(getBackground());
g.fillRect(0, 0, size.width - 1, size.height - 1);
g.setColor(new Color(10, 10, 10));
g.drawRect(0, 0, size.width - 1, size.height - 1);
g.setFont(getFont());
for (int i = 0; i < threadList.size(); i++) {
WorkerThread t = threadList.get(i);
if (t.isRunning()) {
g.setColor(new Color(50, 200, 0));
} else {
g.setColor(new Color(80, 0, 0));
}
g.fillOval(i * 24 + 4, 4, 22 - 8, 22 - 8);
}
g.setColor(getForeground());
g.drawString("Queued: " + queue.size(), threadList.size() * 24 + 4, 16);
}
}

View File

@@ -1,15 +1,5 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.nio.file.*;
import javax.swing.tree.*;
import javax.sound.sampled.*;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
@@ -20,15 +10,7 @@ import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import edu.cmu.sphinx.api.*;
import edu.cmu.sphinx.decoder.adaptation.*;
import edu.cmu.sphinx.result.*;
import org.json.*;
import java.util.Timer; import java.util.Timer;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
@@ -40,6 +22,26 @@ 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;
import org.w3c.dom.Text; import org.w3c.dom.Text;
import javax.sound.sampled.TargetDataLine;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioFormat;
import java.io.File;
import java.io.IOException;
import java.util.TreeMap;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.AudioFileFormat;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import java.io.BufferedReader;
import java.io.InputStream;
import java.util.UUID;
import java.nio.file.Files;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.ByteArrayInputStream;
public class Sentence extends BookTreeNode implements Cacheable { public class Sentence extends BookTreeNode implements Cacheable {
@@ -63,6 +65,12 @@ public class Sentence extends BookTreeNode implements Cacheable {
boolean inSample; boolean inSample;
boolean attention = false; boolean attention = false;
boolean processed = false; boolean processed = false;
boolean isDetected = false;
int state = IDLE;
static final int IDLE = 0;
static final int QUEUED = 1;
static final int PROCESSING = 2;
String effectChain = null; String effectChain = null;
@@ -208,6 +216,10 @@ public class Sentence extends BookTreeNode implements Cacheable {
processed = Utils.s2b(Book.getTextNode(root, "processed")); processed = Utils.s2b(Book.getTextNode(root, "processed"));
runtime = Utils.s2d(Book.getTextNode(root, "time", "-1.000")); runtime = Utils.s2d(Book.getTextNode(root, "time", "-1.000"));
peak = Utils.s2d(Book.getTextNode(root, "peak", "-1.000")); peak = Utils.s2d(Book.getTextNode(root, "peak", "-1.000"));
isDetected = Utils.s2b(Book.getTextNode(root, "detected"));
if (text == null) text = id;
if (text.equals("")) text = id;
if ((crossStartOffset == -1) || (crossEndOffset == -1)) { if ((crossStartOffset == -1) || (crossEndOffset == -1)) {
updateCrossings(true); updateCrossings(true);
@@ -501,6 +513,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
public String getText() { public String getText() {
Debug.trace(); Debug.trace();
if (text == null) return id;
return text; return text;
} }
@@ -685,25 +698,37 @@ public class Sentence extends BookTreeNode implements Cacheable {
return null; return null;
} }
public void doRecognition(StreamSpeechRecognizer recognizer) { public Runnable getRecognitionRunnable() {
Runnable r = new Runnable() {
public void run() {
Debug.d("Starting recognition of", getId());
doRecognition();
}
};
return r;
}
public void doRecognition() {
Debug.trace(); Debug.trace();
try { try {
setText("[recognising...]");
reloadTree(); reloadTree();
byte[] inData = getPCMData(); String command = Options.get("process.command");
Debug.d("Recognizing with command", command);
ProcessBuilder builder = new ProcessBuilder(command, getFile().getCanonicalPath());
Process process = builder.start();
InputStream is = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
ByteArrayInputStream bas = new ByteArrayInputStream(inData);
recognizer.startRecognition(bas);
SpeechResult result;
String res = ""; String res = "";
while ((result = recognizer.getResult()) != null) { String line = null;
res += result.getHypothesis(); while ((line = reader.readLine()) != null) {
res += " "; res += line;
} }
recognizer.stopRecognition();
setText(res); setText(res);
isDetected = true;
reloadTree(); reloadTree();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -712,32 +737,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
public void recognise() { public void recognise() {
Debug.trace(); Debug.trace();
Thread t = new Thread(new Runnable() { Thread t = new Thread(getRecognitionRunnable());
public void run() {
Debug.trace();
try {
Configuration sphinxConfig = new Configuration();
sphinxConfig.setAcousticModelPath(AudiobookRecorder.SPHINX_MODEL);
sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
AudioInputStream s = AudioSystem.getAudioInputStream(getFile());
AudioFormat format = getAudioFormat();
sphinxConfig.setSampleRate((int)(format.getSampleRate()));
StreamSpeechRecognizer recognizer;
recognizer = new StreamSpeechRecognizer(sphinxConfig);
doRecognition(recognizer);
} catch (Exception e) {
e.printStackTrace();
}
}
});
t.start(); t.start();
} }
@@ -1519,6 +1519,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
public void setEffectChain(String key) { public void setEffectChain(String key) {
Debug.trace(); Debug.trace();
if (key == null) key = "none";
if ((effectChain != null) && (effectChain.equals(key))) { if ((effectChain != null) && (effectChain.equals(key))) {
return; return;
} }
@@ -1635,6 +1636,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
sentenceNode.appendChild(Book.makeTextNode(doc, "notes", getNotes())); sentenceNode.appendChild(Book.makeTextNode(doc, "notes", getNotes()));
sentenceNode.appendChild(Book.makeTextNode(doc, "time", getLength())); sentenceNode.appendChild(Book.makeTextNode(doc, "time", getLength()));
sentenceNode.appendChild(Book.makeTextNode(doc, "peak", getPeak())); sentenceNode.appendChild(Book.makeTextNode(doc, "peak", getPeak()));
sentenceNode.appendChild(Book.makeTextNode(doc, "detected", beenDetected()));
return sentenceNode; return sentenceNode;
} }
@@ -1668,7 +1670,11 @@ public class Sentence extends BookTreeNode implements Cacheable {
Debug.trace(); Debug.trace();
if (id.equals("room-noise")) return; if (id.equals("room-noise")) return;
if (getParent() == null) return; if (getParent() == null) return;
AudiobookRecorder.window.bookTreeModel.reload(this); SwingUtilities.invokeLater(new Runnable() {
public void run() {
AudiobookRecorder.window.bookTreeModel.reload(Sentence.this);
}
});
} }
public double getPeak() { public double getPeak() {
@@ -1703,5 +1709,31 @@ public class Sentence extends BookTreeNode implements Cacheable {
return (int)db; return (int)db;
} }
public boolean beenDetected() {
return isDetected;
}
public boolean isProcessing() {
return state == PROCESSING;
}
public boolean isQueued() {
return state == QUEUED;
}
public void setProcessing() {
state = PROCESSING;
reloadTree();
}
public void setQueued() {
state = QUEUED;
reloadTree();
}
public void setDequeued() {
state = IDLE;
reloadTree();
}
} }

View File

@@ -0,0 +1,25 @@
package uk.co.majenko.audiobookrecorder;
import java.lang.Runnable;
public abstract class SentenceJob implements Runnable {
protected Sentence sentence;
public SentenceJob(Sentence s) {
sentence = s;
}
public void setQueued() {
sentence.setQueued();
}
public void setDequeued() {
sentence.setDequeued();
}
public void setProcessing() {
sentence.setProcessing();
}
public abstract void run();
}

View File

@@ -1,8 +1,9 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import java.util.*; import javax.swing.SpinnerModel;
import javax.swing.*; import java.util.ArrayList;
import javax.swing.event.*; import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
public class SteppedNumericSpinnerModel implements SpinnerModel { public class SteppedNumericSpinnerModel implements SpinnerModel {
int min; int min;

View File

@@ -0,0 +1,115 @@
package uk.co.majenko.audiobookrecorder;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToolTip;
import javax.swing.SwingUtilities;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Font;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.font.FontRenderContext;
import java.awt.FontMetrics;
import java.awt.Dimension;
import org.apache.commons.text.WordUtils;
public class Tip extends JLabel implements MouseListener {
String tip = null;
public Tip(String text) {
tip = WordUtils.wrap(text, 50);
setToolTipText(text);
setIcon(Icons.tooltip);
addMouseListener(this);
}
@Override
public JToolTip createToolTip() {
JToolTip tt = new JToolTip() {
public String getTipText() {
return "*" + tip + "*";
}
public void paintComponent(Graphics g) {
Rectangle r = g.getClipBounds();
JLabel l = new JLabel();
AffineTransform affinetransform = new AffineTransform();
FontRenderContext frc = new FontRenderContext(affinetransform,true,true);
Font f = l.getFont().deriveFont(14f);
g.setColor(new Color(200, 200, 180));
g.fillRect(0, 0, r.width, r.height);
g.setColor(new Color(10, 10, 10));
g.setFont(f);
int y = 3;
String[] lines = tip.split("\n");
for (String line : lines) {
Rectangle2D bounds = f.getStringBounds(line, frc);
y += bounds.getHeight();
g.drawString(line, 5, y);
}
}
public Dimension getPreferredSize() {
JLabel l = new JLabel();
AffineTransform affinetransform = new AffineTransform();
FontRenderContext frc = new FontRenderContext(affinetransform,true,true);
Font f = l.getFont().deriveFont(14f);
String[] lines = tip.split("\n");
int w = 0;
int h = 0;
for (String line : lines) {
Rectangle2D bounds = f.getStringBounds(line, frc);
double fw = bounds.getWidth();
if (fw > w) w = (int)fw;
h += bounds.getHeight();
}
Dimension s = new Dimension(w + 10, h + 10);
return s;
}
};
tt.removeAll();
JPanel p = new JPanel();
tt.add(p);
JLabel l = new JLabel(tip);
l.setBackground(new Color(200, 200, 180));
l.setForeground(new Color(0, 0, 0));
p.add(l);
return tt;
}
public void mouseEntered(MouseEvent evt) {
// showTipWindow();
}
public void mouseExited(MouseEvent evt) {
// hideTipWindow();
}
public void mousePressed(MouseEvent evt) {
}
public void mouseReleased(MouseEvent evt) {
}
public void mouseClicked(MouseEvent evt) {
}
}

View File

@@ -1,16 +1,14 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.border.*;
import java.util.*;
import java.io.*;
import java.net.*;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.RenderingHints;
import java.net.URI;
import java.awt.Graphics2D;
import java.awt.Desktop;
import java.util.Date;
import java.util.TimeZone;
public class Utils { public class Utils {
public static Image getScaledImage(Image srcImg, int w, int h){ public static Image getScaledImage(Image srcImg, int w, int h){

View File

@@ -1,11 +1,14 @@
package uk.co.majenko.audiobookrecorder; package uk.co.majenko.audiobookrecorder;
import javax.swing.*; import java.awt.event.MouseListener;
import java.awt.*; import java.awt.event.MouseMotionListener;
import java.awt.event.*; import javax.swing.JPanel;
import java.util.*; import java.util.ArrayList;
import java.io.*; import java.awt.Graphics;
import javax.sound.sampled.*; import java.awt.event.MouseEvent;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.Cursor;
public class Waveform extends JPanel implements MouseListener, MouseMotionListener { public class Waveform extends JPanel implements MouseListener, MouseMotionListener {

View File

@@ -0,0 +1,62 @@
package uk.co.majenko.audiobookrecorder;
import java.util.Queue;
public class WorkerThread extends Thread {
private static int instance = 0;
private final Queue<Runnable> queue;
private final QueueMonitor monitor;
private boolean running = false;
public WorkerThread(Queue<Runnable> queue, QueueMonitor mon) {
this.queue = queue;
monitor = mon;
setName("Worker Thread " + (instance++));
}
@Override
public void run() {
Debug.d(getName(), "started");
while ( true ) {
try {
Runnable work = null;
synchronized ( queue ) {
while ( queue.isEmpty() ) {
Debug.d(getName(), "waiting on work");
queue.wait();
}
Debug.d(getName(), "got work");
// Get the next work item off of the queue
work = queue.remove();
}
running = true;
monitor.repaint();
if (work instanceof SentenceJob) {
SentenceJob sj = (SentenceJob)work;
sj.setProcessing();
}
work.run();
if (work instanceof SentenceJob) {
SentenceJob sj = (SentenceJob)work;
sj.setDequeued();
}
running = false;
monitor.repaint();
}
catch ( InterruptedException ie ) {
ie.printStackTrace();
break; // Terminate
}
}
Debug.d(getName(), "died");
}
public boolean isRunning() {
return running;
}
}