Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 21d7d9d597 | |||
| 746f47a5fa | |||
| c67e6d6abc | |||
| 1f722f5df3 | |||
| df4eae1d66 | |||
| 4d435b4fc1 | |||
| f95ae10d03 | |||
| 423d840d83 | |||
| 1997b0bf9b | |||
| b206fb33aa | |||
| 11b26e396c | |||
| 94139e6ac6 | |||
| c0cc2432ff | |||
| f86aaa3782 | |||
| 690a8f0c3b | |||
| 1de0ca8d60 | |||
| de149c5d85 | |||
| 7d2b11473b | |||
| 4c25fccc86 | |||
| 5e310b0224 | |||
| 169802ccaf | |||
| 28257e00c0 | |||
| 38c6af7090 | |||
| bdbf4c604d | |||
| 73bcba2c9a | |||
| 90ca84cfbf | |||
| a18ca1ce21 | |||
| b92babb5cd | |||
| e3231ec495 | |||
| 4896ee7a65 | |||
| ce3eb7165a | |||
| 4de00b8fac |
38
README.md
38
README.md
@@ -29,12 +29,13 @@ From here on much is controlled by key presses.
|
||||
appended to the currently selected chapter, or to the last chapter if none is selected.
|
||||
* Press and hold "T" to record a new phrase that is the start of a new paragraph. This adds the "post paragraph" gap to the previous sentence. Otherwise it does the same as "R".
|
||||
* Press and hold "F" to record a "continuation" phrase. This sets the previous phrase's post-gap to be the "short" gap instead of the normal length gap.
|
||||
* Press and hold "Y" to record a new phrase that is the start of a new section. This add the "post section" gap to the previous sentence. Otherwise it does the same as "R".
|
||||
* Press "D" to delete the last phrase you recorded.
|
||||
* Press "E" to re-record the currently selected phrase.
|
||||
|
||||
Each phrase you record will be briefly analysed using FFT to find the start and end of the audio and set
|
||||
Each phrase you record can be automatically analysed to find the start and end of the audio and set
|
||||
crop marks appropriately. These can be adjusted in the waveform display when a phrase is selected. You can also
|
||||
re-run the analysis using either the default FFT method or using a peak detector method (finding the first and last points
|
||||
re-run the analysis using either FFT or a peak detector method (finding the first and last points
|
||||
where the audio amplitude rises above the backround noise).
|
||||
|
||||
The phrases also have a "post gap" associated with them. This is the amount of room noise (in milliseconds) to place between
|
||||
@@ -53,18 +54,14 @@ edit the text of this ID to identify the recordings. You
|
||||
may, for instance, change it to have the same text as the
|
||||
audio contains.
|
||||
|
||||
To help with this the Haven On-Demand online speech recognition
|
||||
service is integrated with the system and can be used to try and convert the
|
||||
audio into text. Right clicking on a recording brings
|
||||
up a menu which includes the option to try and convert
|
||||
the audio into text. The detected text is then used to
|
||||
replace the current recording ID / text.
|
||||
The audio can also be automatically converted to text if you have an suitable command-line
|
||||
executable that will work. One example is (on Linux) [DeepSpeech](https://github.com/mozilla/DeepSpeech) by Mozilla.
|
||||
|
||||
File layout
|
||||
-----------
|
||||
|
||||
All data is stored in your "storage" directory (specified in Options). Each book (which is a directory named after the
|
||||
title of the book) has an associated XML file (audiobook.abk) and a directory "files" where all the audio (stored as WAV
|
||||
title of the book) has an associated XML file (audiobook.abx) and a directory "files" where all the audio (stored as WAV
|
||||
files) is placed.
|
||||
|
||||
When you export the book as MP3 a new folder "export" is created within the book's folder where the MP3 files are placed.
|
||||
@@ -81,3 +78,26 @@ Building
|
||||
5. Build with `ant build`
|
||||
6. Run with `java -jar ./AudiobookRecorder.jar`
|
||||
|
||||
|
||||
----
|
||||
|
||||
Extra Resources
|
||||
===============
|
||||
|
||||
* DeepSpeech wrapper script
|
||||
|
||||
This is a small script that will convert the audio into a format DeepSpeech likes and call the `deepspeech` executable, removing any extra rubbish from the output. It
|
||||
also requires `sox` to be installed for the audio conversion.
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
|
||||
ID=$$
|
||||
FILE=$1
|
||||
BINPATH=${HOME}/local/bin
|
||||
MODELS=${HOME}/ds/deepspeech-0.6.1-models
|
||||
|
||||
sox "$FILE" -r 16000 -c 1 -b 16 "/tmp/ds-${ID}.wav"
|
||||
${BINPATH}/deepspeech --model ${MODELS}/output_graph.pbmm --lm ${MODELS}/lm.binary --trie ${MODELS}/trie --audio "/tmp/ds-${ID}.wav" 2>/dev/null
|
||||
rm /tmp/ds-${ID}.wav
|
||||
```
|
||||
|
||||
BIN
deps/commons-lang3.jar
LFS
vendored
Normal file
BIN
deps/commons-lang3.jar
LFS
vendored
Normal file
Binary file not shown.
BIN
deps/commons-text.jar
LFS
vendored
Normal file
BIN
deps/commons-text.jar
LFS
vendored
Normal file
Binary file not shown.
BIN
deps/json-20190722.jar
LFS
vendored
Normal file
BIN
deps/json-20190722.jar
LFS
vendored
Normal file
Binary file not shown.
BIN
deps/sphinx4-core-5prealpha-SNAPSHOT.jar
LFS
vendored
BIN
deps/sphinx4-core-5prealpha-SNAPSHOT.jar
LFS
vendored
Binary file not shown.
BIN
deps/sphinx4-data-5prealpha-SNAPSHOT.jar
LFS
vendored
BIN
deps/sphinx4-data-5prealpha-SNAPSHOT.jar
LFS
vendored
Binary file not shown.
@@ -1 +1 @@
|
||||
version=0.3.2
|
||||
version=0.3.9
|
||||
|
||||
BIN
resources/uk/co/majenko/audiobookrecorder/icons/close.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/close.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/processing.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/processing.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 489 B |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/queued.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/queued.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 717 B |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/tooltip.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/tooltip.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -10,6 +10,7 @@ public class AGC implements Effect {
|
||||
double attack;
|
||||
|
||||
public AGC(double c, double a, double d, double l) {
|
||||
Debug.trace();
|
||||
ceiling = c;
|
||||
attack = a;
|
||||
decay = d;
|
||||
@@ -18,18 +19,21 @@ public class AGC implements Effect {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
Debug.trace();
|
||||
return "AGC (Ceiling = " + ceiling + " attack = " + attack + " decay = " + decay + " limit = " + limit;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Debug.trace();
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
Debug.trace();
|
||||
gain = 1d;
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
double absSampleLeft = Math.abs(samples[i][Sentence.LEFT]) * gain;
|
||||
double absSampleRight = Math.abs(samples[i][Sentence.RIGHT]) * gain;
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
double absSampleLeft = Math.abs(samples[Sentence.LEFT][i]) * gain;
|
||||
double absSampleRight = Math.abs(samples[Sentence.RIGHT][i]) * gain;
|
||||
|
||||
double factor = 0.0d;
|
||||
|
||||
@@ -49,20 +53,23 @@ public class AGC implements Effect {
|
||||
if (gain > limit) gain = limit;
|
||||
if (gain < 0) gain = 0;
|
||||
|
||||
samples[i][Sentence.LEFT] *= gain;
|
||||
samples[i][Sentence.RIGHT] *= gain;
|
||||
samples[Sentence.LEFT][i] *= gain;
|
||||
samples[Sentence.RIGHT][i] *= gain;
|
||||
}
|
||||
}
|
||||
|
||||
public void init(double sr) {
|
||||
Debug.trace();
|
||||
gain = 1d;
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
Debug.trace();
|
||||
System.out.println(toString());
|
||||
}
|
||||
|
||||
public ArrayList<Effect> getChildEffects() {
|
||||
Debug.trace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.BorderLayout;
|
||||
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 AboutPanel() {
|
||||
Debug.trace();
|
||||
setLayout(new BorderLayout());
|
||||
JLabel icon = new JLabel(Icons.appIcon);
|
||||
add(icon, BorderLayout.WEST);
|
||||
@@ -17,7 +22,7 @@ public class AboutPanel extends JPanel {
|
||||
|
||||
JLabel l1 = new JLabel("AudiobookRecorder");
|
||||
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);
|
||||
l2.setAlignmentX(JComponent.CENTER_ALIGNMENT);
|
||||
|
||||
@@ -5,43 +5,53 @@ import java.util.ArrayList;
|
||||
public class Amplifier implements Effect {
|
||||
double gain;
|
||||
public Amplifier() {
|
||||
Debug.trace();
|
||||
gain = 1.0d;
|
||||
}
|
||||
public Amplifier(double g) {
|
||||
Debug.trace();
|
||||
gain = g;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
Debug.trace();
|
||||
return "Amplifier (" + gain + ")";
|
||||
}
|
||||
|
||||
public ArrayList<Effect> getChildEffects() {
|
||||
Debug.trace();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
samples[i][Sentence.LEFT] *= gain;
|
||||
samples[i][Sentence.RIGHT] *= gain;
|
||||
Debug.trace();
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
samples[Sentence.LEFT][i] *= gain;
|
||||
samples[Sentence.RIGHT][i] *= gain;
|
||||
}
|
||||
}
|
||||
|
||||
public double getGain() {
|
||||
Debug.trace();
|
||||
return gain;
|
||||
}
|
||||
|
||||
public void setGain(double g) {
|
||||
Debug.trace();
|
||||
gain = g;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Debug.trace();
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
Debug.trace();
|
||||
System.out.println(toString());
|
||||
}
|
||||
|
||||
public void init(double sf) {
|
||||
Debug.trace();
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,23 +1,5 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
// Biquad.java
|
||||
//
|
||||
// Created by Nigel Redmon on 11/24/12
|
||||
// EarLevel Engineering: earlevel.com
|
||||
// Copyright 2012 Nigel Redmon
|
||||
// Translated to Java 2019 Majenko Technologies
|
||||
//
|
||||
// For a complete explanation of the Biquad code:
|
||||
// http://www.earlevel.com/main/2012/11/26/biquad-c-source-code/
|
||||
//
|
||||
// License:
|
||||
//
|
||||
// This source code is provided as is, without warranty.
|
||||
// You may copy and distribute verbatim copies of this document.
|
||||
// You may modify and use this source code to create binary code
|
||||
// for your own purposes, free or commercial.
|
||||
//
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Biquad implements Effect {
|
||||
@@ -37,6 +19,7 @@ public class Biquad implements Effect {
|
||||
double sampleFrequency;
|
||||
|
||||
public Biquad() {
|
||||
Debug.trace();
|
||||
type = Lowpass;
|
||||
a0 = 1.0d;
|
||||
a1 = 0.0d;
|
||||
@@ -54,6 +37,7 @@ public class Biquad implements Effect {
|
||||
}
|
||||
|
||||
public Biquad(int type, double Fc, double Q, double peakGainDB) {
|
||||
Debug.trace();
|
||||
setBiquad(type, Fc, Q, peakGainDB);
|
||||
lz1 = 0.0;
|
||||
lz2 = 0.0;
|
||||
@@ -63,26 +47,31 @@ public class Biquad implements Effect {
|
||||
}
|
||||
|
||||
public void setType(int typei) {
|
||||
Debug.trace();
|
||||
type = typei;
|
||||
calcBiquad();
|
||||
}
|
||||
|
||||
public void setQ(double Qi) {
|
||||
Debug.trace();
|
||||
Q = Qi;
|
||||
calcBiquad();
|
||||
}
|
||||
|
||||
public void setFc(double Fci) {
|
||||
Debug.trace();
|
||||
Fc = Fci;
|
||||
calcBiquad();
|
||||
}
|
||||
|
||||
public void setPeakGain(double peakGainDB) {
|
||||
Debug.trace();
|
||||
peakGain = peakGainDB;
|
||||
calcBiquad();
|
||||
}
|
||||
|
||||
public void setBiquad(int typei, double Fci, double Qi, double peakGainDB) {
|
||||
Debug.trace();
|
||||
type = typei;
|
||||
Q = Qi;
|
||||
Fc = Fci;
|
||||
@@ -90,27 +79,29 @@ public class Biquad implements Effect {
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
Debug.trace();
|
||||
lz1 = 0d;
|
||||
lz2 = 0d;
|
||||
rz1 = 0d;
|
||||
rz2 = 0d;
|
||||
for (double[] in : samples) {
|
||||
double lout = in[Sentence.LEFT] * a0 + lz1;
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
double lout = samples[Sentence.LEFT][i] * a0 + lz1;
|
||||
|
||||
lz1 = in[Sentence.LEFT] * a1 + lz2 - b1 * lout;
|
||||
lz2 = in[Sentence.LEFT] * a2 - b2 * lout;
|
||||
lz1 = samples[Sentence.LEFT][i] * a1 + lz2 - b1 * lout;
|
||||
lz2 = samples[Sentence.LEFT][i] * a2 - b2 * lout;
|
||||
|
||||
double rout = in[Sentence.RIGHT] * a0 + rz1;
|
||||
double rout = samples[Sentence.RIGHT][i] * a0 + rz1;
|
||||
|
||||
rz1 = in[Sentence.RIGHT] * a1 + rz2 - b1 * rout;
|
||||
rz2 = in[Sentence.RIGHT] * a2 - b2 * rout;
|
||||
rz1 = samples[Sentence.RIGHT][i] * a1 + rz2 - b1 * rout;
|
||||
rz2 = samples[Sentence.RIGHT][i] * a2 - b2 * rout;
|
||||
|
||||
in[Sentence.LEFT] = lout;
|
||||
in[Sentence.RIGHT] = rout;
|
||||
samples[Sentence.LEFT][i] = lout;
|
||||
samples[Sentence.RIGHT][i] = rout;
|
||||
}
|
||||
}
|
||||
|
||||
public void init(double sf) {
|
||||
Debug.trace();
|
||||
sampleFrequency = sf;
|
||||
lz1 = 0d;
|
||||
lz2 = 0d;
|
||||
@@ -120,6 +111,7 @@ public class Biquad implements Effect {
|
||||
}
|
||||
|
||||
void calcBiquad() {
|
||||
Debug.trace();
|
||||
|
||||
double norm;
|
||||
double V = Math.pow(10, Math.abs(peakGain) / 20.0);
|
||||
@@ -221,6 +213,7 @@ public class Biquad implements Effect {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
Debug.trace();
|
||||
String n = "Biquad Filter (";
|
||||
switch (type) {
|
||||
case Lowpass: n += "Lowpass"; break;
|
||||
@@ -242,14 +235,17 @@ public class Biquad implements Effect {
|
||||
}
|
||||
|
||||
public ArrayList<Effect> getChildEffects() {
|
||||
Debug.trace();
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Debug.trace();
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
Debug.trace();
|
||||
System.out.println(toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
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 java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.UUID;
|
||||
import java.util.Properties;
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
@@ -24,7 +25,7 @@ import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
public class Book extends DefaultMutableTreeNode {
|
||||
public class Book extends BookTreeNode {
|
||||
|
||||
String name;
|
||||
String author;
|
||||
@@ -39,13 +40,17 @@ public class Book extends DefaultMutableTreeNode {
|
||||
int channels;
|
||||
int resolution;
|
||||
|
||||
String notes = null;
|
||||
|
||||
ImageIcon icon;
|
||||
|
||||
Properties prefs;
|
||||
|
||||
File location;
|
||||
|
||||
public Book(Properties p, String bookname) {
|
||||
super(bookname);
|
||||
|
||||
Debug.trace();
|
||||
prefs = p;
|
||||
name = bookname;
|
||||
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) {
|
||||
super(getTextNode(root, "title"));
|
||||
|
||||
Debug.trace();
|
||||
name = getTextNode(root, "title");
|
||||
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!!
|
||||
}
|
||||
|
||||
public void loadBookXML(Element root, DefaultTreeModel model) {
|
||||
Debug.trace();
|
||||
name = getTextNode(root, "title");
|
||||
author = getTextNode(root, "author");
|
||||
genre = getTextNode(root, "genre");
|
||||
@@ -66,7 +72,8 @@ public class Book extends DefaultMutableTreeNode {
|
||||
ACX = getTextNode(root, "acx");
|
||||
manuscript = getTextNode(root, "manuscript");
|
||||
|
||||
AudiobookRecorder.window.setNotes(getTextNode(root, "notes"));
|
||||
AudiobookRecorder.window.setBookNotes(getTextNode(root, "notes"));
|
||||
notes = getTextNode(root, "notes");
|
||||
|
||||
Element settings = getNode(root, "settings");
|
||||
Element audioSettings = getNode(settings, "audio");
|
||||
@@ -92,6 +99,7 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public static Element getNode(Element r, String n) {
|
||||
Debug.trace();
|
||||
NodeList nl = r.getElementsByTagName(n);
|
||||
if (nl == null) return null;
|
||||
if (nl.getLength() == 0) return null;
|
||||
@@ -99,31 +107,40 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public static String getTextNode(Element r, String n) {
|
||||
Debug.trace();
|
||||
return getTextNode(r, n, "");
|
||||
}
|
||||
|
||||
public static String getTextNode(Element r, String n, String d) {
|
||||
Debug.trace();
|
||||
Element node = getNode(r, n);
|
||||
if (node == null) return "";
|
||||
if (node == null) return d;
|
||||
return node.getTextContent();
|
||||
}
|
||||
|
||||
public void setAuthor(String a) { author = a; }
|
||||
public void setGenre(String g) { genre = g; }
|
||||
public void setComment(String c) { comment = c; }
|
||||
public void setACX(String c) { ACX = c; }
|
||||
public void setAuthor(String a) { Debug.trace(); author = a; }
|
||||
public void setGenre(String g) { Debug.trace(); genre = g; }
|
||||
public void setComment(String c) { Debug.trace(); comment = c; }
|
||||
public void setACX(String c) { Debug.trace(); ACX = c; }
|
||||
|
||||
public String getAuthor() { return author; }
|
||||
public String getGenre() { return genre; }
|
||||
public String getComment() { return comment; }
|
||||
public String getACX() { if (ACX == null) return ""; return ACX; }
|
||||
public String getAuthor() { Debug.trace(); return author; }
|
||||
public String getGenre() { Debug.trace(); return genre; }
|
||||
public String getComment() { Debug.trace(); return comment; }
|
||||
public String getACX() { Debug.trace(); if (ACX == null) return ""; return ACX; }
|
||||
|
||||
public Chapter getClosingCredits() {
|
||||
Debug.trace();
|
||||
return getChapterById("close");
|
||||
}
|
||||
|
||||
public Chapter getOpeningCredits() {
|
||||
Debug.trace();
|
||||
return getChapterById("open");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Chapter getChapterById(String id) {
|
||||
Debug.trace();
|
||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||
Object ob = (Object)o.nextElement();
|
||||
if (ob instanceof Chapter) {
|
||||
@@ -137,47 +154,39 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public Chapter getLastChapter() {
|
||||
Chapter cc = getClosingCredits();
|
||||
if (cc == null) return null;
|
||||
Chapter c = (Chapter)getChildBefore(cc);
|
||||
if (c == null) return null;
|
||||
if (c.getId().equals("open")) return null;
|
||||
return c;
|
||||
Debug.trace();
|
||||
return (Chapter)getLastLeaf();
|
||||
}
|
||||
|
||||
public Chapter getChapter(int n) {
|
||||
Debug.trace();
|
||||
if (n == 0) return null;
|
||||
return (Chapter)getChildAt(n);
|
||||
}
|
||||
|
||||
public Chapter addChapter() {
|
||||
Chapter lc = getLastChapter();
|
||||
if (lc == null) return new Chapter("1", "Chapter 1");
|
||||
try {
|
||||
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;
|
||||
Debug.trace();
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
return new Chapter(uuid, uuid);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
Debug.trace();
|
||||
return name;
|
||||
}
|
||||
|
||||
public ImageIcon getIcon() {
|
||||
Debug.trace();
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(ImageIcon i) {
|
||||
Debug.trace();
|
||||
icon = i;
|
||||
}
|
||||
|
||||
public void setUserObject(Object o) {
|
||||
Debug.trace();
|
||||
if (o instanceof String) {
|
||||
String newName = (String)o;
|
||||
if (newName.equals(name)) return;
|
||||
@@ -186,10 +195,12 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public File getBookPath() {
|
||||
Debug.trace();
|
||||
return new File(Options.get("path.storage"), name);
|
||||
}
|
||||
|
||||
public void renameBook(String newName) {
|
||||
Debug.trace();
|
||||
File oldDir = getBookPath();
|
||||
File newDir = new File(Options.get("path.storage"), newName);
|
||||
|
||||
@@ -202,7 +213,7 @@ public class Book extends DefaultMutableTreeNode {
|
||||
oldDir.renameTo(newDir);
|
||||
name = newName;
|
||||
AudiobookRecorder.window.saveBookStructure();
|
||||
AudiobookRecorder.window.bookTreeModel.reload(this);
|
||||
reloadTree();
|
||||
Options.set("path.last-book", name);
|
||||
Options.savePreferences();
|
||||
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
|
||||
@@ -210,11 +221,13 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Debug.trace();
|
||||
return name;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void renumberChapters() {
|
||||
Debug.trace();
|
||||
int id = 1;
|
||||
|
||||
for (Enumeration c = children(); c.hasMoreElements();) {
|
||||
@@ -226,41 +239,48 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
}
|
||||
|
||||
public int getSampleRate() { return sampleRate; }
|
||||
public void setSampleRate(int sr) { sampleRate = sr; }
|
||||
public int getChannels() { return channels; }
|
||||
public void setChannels(int c) { channels = c; }
|
||||
public int getResolution() { return resolution; }
|
||||
public void setResolution(int r) { resolution = r; }
|
||||
public int getSampleRate() { Debug.trace(); return sampleRate; }
|
||||
public void setSampleRate(int sr) { Debug.trace(); sampleRate = sr; }
|
||||
public int getChannels() { Debug.trace(); return channels; }
|
||||
public void setChannels(int c) { Debug.trace(); channels = c; }
|
||||
public int getResolution() { Debug.trace(); return resolution; }
|
||||
public void setResolution(int r) { Debug.trace(); resolution = r; }
|
||||
|
||||
public AudioFormat getAudioFormat() {
|
||||
Debug.trace();
|
||||
return new AudioFormat(getSampleRate(), getResolution(), getChannels(), true, false);
|
||||
}
|
||||
|
||||
public String get(String key) {
|
||||
Debug.trace();
|
||||
if (prefs.getProperty(key) == null) { return Options.get(key); }
|
||||
return prefs.getProperty(key);
|
||||
}
|
||||
|
||||
public Integer getInteger(String key) {
|
||||
Debug.trace();
|
||||
if (prefs.getProperty(key) == null) { return Options.getInteger(key); }
|
||||
return Utils.s2i(prefs.getProperty(key));
|
||||
}
|
||||
|
||||
public void set(String key, String value) {
|
||||
Debug.trace();
|
||||
prefs.setProperty(key, value);
|
||||
}
|
||||
|
||||
public void set(String key, Integer value) {
|
||||
Debug.trace();
|
||||
prefs.setProperty(key, "" + value);
|
||||
}
|
||||
|
||||
public File getBookFolder() {
|
||||
Debug.trace();
|
||||
File dir = new File(Options.get("path.storage"), name);
|
||||
return dir;
|
||||
}
|
||||
|
||||
public ArrayList<String> getUsedEffects() {
|
||||
Debug.trace();
|
||||
|
||||
ArrayList<String> out = new ArrayList<String>();
|
||||
|
||||
@@ -281,6 +301,7 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public void purgeBackups() {
|
||||
Debug.trace();
|
||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||
Object ob = (Object)o.nextElement();
|
||||
if (ob instanceof Chapter) {
|
||||
@@ -291,6 +312,7 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public Document buildDocument() throws ParserConfigurationException {
|
||||
Debug.trace();
|
||||
DocumentBuilderFactory dbFactory =
|
||||
DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
@@ -306,7 +328,7 @@ public class Book extends DefaultMutableTreeNode {
|
||||
root.appendChild(makeTextNode(doc, "acx", ACX));
|
||||
root.appendChild(makeTextNode(doc, "manuscript", manuscript));
|
||||
|
||||
root.appendChild(makeTextNode(doc, "notes", AudiobookRecorder.window.getNotes()));
|
||||
root.appendChild(makeTextNode(doc, "notes", AudiobookRecorder.window.getBookNotes()));
|
||||
|
||||
Element settingsNode = doc.createElement("settings");
|
||||
root.appendChild(settingsNode);
|
||||
@@ -339,6 +361,7 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public static Element makeTextNode(Document doc, String name, String text) {
|
||||
Debug.trace();
|
||||
Element node = doc.createElement(name);
|
||||
Text tnode = doc.createTextNode(text == null ? "" : text);
|
||||
node.appendChild(tnode);
|
||||
@@ -346,6 +369,7 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public static Element makeTextNode(Document doc, String name, Integer text) {
|
||||
Debug.trace();
|
||||
Element node = doc.createElement(name);
|
||||
Text tnode = doc.createTextNode(Integer.toString(text));
|
||||
node.appendChild(tnode);
|
||||
@@ -353,6 +377,7 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public static Element makeTextNode(Document doc, String name, Double text) {
|
||||
Debug.trace();
|
||||
Element node = doc.createElement(name);
|
||||
Text tnode = doc.createTextNode(String.format("%.8f", text));
|
||||
node.appendChild(tnode);
|
||||
@@ -360,6 +385,7 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public static Element makeTextNode(Document doc, String name, Boolean text) {
|
||||
Debug.trace();
|
||||
Element node = doc.createElement(name);
|
||||
Text tnode = doc.createTextNode(text ? "true" : "false");
|
||||
node.appendChild(tnode);
|
||||
@@ -367,14 +393,17 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public String getDefaultEffect() {
|
||||
Debug.trace();
|
||||
return defaultEffect;
|
||||
}
|
||||
|
||||
public void setDefaultEffect(String eff) {
|
||||
Debug.trace();
|
||||
defaultEffect = eff;
|
||||
}
|
||||
|
||||
public void setManuscript(File f) {
|
||||
Debug.trace();
|
||||
manuscript = f.getName();
|
||||
File dst = new File(getBookPath(), manuscript);
|
||||
|
||||
@@ -386,6 +415,7 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public File getManuscript() {
|
||||
Debug.trace();
|
||||
if (manuscript == null) return null;
|
||||
if (manuscript.equals("")) return null;
|
||||
File f = new File(getBookPath(), manuscript);
|
||||
@@ -394,4 +424,37 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
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() {
|
||||
Debug.trace();
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (AudiobookRecorder.window == null) return;
|
||||
if (AudiobookRecorder.window.bookTreeModel == null) return;
|
||||
try {
|
||||
AudiobookRecorder.window.bookTreeModel.reload(Book.this);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.regex.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.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) {
|
||||
super();
|
||||
Debug.trace();
|
||||
setLayout(new GridBagLayout());
|
||||
GridBagConstraints con = new GridBagConstraints();
|
||||
|
||||
@@ -69,12 +73,13 @@ public class BookInfoPanel extends JPanel {
|
||||
|
||||
}
|
||||
|
||||
public String getTitle() { return title.getText(); }
|
||||
public String getAuthor() { return author.getText(); }
|
||||
public String getGenre() { return genre.getText(); }
|
||||
public String getComment() { return comment.getText(); }
|
||||
public String getTitle() { Debug.trace(); return title.getText(); }
|
||||
public String getAuthor() { Debug.trace(); return author.getText(); }
|
||||
public String getGenre() { Debug.trace(); return genre.getText(); }
|
||||
public String getComment() { Debug.trace(); return comment.getText(); }
|
||||
|
||||
public String getACX() {
|
||||
Debug.trace();
|
||||
Pattern p = Pattern.compile("\\/titleview\\/([A-Z0-9]{14})");
|
||||
Matcher m = p.matcher(acx.getText());
|
||||
if (m.find()) {
|
||||
@@ -84,10 +89,10 @@ public class BookInfoPanel extends JPanel {
|
||||
return acx.getText();
|
||||
}
|
||||
|
||||
public void setTitle(String t) { title.setText(t); }
|
||||
public void setAuthor(String a) { author.setText(a); }
|
||||
public void setGenre(String g) { genre.setText(g); }
|
||||
public void setComment(String c) { comment.setText(c); }
|
||||
public void setACX(String a) { acx.setText(a); }
|
||||
public void setTitle(String t) { Debug.trace(); title.setText(t); }
|
||||
public void setAuthor(String a) { Debug.trace(); author.setText(a); }
|
||||
public void setGenre(String g) { Debug.trace(); genre.setText(g); }
|
||||
public void setComment(String c) { Debug.trace(); comment.setText(c); }
|
||||
public void setACX(String a) { Debug.trace(); acx.setText(a); }
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
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.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Properties;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Image;
|
||||
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.DocumentBuilder;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
20
src/uk/co/majenko/audiobookrecorder/BookTreeNode.java
Normal file
20
src/uk/co/majenko/audiobookrecorder/BookTreeNode.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
public abstract class BookTreeNode extends DefaultMutableTreeNode {
|
||||
|
||||
public BookTreeNode(String t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
public BookTreeNode() {
|
||||
super("");
|
||||
}
|
||||
|
||||
public abstract void setNotes(String t);
|
||||
public abstract String getNotes();
|
||||
|
||||
public abstract void onSelect();
|
||||
}
|
||||
|
||||
@@ -1,25 +1,42 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.border.*;
|
||||
import java.awt.Component;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
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 Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
|
||||
JLabel ret = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
|
||||
ret.setIconTextGap(0);
|
||||
ret.setIconTextGap(5);
|
||||
ret.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
if (value instanceof Sentence) {
|
||||
Sentence s = (Sentence)value;
|
||||
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new GridBagLayout());
|
||||
GridBagConstraints ctx = new GridBagConstraints();
|
||||
|
||||
OverlayIcon icn = new OverlayIcon(Icons.sentence);
|
||||
|
||||
if (s.getOverrideText() != null) {
|
||||
ret.setText(s.getOverrideText());
|
||||
}
|
||||
|
||||
if (!s.isProcessed()) {
|
||||
ret.setForeground(new Color(0x88, 0x88, 0x88));
|
||||
}
|
||||
|
||||
if (s.getAttentionFlag()) {
|
||||
ret.setForeground(new Color(0xFF, 0xFF, 0x00));
|
||||
icn.add(Overlays.attention, OverlayIcon.TOP_LEFT);
|
||||
@@ -59,19 +76,122 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
||||
}
|
||||
|
||||
if (gaptype.equals("sentence")) {
|
||||
ret.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
p.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
} else if (gaptype.equals("continuation")) {
|
||||
ret.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
p.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
} else if (gaptype.equals("paragraph")) {
|
||||
ret.setBorder(new EmptyBorder(0, 0, 7, 0));
|
||||
p.setBorder(new EmptyBorder(0, 0, 7, 0));
|
||||
} else if (gaptype.equals("section")) {
|
||||
ret.setBorder(new EmptyBorder(0, 0, 15, 0));
|
||||
p.setBorder(new EmptyBorder(0, 0, 15, 0));
|
||||
}
|
||||
|
||||
|
||||
JLabel time = new JLabelFixedWidth(75, " " + Utils.secToTime(s.getLength(), "ss.SSS") + " ");
|
||||
time.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
ctx.gridx = 0;
|
||||
ctx.gridy = 0;
|
||||
ctx.weightx = 1.0d;
|
||||
ctx.fill = GridBagConstraints.HORIZONTAL;
|
||||
ctx.anchor = GridBagConstraints.LINE_START;
|
||||
p.add(ret, ctx);
|
||||
|
||||
if (s.isProcessing()) {
|
||||
JLabel eff = new JLabel();
|
||||
eff.setIcon(Icons.processing);
|
||||
ctx.weightx = 0.0d;
|
||||
ctx.gridx = 1;
|
||||
p.add(eff);
|
||||
} else if (s.isQueued()) {
|
||||
JLabel eff = new JLabel();
|
||||
eff.setIcon(Icons.queued);
|
||||
ctx.weightx = 0.0d;
|
||||
ctx.gridx = 1;
|
||||
p.add(eff);
|
||||
}
|
||||
|
||||
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.gridx = 3;
|
||||
ctx.anchor = GridBagConstraints.LINE_END;
|
||||
int peak = s.getPeakDB();
|
||||
JLabel peakLabel = new JLabelFixedWidth(50, peak + "dB ");
|
||||
peakLabel.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
if (peak > 0) {
|
||||
peakLabel.setForeground(new Color(0xCC, 0x00, 0x00));
|
||||
}
|
||||
p.add(peakLabel, ctx);
|
||||
|
||||
ctx.weightx = 0.0d;
|
||||
ctx.gridx = 4;
|
||||
ctx.anchor = GridBagConstraints.LINE_END;
|
||||
p.add(time, ctx);
|
||||
|
||||
p.setOpaque(false);
|
||||
|
||||
return p;
|
||||
|
||||
} else if (value instanceof Chapter) {
|
||||
Chapter c = (Chapter)value;
|
||||
|
||||
ret.setIcon(Icons.chapter);
|
||||
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new GridBagLayout());
|
||||
GridBagConstraints ctx = new GridBagConstraints();
|
||||
|
||||
JLabel time = new JLabel(Utils.secToTime(c.getLength(), "mm:ss") + " ");
|
||||
|
||||
ctx.gridx = 0;
|
||||
ctx.gridy = 0;
|
||||
ctx.fill = GridBagConstraints.HORIZONTAL;
|
||||
ctx.anchor = GridBagConstraints.LINE_START;
|
||||
ctx.weightx = 1.0d;
|
||||
p.add(ret, ctx);
|
||||
ctx.weightx = 0.0d;
|
||||
ctx.gridx = 1;
|
||||
ctx.anchor = GridBagConstraints.LINE_END;
|
||||
p.add(time, ctx);
|
||||
p.setOpaque(false);
|
||||
return p;
|
||||
} 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;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CacheManager {
|
||||
static ArrayList<Cacheable> cache = new ArrayList<Cacheable>();
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
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 it.sauronsoftware.jave.*;
|
||||
import com.mpatric.mp3agic.*;
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
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.DocumentBuilder;
|
||||
@@ -26,7 +43,7 @@ import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
public class Chapter extends DefaultMutableTreeNode {
|
||||
public class Chapter extends BookTreeNode {
|
||||
|
||||
String name;
|
||||
String id;
|
||||
@@ -34,9 +51,11 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
int preGap;
|
||||
int postGap;
|
||||
|
||||
String notes;
|
||||
|
||||
public Chapter(String i, String chaptername) {
|
||||
super(chaptername);
|
||||
|
||||
Debug.trace();
|
||||
id = i;
|
||||
name = chaptername;
|
||||
preGap = Options.getInteger("catenation.pre-chapter");
|
||||
@@ -44,11 +63,13 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public Chapter(Element root, DefaultTreeModel model) {
|
||||
|
||||
Debug.trace();
|
||||
name = Book.getTextNode(root, "name");
|
||||
id = root.getAttribute("id");
|
||||
preGap = Utils.s2i(Book.getTextNode(root, "pre-gap"));
|
||||
postGap = Utils.s2i(Book.getTextNode(root, "post-gap"));
|
||||
|
||||
notes = Book.getTextNode(root, "notes");
|
||||
|
||||
Element sentencesNode = Book.getNode(root, "sentences");
|
||||
NodeList sentences = sentencesNode.getElementsByTagName("sentence");
|
||||
@@ -61,24 +82,29 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
Debug.trace();
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String i) {
|
||||
Debug.trace();
|
||||
id = i;
|
||||
}
|
||||
|
||||
public Sentence getLastSentence() {
|
||||
Debug.trace();
|
||||
DefaultMutableTreeNode ls = getLastLeaf();
|
||||
if (ls instanceof Sentence) return (Sentence)ls;
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Debug.trace();
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setUserObject(Object o) {
|
||||
Debug.trace();
|
||||
if (o instanceof String) {
|
||||
String so = (String)o;
|
||||
name = so;
|
||||
@@ -86,26 +112,32 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
Debug.trace();
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String n) {
|
||||
Debug.trace();
|
||||
name = n;
|
||||
}
|
||||
|
||||
public void setPreGap(int g) {
|
||||
Debug.trace();
|
||||
preGap = g;
|
||||
}
|
||||
|
||||
public int getPreGap() {
|
||||
Debug.trace();
|
||||
return preGap;
|
||||
}
|
||||
|
||||
public void setPostGap(int g) {
|
||||
Debug.trace();
|
||||
postGap = g;
|
||||
}
|
||||
|
||||
public int getPostGap() {
|
||||
Debug.trace();
|
||||
return postGap;
|
||||
}
|
||||
|
||||
@@ -113,6 +145,7 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
public void exportChapter(ProgressDialog exportDialog) throws
|
||||
FileNotFoundException, IOException, InputFormatException, NotSupportedException,
|
||||
EncoderException, UnsupportedTagException, InvalidDataException {
|
||||
Debug.trace();
|
||||
|
||||
if (getChildCount() == 0) return;
|
||||
|
||||
@@ -231,6 +264,7 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public double getChapterLength() {
|
||||
Debug.trace();
|
||||
double totalTime = Options.getInteger("audio.recording.pre-chapter") / 1000d;
|
||||
for (Enumeration s = children(); s.hasMoreElements();) {
|
||||
Sentence sentence = (Sentence)s.nextElement();
|
||||
@@ -245,6 +279,7 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public ArrayList<String> getUsedEffects() {
|
||||
Debug.trace();
|
||||
|
||||
ArrayList<String> out = new ArrayList<String>();
|
||||
|
||||
@@ -262,6 +297,7 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public void resetPostGaps() {
|
||||
Debug.trace();
|
||||
for (Enumeration s = children(); s.hasMoreElements();) {
|
||||
Sentence snt = (Sentence)s.nextElement();
|
||||
snt.resetPostGap();
|
||||
@@ -269,6 +305,7 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public void purgeBackups() {
|
||||
Debug.trace();
|
||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||
Object ob = (Object)o.nextElement();
|
||||
if (ob instanceof Sentence) {
|
||||
@@ -279,11 +316,13 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public Element getChapterXML(Document doc) {
|
||||
Debug.trace();
|
||||
Element chapterNode = doc.createElement("chapter");
|
||||
chapterNode.setAttribute("id", id);
|
||||
chapterNode.appendChild(Book.makeTextNode(doc, "name", name));
|
||||
chapterNode.appendChild(Book.makeTextNode(doc, "pre-gap", preGap));
|
||||
chapterNode.appendChild(Book.makeTextNode(doc, "post-gap", postGap));
|
||||
chapterNode.appendChild(Book.makeTextNode(doc, "notes", notes));
|
||||
|
||||
Element sentencesNode = doc.createElement("sentences");
|
||||
chapterNode.appendChild(sentencesNode);
|
||||
@@ -299,4 +338,32 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
return chapterNode;
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
Debug.trace();
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(String t) {
|
||||
Debug.trace();
|
||||
notes = t;
|
||||
}
|
||||
|
||||
public void onSelect() {
|
||||
Debug.trace();
|
||||
AudiobookRecorder.window.setChapterNotes(notes);
|
||||
}
|
||||
|
||||
public double getLength() {
|
||||
Debug.trace();
|
||||
double len = 0;
|
||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||
Object ob = (Object)o.nextElement();
|
||||
if (ob instanceof Sentence) {
|
||||
Sentence s = (Sentence)ob;
|
||||
len += s.getLength();
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ public class Clipping implements Effect {
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (double[] sample : samples) {
|
||||
if (sample[Sentence.LEFT] > clip) sample[Sentence.LEFT] = clip;
|
||||
if (sample[Sentence.LEFT] < -clip) sample[Sentence.LEFT] = -clip;
|
||||
if (sample[Sentence.RIGHT] > clip) sample[Sentence.RIGHT] = clip;
|
||||
if (sample[Sentence.RIGHT] < -clip) sample[Sentence.RIGHT] = -clip;
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
if (samples[Sentence.LEFT][i] > clip) samples[Sentence.LEFT][i] = clip;
|
||||
if (samples[Sentence.LEFT][i] < -clip) samples[Sentence.LEFT][i] = -clip;
|
||||
if (samples[Sentence.RIGHT][i] > clip) samples[Sentence.RIGHT][i] = clip;
|
||||
if (samples[Sentence.RIGHT][i] < -clip) samples[Sentence.RIGHT][i] = -clip;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
192
src/uk/co/majenko/audiobookrecorder/CommandLine.java
Normal file
192
src/uk/co/majenko/audiobookrecorder/CommandLine.java
Normal file
@@ -0,0 +1,192 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class CommandLine {
|
||||
HashMap<String, Class<?>> parameterTypes = new HashMap<String, Class<?>>();
|
||||
HashMap<String, String> parameterComments = new HashMap<String, String>();
|
||||
HashMap<String, Object> parameterValues = new HashMap<String, Object>();
|
||||
HashMap<String, String> parameterNames = new HashMap<String, String>();
|
||||
ArrayList<String> extraValues = new ArrayList<String>();
|
||||
|
||||
public CommandLine() {
|
||||
}
|
||||
|
||||
public void addParameter(String key, String name, Class<?> type, String comment) {
|
||||
parameterNames.put(key, name);
|
||||
parameterTypes.put(key, type);
|
||||
parameterComments.put(key, comment);
|
||||
}
|
||||
|
||||
public String[] process(String[] args) {
|
||||
parameterValues = new HashMap<String, Object>();
|
||||
extraValues = new ArrayList<String>();
|
||||
|
||||
for (String arg : args) {
|
||||
if (arg.startsWith("--")) {
|
||||
arg = arg.substring(2);
|
||||
String value = "";
|
||||
int equals = arg.indexOf("=");
|
||||
if (equals > -1) {
|
||||
value = arg.substring(equals + 1);
|
||||
arg = arg.substring(0, equals);
|
||||
}
|
||||
|
||||
Class<?> aclass = parameterTypes.get(arg);
|
||||
if (aclass == null) {
|
||||
help();
|
||||
System.exit(0);
|
||||
}
|
||||
if (aclass == Boolean.class) {
|
||||
Boolean b = true;
|
||||
parameterValues.put(arg, b);
|
||||
continue;
|
||||
}
|
||||
if (value.equals("")) {
|
||||
help();
|
||||
System.exit(0);
|
||||
}
|
||||
if (aclass == Integer.class) {
|
||||
Integer i = 0;
|
||||
try {
|
||||
i = Integer.parseInt(value);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
parameterValues.put(arg, i);
|
||||
continue;
|
||||
}
|
||||
if (aclass == Float.class) {
|
||||
Float f = 0F;
|
||||
try {
|
||||
f = Float.parseFloat(value);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
parameterValues.put(arg, f);
|
||||
continue;
|
||||
}
|
||||
if (aclass == Double.class) {
|
||||
Double d = 0D;
|
||||
try {
|
||||
d = Double.parseDouble(value);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
parameterValues.put(arg, d);
|
||||
continue;
|
||||
}
|
||||
if (aclass == String.class) {
|
||||
parameterValues.put(arg, value);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
extraValues.add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
return extraValues.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public void help() {
|
||||
System.out.println("Available command line arguments:");
|
||||
int maxlen = 0;
|
||||
|
||||
String[] arglist = parameterTypes.keySet().toArray(new String[0]);
|
||||
Arrays.sort(arglist);
|
||||
|
||||
for (String s : arglist) {
|
||||
int thislen = s.length();
|
||||
if (parameterTypes.get(s) != Boolean.class) {
|
||||
thislen++;
|
||||
thislen += parameterNames.get(s).length();
|
||||
}
|
||||
if (thislen > maxlen) {
|
||||
maxlen = thislen;
|
||||
}
|
||||
}
|
||||
for (String s : arglist) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
System.out.print(" --");
|
||||
sb.append(s);
|
||||
if (parameterTypes.get(s) != Boolean.class) {
|
||||
sb.append("=");
|
||||
sb.append(parameterNames.get(s));
|
||||
}
|
||||
while (sb.length() < maxlen) {
|
||||
sb.append(" ");
|
||||
}
|
||||
System.out.print(sb.toString());
|
||||
System.out.print(" ");
|
||||
System.out.println(parameterComments.get(s));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSet(String key) {
|
||||
Object value = parameterValues.get(key);
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
Class<?> type = parameterTypes.get(key);
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
if (type != String.class) {
|
||||
return null;
|
||||
}
|
||||
String value = (String)parameterValues.get(key);
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getInteger(String key) {
|
||||
Class<?> type = parameterTypes.get(key);
|
||||
if (type == null) {
|
||||
return 0;
|
||||
}
|
||||
if (type != Integer.class) {
|
||||
return 0;
|
||||
}
|
||||
Integer value = (Integer)parameterValues.get(key);
|
||||
if (value == null) {
|
||||
return 0;
|
||||
}
|
||||
return (int)value;
|
||||
}
|
||||
|
||||
public float getFloat(String key) {
|
||||
Class<?> type = parameterTypes.get(key);
|
||||
if (type == null) {
|
||||
return 0f;
|
||||
}
|
||||
if (type != Float.class) {
|
||||
return 0f;
|
||||
}
|
||||
Float value = (Float)parameterValues.get(key);
|
||||
if (value == null) {
|
||||
return 0f;
|
||||
}
|
||||
return (float)value;
|
||||
}
|
||||
|
||||
public double getDouble(String key) {
|
||||
Class<?> type = parameterTypes.get(key);
|
||||
if (type == null) {
|
||||
return 0d;
|
||||
}
|
||||
if (type != Double.class) {
|
||||
return 0d;
|
||||
}
|
||||
Double value = (Double)parameterValues.get(key);
|
||||
if (value == null) {
|
||||
return 0d;
|
||||
}
|
||||
return (double)value;
|
||||
}
|
||||
|
||||
public void set(String key, String value) {
|
||||
parameterValues.put(key, value);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.tree.AbstractLayoutCache;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.plaf.basic.BasicTreeUI;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Graphics;
|
||||
|
||||
public class CustomTreeUI extends BasicTreeUI {
|
||||
|
||||
|
||||
@@ -1,12 +1,53 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.Date;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class Debug {
|
||||
static long timestamp;
|
||||
static public boolean debugEnabled = false;
|
||||
static public boolean traceEnabled = false;
|
||||
|
||||
static void debug(String msg) {
|
||||
if (!debugEnabled) return;
|
||||
long now = System.currentTimeMillis();
|
||||
long diff = now - timestamp;
|
||||
timestamp = now;
|
||||
System.err.println(String.format("%8d - %s", diff, msg));
|
||||
}
|
||||
|
||||
static void d(Object... args) {
|
||||
if (!debugEnabled) return;
|
||||
|
||||
Thread t = Thread.currentThread();
|
||||
StackTraceElement[] st = t.getStackTrace();
|
||||
StackTraceElement caller = st[2];
|
||||
|
||||
String tag = "[" + getCurrentLocalDateTimeStamp() + "] " + caller.getFileName() + " " + caller.getLineNumber() + " (" + caller.getMethodName() + "):";
|
||||
|
||||
System.err.print(tag);
|
||||
|
||||
for (Object o : args) {
|
||||
System.err.print(" ");
|
||||
System.err.print(o);
|
||||
}
|
||||
System.err.println();
|
||||
}
|
||||
|
||||
static void trace() {
|
||||
if (!traceEnabled) return;
|
||||
Thread t = Thread.currentThread();
|
||||
StackTraceElement[] st = t.getStackTrace();
|
||||
StackTraceElement caller = st[3];
|
||||
StackTraceElement callee = st[2];
|
||||
|
||||
String tag = "[" + getCurrentLocalDateTimeStamp() + "] " + t.getName() + " - " + caller.getFileName() + ":" + caller.getLineNumber() + " " + caller.getMethodName() + "(...) -> " + callee.getFileName() + ":" + callee.getLineNumber() + " " + callee.getMethodName() + "(...)";
|
||||
|
||||
System.err.println(tag);
|
||||
}
|
||||
|
||||
public static String getCurrentLocalDateTimeStamp() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,60 +17,50 @@ public class DelayLine implements Effect {
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
double[][] savedSamples = new double[samples.length][2];
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
savedSamples[i][Sentence.LEFT] = samples[i][Sentence.LEFT];
|
||||
savedSamples[i][Sentence.RIGHT] = samples[i][Sentence.RIGHT];
|
||||
double[][] savedSamples = new double[2][samples[Sentence.LEFT].length];
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
savedSamples[Sentence.LEFT][i] = samples[Sentence.LEFT][i];
|
||||
savedSamples[Sentence.RIGHT][i] = samples[Sentence.RIGHT][i];
|
||||
}
|
||||
if (wetOnly) {
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
samples[i][Sentence.LEFT] = 0d;
|
||||
samples[i][Sentence.RIGHT] = 0d;
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
samples[Sentence.LEFT][i] = 0d;
|
||||
samples[Sentence.RIGHT][i] = 0d;
|
||||
}
|
||||
}
|
||||
|
||||
double[][] subSamples = new double[samples.length][2];
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
subSamples[i][Sentence.LEFT] = savedSamples[i][Sentence.LEFT];
|
||||
subSamples[i][Sentence.RIGHT] = savedSamples[i][Sentence.RIGHT];
|
||||
double[][] subSamples = new double[2][samples[Sentence.LEFT].length];
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
subSamples[Sentence.LEFT][i] = savedSamples[Sentence.LEFT][i];
|
||||
subSamples[Sentence.RIGHT][i] = savedSamples[Sentence.RIGHT][i];
|
||||
}
|
||||
for (DelayLineStore d : delayLines) {
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
subSamples[i][Sentence.LEFT] = savedSamples[i][Sentence.LEFT];
|
||||
subSamples[i][Sentence.RIGHT] = savedSamples[i][Sentence.RIGHT];
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
subSamples[Sentence.LEFT][i] = savedSamples[Sentence.LEFT][i];
|
||||
subSamples[Sentence.RIGHT][i] = savedSamples[Sentence.RIGHT][i];
|
||||
}
|
||||
|
||||
d.process(subSamples);
|
||||
|
||||
for (int i = 0; i < subSamples.length; i++) {
|
||||
for (int i = 0; i < subSamples[Sentence.LEFT].length; i++) {
|
||||
int off = i + d.getSamples();
|
||||
if ((off < samples.length) && (off > 0)) {
|
||||
|
||||
double[] ns = mix(samples[off], subSamples[i]);
|
||||
samples[off][Sentence.LEFT] = ns[Sentence.LEFT];
|
||||
samples[off][Sentence.RIGHT] = ns[Sentence.RIGHT];
|
||||
if ((off < samples[Sentence.LEFT].length) && (off > 0)) {
|
||||
samples[Sentence.LEFT][off] = mix(samples[Sentence.LEFT][off], subSamples[Sentence.LEFT][i]);
|
||||
samples[Sentence.RIGHT][off] = mix(samples[Sentence.RIGHT][off], subSamples[Sentence.RIGHT][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double[] mix(double[] a, double[] b) {
|
||||
double[] out = new double[2];
|
||||
double mix(double a, double b) {
|
||||
double out;
|
||||
|
||||
if ((a[Sentence.LEFT] < 0) && (b[Sentence.LEFT] < 0)) {
|
||||
out[Sentence.LEFT] = (a[Sentence.LEFT] + b[Sentence.LEFT]) - (a[Sentence.LEFT] * b[Sentence.LEFT]);
|
||||
} else if ((a[Sentence.LEFT] > 0) && (b[Sentence.LEFT] > 0)) {
|
||||
out[Sentence.LEFT] = (a[Sentence.LEFT] + b[Sentence.LEFT]) - (a[Sentence.LEFT] * b[Sentence.LEFT]);
|
||||
if ((a < 0) && (b < 0)) {
|
||||
out = (a + b) - (a * b);
|
||||
} else if ((a > 0) && (b > 0)) {
|
||||
out = (a + b) - (a * b);
|
||||
} else {
|
||||
out[Sentence.LEFT] = a[Sentence.LEFT] + b[Sentence.LEFT];
|
||||
}
|
||||
|
||||
if ((a[Sentence.RIGHT] < 0) && (b[Sentence.RIGHT] < 0)) {
|
||||
out[Sentence.RIGHT] = (a[Sentence.RIGHT] + b[Sentence.RIGHT]) - (a[Sentence.RIGHT] * b[Sentence.RIGHT]);
|
||||
} else if ((a[Sentence.RIGHT] > 0) && (b[Sentence.RIGHT] > 0)) {
|
||||
out[Sentence.RIGHT] = (a[Sentence.RIGHT] + b[Sentence.RIGHT]) - (a[Sentence.RIGHT] * b[Sentence.RIGHT]);
|
||||
} else {
|
||||
out[Sentence.RIGHT] = a[Sentence.RIGHT] + b[Sentence.RIGHT];
|
||||
out = a + b;
|
||||
}
|
||||
|
||||
return out;
|
||||
|
||||
@@ -29,16 +29,16 @@ public class DelayLineStore {
|
||||
e.process(samples);
|
||||
}
|
||||
|
||||
for (double[] sample : samples) {
|
||||
sample[Sentence.LEFT] *= gain;
|
||||
sample[Sentence.RIGHT] *= gain;
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
samples[Sentence.LEFT][i] *= gain;
|
||||
samples[Sentence.RIGHT][i] *= gain;
|
||||
|
||||
if (pan < 0) {
|
||||
double p = 1 + pan;
|
||||
sample[Sentence.RIGHT] *= p;
|
||||
samples[Sentence.RIGHT][i] *= p;
|
||||
} else {
|
||||
double p = 1 - pan;
|
||||
sample[Sentence.LEFT] *= p;
|
||||
samples[Sentence.LEFT][i] *= p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.border.*;
|
||||
import java.net.*;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextArea;
|
||||
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 DonationPanel() {
|
||||
|
||||
@@ -1,130 +1,93 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
/**
|
||||
* @author Orlando Selenu
|
||||
*
|
||||
*/
|
||||
public class FFT {
|
||||
/**
|
||||
* The Fast Fourier Transform (generic version, with NO optimizations).
|
||||
*
|
||||
* @param inputReal
|
||||
* an array of length n, the real part
|
||||
* @param inputImag
|
||||
* an array of length n, the imaginary part
|
||||
* @param DIRECT
|
||||
* TRUE = direct transform, FALSE = inverse transform
|
||||
* @return a new array of length 2n
|
||||
*/
|
||||
public static double[] fft(final double[] inputReal, double[] inputImag,
|
||||
boolean DIRECT) {
|
||||
// - n is the dimension of the problem
|
||||
// - nu is its logarithm in base e
|
||||
int n = inputReal.length;
|
||||
public static double[] fft(final double[] inputReal, double[] inputImag, boolean DIRECT) {
|
||||
int n = inputReal.length;
|
||||
|
||||
// If n is a power of 2, then ld is an integer (_without_ decimals)
|
||||
double ld = Math.log(n) / Math.log(2.0);
|
||||
double ld = Math.log(n) / Math.log(2.0);
|
||||
|
||||
// Here I check if n is a power of 2. If exist decimals in ld, I quit
|
||||
// from the function returning null.
|
||||
if (((int) ld) - ld != 0) {
|
||||
System.out.println("The number of elements is not a power of 2.");
|
||||
return null;
|
||||
}
|
||||
if (((int) ld) - ld != 0) {
|
||||
System.out.println("The number of elements is not a power of 2.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Declaration and initialization of the variables
|
||||
// ld should be an integer, actually, so I don't lose any information in
|
||||
// the cast
|
||||
int nu = (int) ld;
|
||||
int n2 = n / 2;
|
||||
int nu1 = nu - 1;
|
||||
double[] xReal = new double[n];
|
||||
double[] xImag = new double[n];
|
||||
double tReal, tImag, p, arg, c, s;
|
||||
int nu = (int) ld;
|
||||
int n2 = n / 2;
|
||||
int nu1 = nu - 1;
|
||||
double[] xReal = new double[n];
|
||||
double[] xImag = new double[n];
|
||||
double tReal, tImag, p, arg, c, s;
|
||||
|
||||
double constant;
|
||||
if (DIRECT) {
|
||||
constant = -2 * Math.PI;
|
||||
} else {
|
||||
constant = 2 * Math.PI;
|
||||
}
|
||||
|
||||
// Here I check if I'm going to do the direct transform or the inverse
|
||||
// transform.
|
||||
double constant;
|
||||
if (DIRECT)
|
||||
constant = -2 * Math.PI;
|
||||
else
|
||||
constant = 2 * Math.PI;
|
||||
for (int i = 0; i < n; i++) {
|
||||
xReal[i] = inputReal[i];
|
||||
xImag[i] = inputImag[i];
|
||||
}
|
||||
|
||||
// I don't want to overwrite the input arrays, so here I copy them. This
|
||||
// choice adds \Theta(2n) to the complexity.
|
||||
for (int i = 0; i < n; i++) {
|
||||
xReal[i] = inputReal[i];
|
||||
xImag[i] = inputImag[i];
|
||||
}
|
||||
|
||||
// First phase - calculation
|
||||
int k = 0;
|
||||
for (int l = 1; l <= nu; l++) {
|
||||
while (k < n) {
|
||||
for (int i = 1; i <= n2; i++) {
|
||||
p = bitreverseReference(k >> nu1, nu);
|
||||
// direct FFT or inverse FFT
|
||||
arg = constant * p / n;
|
||||
c = Math.cos(arg);
|
||||
s = Math.sin(arg);
|
||||
tReal = xReal[k + n2] * c + xImag[k + n2] * s;
|
||||
tImag = xImag[k + n2] * c - xReal[k + n2] * s;
|
||||
xReal[k + n2] = xReal[k] - tReal;
|
||||
xImag[k + n2] = xImag[k] - tImag;
|
||||
xReal[k] += tReal;
|
||||
xImag[k] += tImag;
|
||||
k++;
|
||||
int k = 0;
|
||||
for (int l = 1; l <= nu; l++) {
|
||||
while (k < n) {
|
||||
for (int i = 1; i <= n2; i++) {
|
||||
p = bitreverseReference(k >> nu1, nu);
|
||||
// direct FFT or inverse FFT
|
||||
arg = constant * p / n;
|
||||
c = Math.cos(arg);
|
||||
s = Math.sin(arg);
|
||||
tReal = xReal[k + n2] * c + xImag[k + n2] * s;
|
||||
tImag = xImag[k + n2] * c - xReal[k + n2] * s;
|
||||
xReal[k + n2] = xReal[k] - tReal;
|
||||
xImag[k + n2] = xImag[k] - tImag;
|
||||
xReal[k] += tReal;
|
||||
xImag[k] += tImag;
|
||||
k++;
|
||||
}
|
||||
k += n2;
|
||||
}
|
||||
k += n2;
|
||||
k = 0;
|
||||
nu1--;
|
||||
n2 /= 2;
|
||||
}
|
||||
|
||||
k = 0;
|
||||
nu1--;
|
||||
n2 /= 2;
|
||||
}
|
||||
|
||||
// Second phase - recombination
|
||||
k = 0;
|
||||
int r;
|
||||
while (k < n) {
|
||||
r = bitreverseReference(k, nu);
|
||||
if (r > k) {
|
||||
tReal = xReal[k];
|
||||
tImag = xImag[k];
|
||||
xReal[k] = xReal[r];
|
||||
xImag[k] = xImag[r];
|
||||
xReal[r] = tReal;
|
||||
xImag[r] = tImag;
|
||||
int r;
|
||||
while (k < n) {
|
||||
r = bitreverseReference(k, nu);
|
||||
if (r > k) {
|
||||
tReal = xReal[k];
|
||||
tImag = xImag[k];
|
||||
xReal[k] = xReal[r];
|
||||
xImag[k] = xImag[r];
|
||||
xReal[r] = tReal;
|
||||
xImag[r] = tImag;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
k++;
|
||||
|
||||
double[] newArray = new double[xReal.length * 2];
|
||||
double radice = 1 / Math.sqrt(n);
|
||||
for (int i = 0; i < newArray.length; i += 2) {
|
||||
int i2 = i / 2;
|
||||
newArray[i] = xReal[i2] * radice;
|
||||
newArray[i + 1] = xImag[i2] * radice;
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
|
||||
// Here I have to mix xReal and xImag to have an array (yes, it should
|
||||
// be possible to do this stuff in the earlier parts of the code, but
|
||||
// it's here to readibility).
|
||||
double[] newArray = new double[xReal.length * 2];
|
||||
double radice = 1 / Math.sqrt(n);
|
||||
for (int i = 0; i < newArray.length; i += 2) {
|
||||
int i2 = i / 2;
|
||||
// I used Stephen Wolfram's Mathematica as a reference so I'm going
|
||||
// to normalize the output while I'm copying the elements.
|
||||
newArray[i] = xReal[i2] * radice;
|
||||
newArray[i + 1] = xImag[i2] * radice;
|
||||
private static int bitreverseReference(int j, int nu) {
|
||||
int j2;
|
||||
int j1 = j;
|
||||
int k = 0;
|
||||
for (int i = 1; i <= nu; i++) {
|
||||
j2 = j1 / 2;
|
||||
k = 2 * k + j1 - 2 * j2;
|
||||
j1 = j2;
|
||||
}
|
||||
return k;
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* The reference bitreverse function.
|
||||
*/
|
||||
private static int bitreverseReference(int j, int nu) {
|
||||
int j2;
|
||||
int j1 = j;
|
||||
int k = 0;
|
||||
for (int i = 1; i <= nu; i++) {
|
||||
j2 = j1 / 2;
|
||||
k = 2 * k + j1 - 2 * j2;
|
||||
j1 = j2;
|
||||
}
|
||||
return k;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.TimerTask;
|
||||
import java.util.Timer;
|
||||
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 {
|
||||
|
||||
boolean flash = false;
|
||||
boolean col = false;
|
||||
|
||||
java.util.Timer ticker;
|
||||
Timer ticker;
|
||||
|
||||
public FlashPanel() {
|
||||
super();
|
||||
ticker = new java.util.Timer(true);
|
||||
ticker = new Timer(true);
|
||||
ticker.scheduleAtFixedRate(new TimerTask() {
|
||||
public void run() {
|
||||
if (flash) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class Icons {
|
||||
static public final ImageIcon book = new ImageIcon(Icons.class.getResource("icons/book.png"));
|
||||
@@ -39,4 +39,8 @@ public class Icons {
|
||||
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 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"));
|
||||
static public final ImageIcon close = new ImageIcon(Icons.class.getResource("icons/close.png"));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.KeyStroke;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class JButtonSpacePlay extends JButton {
|
||||
public JButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
||||
|
||||
38
src/uk/co/majenko/audiobookrecorder/JLabelFixedWidth.java
Normal file
38
src/uk/co/majenko/audiobookrecorder/JLabelFixedWidth.java
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.JSlider;
|
||||
|
||||
public class JSliderOb extends JSlider {
|
||||
Object object;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
import javax.swing.*;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class JTextFieldOb extends JTextField {
|
||||
Object object;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class JToggleButtonSpacePlay extends JToggleButton {
|
||||
public JToggleButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
||||
|
||||
@@ -14,10 +14,6 @@ public class KVPair<K,V> implements Comparable {
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
// if (o instanceof KVPair) {
|
||||
// KVPair ko = (KVPair)o;
|
||||
// return key.compareTo(ko.key);
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class LFO implements Effect {
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (double[] sample : samples) {
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
double v = 0;
|
||||
switch (waveform) {
|
||||
case SINE: v = Math.sin(phase); break;
|
||||
@@ -68,12 +68,12 @@ public class LFO implements Effect {
|
||||
// Apply it to the sample
|
||||
switch (mode) {
|
||||
case REPLACE:
|
||||
sample[Sentence.LEFT] = (sample[Sentence.LEFT] * v);
|
||||
sample[Sentence.RIGHT] = (sample[Sentence.RIGHT] * v);
|
||||
samples[Sentence.LEFT][i] = (samples[Sentence.LEFT][i] * v);
|
||||
samples[Sentence.RIGHT][i] = (samples[Sentence.RIGHT][i] * v);
|
||||
break;
|
||||
case ADD:
|
||||
sample[Sentence.LEFT] += (sample[Sentence.LEFT] * v);
|
||||
sample[Sentence.RIGHT] += (sample[Sentence.RIGHT] * v);
|
||||
samples[Sentence.LEFT][i] += (samples[Sentence.LEFT][i] * v);
|
||||
samples[Sentence.RIGHT][i] += (samples[Sentence.RIGHT][i] * v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.Color;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class MainToolBar extends JToolBar {
|
||||
|
||||
@@ -16,7 +19,6 @@ public class MainToolBar extends JToolBar {
|
||||
JButtonSpacePlay playonSentence;
|
||||
JButtonSpacePlay playtoSentence;
|
||||
JButtonSpacePlay stopPlaying;
|
||||
JButtonSpacePlay eq;
|
||||
JButtonSpacePlay openManuscript;
|
||||
JToggleButtonSpacePlay mic;
|
||||
|
||||
@@ -99,16 +101,6 @@ public class MainToolBar extends JToolBar {
|
||||
});
|
||||
add(stopPlaying);
|
||||
|
||||
addSeparator();
|
||||
eq = new JButtonSpacePlay(Icons.eq, "Reload Effects", new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
root.loadEffects();
|
||||
CacheManager.purgeCache();
|
||||
}
|
||||
});
|
||||
|
||||
add(eq);
|
||||
|
||||
addSeparator();
|
||||
|
||||
mic = new JToggleButtonSpacePlay(Icons.mic, "Enable / disable microphone", new ActionListener() {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.awt.event.*;
|
||||
|
||||
public class MarkerDragEvent {
|
||||
|
||||
Object src;
|
||||
|
||||
51
src/uk/co/majenko/audiobookrecorder/NoiseFloor.java
Normal file
51
src/uk/co/majenko/audiobookrecorder/NoiseFloor.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Color;
|
||||
|
||||
public class NoiseFloor extends JPanel {
|
||||
|
||||
int noiseFloor = 0;
|
||||
|
||||
public NoiseFloor() {
|
||||
super();
|
||||
noiseFloor = 0;
|
||||
}
|
||||
|
||||
public void setNoiseFloor(int n) {
|
||||
noiseFloor = n;
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(128, 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());
|
||||
|
||||
g.setColor(getForeground());
|
||||
g.drawString("Noise Floor: " + noiseFloor + "dB", 6, 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.JScrollPane;
|
||||
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 {
|
||||
|
||||
|
||||
@@ -1,14 +1,42 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.prefs.*;
|
||||
import java.io.*;
|
||||
import javax.swing.tree.*;
|
||||
import java.io.File;
|
||||
import java.util.TreeSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.prefs.Preferences;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.BorderLayout;
|
||||
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 {
|
||||
|
||||
@@ -16,8 +44,6 @@ public class Options extends JDialog {
|
||||
|
||||
GridBagConstraints constraint;
|
||||
|
||||
public static ArrayList<EffectGroup> effectChains;
|
||||
|
||||
JComboBox<KVPair> mixerList;
|
||||
JComboBox<KVPair> playbackList;
|
||||
JComboBox<KVPair> channelList;
|
||||
@@ -34,6 +60,7 @@ public class Options extends JDialog {
|
||||
JSpinner shortSentenceGap;
|
||||
JSpinner postParagraphGap;
|
||||
JSpinner postSectionGap;
|
||||
JSpinner maxGainVariance;
|
||||
JTextField ffmpegLocation;
|
||||
JComboBox<KVPair> bitRate;
|
||||
JComboBox<KVPair> channels;
|
||||
@@ -49,6 +76,9 @@ public class Options extends JDialog {
|
||||
|
||||
JTextField externalEditor;
|
||||
|
||||
JTextField speechCommand;
|
||||
JSpinner workerThreads;
|
||||
|
||||
JTextArea startupScript;
|
||||
|
||||
ArrayList<JTextField[]> processorList;
|
||||
@@ -68,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);
|
||||
constraint.gridx = 0;
|
||||
constraint.gridwidth = 1;
|
||||
@@ -79,6 +109,9 @@ public class Options extends JDialog {
|
||||
JComboBox<KVPair> o = new JComboBox<KVPair>(options);
|
||||
constraint.gridx = 1;
|
||||
panel.add(o, constraint);
|
||||
Tip t = new Tip(tip);
|
||||
constraint.gridx = 2;
|
||||
panel.add(t, constraint);
|
||||
|
||||
for (KVPair p : options) {
|
||||
if (p.key.equals(def)) {
|
||||
@@ -109,7 +142,7 @@ public class Options extends JDialog {
|
||||
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);
|
||||
constraint.gridx = 0;
|
||||
constraint.gridwidth = 1;
|
||||
@@ -123,13 +156,18 @@ public class Options extends JDialog {
|
||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||
panel.add(a, constraint);
|
||||
|
||||
Tip t = new Tip(tip);
|
||||
constraint.gridx = 2;
|
||||
panel.add(t, constraint);
|
||||
|
||||
|
||||
constraint.fill = GridBagConstraints.NONE;
|
||||
|
||||
constraint.gridy++;
|
||||
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);
|
||||
constraint.gridx = 0;
|
||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||
@@ -140,13 +178,18 @@ public class Options extends JDialog {
|
||||
panel.add(b, constraint);
|
||||
constraint.fill = GridBagConstraints.NONE;
|
||||
|
||||
Tip t = new Tip(tip);
|
||||
constraint.gridx = 2;
|
||||
panel.add(t, constraint);
|
||||
|
||||
|
||||
constraint.gridy++;
|
||||
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);
|
||||
constraint.gridx = 0;
|
||||
constraint.gridwidth = 1;
|
||||
@@ -208,6 +251,10 @@ public class Options extends JDialog {
|
||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||
panel.add(p, constraint);
|
||||
|
||||
Tip t = new Tip(tip);
|
||||
constraint.gridx = 2;
|
||||
panel.add(t, constraint);
|
||||
|
||||
constraint.fill = GridBagConstraints.NONE;
|
||||
|
||||
constraint.gridy++;
|
||||
@@ -234,7 +281,7 @@ public class Options extends JDialog {
|
||||
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);
|
||||
constraint.gridx = 0;
|
||||
constraint.gridwidth = 1;
|
||||
@@ -254,6 +301,10 @@ public class Options extends JDialog {
|
||||
|
||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||
panel.add(p, constraint);
|
||||
Tip t = new Tip(tip);
|
||||
constraint.gridx = 2;
|
||||
panel.add(t, constraint);
|
||||
|
||||
|
||||
constraint.fill = GridBagConstraints.NONE;
|
||||
|
||||
@@ -262,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;
|
||||
JCheckBox cb = new JCheckBox(label);
|
||||
cb.setSelected(state);
|
||||
panel.add(cb, constraint);
|
||||
Tip t = new Tip(tip);
|
||||
constraint.gridx = 2;
|
||||
panel.add(t, constraint);
|
||||
|
||||
|
||||
constraint.gridy++;
|
||||
return cb;
|
||||
}
|
||||
@@ -294,92 +350,71 @@ public class Options extends JDialog {
|
||||
|
||||
addSeparator(optionsPanel);
|
||||
|
||||
mixerList = addDropdown(optionsPanel, "Recording device:", getRecordingMixerList(), get("audio.recording.device"));
|
||||
channelList = addDropdown(optionsPanel, "Channels:", getChannelCountList(), get("audio.recording.channels"));
|
||||
rateList = addDropdown(optionsPanel, "Sample rate:", getSampleRateList(), get("audio.recording.samplerate"));
|
||||
bitDepth = addDropdown(optionsPanel, "Sample resolution:", getResolutionList(), get("audio.recording.resolution"));
|
||||
trimMethod = addDropdown(optionsPanel, "Auto-trim method:", getTrimMethods(), get("audio.recording.trim"));
|
||||
fftThreshold = addSpinner(optionsPanel, "FFT threshold:", 0, 100, 1, getInteger("audio.recording.trim.fft"), "");
|
||||
fftBlockSize = addDropdown(optionsPanel, "FFT Block size:", getFFTBlockSizes(), get("audio.recording.trim.blocksize"));
|
||||
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"), "How many channels do you want to record - stereo or mono?");
|
||||
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"), "The higher the resolution the better the quality, but the bigger the files.");
|
||||
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"), "", "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"), "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"), "", "This is how much the gain is allowed to vary by from phrase to phrase when normalizing an entire chapter.");
|
||||
|
||||
addSeparator(optionsPanel);
|
||||
|
||||
playbackList = addDropdown(optionsPanel, "Playback device:", getPlaybackMixerList(), get("audio.playback.device"));
|
||||
playbackBlockSize = addDropdown(optionsPanel, "Playback Block size:", getPlaybackBlockSizes(), get("audio.playback.blocksize"));
|
||||
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"), "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);
|
||||
storageFolder = addFilePath(optionsPanel, "Storage folder:", get("path.storage"), true);
|
||||
archiveFolder = addFilePath(optionsPanel, "Archive folder:", get("path.archive"), 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, "This is where audiobooks are archived to.");
|
||||
|
||||
addSeparator(optionsPanel);
|
||||
|
||||
preChapterGap = addSpinner(optionsPanel, "Default pre-chapter gap:", 0, 5000, 100, getInteger("catenation.pre-chapter"), "ms");
|
||||
postChapterGap = addSpinner(optionsPanel, "Default post-chapter gap:", 0, 5000, 100, getInteger("catenation.post-chapter"), "ms");
|
||||
postSentenceGap = addSpinner(optionsPanel, "Default post-sentence gap:", 0, 5000, 100, getInteger("catenation.post-sentence"), "ms");
|
||||
shortSentenceGap = addSpinner(optionsPanel, "Short post-sentence gap:", 0, 5000, 100, getInteger("catenation.short-sentence"), "ms");
|
||||
postParagraphGap = addSpinner(optionsPanel, "Default post-paragraph gap:", 0, 5000, 100, getInteger("catenation.post-paragraph"), "ms");
|
||||
postSectionGap = addSpinner(optionsPanel, "Default post-section gap:", 0, 5000, 100, getInteger("catenation.post-section"), "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", "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", "How much room noise to add between normal sentences.");
|
||||
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", "How much room noise to add between paragraphs.");
|
||||
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);
|
||||
|
||||
ffmpegLocation = addFilePath(optionsPanel, "FFMPEG location:", get("path.ffmpeg"), false);
|
||||
bitRate = addDropdown(optionsPanel, "Export bitrate:", getBitrates(), get("audio.export.bitrate"));
|
||||
channels = addDropdown(optionsPanel, "Export channels:", getChannelCountList(), get("audio.export.channels"));
|
||||
exportRate = addDropdown(optionsPanel, "Export sample rate:", getSampleRateList(), get("audio.export.samplerate"));
|
||||
ffmpegLocation = addFilePath(optionsPanel, "FFMPEG location:", get("path.ffmpeg"), false, "Path to your ffmpeg executable.");
|
||||
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"), "Mono or stereo MP3 production");
|
||||
exportRate = addDropdown(optionsPanel, "Export sample rate:", getSampleRateList(), get("audio.export.samplerate"), "Sample frequency of the produced MP3");
|
||||
|
||||
|
||||
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 minus one.");
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
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();
|
||||
startScript.setLayout(new BorderLayout());
|
||||
startScript.setBorder(new EmptyBorder(15, 15, 15, 15));
|
||||
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);
|
||||
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();
|
||||
processors.setLayout(new BorderLayout());
|
||||
@@ -404,19 +439,16 @@ public class Options extends JDialog {
|
||||
String command = get("editor.processor." + i + ".command");
|
||||
if (name == null || command == null) 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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
tabs.add("Processors", processors);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
add(tabs, BorderLayout.CENTER);
|
||||
|
||||
setTitle("Options");
|
||||
@@ -582,6 +614,7 @@ public class Options extends JDialog {
|
||||
defaultPrefs.put("catenation.post-section", "3000");
|
||||
|
||||
defaultPrefs.put("audio.recording.trim.fft", "10");
|
||||
defaultPrefs.put("audio.recording.variance", "10");
|
||||
|
||||
defaultPrefs.put("path.storage", (new File(System.getProperty("user.home"), "Recordings")).toString());
|
||||
defaultPrefs.put("path.archive", (new File(new File(System.getProperty("user.home"), "Recordings"),"archive")).toString());
|
||||
@@ -591,6 +624,8 @@ public class Options extends JDialog {
|
||||
defaultPrefs.put("audio.export.channels", "2");
|
||||
defaultPrefs.put("audio.export.samplerate", "44100");
|
||||
defaultPrefs.put("process.sphinx", "false");
|
||||
defaultPrefs.put("process.command", "speech-to-text \"%f\"");
|
||||
defaultPrefs.put("process.threads", "10");
|
||||
|
||||
defaultPrefs.put("editor.external", "");
|
||||
|
||||
@@ -598,10 +633,6 @@ public class Options extends JDialog {
|
||||
|
||||
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) {
|
||||
prefs = Preferences.userNodeForPackage(AudiobookRecorder.class);
|
||||
}
|
||||
@@ -715,16 +746,15 @@ public class Options extends JDialog {
|
||||
set("audio.export.channels", ((KVPair)channels.getSelectedItem()).key);
|
||||
set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
|
||||
set("process.sphinx", enableParsing.isSelected());
|
||||
set("process.command", speechCommand.getText());
|
||||
set("process.threads", workerThreads.getValue());
|
||||
set("editor.external", externalEditor.getText());
|
||||
set("cache.size", cacheSize.getValue());
|
||||
set("audio.recording.trim.fft", fftThreshold.getValue());
|
||||
set("audio.recording.variance", maxGainVariance.getValue());
|
||||
set("audio.recording.trim.blocksize", ((KVPair)fftBlockSize.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());
|
||||
|
||||
int procNo = 0;
|
||||
@@ -819,51 +849,4 @@ public class Options extends JDialog {
|
||||
pairs[7] = new KVPair<String, String>("131072", "131072");
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,3 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Majenko Technologies
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of Majenko Technologies nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class Overlays {
|
||||
static public final ImageIcon locked = new ImageIcon(Overlays.class.getResource("overlays/locked.png"));
|
||||
|
||||
@@ -20,13 +20,13 @@ public class Pan implements Effect {
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (double[] sample : samples) {
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
if (pan < 0) {
|
||||
double p = 1 + pan;
|
||||
sample[Sentence.RIGHT] *= p;
|
||||
samples[Sentence.RIGHT][i] *= p;
|
||||
} else {
|
||||
double p = 1 - pan;
|
||||
sample[Sentence.LEFT] *= p;
|
||||
samples[Sentence.LEFT][i] *= p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.border.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import it.sauronsoftware.jave.*;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JProgressBar;
|
||||
import java.awt.BorderLayout;
|
||||
import it.sauronsoftware.jave.MultimediaInfo;
|
||||
import it.sauronsoftware.jave.EncoderProgressListener;
|
||||
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 {
|
||||
JLabel message;
|
||||
|
||||
110
src/uk/co/majenko/audiobookrecorder/QueueMonitor.java
Normal file
110
src/uk/co/majenko/audiobookrecorder/QueueMonitor.java
Normal file
@@ -0,0 +1,110 @@
|
||||
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;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
public class QueueMonitor extends JPanel implements MouseListener {
|
||||
|
||||
ArrayList<WorkerThread> threadList = new ArrayList<WorkerThread>();
|
||||
Queue<Runnable> queue;
|
||||
|
||||
public QueueMonitor(Queue<Runnable> q) {
|
||||
super();
|
||||
queue = q;
|
||||
addMouseListener(this);
|
||||
}
|
||||
|
||||
public void addThread(WorkerThread t) {
|
||||
threadList.add(t);
|
||||
}
|
||||
|
||||
public void purgeQueue() {
|
||||
Runnable work;
|
||||
synchronized (queue) {
|
||||
while (queue.size() > 0) {
|
||||
work = queue.remove();
|
||||
if (work instanceof SentenceJob) {
|
||||
SentenceJob sj = (SentenceJob)work;
|
||||
sj.setDequeued();
|
||||
}
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(150 + (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);
|
||||
|
||||
if (queue.size() > 0) {
|
||||
Icons.close.paintIcon(this, g, size.width - 23, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent evt) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent evt) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent evt) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent evt) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if (queue.size() == 0) return; // No button - ignore it
|
||||
Dimension size = getPreferredSize();
|
||||
if (evt.getX() > (size.width - 24)) {
|
||||
purgeQueue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
17
src/uk/co/majenko/audiobookrecorder/SentenceExternalJob.java
Normal file
17
src/uk/co/majenko/audiobookrecorder/SentenceExternalJob.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.lang.Runnable;
|
||||
|
||||
public class SentenceExternalJob extends SentenceJob {
|
||||
protected int command;
|
||||
|
||||
public SentenceExternalJob(Sentence s, int c) {
|
||||
super(s);
|
||||
command = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
sentence.runExternalProcessor(command);
|
||||
}
|
||||
}
|
||||
25
src/uk/co/majenko/audiobookrecorder/SentenceJob.java
Normal file
25
src/uk/co/majenko/audiobookrecorder/SentenceJob.java
Normal 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();
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.SpinnerModel;
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
|
||||
public class SteppedNumericSpinnerModel implements SpinnerModel {
|
||||
int min;
|
||||
|
||||
115
src/uk/co/majenko/audiobookrecorder/Tip.java
Normal file
115
src/uk/co/majenko/audiobookrecorder/Tip.java
Normal 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) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
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.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 static Image getScaledImage(Image srcImg, int w, int h){
|
||||
@@ -76,4 +76,12 @@ public class Utils {
|
||||
Runtime.getRuntime().freeMemory()
|
||||
));
|
||||
}
|
||||
|
||||
public static String secToTime(double sec, String fmt) {
|
||||
Date d = new Date((long)(sec * 1000d));
|
||||
SimpleDateFormat df = new SimpleDateFormat(fmt);
|
||||
df.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
String time = df.format(d);
|
||||
return time;
|
||||
}
|
||||
}
|
||||
|
||||
77
src/uk/co/majenko/audiobookrecorder/VersionChecker.java
Normal file
77
src/uk/co/majenko/audiobookrecorder/VersionChecker.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.lang.Runnable;
|
||||
import java.net.URL;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.BufferedReader;
|
||||
import org.json.JSONObject;
|
||||
import javax.swing.JButton;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class VersionChecker implements Runnable {
|
||||
public VersionChecker() {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
URL url = new URL("https://api.github.com/repos/MajenkoProjects/AudiobookRecorder/releases/latest");
|
||||
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
|
||||
InputStream is = conn.getInputStream();
|
||||
InputStreamReader isr = new InputStreamReader(is);
|
||||
BufferedReader br = new BufferedReader(isr);
|
||||
|
||||
String inputLine;
|
||||
StringBuilder jsonData = new StringBuilder();
|
||||
|
||||
while ((inputLine = br.readLine()) != null) {
|
||||
jsonData.append(inputLine);
|
||||
}
|
||||
|
||||
br.close();
|
||||
|
||||
JSONObject job = new JSONObject(jsonData.toString());
|
||||
|
||||
String installed = AudiobookRecorder.config.getProperty("version");
|
||||
String available = job.getString("tag_name");
|
||||
if (available.startsWith("v")) {
|
||||
available = available.substring(1);
|
||||
}
|
||||
String website = job.getString("html_url");
|
||||
|
||||
|
||||
String[] installedParts = installed.split("\\.");
|
||||
String[] availableParts = available.split("\\.");
|
||||
// Must be x.y.z
|
||||
|
||||
if (installedParts.length != 3) return;
|
||||
if (availableParts.length != 3) return;
|
||||
|
||||
// Convert to xxxyyyzzz
|
||||
String installedVersion = String.format("%03d%03d%03d", Utils.s2i(installedParts[0]), Utils.s2i(installedParts[1]), Utils.s2i(installedParts[2]));
|
||||
String availableVersion = String.format("%03d%03d%03d", Utils.s2i(availableParts[0]), Utils.s2i(availableParts[1]), Utils.s2i(availableParts[2]));
|
||||
|
||||
if (Utils.s2i(installedVersion) >= Utils.s2i(availableVersion)) return;
|
||||
|
||||
System.err.println("Version installed: " + installed);
|
||||
System.err.println("Version available: " + available);
|
||||
System.err.println("URL: " + website);
|
||||
|
||||
JButton upgrade = new JButton("A new version is available.");
|
||||
upgrade.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
Utils.browse(website);
|
||||
}
|
||||
});
|
||||
|
||||
AudiobookRecorder.window.statusBar.add(upgrade);
|
||||
AudiobookRecorder.window.statusBar.revalidate();
|
||||
|
||||
} catch (Exception ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import javax.sound.sampled.*;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import javax.swing.JPanel;
|
||||
import java.util.ArrayList;
|
||||
import java.awt.Graphics;
|
||||
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 {
|
||||
|
||||
@@ -34,6 +37,8 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
int offsetFactor = 0;
|
||||
int offset = 0;
|
||||
|
||||
String loadedId = null;
|
||||
|
||||
ArrayList<MarkerDragListener> markerDragListeners;
|
||||
|
||||
public Waveform() {
|
||||
@@ -79,7 +84,7 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
|
||||
if (samples != null) {
|
||||
|
||||
int num = samples.length;
|
||||
int num = samples[Sentence.LEFT].length;
|
||||
step = num / zoomFactor / w;
|
||||
if (step == 0) return;
|
||||
|
||||
@@ -97,8 +102,8 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
double lmax = 0;
|
||||
|
||||
for (int o = 0; o < step; o++) {
|
||||
if (offset + (n * step) + o >= samples.length) break;
|
||||
double sample = (samples[offset + (n * step) + o][Sentence.LEFT] + samples[offset + (n * step) + o][Sentence.RIGHT]) / 2d;
|
||||
if (offset + (n * step) + o >= samples[Sentence.LEFT].length) break;
|
||||
double sample = (samples[Sentence.LEFT][offset + (n * step) + o] + samples[Sentence.RIGHT][offset + (n * step) + o]) / 2d;
|
||||
if (sample >= 0) {
|
||||
have += sample;
|
||||
hcnt++;
|
||||
@@ -387,4 +392,12 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
public int getCutEnd() {
|
||||
return cutExit;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
loadedId = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return loadedId;
|
||||
}
|
||||
}
|
||||
|
||||
62
src/uk/co/majenko/audiobookrecorder/WorkerThread.java
Normal file
62
src/uk/co/majenko/audiobookrecorder/WorkerThread.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user