Skip to content

Commit

Permalink
* Fixed: Most of the created files had two dots before the file exten…
Browse files Browse the repository at this point in the history
…sion.

* Fixed: Output folder was not checked for existence when only Analyze was executed but it is required now for the log file.
* Fixed: Crash when left/right WAV files should be combined to stereo.
* DecentSampler
  * Fixed: Added workaround for absolute sample paths in dslibrary files.
* Kontakt
  * New: Improved category detection, especially for Instruments in NKM files.
* Kontakt 1/2
  * Fixed: Improved lookup of sample files which are referenced by absolute paths.
  * Fixed: Added support for file paths which include encoded UTF-8 characters in the format of %xxxx.
* Kontakt 5+
  * Fixed: File could not be read if a sound description was set.
* Attempts to write Kontakt 6.8 but still unfinished.
  • Loading branch information
git-moss committed Feb 2, 2025
1 parent 4d0b180 commit a705f7c
Show file tree
Hide file tree
Showing 63 changed files with 2,294 additions and 759 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changes

## 12.1.0

* Fixed: Most of the created files had two dots before the file extension.
* Fixed: Output folder was not checked for existence when only Analyze was executed but it is required now for the log file.
* Fixed: Crash when left/right WAV files should be combined to stereo.
* DecentSampler
* Fixed: Added workaround for absolute sample paths in dslibrary files.
* Kontakt
* New: Improved category detection, especially for Instruments in NKM files.
* Kontakt 1/2
* Fixed: Improved lookup of sample files which are referenced by absolute paths.
* Fixed: Added support for file paths which include encoded UTF-8 characters in the format of %xxxx.
* Kontakt 5+
* Fixed: File could not be read if a sound description was set.

## 12.0.0

* New: Implemented a new logging component. Much faster and does not crash anymore.
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.mossgrabers</groupId>
<artifactId>convertwithmoss</artifactId>
<version>12.0.0</version>
<version>12.1.0</version>
<packaging>jar</packaging>
<name>ConvertWithMoss</name>
<organization>
Expand Down Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>23.0.1</version>
<version>23.0.2</version>
</dependency>
<dependency>
<groupId>com.github.trilarion</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ protected static String formatDouble (final double value)
*/
protected File createUniqueFilename (final File destinationFolder, final String sampleName, final String extension)
{
final String ext = "." + extension;
final String ext = extension.isBlank () ? "" : "." + extension;
File multiFile = new File (destinationFolder, sampleName + ext);
int counter = 1;
while (multiFile.exists ())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ protected void detect (final File folder)
if (this.waitForDelivery ())
return;

for (final File file: this.listFiles (folder, this.fileEndings))
final File [] listFiles = this.listFiles (folder, this.fileEndings);
if (listFiles == null)
{
this.notifier.log ("IDS_NOT_A_DIRECTORY", folder.getAbsolutePath ());
return;
}
for (final File file: listFiles)
{
// Ignore MacOS crap
if (file.getName ().startsWith ("._"))
Expand Down Expand Up @@ -550,14 +556,15 @@ protected WavFileSampleData getFirstSample (final List<IGroup> groups)
/**
* If the sample is not found in the given folder, a search is started from one folder up and
* search recursively for the wave file.
*
*
* @param notifier Where to write logging info to
* @param folder The folder where the sample is expected
* @param previousFolder The folder in which the previous sample was found, might be null
* @param fileName The name of the sample file
* @param levels The number of levels to move upwards to start the search
* @return The sample file
*/
protected File findSampleFile (final File folder, final File previousFolder, final String fileName, final int levels)
public static File findSampleFile (final INotifier notifier, final File folder, final File previousFolder, final String fileName, final int levels)
{
final File file = new File (fileName);

Expand Down Expand Up @@ -585,13 +592,13 @@ protected File findSampleFile (final File folder, final File previousFolder, fin
}

// ... and search recursively...
this.notifier.log ("IDS_NOTIFY_SEARCH_SAMPLE_IN", startDirectory.getAbsolutePath ());
final File found = this.findSampleFileRecursively (startDirectory, sampleFile.getName ());
notifier.log ("IDS_NOTIFY_SEARCH_SAMPLE_IN", startDirectory.getAbsolutePath ());
final File found = findSampleFileRecursively (startDirectory, sampleFile.getName ());
// Returning the original file triggers the expected error...
if (found == null)
return sampleFile;

this.notifier.log ("IDS_NOTIFY_SEARCH_SAMPLE_IN_FOUND");
notifier.log ("IDS_NOTIFY_SEARCH_SAMPLE_IN_FOUND");
return found;
}

Expand All @@ -616,7 +623,7 @@ else if (file.isAbsolute ())
}


private File findSampleFileRecursively (final File folder, final String fileName)
private static File findSampleFileRecursively (final File folder, final String fileName)
{
File sampleFile = new File (folder, fileName);
if (sampleFile.exists ())
Expand All @@ -629,7 +636,7 @@ private File findSampleFileRecursively (final File folder, final String fileName
if (subFolder.isHidden () || subFolder.getName ().startsWith ("."))
continue;

sampleFile = this.findSampleFileRecursively (subFolder, fileName);
sampleFile = findSampleFileRecursively (subFolder, fileName);
if (sampleFile != null)
return sampleFile;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public abstract class AbstractFileSampleData extends AbstractSampleData implemen
protected String filename;
protected File sampleFile;
protected final File zipFile;
protected final File zipEntry;
protected final File zipEntryFile;
protected Optional<String> combinedFilename = Optional.empty ();
protected Optional<String> filenameWithoutLayer = Optional.empty ();

Expand Down Expand Up @@ -91,7 +91,7 @@ protected AbstractFileSampleData (final String filename, final File sampleFile,
this.filename = filename;
this.sampleFile = sampleFile;
this.zipFile = zipFile;
this.zipEntry = zipEntry;
this.zipEntryFile = zipEntry;
}


Expand All @@ -108,17 +108,9 @@ public void writeSample (final OutputStream outputStream) throws IOException
if (this.zipFile == null)
return;

try (final ZipFile zf = new ZipFile (this.zipFile))
try (final ZipFile zf = new ZipFile (this.zipFile); final InputStream in = zf.getInputStream (this.getHarmonizedZipEntry (zf)))
{
final String path = this.zipEntry.getPath ().replace ('\\', '/');
final ZipEntry entry = zf.getEntry (path);
if (entry == null)
throw new FileNotFoundException (Functions.getMessage ("IDS_NOTIFY_ERR_FILE_NOT_FOUND_IN_ZIP", path));

try (final InputStream in = zf.getInputStream (entry))
{
in.transferTo (outputStream);
}
in.transferTo (outputStream);
}
}

Expand All @@ -133,17 +125,9 @@ protected void createAudioMetadata () throws IOException
return;
}

try (final ZipFile zf = new ZipFile (this.zipFile))
try (final ZipFile zf = new ZipFile (this.zipFile); final InputStream in = zf.getInputStream (this.getHarmonizedZipEntry (zf)))
{
final String path = this.zipEntry.getPath ().replace ('\\', '/');
final ZipEntry entry = zf.getEntry (path);
if (entry == null)
throw new FileNotFoundException (Functions.getMessage ("IDS_NOTIFY_ERR_FILE_NOT_FOUND_IN_ZIP", path));

try (final InputStream in = zf.getInputStream (entry))
{
this.audioMetadata = AudioFileUtils.getMetadata (in);
}
this.audioMetadata = AudioFileUtils.getMetadata (in);
}
}

