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);
}
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);
}
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());
}
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));
}
}
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());
}
Aggregations