Add audio codec for Impulse Tracker Modules.
[demoscenemusic.git] / src / main / java / net / pterodactylus / demoscenemusic / utils / AudioCodecs.java
index f09e79f..04d23b8 100644 (file)
@@ -38,6 +38,36 @@ public class AudioCodecs {
                codecDescriptions.put("wav", new AudioCodecDescription("wav", "Waveform Audio", "WAV", "audio/vnc.wave", true, true));
                codecDescriptions.put("mod", new AudioCodecDescription("mod", "Module", "MOD", "audio/mod", false, true));
                codecDescriptions.put("ft2", new AudioCodecDescription("ft2", "FastTracker II Module", "XM", "audio/xm", false, true));
+               codecDescriptions.put("it",  new AudioCodecDescription("it", "Impulse Tracker Module", "IT", "audio/it", false, true));
+       }
+
+       /**
+        * Tries to automatically detect the audio codec from the filename. In most
+        * cases this will match the {@link AudioCodecDescription#code} of the codec
+        * but in some cases other extensions are possible, too. Also, on Amiga
+        * filenames usually start with the extension (mod files are often named
+        * ā€œmod.somethingsomethingsomethingdarksideā€).
+        *
+        * @param filename
+        *            The name of the file
+        * @return The audio codec of the file, or {@code null} if no codec could be
+        *         detected
+        */
+       public static AudioCodecDescription detect(String filename) {
+               String extension = filename.substring(filename.lastIndexOf('.') + 1).toLowerCase();
+               if (codecDescriptions.containsKey(extension)) {
+                       return codecDescriptions.get(extension);
+               }
+               if (extension.equals("ogg")) {
+                       return codecDescriptions.get("vorbis");
+               }
+               if (extension.equals("mp4")) {
+                       return codecDescriptions.get("aac");
+               }
+               if (extension.equals("xm")) {
+                       return codecDescriptions.get("ft2");
+               }
+               return null;
        }
 
        /**
@@ -94,6 +124,18 @@ public class AudioCodecs {
                        this.lossless = lossless;
                }
 
+               //
+               // OBJECT METHODS
+               //
+
+               /**
+                * {@inheritDoc}
+                */
+               @Override
+               public String toString() {
+                       return String.format("AudioCodec[%s,%s,%s,%s,%s,%s]", code, name, shortName, mimeType, streaming, lossless);
+               }
+
        }
 
 }