diff --git a/src/main/java/de/edirom/meigarage/meico/Conversion.java b/src/main/java/de/edirom/meigarage/meico/Conversion.java index 9d7460f..21c2ebd 100644 --- a/src/main/java/de/edirom/meigarage/meico/Conversion.java +++ b/src/main/java/de/edirom/meigarage/meico/Conversion.java @@ -31,7 +31,7 @@ public enum Conversion { true, // "visible as input" 9 // "cost" ), - MEI40TOMIDI( + MEI40TOMIDIMEICO( "mei40tomidimeico", // "id" "text/xml", // "input mime type" "mei40", // "input format id" @@ -44,6 +44,19 @@ public enum Conversion { true, // "visible as input" 9 // "cost" ), + MEI40TOMP3( + "mei40tomp3meico", // "id" + "text/xml", // "input mime type" + "mei40", // "input format id" + "MEI 4.0 (2018) Document", // "input description" + "score", // "input type" (score, audio, image, customization) + "audio/mp3", // "output mime type" + "mp3", // "output format id" + "MP3 audio file (MP3)", // "output description" + "audio", // "output type" (score, audio, image, customization) + true, // "visible as input" + 9 // "cost" + ), MIDITOMSM( "miditomsm", // "id" "audio/x-midi", // "input mime type" @@ -70,6 +83,19 @@ public enum Conversion { true, // "visible as input" 9 // "cost" ), + MIDIMEICOTOMP3( + "miditomp3", // "id" + "audio/x-midi", // "input mime type" + "midi-meico", // "input format id" + "Musical Instrument Digital Interface (MIDI)", // "input description" + "audio", // "input type" (score, audio, image, customization) + "audio/mp3", // "output mime type" + "mp3", // "output format id" + "MP3 audio file (MP3)", // "output description" + "audio", // "output type" (score, audio, image, customization) + true, // "visible as input" + 9 // "cost" + ), MEI30TOMSM( "mei30tomsm", // "id" "text/xml", // "input mime type" @@ -108,6 +134,19 @@ public enum Conversion { "score", // "output type" (score, audio, image, customization) true, // "visible as input" 9 // "cost" + ), + MEI30TOMP3( + "mei30tomp3meico", // "id" + "text/xml", // "input mime type" + "mei30", // "input format id" + "MEI 3.0 (2016) Document", // "input description" + "score", // "input type" (score, audio, image, customization) + "audio/mp3", // "output mime type" + "mp3", // "output format id" + "MP3 audio file (MP3)", // "output description" + "audio", // "output type" (score, audio, image, customization) + true, // "visible as input" + 9 // "cost" ); // abc, darms, mei, pae, xml diff --git a/src/main/java/de/edirom/meigarage/meico/ConverterConfiguration.java b/src/main/java/de/edirom/meigarage/meico/ConverterConfiguration.java index a388140..99b0268 100644 --- a/src/main/java/de/edirom/meigarage/meico/ConverterConfiguration.java +++ b/src/main/java/de/edirom/meigarage/meico/ConverterConfiguration.java @@ -23,12 +23,13 @@ public class ConverterConfiguration { static { CONVERSIONS.add(getConversionActionArgument(Conversion.MEI40TOMSM)); CONVERSIONS.add(getConversionActionArgument(Conversion.MEI40TOMPM)); - CONVERSIONS.add(getConversionActionArgument(Conversion.MEI40TOMIDI)); + CONVERSIONS.add(getConversionActionArgument(Conversion.MEI40TOMIDIMEICO)); CONVERSIONS.add(getConversionActionArgument(Conversion.MIDITOMSM)); CONVERSIONS.add(getConversionActionArgument(Conversion.MIDITOMP3)); CONVERSIONS.add(getConversionActionArgument(Conversion.MEI30TOMSM)); CONVERSIONS.add(getConversionActionArgument(Conversion.MEI30TOMPM)); CONVERSIONS.add(getConversionActionArgument(Conversion.MEI30TOMIDI)); + CONVERSIONS.add(getConversionActionArgument(Conversion.MIDIMEICOTOMP3)); } private static ConversionActionArguments getConversionActionArgument(Conversion format) { diff --git a/src/main/java/de/edirom/meigarage/meico/MeicoConverter.java b/src/main/java/de/edirom/meigarage/meico/MeicoConverter.java index fc1b6d0..4d1260a 100644 --- a/src/main/java/de/edirom/meigarage/meico/MeicoConverter.java +++ b/src/main/java/de/edirom/meigarage/meico/MeicoConverter.java @@ -13,6 +13,7 @@ import pl.psnc.dl.ege.exception.ConverterException; import pl.psnc.dl.ege.types.ConversionActionArguments; import pl.psnc.dl.ege.types.DataType; +import pl.psnc.dl.ege.utils.EGEIOUtils; import pl.psnc.dl.ege.utils.IOResolver; import java.io.*; @@ -83,11 +84,16 @@ else if (fromDataType.getFormat().equals(Conversion.MEI40TOMPM.getIFormatId()) & } // MEI 4.0 to MIDI - else if (fromDataType.getFormat().equals(Conversion.MEI40TOMIDI.getIFormatId()) && - toDataType.getFormat().equals(Conversion.MEI40TOMIDI.getOFormatId())) { + else if (fromDataType.getFormat().equals(Conversion.MEI40TOMIDIMEICO.getIFormatId()) && + toDataType.getFormat().equals(Conversion.MEI40TOMIDIMEICO.getOFormatId())) { performMeicoTransformation(inputStream, outputStream, "mei40", "midi", properties, tempDir); } + // MEI4.0 to MP3 MEI40TOMP3 + else if(fromDataType.getFormat().equals(Conversion.MEI40TOMP3.getIFormatId()) && + toDataType.getFormat().equals(Conversion.MEI40TOMP3.getOFormatId())) { + performMeicoTransformation(inputStream, outputStream, "mei40", "mp3", properties, tempDir); + } // MIDITOMSM else if (fromDataType.getFormat().equals(Conversion.MIDITOMSM.getIFormatId()) && toDataType.getFormat().equals(Conversion.MIDITOMSM.getOFormatId())) { @@ -99,6 +105,12 @@ else if (fromDataType.getFormat().equals(Conversion.MIDITOMP3.getIFormatId()) && toDataType.getFormat().equals(Conversion.MIDITOMP3.getOFormatId())) { performMeicoTransformation(inputStream, outputStream, "midi", "mp3", properties, tempDir); + } + //MIDIMEICOTOMP3 + else if (fromDataType.getFormat().equals(Conversion.MIDIMEICOTOMP3.getIFormatId()) && + toDataType.getFormat().equals(Conversion.MIDIMEICOTOMP3.getOFormatId())) { + performMeicoTransformation(inputStream, outputStream, "midi", "mp3", properties, tempDir); + } //MEI30TOMSM else if (fromDataType.getFormat().equals(Conversion.MEI30TOMSM.getIFormatId()) && @@ -118,6 +130,11 @@ else if (fromDataType.getFormat().equals(Conversion.MEI30TOMPM.getIFormatId()) & performMeicoTransformation(inputStream, outputStream, "mei30", "midi", properties, tempDir); } + // MEI3.0 to MP3 MEI30TOMP3 + else if(fromDataType.getFormat().equals(Conversion.MEI30TOMP3.getIFormatId()) && + toDataType.getFormat().equals(Conversion.MEI30TOMP3.getOFormatId())) { + performMeicoTransformation(inputStream, outputStream, "mei30", "mp3", properties, tempDir); + } } private void performMeicoTransformation(InputStream inputStream, OutputStream outputStream, @@ -126,7 +143,6 @@ private void performMeicoTransformation(InputStream inputStream, OutputStream ou File inTmpDir = null; File outTempDir = null; - InputStream is = null; try { inTmpDir = prepareTempDir(tempDir); ior.decompressStream(inputStream, inTmpDir); @@ -159,18 +175,36 @@ private void performMeicoTransformation(InputStream inputStream, OutputStream ou for (int i = 0; i < midis.size(); ++i) { midis.get(i).writeMidi(outTempDir.getPath() + "/" + midis.get(i).getFile().getName()); // write midi file to the file system } - } else { + } + else if (outputFormat.equals("mp3")) { + List midis = new ArrayList<>(); + for (int i = 0; i < msmpms.getKey().size(); ++i) { + midis.add(msmpms.getKey().get(i).exportExpressiveMidi(msmpms.getValue().get(i).getPerformance(0))); // convert msm + mpm to expressive midi; + } + for (int i = 0; i < midis.size(); ++i) { + Audio audio = midis.get(i).exportAudio(); + audio.writeMp3(outTempDir.getPath() + "/" + audio.getFile().getName().substring(0, audio.getFile().getName().lastIndexOf(".")) + ".mp3"); // write midi file to the file system + } + } else { LOGGER.error("Output format" + outputFormat + "not available"); } } else if (inputFormat.equals("midi")) { Midi midi = new Midi(inputFile); - if (outputFormat.equals("msm")) { Msm msm = midi.exportMsm(); msm.writeMsm(outTempDir.getPath() + "/" + msm.getFile().getName()); } else if (outputFormat.equals("mp3")) { Audio audio = midi.exportAudio(); // mittels exportAudio(soundbank) kannst Du auch andere Instrumentenklänge verwenden - audio.writeMp3(outTempDir.getPath() + "/" + audio.getFile().getName().substring(0, audio.getFile().getName().lastIndexOf(".")) + ".mp3"); + byte[] mp3 = audio.getAudioAsMp3(); + String path = outTempDir.getPath() + "/" + audio.getFile().getName().substring(0, audio.getFile().getName().lastIndexOf(".")) + ".mp3"; + //audio.writeMp3(path); + //not using meico writing method for audio because it caused errors on rancher setup + File outputFile = new File(path); + LOGGER.info("starting to write audio file to disk"); + try (FileOutputStream outputStream2 = new FileOutputStream(outputFile)) { + outputStream2.write(mp3); + } + LOGGER.info("written audio file to " + path); } else { LOGGER.error("Output format" + outputFormat + "not available"); } @@ -192,14 +226,9 @@ private void performMeicoTransformation(InputStream inputStream, OutputStream ou //EGEIOUtils.deleteDirectory(outTempDir) ; if (inTmpDir != null && inTmpDir.exists()) - //EGEIOUtils.deleteDirectory(inTmpDir) + EGEIOUtils.deleteDirectory(inTmpDir) ; } - try { - is.close(); - } catch (Exception ex) { - // do nothing - } } private File prepareTempDir() {