Expand All @@ -154,4 +138,24 @@ public String getFilename ()
{
return this.filename;
}


/**
* Get the entry in the ZIP file.
*
* @param zf The ZIP file object
* @return The entry
* @throws FileNotFoundException If the entry could not be found in the ZIP
*/
protected ZipEntry getHarmonizedZipEntry (final ZipFile zf) throws FileNotFoundException
{
String path = this.zipEntryFile.getPath ().replace ('\\', '/');
// Folders in the ZIP are always relative!
if (path.startsWith ("/"))
path = path.substring (1);
final ZipEntry zipEntry = zf.getEntry (path);
if (zipEntry == null)
throw new FileNotFoundException (Functions.getMessage ("IDS_NOTIFY_ERR_FILE_NOT_FOUND_IN_ZIP", path));
return zipEntry;
}
}
44 changes: 31 additions & 13 deletions src/main/java/de/mossgrabers/convertwithmoss/file/StreamUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,7 @@ public static int fromBytesLE (final byte [] data)
*/
public static float readFloatLE (final InputStream in) throws IOException
{
final byte [] data = in.readNBytes (4);
return ByteBuffer.wrap (data).order (ByteOrder.LITTLE_ENDIAN).getFloat ();
return readFloatLE (in.readNBytes (4));
}


Expand Down Expand Up @@ -464,27 +463,32 @@ public static float readFloatLE (final byte [] data)


/**
* Converts a N byte double value.
* Converts and writes a 4 byte float value.
*
* @param data The N byte array
* @return The double value
* @param out The output stream to write to
* @param value The float value
* @param isBigEndian True if bytes of the size number are stored big-endian otherwise
* little-endian (least significant bytes first)
* @throws IOException Data could not be written
*/
public static double readDoubleLE (final byte [] data)
public static void writeDouble (final OutputStream out, final double value, final boolean isBigEndian) throws IOException
{
return readDouble (data, false);
out.write (ByteBuffer.allocate (8).order (isBigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN).putDouble (value).array ());
}


