use of com.xenoage.zong.musiclayout.notation.chord.ChordLps in project Zong by Xenoage.
the class NotesNotator method compute.
/**
* Computes the displacement of the notes of the given chord, which has a stem into
* the given direction, using the given musical context.
*/
public NotesNotation compute(Chord chord, StemDirection stemDirection, ChordWidths chordWidths, MusicContext musicContext) {
ChordLps lp = new ChordLps(chord, musicContext);
ChordClass chordClass = computeChordClass(lp, stemDirection);
float noteheadWidth = chordWidths.get(chord.getDisplayedDuration());
float stemOffset = computeStemOffset(chordClass, noteheadWidth);
float notesWidth = computeNotesWidth(chordClass, noteheadWidth);
NoteDisplacement[] notes = computeNotes(lp, stemDirection, stemOffset);
int dotsCount = computeDotsCount(chord.getDuration());
float[] dotsOffsets = computeDotsOffsets(notesWidth, dotsCount, chordWidths);
int[] dotsLp = (dotsCount > 0 ? computeDotsLp(lp) : emptyIntArray);
boolean leftSuspended = isLeftSuspended(notes);
float totalWidth;
if (dotsCount > 0)
totalWidth = dotsOffsets[dotsCount - 1];
else
totalWidth = notesWidth;
return new NotesNotation(totalWidth, noteheadWidth, notes, dotsOffsets, dotsLp, stemOffset, leftSuspended);
}
use of com.xenoage.zong.musiclayout.notation.chord.ChordLps in project Zong by Xenoage.
the class OneMeasureOneStaff method compute.
public StemDirection[] compute(ChordLps[] chordsLps, int staffLinesCount) {
int staffMiddleLp = staffLinesCount - 1;
int upCount = 0;
int downCount = 0;
int furthestDistance = 0;
StemDirection furthestDistanceDir = Up;
// the chord with the note furthest away from the middle staff line
for (ChordLps chordLps : chordsLps) {
StemDirection preferredDir = singleStemDirector.compute(chordLps, staffLinesCount);
int distance;
if (preferredDir == Up) {
upCount++;
distance = staffMiddleLp - chordLps.getTop();
} else {
downCount++;
distance = chordLps.getBottom() - staffMiddleLp;
}
if (// new furthest distance found
distance > furthestDistance || // equal furthest distance found, but Down wins (Ross, p. 95):
(distance == furthestDistance && preferredDir == Down)) {
furthestDistance = distance;
furthestDistanceDir = preferredDir;
}
}
// the mostly used stem direction wins (Ross, p. 95)
// if both directions are equally distributed, the stem direction of
// the chord with the note furthest away from the staff middle line wins (Ross, p. 95)
StemDirection finalStemDir;
if (upCount != downCount)
finalStemDir = (upCount > downCount ? Up : Down);
else
finalStemDir = furthestDistanceDir;
// use same direction for all stems
StemDirection[] dirs = new StemDirection[chordsLps.length];
for (int i : range(dirs)) dirs[i] = finalStemDir;
return dirs;
}
use of com.xenoage.zong.musiclayout.notation.chord.ChordLps in project Zong by Xenoage.
the class StemDrawerTest method getPreferredStemLengthTest.
@Test
public void getPreferredStemLengthTest() {
test(Example.all, (suite, example) -> {
float expectedLengthIs = example.stemLengthIs;
float lengthIs = testee.getPreferredStemLengthIs(new ChordLps(example.noteLp), example.stemDir, example.staffLines);
assertEquals(suite.getName() + ": " + example.name + " expected stem length of " + expectedLengthIs + ", but was " + lengthIs, expectedLengthIs, lengthIs, df);
});
}
use of com.xenoage.zong.musiclayout.notation.chord.ChordLps in project Zong by Xenoage.
the class StemDrawerTest method isStemLengthenedToMiddleLineTest.
@Test
public void isStemLengthenedToMiddleLineTest() {
test(Example.all, (suite, example) -> {
boolean expected = example.isLengthenedToMiddleLine;
boolean lengthened = testee.isStemExtendedToMiddleLine(new ChordLps(example.noteLp), example.stemDir, example.staffLines);
assertEquals(suite.getName() + ": " + example.name + " expected " + (expected ? "" : "NO ") + "stem lengthening but it was " + (lengthened ? "" : "NOT ") + "lengthened.", expected, lengthened);
});
}
use of com.xenoage.zong.musiclayout.notation.chord.ChordLps in project Zong by Xenoage.
the class OneMeasureOneStaff method compute.
@Override
public StemDirection[] compute(Beam beam, Score score) {
int staffLinesCount = getStaffLinesCount(beam.getChord(0), score);
ChordLps[] chordsLps = new ChordLps[beam.size()];
for (int iChord : range(chordsLps)) {
Chord chord = beam.getChord(iChord);
MP mp = MP.getMP(chord);
MusicContext mc = score.getMusicContext(mp, BeforeOrAt, Before);
chordsLps[iChord] = new ChordLps(chord, mc);
}
return compute(chordsLps, staffLinesCount);
}
Aggregations