Search in sources :

Example 66 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class VoicesBeatOffsetterTest method computeBeatOffsets_File4.

/**
 * Test file "BeatOffsetsStrategyTest-4.xml".
 */
@Test
public void computeBeatOffsets_File4() {
    Score score = MusicXmlScoreFileInputTest.loadXMLTestScore("VoicesBeatOffsetterTest-4.xml");
    LinkedList<VoiceSpacing> voiceSpacings = createVoiceSpacings(score);
    BeatOffset[] beatOffsets = testee.compute(voiceSpacings, Companion.fr(3, 4), minimalBeatsOffsetIs).toArray(new BeatOffset[0]);
    // distance between beat 1/4 and 2/4 must be width_1_4
    float is = score.getFormat().getInterlineSpace();
    assertEquals(width_1_4 * is, beatOffsets[3].getOffsetMm() - beatOffsets[2].getOffsetMm(), df);
}
Also used : Score(com.xenoage.zong.core.Score) MusicXmlScoreFileInputTest(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest) Test(org.junit.Test)

Example 67 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class VoicesBeatOffsetterTest method computeBeatOffsets_File1.

/**
 * Test file "BeatOffsetsStrategyTest-1.xml".
 */
@Test
public void computeBeatOffsets_File1() {
    Score score = MusicXmlScoreFileInputTest.loadXMLTestScore("VoicesBeatOffsetterTest-1.xml");
    LinkedList<VoiceSpacing> voiceSpacings = createVoiceSpacings(score);
    BeatOffset[] beatOffsets = testee.compute(voiceSpacings, Companion.fr(3, 4), minimalBeatsOffsetIs).toArray(new BeatOffset[0]);
    // file must have 5 beat offsets with increasing mm offsets
    assertEquals(5, beatOffsets.length);
    assertEquals(Companion.fr(0, 4), beatOffsets[0].getBeat());
    assertEquals(Companion.fr(1, 4), beatOffsets[1].getBeat());
    assertEquals(Companion.fr(2, 4), beatOffsets[2].getBeat());
    assertEquals(Companion.fr(5, 8), beatOffsets[3].getBeat());
    assertEquals(Companion.fr(3, 4), beatOffsets[4].getBeat());
    for (int i = 0; i < beatOffsets.length - 1; i++) {
        assertTrue(beatOffsets[i].getOffsetMm() < beatOffsets[i + 1].getOffsetMm());
    }
    // distance between beat 1/4 and 2/4 must be width_1_4
    float is = score.getFormat().getInterlineSpace();
    assertEquals(width_1_4 * is, beatOffsets[2].getOffsetMm() - beatOffsets[1].getOffsetMm(), df);
}
Also used : Score(com.xenoage.zong.core.Score) MusicXmlScoreFileInputTest(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest) Test(org.junit.Test)

Example 68 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class Content method onScoreUpdated.

/**
 * Call this method when the score was modified.
 * The layout and playback is recomputed.
 */
public void onScoreUpdated() {
    // layout the first page
    layout = scoreDoc.getLayout();
    Score score = scoreDoc.getScore();
    layout.updateScoreLayouts(score);
    // create playback layouter for the playback cursor
    playbackLayouter = new PlaybackLayouter(layout.getScoreFrameChain(score).getScoreLayout());
    // set image to view
    mainWindow.renderLayout(layout);
    // load score into MIDI playback
    Playback.openScore(scoreDoc.getScore());
}
Also used : Score(com.xenoage.zong.core.Score) PlaybackLayouter(com.xenoage.zong.musiclayout.layouter.PlaybackLayouter)

Example 69 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class DirToMidiConvert method execute.

@Override
public void execute() {
    DirectoryChooser dc = new DirectoryChooser();
    // use last document directory
    File initDir = FileSettings.getLastDir();
    if (initDir != null)
        dc.setInitialDirectory(initDir);
    /* TODO - how to extend the DirectoryChooser in JavaFX?
		//see http://stackoverflow.com/questions/25982945/javafx-filechooser-and-directorychooser-accessory-component
		JCheckBox chkSubdir = new JCheckBox(Lang.get(Voc.IncludeSubdirectories), true);
		JCheckBox chkCancel = new JCheckBox(Lang.get(Voc.CancelAtFirstError), false);
		JPanel pnlOptions = new JPanel();
		pnlOptions.setLayout(new BoxLayout(pnlOptions, BoxLayout.Y_AXIS));
		pnlOptions.add(chkSubdir);
		pnlOptions.add(chkCancel);
		fc.setAccessory(pnlOptions); */
    // TODO
    boolean subDirs = true;
    // TODO
    boolean cancelOnFirstError = false;
    File dir = dc.showDialog(ownerWindow);
    if (dir != null) {
        // remember directory
        FileSettings.rememberDir(dir);
        // start conversion - TODO: show progress
        List<File> files = listFiles(dir, subDirs);
        int countOK = 0;
        int countFailed = 0;
        for (File file : files) {
            try {
                // only process MusicXML files
                FileType fileType = FileTypeReader.getFileType(new JseInputStream(file));
                if (fileType != null) {
                    String filePath = file.getAbsolutePath();
                    List<Score> scores = pApp().loadMxlScores(filePath, new AllFilter<>());
                    if ((scores.size() == 0)) /* TODO && chkCancel.isSelected() */
                    {
                        countFailed++;
                        break;
                    }
                    boolean useNumber = scores.size() > 1;
                    It<Score> scoresIt = new It<>(scores);
                    for (Score score : scoresIt) {
                        Sequence seq = MidiConverter.convertToSequence(score, optionsForFileExport, new JseMidiSequenceWriter()).getSequence();
                        String number = (useNumber ? ("-" + (scoresIt.getIndex() + 1)) : "");
                        String newPath = filePath;
                        if (filePath.toLowerCase().endsWith(".xml") || filePath.toLowerCase().endsWith(".mxl")) {
                            newPath = newPath.substring(0, filePath.length() - 4);
                        }
                        newPath += (number + ".mid");
                        MidiSystem.write(seq, 1, new File(newPath));
                        countOK++;
                    }
                }
            } catch (IOException ex) {
                countFailed++;
                if (cancelOnFirstError) {
                    break;
                }
            }
        }
        app().showMessageDialog(Lang.get(Voc.DirectoryConversionResult, "" + countOK, "" + countFailed));
    }
}
Also used : It(com.xenoage.utils.iterators.It) Sequence(javax.sound.midi.Sequence) IOException(java.io.IOException) Score(com.xenoage.zong.core.Score) FileType(com.xenoage.zong.io.musicxml.FileType) JseInputStream(com.xenoage.utils.jse.io.JseInputStream) JseMidiSequenceWriter(com.xenoage.zong.desktop.io.midi.out.JseMidiSequenceWriter) File(java.io.File) DirectoryChooser(javafx.stage.DirectoryChooser)