/**
* Converts a N byte double value.
* Converts a 8 byte double value.
*
* @param data The N byte array
* @param in The input stream to read from
* @return The double value
* @param isBigEndian True if bytes of the size number are stored big-endian otherwise
* little-endian (least significant bytes first)
* @return The double value
* @throws IOException Data could not be read
*/
public static double readDouble (final byte [] data, final boolean isBigEndian)
public static double readDouble (final InputStream in, final boolean isBigEndian) throws IOException
{
final byte [] data = in.readNBytes (8);
return ByteBuffer.wrap (data).order (isBigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN).getDouble ();
}

Expand Down Expand Up @@ -767,8 +771,22 @@ public static String readUTF16 (final byte [] data, final boolean isBigEndian)
public static String readWithLengthUTF16 (final InputStream in) throws IOException
{
final int size = (int) readUnsigned32 (in, false);
final byte [] wideStringBytes = in.readNBytes (size * 2);
return new String (wideStringBytes, StandardCharsets.UTF_16LE);
return new String (in.readNBytes (size * 2), StandardCharsets.UTF_16LE);
}


/**
* Writes an UTF-16 string. The length of the string is stored in the first 4 bytes
* (little-endian). There are no null termination bytes.
*
* @param out The output stream to write to
* @param text The read string
* @throws IOException Could not read the string
*/
public static void writeWithLengthUTF16 (final OutputStream out, final String text) throws IOException
{
writeUnsigned32 (out, text.length (), false);
out.write (text.getBytes (StandardCharsets.UTF_16LE));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -16,7 +15,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import javax.sound.sampled.AudioFileFormat;
Expand Down Expand Up @@ -99,16 +97,9 @@ public void writeSample (final OutputStream outputStream) throws IOException
return;
}

try (final ZipFile zf = new ZipFile (this.zipFile))
try (final ZipFile zf = new ZipFile (this.zipFile); final InputStream inputStream = zf.getInputStream (this.getHarmonizedZipEntry (zf)))
{
final String path = this.zipEntry.getPath ().replace ('\\', '/');
final ZipEntry entry = zf.getEntry (path);
if (entry == null)
throw new FileNotFoundException (Functions.getMessage ("IDS_NOTIFY_ERR_FILE_NOT_FOUND_IN_ZIP", path));
try (final InputStream inputStream = zf.getInputStream (entry))
{
this.readConvertWrite (inputStream, outputStream);
}
this.readConvertWrite (inputStream, outputStream);
}
}

Expand Down Expand Up @@ -241,17 +232,9 @@ public AiffFile getAiffFile () throws IOException
else
{
this.aiffFile = new AiffFile ();

try (final ZipFile zf = new ZipFile (this.zipFile))
try (final ZipFile zf = new ZipFile (this.zipFile); final InputStream in = zf.getInputStream (this.getHarmonizedZipEntry (zf)))
{
final String path = this.zipEntry.getPath ().replace ('\\', '/');
final ZipEntry entry = zf.getEntry (path);
if (entry == null)
throw new FileNotFoundException (Functions.getMessage ("IDS_NOTIFY_ERR_FILE_NOT_FOUND_IN_ZIP", path));
try (final InputStream in = zf.getInputStream (entry))
{
this.aiffFile.read (in);
}
this.aiffFile.read (in);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public class TagDetector
});
CATEGORIES.put (CATEGORY_BASS, new String []
{
"Bass Guitar",
CATEGORY_BASS,
"Fretless",
"Slap",
Expand Down Expand Up @@ -219,6 +220,7 @@ public class TagDetector
CATEGORIES.put (CATEGORY_DRUM, new String []
{
CATEGORY_DRUM,
"Drum Kit",
"Drum-Set",
"Drumset",
"Cymbal",
Expand Down Expand Up @@ -250,10 +252,12 @@ public class TagDetector
"Heart",
"Stadium",
"Applause",
"Surround"
"Surround",
"Alarm"
});
CATEGORIES.put (CATEGORY_GUITAR, new String []
{
"Electric Guitar",
CATEGORY_GUITAR,
"Rajao",
"Banjo"
Expand Down Expand Up @@ -294,9 +298,11 @@ public class TagDetector
{
CATEGORY_ORCHESTRAL,
"Orchestra",
"Score"
});
CATEGORIES.put (CATEGORY_ORGAN, new String []
{
"Pipe Organ",
CATEGORY_ORGAN,
"Tonewheel",
"Accordion",
Expand Down Expand Up @@ -340,8 +346,11 @@ public class TagDetector
"Upright",
"Digital Piano",
"Klavier",
"Harpsichord",
"Spinet",
"Clav",
"Suitcase",
"SCase",
"Whirly",
"Wurlitz",
"Mark I",
Expand Down Expand Up @@ -398,6 +407,7 @@ public class TagDetector
"Analog",
"Sweep",
"Swell",
"Virus",
"Mini",
"Moog",
"Syn",
Expand Down
Loading

0 comments on commit a705f7c

Please sign in to comment.