Search in sources :

Example 1 with JseOutputStream

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();
}
Also used : OutputStream(com.xenoage.utils.io.OutputStream) JseOutputStream(com.xenoage.utils.jse.io.JseOutputStream) JseOutputStream(com.xenoage.utils.jse.io.JseOutputStream) File(java.io.File)

Example 2 with JseOutputStream

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);
    }
}
Also used : JseOutputStream(com.xenoage.utils.jse.io.JseOutputStream) JseMidiSequenceWriter(com.xenoage.zong.desktop.io.midi.out.JseMidiSequenceWriter) MidiSequence(com.xenoage.zong.io.midi.out.MidiSequence) Sequence(javax.sound.midi.Sequence) IOException(java.io.IOException) IOException(java.io.IOException)

Example 3 with JseOutputStream

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));
}
Also used : JseOutputStream(com.xenoage.utils.jse.io.JseOutputStream) Sequence(javax.sound.midi.Sequence)

Example 4 with JseOutputStream

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) OutputStream(com.xenoage.utils.io.OutputStream) JseOutputStream(com.xenoage.utils.jse.io.JseOutputStream) JseOutputStream(com.xenoage.utils.jse.io.JseOutputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Example 5 with JseOutputStream

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;
    }
}
Also used : MusicXmlScoreDocFileInput(com.xenoage.zong.desktop.io.musicxml.in.MusicXmlScoreDocFileInput) JseInputStream(com.xenoage.utils.jse.io.JseInputStream) JseOutputStream(com.xenoage.utils.jse.io.JseOutputStream) PdfScoreDocFileOutput(com.xenoage.zong.desktop.io.pdf.out.PdfScoreDocFileOutput) List(java.util.List) MidiScoreDocFileOutput(com.xenoage.zong.desktop.io.midi.out.MidiScoreDocFileOutput) File(java.io.File) ScoreDoc(com.xenoage.zong.documents.ScoreDoc)

Aggregations

JseOutputStream (com.xenoage.utils.jse.io.JseOutputStream)6 File (java.io.File)3 OutputStream (com.xenoage.utils.io.OutputStream)2 IOException (java.io.IOException)2 Sequence (javax.sound.midi.Sequence)2 JseInputStream (com.xenoage.utils.jse.io.JseInputStream)1 JseMidiSequenceWriter (com.xenoage.zong.desktop.io.midi.out.JseMidiSequenceWriter)1 MidiScoreDocFileOutput (com.xenoage.zong.desktop.io.midi.out.MidiScoreDocFileOutput)1 MusicXmlScoreDocFileInput (com.xenoage.zong.desktop.io.musicxml.in.MusicXmlScoreDocFileInput)1 PdfScoreDocFileOutput (com.xenoage.zong.desktop.io.pdf.out.PdfScoreDocFileOutput)1 ScoreDoc (com.xenoage.zong.documents.ScoreDoc)1 MidiSequence (com.xenoage.zong.io.midi.out.MidiSequence)1 Layout (com.xenoage.zong.layout.Layout)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 List (java.util.List)1