Added trim method option in preferences

This commit is contained in:
2018-09-30 01:21:13 +01:00
parent 5f5550b166
commit d8cd72809c
4 changed files with 39 additions and 6 deletions

View File

@@ -734,6 +734,7 @@ public class AudiobookRecorder extends JFrame {
JPopupMenu menu = new JPopupMenu();
JMenuObject peak = new JMenuObject("Auto-trim all (Peak)", c);
JMenuObject fft = new JMenuObject("Auto-trim all (FFT)", c);
JMenuObject moveUp = new JMenuObject("Move Up", c);
JMenuObject moveDown = new JMenuObject("Move Down", c);
JMenu mergeWith = new JMenu("Merge chapter with");
@@ -839,6 +840,19 @@ public class AudiobookRecorder extends JFrame {
}
});
fft.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Chapter c = (Chapter)o.getObject();
for (Enumeration s = c.children(); s.hasMoreElements();) {
Sentence snt = (Sentence)s.nextElement();
if (!snt.isLocked()) {
snt.autoTrimSampleFFT();
}
}
}
});
lockAll.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
@@ -886,6 +900,7 @@ public class AudiobookRecorder extends JFrame {
menu.add(mergeWith);
menu.addSeparator();
menu.add(peak);
menu.add(fft);
menu.addSeparator();
menu.add(lockAll);
menu.add(unlockAll);
@@ -1431,7 +1446,7 @@ public class AudiobookRecorder extends JFrame {
}
ms *= 10;
ms /= 9;
ms /= 7;
return ms;
}

View File

@@ -20,6 +20,7 @@ public class Options extends JDialog {
JComboBox<KVPair> channelList;
JComboBox<KVPair> rateList;
JComboBox<KVPair> bitDepth;
JComboBox<KVPair> trimMethod;
JTextField storageFolder;
JSpinner preChapterGap;
JSpinner postChapterGap;
@@ -247,6 +248,7 @@ public class Options extends JDialog {
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"));
addSeparator(optionsPanel);
@@ -444,6 +446,7 @@ public class Options extends JDialog {
defaultPrefs.put("audio.recording.channels", "2");
defaultPrefs.put("audio.recording.samplerate", "44100");
defaultPrefs.put("audio.recording.resolution", "16");
defaultPrefs.put("audio.recording.trim", "peak");
if (playbackMixers.length > 0) {
defaultPrefs.put("audio.playback.device", playbackMixers[0].key);
} else {
@@ -589,6 +592,7 @@ public class Options extends JDialog {
set("audio.recording.channels", ((KVPair)channelList.getSelectedItem()).key);
set("audio.recording.samplerate", ((KVPair)rateList.getSelectedItem()).key);
set("audio.recording.resolution", ((KVPair)bitDepth.getSelectedItem()).key);
set("audio.recording.trim", ((KVPair)trimMethod.getSelectedItem()).key);
set("audio.playback.device", ((KVPair)playbackList.getSelectedItem()).key);
set("path.storage", storageFolder.getText());
set("path.ffmpeg", ffmpegLocation.getText());
@@ -652,4 +656,11 @@ public class Options extends JDialog {
pairs[0] = new KVPair("16", "16 Bit");
return pairs;
}
public static KVPair[] getTrimMethods() {
KVPair[] pairs = new KVPair[2];
pairs[0] = new KVPair("peak", "Peak Amplitude");
pairs[1] = new KVPair("fft", "FFT Analysis");
return pairs;
}
}

View File

@@ -149,7 +149,12 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
storedAudioData = null;
if (!id.equals("room-noise")) {
autoTrimSamplePeak();
String tm = Options.get("audio.recording.trim");
if (tm.equals("peak")) {
autoTrimSamplePeak();
} else if (tm.equals("fft")) {
autoTrimSampleFFT();
}
if (Options.getBoolean("process.sphinx")) {
recognise();
}
@@ -256,6 +261,8 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
end = i;
}
end++;
if (end <= 0) {
end = blocks - 1;
}

View File

@@ -185,13 +185,13 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
public void mousePressed(MouseEvent e) {
int x = e.getX();
if ((x >= ((leftMarker - offset)/step) - 2) && (x <= ((leftMarker - offset)/step) + 2)) {
if ((x >= ((leftMarker - offset)/step) - 10) && (x <= ((leftMarker - offset)/step) + 10)) {
leftMarkerSaved = leftMarker;
rightMarkerSaved = rightMarker;
dragging = 1;
return;
}
if ((x >= ((rightMarker - offset)/step) - 2) && (x <= ((rightMarker - offset)/step) + 2)) {
if ((x >= ((rightMarker - offset)/step) - 10) && (x <= ((rightMarker - offset)/step) + 10)) {
rightMarkerSaved = rightMarker;
leftMarkerSaved = leftMarker;
dragging = 2;
@@ -219,11 +219,11 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
public void mouseMoved(MouseEvent e) {
int x = e.getX();
if ((x >= ((leftMarker - offset)/step) - 2) && (x <= ((leftMarker - offset)/step) + 2)) {
if ((x >= ((leftMarker - offset)/step) - 10) && (x <= ((leftMarker - offset)/step) + 10)) {
setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
return;
}
if ((x >= ((rightMarker - offset)/step) - 2) && (x <= ((rightMarker - offset)/step) + 2)) {
if ((x >= ((rightMarker - offset)/step) - 10) && (x <= ((rightMarker - offset)/step) + 10)) {
setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
return;
}