Filtered mixers to only display compatible ones

This commit is contained in:
2018-09-11 10:51:58 +01:00
parent 25efcb553c
commit 9ef3ac930c
2 changed files with 102 additions and 11 deletions
@@ -24,6 +24,7 @@ public class Options extends JDialog {
JTextField ffmpegLocation; JTextField ffmpegLocation;
JComboBox<KVPair> bitRate; JComboBox<KVPair> bitRate;
JComboBox<KVPair> exportRate; JComboBox<KVPair> exportRate;
JCheckBox enableParsing;
static HashMap<String, String> defaultPrefs; static HashMap<String, String> defaultPrefs;
@@ -148,6 +149,16 @@ public class Options extends JDialog {
} }
JCheckBox addCheckBox(String label, boolean state) {
constraint.gridx = 1;
JCheckBox cb = new JCheckBox(label);
cb.setSelected(state);
add(cb, constraint);
constraint.gridy++;
return cb;
}
public Options(JFrame parent) { public Options(JFrame parent) {
loadPreferences(); // Just in case. It should do nothing. loadPreferences(); // Just in case. It should do nothing.
@@ -164,13 +175,13 @@ public class Options extends JDialog {
addSeparator(); addSeparator();
mixerList = addDropdown("Recording device:", getMixerList(), get("audio.recording.device")); mixerList = addDropdown("Recording device:", getRecordingMixerList(), get("audio.recording.device"));
channelList = addDropdown("Channels:", getChannelCountList(), get("audio.recording.channels")); channelList = addDropdown("Channels:", getChannelCountList(), get("audio.recording.channels"));
rateList = addDropdown("Sample rate:", getSampleRateList(), get("audio.recording.samplerate")); rateList = addDropdown("Sample rate:", getSampleRateList(), get("audio.recording.samplerate"));
addSeparator(); addSeparator();
playbackList = addDropdown("Playback device:", getMixerList(), get("audio.playback.device")); playbackList = addDropdown("Playback device:", getPlaybackMixerList(), get("audio.playback.device"));
addSeparator(); addSeparator();
storageFolder = addFilePath("Storage folder:", get("path.storage")); storageFolder = addFilePath("Storage folder:", get("path.storage"));
@@ -189,6 +200,9 @@ public class Options extends JDialog {
addSeparator(); addSeparator();
enableParsing = addCheckBox("Enable sphinx speech-to-text (**SLOW**)", getBoolean("process.sphinx"));
addSeparator();
setTitle("Options"); setTitle("Options");
@@ -232,14 +246,79 @@ public class Options extends JDialog {
setVisible(true); setVisible(true);
} }
static KVPair[] getMixerList() { static KVPair[] getRecordingMixerList() {
TreeSet<KVPair> list = new TreeSet<KVPair>(); TreeSet<KVPair> list = new TreeSet<KVPair>();
AudioFormat stereoFormat = new AudioFormat(44100f, 16, 2, true, false);
AudioFormat monoFormat = new AudioFormat(44100f, 16, 2, true, false);
DataLine.Info stereoDIF = new DataLine.Info(TargetDataLine.class, stereoFormat);
DataLine.Info monoDIF = new DataLine.Info(TargetDataLine.class, monoFormat);
Mixer.Info[] info = AudioSystem.getMixerInfo(); Mixer.Info[] info = AudioSystem.getMixerInfo();
for (Mixer.Info i : info) { for (Mixer.Info i : info) {
Mixer m = AudioSystem.getMixer(i);
boolean supported = false;
Line l;
try {
l = m.getLine(stereoDIF);
supported = true;
} catch (Exception e) {
}
try {
l = m.getLine(monoDIF);
supported = true;
} catch (Exception e) {
}
if (supported) {
KVPair p = new KVPair(i.getName(), i.getDescription()); KVPair p = new KVPair(i.getName(), i.getDescription());
list.add(p); list.add(p);
} }
}
return list.toArray(new KVPair[0]);
}
static KVPair[] getPlaybackMixerList() {
TreeSet<KVPair> list = new TreeSet<KVPair>();
AudioFormat stereoFormat = new AudioFormat(44100f, 16, 2, true, false);
AudioFormat monoFormat = new AudioFormat(44100f, 16, 2, true, false);
DataLine.Info stereoDIF = new DataLine.Info(SourceDataLine.class, stereoFormat);
DataLine.Info monoDIF = new DataLine.Info(SourceDataLine.class, monoFormat);
Mixer.Info[] info = AudioSystem.getMixerInfo();
for (Mixer.Info i : info) {
Mixer m = AudioSystem.getMixer(i);
boolean supported = false;
Line l;
try {
l = m.getLine(stereoDIF);
supported = true;
} catch (Exception e) {
}
try {
l = m.getLine(monoDIF);
supported = true;
} catch (Exception e) {
}
if (supported) {
KVPair p = new KVPair(i.getName(), i.getDescription());
list.add(p);
}
}
return list.toArray(new KVPair[0]); return list.toArray(new KVPair[0]);
} }
@@ -262,12 +341,13 @@ public class Options extends JDialog {
defaultPrefs = new HashMap<String, String>(); defaultPrefs = new HashMap<String, String>();
KVPair[] mixers = getMixerList(); KVPair[] recordingMixers = getRecordingMixerList();
KVPair[] playbackMixers = getPlaybackMixerList();
defaultPrefs.put("audio.recording.device", mixers[0].key); defaultPrefs.put("audio.recording.device", recordingMixers[0].key);
defaultPrefs.put("audio.recording.channels", "2"); defaultPrefs.put("audio.recording.channels", "2");
defaultPrefs.put("audio.recording.samplerate", "48000"); defaultPrefs.put("audio.recording.samplerate", "48000");
defaultPrefs.put("audio.playback.device", mixers[0].key); defaultPrefs.put("audio.playback.device", playbackMixers[0].key);
defaultPrefs.put("catenation.pre-chapter", "2000"); defaultPrefs.put("catenation.pre-chapter", "2000");
defaultPrefs.put("catenation.post-chapter", "2000"); defaultPrefs.put("catenation.post-chapter", "2000");
@@ -279,6 +359,8 @@ public class Options extends JDialog {
defaultPrefs.put("audio.export.bitrate", "256000"); defaultPrefs.put("audio.export.bitrate", "256000");
defaultPrefs.put("audio.export.samplerate", "44100"); defaultPrefs.put("audio.export.samplerate", "44100");
defaultPrefs.put("process.sphinx", "false");
if (prefs == null) { if (prefs == null) {
prefs = Preferences.userNodeForPackage(AudiobookRecorder.class); prefs = Preferences.userNodeForPackage(AudiobookRecorder.class);
} }
@@ -310,6 +392,16 @@ public class Options extends JDialog {
return 0; return 0;
} }
public static boolean getBoolean(String key) {
String v = get(key);
if (v == null) return false;
if (v.equals("true")) return true;
if (v.equals("t")) return true;
if (v.equals("yes")) return true;
if (v.equals("y")) return true;
return false;
}
public static void set(String key, String value) { public static void set(String key, String value) {
if (prefs == null) return; if (prefs == null) return;
prefs.put(key, value); prefs.put(key, value);
@@ -327,6 +419,7 @@ public class Options extends JDialog {
set("catenation.post-sentence", "" + postSentenceGap.getValue()); set("catenation.post-sentence", "" + postSentenceGap.getValue());
set("audio.export.bitrate", ((KVPair)bitRate.getSelectedItem()).key); set("audio.export.bitrate", ((KVPair)bitRate.getSelectedItem()).key);
set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key); set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
set("process.sphinx", enableParsing.isSelected() ? "true" : "false");
savePreferences(); savePreferences();
} }
@@ -437,8 +437,7 @@ public class Sentence extends DefaultMutableTreeNode {
public void recognise() { public void recognise() {
return; if (!Options.getBoolean("process.sphinx")) return;
/*
Thread t = new Thread(new Runnable() { Thread t = new Thread(new Runnable() {
@@ -503,7 +502,6 @@ public class Sentence extends DefaultMutableTreeNode {
}); });
t.start(); t.start();
*/
} }
public void setLocked(boolean l) { public void setLocked(boolean l) {