8140620: Find and load default.sf2 as the default soundbank on Linux
authoromajid
Tue, 27 Oct 2015 15:19:15 -0400
changeset 33852 5072049a858d
parent 33851 8c60451ba63a
child 33853 a26aa530a23a
8140620: Find and load default.sf2 as the default soundbank on Linux Reviewed-by: serb
jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftSynthesizer.java
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftSynthesizer.java	Tue Oct 27 14:16:24 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftSynthesizer.java	Tue Oct 27 15:19:15 2015 -0400
@@ -671,6 +671,40 @@
             actions.add(new PrivilegedAction<InputStream>() {
                 public InputStream run() {
                     if (System.getProperties().getProperty("os.name")
+                            .startsWith("Linux")) {
+
+                        File[] systemSoundFontsDir = new File[] {
+                            /* Arch, Fedora, Mageia */
+                            new File("/usr/share/soundfonts/"),
+                            new File("/usr/local/share/soundfonts/"),
+                            /* Debian, Gentoo, OpenSUSE, Ubuntu */
+                            new File("/usr/share/sounds/sf2/"),
+                            new File("/usr/local/share/sounds/sf2/"),
+                        };
+
+                        /*
+                         * Look for a default.sf2
+                         */
+                        for (File systemSoundFontDir : systemSoundFontsDir) {
+                            if (systemSoundFontDir.exists()) {
+                                File defaultSoundFont = new File(systemSoundFontDir, "default.sf2");
+                                if (defaultSoundFont.exists()) {
+                                    try {
+                                        return new FileInputStream(defaultSoundFont);
+                                    } catch (IOException e) {
+                                        // continue with lookup
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    return null;
+                }
+            });
+
+            actions.add(new PrivilegedAction<InputStream>() {
+                public InputStream run() {
+                    if (System.getProperties().getProperty("os.name")
                             .startsWith("Windows")) {
                         File gm_dls = new File(System.getenv("SystemRoot")
                                 + "\\system32\\drivers\\gm.dls");