Search in sources :

Example 1 with MidiScoreDocFileOutput

use of com.xenoage.zong.desktop.io.midi.out.MidiScoreDocFileOutput in project Zong by Xenoage.

the class Content method saveAs.

/**
 * Saves the current score using the given format.
 * pdf, png, mid and ogg is supported by this demo.
 */
public void saveAs(String format) {
    FileOutput<ScoreDoc> out = null;
    switch(format) {
        case "pdf":
            out = new PdfScoreDocFileOutput();
            break;
        case "png":
            out = new PngScoreDocFileOutput();
            break;
        case "mid":
            out = new MidiScoreDocFileOutput();
            break;
        case "ogg":
            out = new OggScoreDocFileOutput();
            break;
        default:
            return;
    }
    String filePath = "demo." + format;
    try {
        DocumentIO.write(scoreDoc, new File(filePath), out);
        mainWindow.showMessageDialog(filePath + " saved.");
    } catch (Exception ex) {
        Err.handle(Report.Companion.error(ex));
    }
}
Also used : PngScoreDocFileOutput(com.xenoage.zong.desktop.io.png.out.PngScoreDocFileOutput) OggScoreDocFileOutput(com.xenoage.zong.desktop.io.ogg.out.OggScoreDocFileOutput) PdfScoreDocFileOutput(com.xenoage.zong.desktop.io.pdf.out.PdfScoreDocFileOutput) MidiScoreDocFileOutput(com.xenoage.zong.desktop.io.midi.out.MidiScoreDocFileOutput) File(java.io.File) ScoreDoc(com.xenoage.zong.documents.ScoreDoc)

Example 2 with MidiScoreDocFileOutput

use of com.xenoage.zong.desktop.io.midi.out.MidiScoreDocFileOutput 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

MidiScoreDocFileOutput (com.xenoage.zong.desktop.io.midi.out.MidiScoreDocFileOutput)2 PdfScoreDocFileOutput (com.xenoage.zong.desktop.io.pdf.out.PdfScoreDocFileOutput)2 ScoreDoc (com.xenoage.zong.documents.ScoreDoc)2 File (java.io.File)2 JseInputStream (com.xenoage.utils.jse.io.JseInputStream)1 JseOutputStream (com.xenoage.utils.jse.io.JseOutputStream)1 MusicXmlScoreDocFileInput (com.xenoage.zong.desktop.io.musicxml.in.MusicXmlScoreDocFileInput)1 OggScoreDocFileOutput (com.xenoage.zong.desktop.io.ogg.out.OggScoreDocFileOutput)1 PngScoreDocFileOutput (com.xenoage.zong.desktop.io.png.out.PngScoreDocFileOutput)1 List (java.util.List)1