use of com.xenoage.utils.jse.io.JseOutputStream in project Zong by Xenoage.
the class OggScoreFileOutput method writeOgg.
/**
* Writes the given score as a OGG Vorbis file into the given stream.
*/
public static void writeOgg(Score score, OutputStream stream) throws IOException {
// save temporary WAVE file first
File tempFile = File.createTempFile(OggScoreFileOutput.class.getName(), ".wav");
try (OutputStream tempStream = new JseOutputStream(tempFile)) {
WavScoreFileOutput.writeWav(score, tempStream);
}
// convert to ogg
VorbisEncoder.convert(tempFile.getAbsolutePath(), new JseOutputStream(stream));
tempFile.delete();
}
use of com.xenoage.utils.jse.io.JseOutputStream in project Zong by Xenoage.
the class WavScoreFileOutput method writeWav.
/**
* Writes the given score as a WAV file into the given stream.
*/
public static void writeWav(Score score, OutputStream stream) throws IOException {
// save WAVE file
try {
// create midi sequence
MidiSequence<Sequence> sequence = MidiConverter.convertToSequence(score, optionsForFileExport, new JseMidiSequenceWriter());
// for all instruments
MidiToWaveRenderer.render(SynthManager.getSoundbank(), sequence.getSequence(), null, new JseOutputStream(stream));
} catch (Exception ex) {
INSTANCE.log(Companion.warning(ex));
throw new IOException(ex);
}
}
use of com.xenoage.utils.jse.io.JseOutputStream in project Zong by Xenoage.
the class MidiScoreFileOutput method writeMidi.
/**
* Writes the given score as a MIDI file into the given stream.
*/
public static void writeMidi(Score score, OutputStream stream) throws IOException {
Sequence sequence = MidiConverter.convertToSequence(score, optionsForFileExport, new JseMidiSequenceWriter()).getSequence();
int type = MidiScoreFileOutput.getPreferredMidiType(sequence);
MidiSystem.write(sequence, type, new JseOutputStream(stream));
}
use of com.xenoage.utils.jse.io.JseOutputStream in project Zong by Xenoage.
the class Mp3ScoreFileOutput method writeMp3.
/**
* Writes the given score as a MP3 into the given stream.
*/
public static void writeMp3(Score score, OutputStream stream) throws IOException {
// look if LAME is installed
try {
Runtime.getRuntime().exec("lame");
} catch (Exception ex) {
handle(Companion.warning(Lang.get(Voc.CouldNotFindLAME, Zong.INSTANCE.getWebsite() + "/lame")));
}
// save temporary WAVE file first
File tempWAVFile = File.createTempFile(Mp3ScoreFileOutput.class.getName(), ".wav");
try (OutputStream tempStream = new JseOutputStream(tempWAVFile)) {
WavScoreFileOutput.writeWav(score, tempStream);
}
// create temporary MP3 file
File tempMP3File = File.createTempFile(Mp3ScoreFileOutput.class.getName(), ".mp3");
// convert to MP3
try {
Process process = new ProcessBuilder("lame", tempWAVFile.getAbsolutePath(), tempMP3File.getAbsolutePath()).start();
if (debugToConsole) {
// forward LAME error output to console
try (BufferedReader br = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
}
process.waitFor();
int exitValue = process.exitValue();
if (exitValue != 0)
throw new IOException("LAME process returned: " + exitValue);
tempWAVFile.delete();
// copy MP3 file to output stream
try (JseOutputStream mp3Stream = new JseOutputStream(stream)) {
JseFileUtils.copyFileToStream(tempMP3File, mp3Stream);
}
tempMP3File.delete();
} catch (Exception ex) {
tempWAVFile.delete();
tempMP3File.delete();
throw new IOException(ex);
}
}
use of com.xenoage.utils.jse.io.JseOutputStream in project Zong by Xenoage.
the class MusicXmlMassTest method testFile.
// */
private boolean testFile(File file) {
try {
// Load the file
// TIDY
ScoreDocFactory.setErrorLayoutEnabled(false);
ScoreDoc score = new MusicXmlScoreDocFileInput().read(new JseInputStream(file), file.getAbsolutePath());
// TIDY
ScoreDocFactory.setErrorLayoutEnabled(true);
// Check layout of loaded file
if (checkLayout) {
checkLayout(score, file.getName());
}
// Save it as MusicXML
File mxlSavedFile = getTempOutputPath(file, "-saved.mxl");
if (saveAsMxl) {
// new MusicXMLScoreDocFileOutput().write(score, new FileOutputStream(mxlSavedFile), mxlSavedFile);
}
// Save it as PDF
if (saveAsPdf) {
File pdfFile = getTempOutputPath(file, ".pdf");
new PdfScoreDocFileOutput().write(score, 0, new JseOutputStream(pdfFile));
}
// Save it as MIDI
if (saveAsMid) {
File midFile = getTempOutputPath(file, ".mid");
new MidiScoreDocFileOutput().write(score, 0, new JseOutputStream(midFile));
}
// Load it from saved MusicXML
if (loadFromSavedMxl) {
// TODO
}
// Success
System.out.print("OK: " + file.toString().substring(dir.length()) + " (" + score.getScore().getInfo().getTitle() + ")");
@SuppressWarnings("unchecked") List<String> errorMessages = (List<String>) score.getScore().getMetaData().get("mxlerrors");
if (errorMessages != null)
System.out.print(" ! " + errorMessages.size() + " warning(s)");
System.out.println();
return true;
} catch (Throwable ex) {
ex.printStackTrace();
// fail("Failed to load file: " + file);
System.out.println("fail: " + file.toString().substring(dir.length()));
return false;
}
}
Aggregations