Skip to content

Commit

Permalink
Make Sound.list() compatible with Java < 11 (see #95)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinstadler committed Dec 21, 2023
1 parent a84c5d7 commit 09b69b7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/processing/sound/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,17 @@ private static int longestDeviceNameLength(int[] deviceIds) {
return longestLength;
}

private static String deviceNameTableDivider(int longestDeviceNameLength) {
return String.format("%" + (longestDeviceNameLength+2) + "s", "").replace(' ', '-');
}

private static void printDeviceTable(int[] deviceIds) {
AudioDeviceManager audioManager = Sound.getAudioDeviceManager();
int longestLength = Sound.longestDeviceNameLength(deviceIds);
String lineFormat = " %-3s %3s | %-" + longestLength + "s | %6s | %4s%n";

System.out.format(lineFormat, "", "id", "Device name", "inputs", "outputs");
System.out.println(" ----+" + "-".repeat(longestLength+2) + "+--------".repeat(2));
System.out.println(" ----+" + Sound.deviceNameTableDivider(longestLength) + "+--------".repeat(2));
for (int i : deviceIds) {
System.out.format(lineFormat,
Engine.getEngine().inputDevice == i ? (Engine.getEngine().outputDevice == i ? "I,O" : "I") :
Expand All @@ -145,13 +149,13 @@ private static void printDeviceTable(int[] inputDeviceIds, int[] outputDeviceIds
String lineFormat = " %1s %3s | %-" + longestLength + "s | %4s%n";

System.out.format(lineFormat, " ", "id", "Input device name", "inputs");
System.out.println(" ----+" + "-".repeat(longestLength+2) + "+--------");
System.out.println(" ----+" + Sound.deviceNameTableDivider(longestLength) + "+--------");
for (int i : inputDeviceIds) {
System.out.format(lineFormat, Engine.getEngine().inputDevice == i ? "I" : " ", i, Engine.getEngine().getDeviceName(i), audioManager.getMaxInputChannels(i));
}
System.out.println();
System.out.format(lineFormat, " ", "id", "Output device name", "outputs");
System.out.println(" ----+" + "-".repeat(longestLength+2) + "+--------");
System.out.println(" ----+" + Sound.deviceNameTableDivider(longestLength) + "+--------");
for (int i : outputDeviceIds) {
System.out.format(lineFormat, Engine.getEngine().outputDevice == i ? "O" : " ", i, Engine.getEngine().getDeviceName(i), audioManager.getMaxOutputChannels(i));
}
Expand Down

0 comments on commit 09b69b7

Please sign in to comment.