Skip to content

Commit

Permalink
fixing midi2mp3 and mei2midimeico
Browse files Browse the repository at this point in the history
  • Loading branch information
anneferger committed Mar 15, 2023
1 parent e3cfba3 commit c5e1919
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 14 deletions.
41 changes: 40 additions & 1 deletion src/main/java/de/edirom/meigarage/meico/Conversion.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
53 changes: 41 additions & 12 deletions src/main/java/de/edirom/meigarage/meico/MeicoConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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())) {
Expand All @@ -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()) &&
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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<meico.midi.Midi> 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");
}
Expand All @@ -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() {
Expand Down

0 comments on commit c5e1919

Please sign in to comment.