Example 70 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class CursorTest method write_MeasureElement_Test.

@Test
public void write_MeasureElement_Test() {
    Score score = ScoreFactory.create1Staff();
    Cursor cursor = new Cursor(score, mpe0, true);
    cursor.write(new Rest(Companion.fr(1, 4)));
    cursor.write(new Rest(Companion.fr(1, 4)));
    cursor.write(new Rest(Companion.fr(1, 4)));
    // write clef at 1/4
    Clef clef1 = new Clef(ClefType.Companion.getClefBass());
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write(clef1);
    BeatEList<Clef> clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
    assertEquals(1, clefs.size());
    assertEquals(Companion.beatE(clef1, Companion.fr(1, 4)), clefs.getFirst());
    // write clef at 2/4
    Clef clef2 = new Clef(ClefType.Companion.getClefTreble());
    cursor.setMp(atElement(0, 0, 0, 2));
    cursor.write(clef2);
    clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
    assertEquals(2, clefs.size());
    assertEquals(Companion.beatE(clef1, Companion.fr(1, 4)), clefs.getFirst());
    assertEquals(Companion.beatE(clef2, Companion.fr(2, 4)), clefs.getElements().get(1));
    // overwrite clef at 1/4
    Clef clef3 = new Clef(ClefType.Companion.getClefTreble());
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write(clef3);
    clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
    assertEquals(2, clefs.size());
    assertEquals(Companion.beatE(clef3, Companion.fr(1, 4)), clefs.getFirst());
    assertEquals(Companion.beatE(clef2, Companion.fr(2, 4)), clefs.getElements().get(1));
    // write key at 1/4
    Key key = new TraditionalKey(5, Mode.Major);
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write((MeasureElement) key);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    // write direction at 1/4
    Direction direction1 = new Dynamic(DynamicValue.ff);
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write((MeasureElement) direction1);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    // key must still be there
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getDirections().size());
    // write another direction at 1/4, which does not replace the first one
    Direction direction2 = new Coda();
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write((MeasureElement) direction2);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    // key must still be there
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    // now two directions
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getDirections().size());
    // write instrument change at 1/4
    InstrumentChange instrChange = new InstrumentChange(Instrument.Companion.getDefaultInstrument());
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write(instrChange);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    // key must still be there
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    // directions must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getDirections().size());
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getInstrumentChanges().size());
    // check all added elements
    BeatEList<MeasureElement> all = score.getMeasure(atMeasure(0, 0)).getMeasureElements();
    assertEquals(6, all.size());
    assertEquals(clef3, all.getElements().get(0).getElement());
    assertEquals(key, all.getElements().get(1).getElement());
    assertEquals(direction1, all.getElements().get(2).getElement());
    assertEquals(direction2, all.getElements().get(3).getElement());
    assertEquals(instrChange, all.getElements().get(4).getElement());
    assertEquals(clef2, all.getElements().get(5).getElement());
}
Also used : InstrumentChange(com.xenoage.zong.core.music.InstrumentChange) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Coda(com.xenoage.zong.core.music.direction.Coda) Clef(com.xenoage.zong.core.music.clef.Clef) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Direction(com.xenoage.zong.core.music.direction.Direction) MeasureElement(com.xenoage.zong.core.music.MeasureElement) Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Key(com.xenoage.zong.core.music.key.Key) Test(org.junit.Test)

Aggregations

Score (com.xenoage.zong.core.Score)99 Test (org.junit.Test)62 Rest (com.xenoage.zong.core.music.rest.Rest)22 MP (com.xenoage.zong.core.position.MP)19 Voice (com.xenoage.zong.core.music.Voice)15 Cursor (com.xenoage.zong.io.selection.Cursor)15 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)14 Chord (com.xenoage.zong.core.music.chord.Chord)11 StavesList (com.xenoage.zong.core.music.StavesList)9 MusicXmlScoreFileInputTest (com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest)9 Part (com.xenoage.zong.core.music.Part)8 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)7 lombok.val (lombok.val)7 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)6 Direction (com.xenoage.zong.core.music.direction.Direction)5 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)5 Size2f (com.xenoage.utils.math.geom.Size2f)4 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)4 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)4 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)4